2011-08-09 06:24:12 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-09 06:24:12 +04:00
|
|
|
* X11 Windows
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2014-05-23 15:09:11 +04:00
|
|
|
* Copyright 2012 HP Development Company, LLC
|
2016-04-05 18:07:45 +03:00
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
2011-08-09 06:24:12 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:20:53 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-11-29 01:50:08 +04:00
|
|
|
#include <stdarg.h>
|
2012-07-09 10:52:15 +04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
2011-10-28 20:27:09 +04:00
|
|
|
#include <X11/Xlib.h>
|
2011-08-09 06:24:12 +04:00
|
|
|
#include <X11/Xutil.h>
|
2011-08-23 23:52:17 +04:00
|
|
|
#include <X11/Xatom.h>
|
2012-08-15 01:20:53 +04:00
|
|
|
|
2014-05-23 15:09:11 +04:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2011-08-24 06:58:36 +04:00
|
|
|
|
2014-05-23 15:09:11 +04:00
|
|
|
#include <winpr/thread.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2015-07-03 14:26:15 +03:00
|
|
|
#include <winpr/string.h>
|
2012-11-20 08:49:08 +04:00
|
|
|
|
2011-09-02 02:08:53 +04:00
|
|
|
#include <freerdp/rail.h>
|
2014-09-12 19:13:01 +04:00
|
|
|
#include <freerdp/log.h>
|
2011-09-02 02:08:53 +04:00
|
|
|
|
2011-08-24 06:58:36 +04:00
|
|
|
#ifdef WITH_XEXT
|
2011-08-23 00:06:12 +04:00
|
|
|
#include <X11/extensions/shape.h>
|
2011-08-24 06:58:36 +04:00
|
|
|
#endif
|
2011-08-09 06:24:12 +04:00
|
|
|
|
2013-04-26 01:00:43 +04:00
|
|
|
#ifdef WITH_XI
|
|
|
|
#include <X11/extensions/XInput2.h>
|
2013-05-08 05:42:49 +04:00
|
|
|
#include "xf_input.h"
|
2013-04-26 01:00:43 +04:00
|
|
|
#endif
|
|
|
|
|
2014-11-13 00:42:32 +03:00
|
|
|
#include "xf_rail.h"
|
2013-05-11 01:51:09 +04:00
|
|
|
#include "xf_input.h"
|
|
|
|
|
2014-09-12 19:13:01 +04:00
|
|
|
#define TAG CLIENT_TAG("x11")
|
|
|
|
|
2013-04-02 23:13:10 +04:00
|
|
|
#ifdef WITH_DEBUG_X11
|
2016-10-07 15:04:40 +03:00
|
|
|
#define DEBUG_X11(...) WLog_DBG(TAG, __VA_ARGS__)
|
2013-04-02 23:13:10 +04:00
|
|
|
#else
|
2019-11-06 17:24:51 +03:00
|
|
|
#define DEBUG_X11(...) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
} while (0)
|
2013-04-02 23:13:10 +04:00
|
|
|
#endif
|
|
|
|
|
2011-10-22 20:55:03 +04:00
|
|
|
#include "FreeRDP_Icon_256px.h"
|
|
|
|
#define xf_icon_prop FreeRDP_Icon_256px_prop
|
|
|
|
|
2011-08-09 06:24:12 +04:00
|
|
|
#include "xf_window.h"
|
|
|
|
|
2011-08-17 22:13:44 +04:00
|
|
|
/* Extended Window Manager Hints: http://standards.freedesktop.org/wm-spec/wm-spec-1.3.html */
|
|
|
|
|
2011-12-03 02:51:30 +04:00
|
|
|
/* bit definitions for MwmHints.flags */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define MWM_HINTS_FUNCTIONS (1L << 0)
|
|
|
|
#define MWM_HINTS_DECORATIONS (1L << 1)
|
|
|
|
#define MWM_HINTS_INPUT_MODE (1L << 2)
|
|
|
|
#define MWM_HINTS_STATUS (1L << 3)
|
2011-12-03 02:51:30 +04:00
|
|
|
|
|
|
|
/* bit definitions for MwmHints.functions */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define MWM_FUNC_ALL (1L << 0)
|
|
|
|
#define MWM_FUNC_RESIZE (1L << 1)
|
|
|
|
#define MWM_FUNC_MOVE (1L << 2)
|
|
|
|
#define MWM_FUNC_MINIMIZE (1L << 3)
|
|
|
|
#define MWM_FUNC_MAXIMIZE (1L << 4)
|
|
|
|
#define MWM_FUNC_CLOSE (1L << 5)
|
2011-12-03 02:51:30 +04:00
|
|
|
|
|
|
|
/* bit definitions for MwmHints.decorations */
|
2019-11-06 17:24:51 +03:00
|
|
|
#define MWM_DECOR_ALL (1L << 0)
|
|
|
|
#define MWM_DECOR_BORDER (1L << 1)
|
|
|
|
#define MWM_DECOR_RESIZEH (1L << 2)
|
|
|
|
#define MWM_DECOR_TITLE (1L << 3)
|
|
|
|
#define MWM_DECOR_MENU (1L << 4)
|
|
|
|
#define MWM_DECOR_MINIMIZE (1L << 5)
|
|
|
|
#define MWM_DECOR_MAXIMIZE (1L << 6)
|
2011-12-03 02:51:30 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define PROP_MOTIF_WM_HINTS_ELEMENTS 5
|
2011-08-09 06:24:12 +04:00
|
|
|
|
|
|
|
struct _PropMotifWmHints
|
|
|
|
{
|
2011-08-18 00:57:21 +04:00
|
|
|
unsigned long flags;
|
|
|
|
unsigned long functions;
|
|
|
|
unsigned long decorations;
|
|
|
|
long inputMode;
|
|
|
|
unsigned long status;
|
2011-08-09 06:24:12 +04:00
|
|
|
};
|
|
|
|
typedef struct _PropMotifWmHints PropMotifWmHints;
|
|
|
|
|
2017-10-31 20:00:15 +03:00
|
|
|
static void xf_SetWindowTitleText(xfContext* xfc, Window window, const char* name)
|
|
|
|
{
|
2019-10-29 12:18:09 +03:00
|
|
|
const size_t i = strnlen(name, MAX_PATH);
|
2017-10-31 20:00:15 +03:00
|
|
|
XStoreName(xfc->display, window, name);
|
|
|
|
Atom wm_Name = xfc->_NET_WM_NAME;
|
|
|
|
Atom utf8Str = xfc->UTF8_STRING;
|
2019-11-06 17:24:51 +03:00
|
|
|
XChangeProperty(xfc->display, window, wm_Name, utf8Str, 8, PropModeReplace,
|
|
|
|
(const unsigned char*)name, (int)i);
|
2017-10-31 20:00:15 +03:00
|
|
|
}
|
|
|
|
|
2011-11-29 01:50:08 +04:00
|
|
|
/**
|
|
|
|
* Post an event from the client to the X server
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_SendClientEvent(xfContext* xfc, Window window, Atom atom, unsigned int numArgs, ...)
|
2011-08-24 08:46:34 +04:00
|
|
|
{
|
2014-05-23 15:09:11 +04:00
|
|
|
XEvent xevent;
|
|
|
|
unsigned int i;
|
|
|
|
va_list argp;
|
|
|
|
va_start(argp, numArgs);
|
2014-08-20 13:54:05 +04:00
|
|
|
ZeroMemory(&xevent, sizeof(XEvent));
|
2014-05-23 15:09:11 +04:00
|
|
|
xevent.xclient.type = ClientMessage;
|
|
|
|
xevent.xclient.serial = 0;
|
|
|
|
xevent.xclient.send_event = False;
|
|
|
|
xevent.xclient.display = xfc->display;
|
2014-11-12 04:26:47 +03:00
|
|
|
xevent.xclient.window = window;
|
2014-05-23 15:09:11 +04:00
|
|
|
xevent.xclient.message_type = atom;
|
|
|
|
xevent.xclient.format = 32;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
for (i = 0; i < numArgs; i++)
|
2014-05-23 15:09:11 +04:00
|
|
|
{
|
|
|
|
xevent.xclient.data.l[i] = va_arg(argp, int);
|
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_X11("Send ClientMessage Event: wnd=0x%04lX", (unsigned long)xevent.xclient.window);
|
2014-05-23 15:09:11 +04:00
|
|
|
XSendEvent(xfc->display, RootWindowOfScreen(xfc->screen), False,
|
2016-08-03 15:16:20 +03:00
|
|
|
SubstructureRedirectMask | SubstructureNotifyMask, &xevent);
|
2014-05-23 15:09:11 +04:00
|
|
|
XSync(xfc->display, False);
|
|
|
|
va_end(argp);
|
2011-08-24 08:46:34 +04:00
|
|
|
}
|
|
|
|
|
2018-09-18 22:25:51 +03:00
|
|
|
void xf_SetWindowMinimized(xfContext* xfc, xfWindow* window)
|
|
|
|
{
|
|
|
|
XIconifyWindow(xfc->display, window->handle, xfc->screen_number);
|
|
|
|
}
|
|
|
|
|
2014-11-12 04:26:47 +03:00
|
|
|
void xf_SetWindowFullscreen(xfContext* xfc, xfWindow* window, BOOL fullscreen)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
2018-10-24 18:22:43 +03:00
|
|
|
UINT32 i;
|
2016-08-03 15:16:20 +03:00
|
|
|
rdpSettings* settings = xfc->context.settings;
|
2015-04-16 18:29:52 +03:00
|
|
|
int startX, startY;
|
|
|
|
UINT32 width = window->width;
|
|
|
|
UINT32 height = window->height;
|
2019-11-06 17:24:51 +03:00
|
|
|
/* xfc->decorations is set by caller depending on settings and whether it is fullscreen or not
|
|
|
|
*/
|
2015-02-23 20:22:28 +03:00
|
|
|
window->decorations = xfc->decorations;
|
2018-04-29 00:13:17 +03:00
|
|
|
/* show/hide decorations (e.g. title bar) as guided by xfc->decorations */
|
2015-02-23 20:22:28 +03:00
|
|
|
xf_SetWindowDecorations(xfc, window->handle, window->decorations);
|
2018-04-29 00:13:17 +03:00
|
|
|
DEBUG_X11(TAG, "X window decoration set to %d", (int)window->decorations);
|
2018-11-15 16:42:31 +03:00
|
|
|
xf_floatbar_toggle_fullscreen(xfc->window->floatbar, fullscreen);
|
2018-09-18 22:25:51 +03:00
|
|
|
|
2015-04-16 18:29:52 +03:00
|
|
|
if (fullscreen)
|
|
|
|
{
|
|
|
|
xfc->savedWidth = xfc->window->width;
|
|
|
|
xfc->savedHeight = xfc->window->height;
|
|
|
|
xfc->savedPosX = xfc->window->left;
|
|
|
|
xfc->savedPosY = xfc->window->top;
|
2018-11-15 16:40:03 +03:00
|
|
|
startX = (settings->DesktopPosX != UINT32_MAX) ? settings->DesktopPosX : 0;
|
|
|
|
startY = (settings->DesktopPosY != UINT32_MAX) ? settings->DesktopPosY : 0;
|
2015-04-16 18:29:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
width = xfc->savedWidth;
|
|
|
|
height = xfc->savedHeight;
|
|
|
|
startX = xfc->savedPosX;
|
|
|
|
startY = xfc->savedPosY;
|
|
|
|
}
|
|
|
|
|
2015-02-23 20:22:28 +03:00
|
|
|
/* Determine the x,y starting location for the fullscreen window */
|
2017-12-20 14:02:23 +03:00
|
|
|
if (fullscreen)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
2015-02-23 20:22:28 +03:00
|
|
|
/* Initialize startX and startY with reasonable values */
|
2016-08-03 15:16:20 +03:00
|
|
|
startX = xfc->context.settings->MonitorDefArray[0].x;
|
|
|
|
startY = xfc->context.settings->MonitorDefArray[0].y;
|
2015-02-23 20:22:28 +03:00
|
|
|
|
|
|
|
/* Search all monitors to find the lowest startX and startY values */
|
2016-08-03 15:16:20 +03:00
|
|
|
for (i = 0; i < xfc->context.settings->MonitorCount; i++)
|
2015-02-23 20:22:28 +03:00
|
|
|
{
|
2016-08-03 15:16:20 +03:00
|
|
|
startX = MIN(startX, xfc->context.settings->MonitorDefArray[i].x);
|
|
|
|
startY = MIN(startY, xfc->context.settings->MonitorDefArray[i].y);
|
2015-02-23 20:22:28 +03:00
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2015-02-23 20:22:28 +03:00
|
|
|
/* Lastly apply any monitor shift(translation from remote to local coordinate system)
|
|
|
|
* to startX and startY values
|
|
|
|
*/
|
2017-12-20 14:02:23 +03:00
|
|
|
startX += xfc->context.settings->MonitorLocalShiftX;
|
|
|
|
startY += xfc->context.settings->MonitorLocalShiftY;
|
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2018-04-29 00:13:17 +03:00
|
|
|
/*
|
2019-11-06 17:24:51 +03:00
|
|
|
It is safe to proceed with simply toogling _NET_WM_STATE_FULLSCREEN window state on the
|
|
|
|
following conditions:
|
2018-04-29 00:13:17 +03:00
|
|
|
- The window manager supports multiple monitor full screen
|
|
|
|
- The user requested to use a single monitor to render the remote desktop
|
|
|
|
*/
|
|
|
|
if (xfc->_NET_WM_FULLSCREEN_MONITORS != None || settings->MonitorCount == 1)
|
2017-12-20 14:02:23 +03:00
|
|
|
{
|
|
|
|
xf_ResizeDesktopWindow(xfc, window, width, height);
|
2015-11-04 17:01:31 +03:00
|
|
|
|
2017-12-20 14:02:23 +03:00
|
|
|
if (fullscreen)
|
|
|
|
{
|
|
|
|
/* enter full screen: move the window before adding NET_WM_STATE_FULLSCREEN */
|
|
|
|
XMoveWindow(xfc->display, window->handle, startX, startY);
|
|
|
|
}
|
2015-11-04 17:01:31 +03:00
|
|
|
|
2017-12-20 14:02:23 +03:00
|
|
|
/* Set the fullscreen state */
|
|
|
|
xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4,
|
|
|
|
fullscreen ? _NET_WM_STATE_ADD : _NET_WM_STATE_REMOVE,
|
|
|
|
xfc->_NET_WM_STATE_FULLSCREEN, 0, 0);
|
2015-11-04 19:58:21 +03:00
|
|
|
|
2017-12-20 14:02:23 +03:00
|
|
|
if (!fullscreen)
|
|
|
|
{
|
|
|
|
/* leave full screen: move the window after removing NET_WM_STATE_FULLSCREEN */
|
|
|
|
XMoveWindow(xfc->display, window->handle, startX, startY);
|
|
|
|
}
|
2018-03-19 13:54:06 +03:00
|
|
|
|
|
|
|
/* Set monitor bounds */
|
|
|
|
if (settings->MonitorCount > 1)
|
|
|
|
{
|
|
|
|
xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_FULLSCREEN_MONITORS, 5,
|
2019-11-06 17:24:51 +03:00
|
|
|
xfc->fullscreenMonitors.top, xfc->fullscreenMonitors.bottom,
|
|
|
|
xfc->fullscreenMonitors.left, xfc->fullscreenMonitors.right, 1);
|
2018-03-19 13:54:06 +03:00
|
|
|
}
|
2017-12-20 14:02:23 +03:00
|
|
|
}
|
|
|
|
else
|
2015-11-04 19:58:21 +03:00
|
|
|
{
|
2017-12-20 14:02:23 +03:00
|
|
|
if (fullscreen)
|
|
|
|
{
|
|
|
|
xf_SetWindowDecorations(xfc, window->handle, FALSE);
|
|
|
|
|
|
|
|
if (xfc->fullscreenMonitors.top)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_ADD,
|
2017-12-20 14:02:23 +03:00
|
|
|
xfc->fullscreenMonitors.top, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
XSetWindowAttributes xswa;
|
|
|
|
xswa.override_redirect = True;
|
|
|
|
XChangeWindowAttributes(xfc->display, window->handle, CWOverrideRedirect, &xswa);
|
|
|
|
XRaiseWindow(xfc->display, window->handle);
|
|
|
|
xswa.override_redirect = False;
|
|
|
|
XChangeWindowAttributes(xfc->display, window->handle, CWOverrideRedirect, &xswa);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if window is in maximized state, save and remove */
|
|
|
|
if (xfc->_NET_WM_STATE_MAXIMIZED_VERT != None)
|
|
|
|
{
|
|
|
|
BYTE state;
|
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes;
|
|
|
|
BYTE* prop;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (xf_GetWindowProperty(xfc, window->handle, xfc->_NET_WM_STATE, 255, &nitems,
|
|
|
|
&bytes, &prop))
|
2017-12-20 14:02:23 +03:00
|
|
|
{
|
|
|
|
state = 0;
|
|
|
|
|
|
|
|
while (nitems-- > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (((Atom*)prop)[nitems] == xfc->_NET_WM_STATE_MAXIMIZED_VERT)
|
2017-12-20 14:02:23 +03:00
|
|
|
state |= 0x01;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (((Atom*)prop)[nitems] == xfc->_NET_WM_STATE_MAXIMIZED_HORZ)
|
2017-12-20 14:02:23 +03:00
|
|
|
state |= 0x02;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
{
|
|
|
|
xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4,
|
|
|
|
_NET_WM_STATE_REMOVE, xfc->_NET_WM_STATE_MAXIMIZED_VERT,
|
|
|
|
0, 0);
|
|
|
|
xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4,
|
|
|
|
_NET_WM_STATE_REMOVE, xfc->_NET_WM_STATE_MAXIMIZED_HORZ,
|
|
|
|
0, 0);
|
|
|
|
xfc->savedMaximizedState = state;
|
|
|
|
}
|
|
|
|
|
|
|
|
XFree(prop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
width = xfc->vscreen.area.right - xfc->vscreen.area.left + 1;
|
|
|
|
height = xfc->vscreen.area.bottom - xfc->vscreen.area.top + 1;
|
2018-04-29 00:13:17 +03:00
|
|
|
DEBUG_X11("X window move and resize %dx%d@%dx%d", startX, startY, width, height);
|
2017-12-20 14:02:23 +03:00
|
|
|
xf_ResizeDesktopWindow(xfc, window, width, height);
|
|
|
|
XMoveWindow(xfc->display, window->handle, startX, startY);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xf_SetWindowDecorations(xfc, window->handle, window->decorations);
|
|
|
|
xf_ResizeDesktopWindow(xfc, window, width, height);
|
|
|
|
XMoveWindow(xfc->display, window->handle, startX, startY);
|
|
|
|
|
|
|
|
if (xfc->fullscreenMonitors.top)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_REMOVE,
|
2017-12-20 14:02:23 +03:00
|
|
|
xfc->fullscreenMonitors.top, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore maximized state, if the window was maximized before setting fullscreen */
|
|
|
|
if (xfc->savedMaximizedState & 0x01)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_ADD,
|
|
|
|
xfc->_NET_WM_STATE_MAXIMIZED_VERT, 0, 0);
|
2017-12-20 14:02:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xfc->savedMaximizedState & 0x02)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_SendClientEvent(xfc, window->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_ADD,
|
|
|
|
xfc->_NET_WM_STATE_MAXIMIZED_HORZ, 0, 0);
|
2017-12-20 14:02:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
xfc->savedMaximizedState = 0;
|
|
|
|
}
|
2015-11-04 19:58:21 +03:00
|
|
|
}
|
2011-08-09 06:24:12 +04:00
|
|
|
}
|
|
|
|
|
2011-08-17 22:13:44 +04:00
|
|
|
/* http://tronche.com/gui/x/xlib/window-information/XGetWindowProperty.html */
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL xf_GetWindowProperty(xfContext* xfc, Window window, Atom property, int length,
|
2016-08-03 15:16:20 +03:00
|
|
|
unsigned long* nitems, unsigned long* bytes, BYTE** prop)
|
2011-08-17 22:13:44 +04:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
Atom actual_type;
|
|
|
|
int actual_format;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (property == None)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = XGetWindowProperty(xfc->display, window, property, 0, length, False, AnyPropertyType,
|
2016-08-03 15:16:20 +03:00
|
|
|
&actual_type, &actual_format, nitems, bytes, prop);
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (status != Success)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (actual_type == None)
|
2011-10-17 17:39:06 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_INFO(TAG, "Property %lu does not exist", (unsigned long)property);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-10-17 17:39:06 +04:00
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-17 22:13:44 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 04:26:47 +03:00
|
|
|
BOOL xf_GetCurrentDesktop(xfContext* xfc)
|
2011-08-17 22:13:44 +04:00
|
|
|
{
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL status;
|
2011-08-17 22:13:44 +04:00
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes;
|
2016-08-03 15:16:20 +03:00
|
|
|
unsigned char* prop;
|
2019-11-06 17:24:51 +03:00
|
|
|
status = xf_GetWindowProperty(xfc, DefaultRootWindow(xfc->display), xfc->_NET_CURRENT_DESKTOP,
|
|
|
|
1, &nitems, &bytes, &prop);
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (!status)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
xfc->current_desktop = (int)*prop;
|
2012-10-09 07:21:26 +04:00
|
|
|
free(prop);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-17 22:13:44 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 04:26:47 +03:00
|
|
|
BOOL xf_GetWorkArea(xfContext* xfc)
|
2011-08-17 22:13:44 +04:00
|
|
|
{
|
2016-08-03 15:16:20 +03:00
|
|
|
long* plong;
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL status;
|
2011-08-17 22:13:44 +04:00
|
|
|
unsigned long nitems;
|
|
|
|
unsigned long bytes;
|
2016-08-03 15:16:20 +03:00
|
|
|
unsigned char* prop;
|
2013-06-13 02:57:25 +04:00
|
|
|
status = xf_GetCurrentDesktop(xfc);
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (!status)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
status = xf_GetWindowProperty(xfc, DefaultRootWindow(xfc->display), xfc->_NET_WORKAREA, 32 * 4,
|
|
|
|
&nitems, &bytes, &prop);
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (!status)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2019-02-07 16:40:36 +03:00
|
|
|
if ((xfc->current_desktop * 4 + 3) >= (INT64)nitems)
|
2013-02-15 02:43:37 +04:00
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(prop);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-11-01 23:31:57 +04:00
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
plong = (long*)prop;
|
2013-06-13 02:57:25 +04:00
|
|
|
xfc->workArea.x = plong[xfc->current_desktop * 4 + 0];
|
|
|
|
xfc->workArea.y = plong[xfc->current_desktop * 4 + 1];
|
|
|
|
xfc->workArea.width = plong[xfc->current_desktop * 4 + 2];
|
|
|
|
xfc->workArea.height = plong[xfc->current_desktop * 4 + 3];
|
2012-10-09 07:21:26 +04:00
|
|
|
free(prop);
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-17 22:13:44 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 04:26:47 +03:00
|
|
|
void xf_SetWindowDecorations(xfContext* xfc, Window window, BOOL show)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
|
|
|
PropMotifWmHints hints;
|
2011-12-03 02:51:30 +04:00
|
|
|
hints.decorations = (show) ? MWM_DECOR_ALL : 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
hints.functions = MWM_FUNC_ALL;
|
2011-12-03 02:51:30 +04:00
|
|
|
hints.flags = MWM_HINTS_DECORATIONS | MWM_HINTS_FUNCTIONS;
|
2012-03-16 18:45:14 +04:00
|
|
|
hints.inputMode = 0;
|
|
|
|
hints.status = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
XChangeProperty(xfc->display, window, xfc->_MOTIF_WM_HINTS, xfc->_MOTIF_WM_HINTS, 32,
|
|
|
|
PropModeReplace, (BYTE*)&hints, PROP_MOTIF_WM_HINTS_ELEMENTS);
|
2011-08-09 06:24:12 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 04:26:47 +03:00
|
|
|
void xf_SetWindowUnlisted(xfContext* xfc, Window window)
|
2011-08-30 22:21:16 +04:00
|
|
|
{
|
|
|
|
Atom window_state[2];
|
2013-06-13 02:57:25 +04:00
|
|
|
window_state[0] = xfc->_NET_WM_STATE_SKIP_PAGER;
|
|
|
|
window_state[1] = xfc->_NET_WM_STATE_SKIP_TASKBAR;
|
2019-11-06 17:24:51 +03:00
|
|
|
XChangeProperty(xfc->display, window, xfc->_NET_WM_STATE, XA_ATOM, 32, PropModeReplace,
|
|
|
|
(BYTE*)&window_state, 2);
|
2011-08-30 22:21:16 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
static void xf_SetWindowPID(xfContext* xfc, Window window, pid_t pid)
|
2012-07-09 10:52:15 +04:00
|
|
|
{
|
|
|
|
Atom am_wm_pid;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (!pid)
|
2012-07-09 10:52:15 +04:00
|
|
|
pid = getpid();
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2015-10-15 22:59:53 +03:00
|
|
|
am_wm_pid = xfc->_NET_WM_PID;
|
2019-11-06 17:24:51 +03:00
|
|
|
XChangeProperty(xfc->display, window, am_wm_pid, XA_CARDINAL, 32, PropModeReplace, (BYTE*)&pid,
|
|
|
|
1);
|
2012-07-09 10:52:15 +04:00
|
|
|
}
|
|
|
|
|
2017-10-31 20:00:15 +03:00
|
|
|
static const char* get_shm_id(void)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
2014-05-23 15:09:11 +04:00
|
|
|
static char shm_id[64];
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(shm_id, sizeof(shm_id), "/com.freerdp.xfreerdp.tsmf_%016X", GetCurrentProcessId());
|
2014-05-23 15:09:11 +04:00
|
|
|
return shm_id;
|
|
|
|
}
|
2011-08-09 06:24:12 +04:00
|
|
|
|
2017-08-14 11:10:53 +03:00
|
|
|
Window xf_CreateDummyWindow(xfContext* xfc)
|
2016-08-18 21:14:52 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
return XCreateSimpleWindow(xfc->display, DefaultRootWindow(xfc->display), 0, 0, 1, 1, 0, 0, 0);
|
2016-08-18 21:14:52 +03:00
|
|
|
}
|
|
|
|
|
2017-08-14 11:10:53 +03:00
|
|
|
void xf_DestroyDummyWindow(xfContext* xfc, Window window)
|
2016-08-18 21:14:52 +03:00
|
|
|
{
|
|
|
|
if (window)
|
|
|
|
XDestroyWindow(xfc->display, window);
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
xfWindow* xf_CreateDesktopWindow(xfContext* xfc, char* name, int width, int height)
|
2014-05-23 15:09:11 +04:00
|
|
|
{
|
|
|
|
XEvent xevent;
|
2015-02-10 23:15:30 +03:00
|
|
|
int input_mask;
|
2014-11-12 04:26:47 +03:00
|
|
|
xfWindow* window;
|
2015-02-10 23:15:30 +03:00
|
|
|
Window parentWindow;
|
|
|
|
XClassHint* classHints;
|
2014-06-23 20:08:34 +04:00
|
|
|
rdpSettings* settings;
|
2019-11-06 17:24:51 +03:00
|
|
|
window = (xfWindow*)calloc(1, sizeof(xfWindow));
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
if (!window)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
settings = xfc->context.settings;
|
2019-11-06 17:24:51 +03:00
|
|
|
parentWindow = (Window)xfc->context.settings->ParentWindowId;
|
2015-02-10 23:15:30 +03:00
|
|
|
window->width = width;
|
|
|
|
window->height = height;
|
2015-02-23 20:22:28 +03:00
|
|
|
window->decorations = xfc->decorations;
|
2015-02-10 23:15:30 +03:00
|
|
|
window->is_mapped = FALSE;
|
|
|
|
window->is_transient = FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
window->handle = XCreateWindow(xfc->display, RootWindowOfScreen(xfc->screen), xfc->workArea.x,
|
|
|
|
xfc->workArea.y, xfc->workArea.width, xfc->workArea.height, 0,
|
|
|
|
xfc->depth, InputOutput, xfc->visual,
|
2016-08-03 15:16:20 +03:00
|
|
|
CWBackPixel | CWBackingStore | CWOverrideRedirect | CWColormap |
|
2019-11-06 17:24:51 +03:00
|
|
|
CWBorderPixel | CWWinGravity | CWBitGravity,
|
|
|
|
&xfc->attribs);
|
|
|
|
window->shmid = shm_open(get_shm_id(), (O_CREAT | O_RDWR), (S_IREAD | S_IWRITE));
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
if (window->shmid < 0)
|
|
|
|
{
|
|
|
|
DEBUG_X11("xf_CreateDesktopWindow: failed to get access to shared memory - shmget()\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
void* mem;
|
|
|
|
ftruncate(window->shmid, sizeof(window->handle));
|
2019-11-06 17:24:51 +03:00
|
|
|
mem = mmap(0, sizeof(window->handle), PROT_READ | PROT_WRITE, MAP_SHARED, window->shmid, 0);
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2015-03-17 05:10:58 +03:00
|
|
|
if (mem == MAP_FAILED)
|
2012-06-13 23:45:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
DEBUG_X11("xf_CreateDesktopWindow: failed to assign pointer to the memory address - "
|
|
|
|
"shmat()\n");
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-10 23:15:30 +03:00
|
|
|
window->xfwin = mem;
|
|
|
|
*window->xfwin = window->handle;
|
2012-06-13 23:45:58 +04:00
|
|
|
}
|
2015-02-10 23:15:30 +03:00
|
|
|
}
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
classHints = XAllocClassHint();
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
if (classHints)
|
|
|
|
{
|
|
|
|
classHints->res_name = "xfreerdp";
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (xfc->context.settings->WmClass)
|
|
|
|
classHints->res_class = xfc->context.settings->WmClass;
|
2015-02-10 23:15:30 +03:00
|
|
|
else
|
|
|
|
classHints->res_class = "xfreerdp";
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
XSetClassHint(xfc->display, window->handle, classHints);
|
|
|
|
XFree(classHints);
|
|
|
|
}
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
xf_ResizeDesktopWindow(xfc, window, width, height);
|
2015-02-23 20:22:28 +03:00
|
|
|
xf_SetWindowDecorations(xfc, window->handle, window->decorations);
|
2015-02-10 23:15:30 +03:00
|
|
|
xf_SetWindowPID(xfc, window->handle, 0);
|
2019-11-06 17:24:51 +03:00
|
|
|
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
|
|
|
VisibilityChangeMask | FocusChangeMask | StructureNotifyMask | PointerMotionMask |
|
|
|
|
ExposureMask | PropertyChangeMask;
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
if (xfc->grab_keyboard)
|
|
|
|
input_mask |= EnterWindowMask | LeaveWindowMask;
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
XChangeProperty(xfc->display, window->handle, xfc->_NET_WM_ICON, XA_CARDINAL, 32,
|
|
|
|
PropModeReplace, (BYTE*)xf_icon_prop, ARRAYSIZE(xf_icon_prop));
|
2014-06-23 20:08:34 +04:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
if (parentWindow)
|
|
|
|
XReparentWindow(xfc->display, window->handle, parentWindow, 0, 0);
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
XSelectInput(xfc->display, window->handle, input_mask);
|
|
|
|
XClearWindow(xfc->display, window->handle);
|
2018-11-17 17:32:52 +03:00
|
|
|
xf_SetWindowTitleText(xfc, window->handle, name);
|
2015-02-10 23:15:30 +03:00
|
|
|
XMapWindow(xfc->display, window->handle);
|
|
|
|
xf_input_init(xfc, window->handle);
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
/*
|
|
|
|
* NOTE: This must be done here to handle reparenting the window,
|
|
|
|
* so that we don't miss the event and hang waiting for the next one
|
|
|
|
*/
|
|
|
|
do
|
|
|
|
{
|
|
|
|
XMaskEvent(xfc->display, VisibilityChangeMask, &xevent);
|
2019-11-06 17:24:51 +03:00
|
|
|
} while (xevent.type != VisibilityNotify);
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2015-02-10 23:15:30 +03:00
|
|
|
/*
|
|
|
|
* The XCreateWindow call will start the window in the upper-left corner of our current
|
|
|
|
* monitor instead of the upper-left monitor for remote app mode (which uses all monitors).
|
|
|
|
* This extra call after the window is mapped will position the login window correctly
|
|
|
|
*/
|
2016-08-03 15:16:20 +03:00
|
|
|
if (xfc->context.settings->RemoteApplicationMode)
|
2015-02-10 23:15:30 +03:00
|
|
|
{
|
|
|
|
XMoveWindow(xfc->display, window->handle, 0, 0);
|
2011-08-09 06:24:12 +04:00
|
|
|
}
|
2018-11-15 16:40:03 +03:00
|
|
|
else if (settings->DesktopPosX != UINT32_MAX && settings->DesktopPosY != UINT32_MAX)
|
2015-02-10 23:15:30 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
XMoveWindow(xfc->display, window->handle, settings->DesktopPosX, settings->DesktopPosY);
|
2015-02-10 23:15:30 +03:00
|
|
|
}
|
|
|
|
|
2018-11-21 11:49:50 +03:00
|
|
|
window->floatbar = xf_floatbar_new(xfc, window->handle, name, settings->Floatbar);
|
2011-08-09 06:24:12 +04:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_ResizeDesktopWindow(xfContext* xfc, xfWindow* window, int width, int height)
|
2011-09-06 12:22:53 +04:00
|
|
|
{
|
2014-11-12 04:26:47 +03:00
|
|
|
XSizeHints* size_hints;
|
2018-03-24 15:46:39 +03:00
|
|
|
rdpSettings* settings = NULL;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2015-04-14 18:59:06 +03:00
|
|
|
if (!xfc || !window)
|
2016-08-03 15:16:20 +03:00
|
|
|
return;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2018-03-24 15:46:39 +03:00
|
|
|
settings = xfc->context.settings;
|
|
|
|
|
2015-04-14 18:59:06 +03:00
|
|
|
if (!(size_hints = XAllocSizeHints()))
|
2016-08-03 15:16:20 +03:00
|
|
|
return;
|
2014-12-01 13:56:44 +03:00
|
|
|
|
2015-04-14 18:59:06 +03:00
|
|
|
size_hints->flags = PMinSize | PMaxSize | PWinGravity;
|
|
|
|
size_hints->win_gravity = NorthWestGravity;
|
|
|
|
size_hints->min_width = size_hints->min_height = 1;
|
|
|
|
size_hints->max_width = size_hints->max_height = 16384;
|
|
|
|
XResizeWindow(xfc->display, window->handle, width, height);
|
2017-11-29 12:26:04 +03:00
|
|
|
#ifdef WITH_XRENDER
|
2017-12-20 14:02:23 +03:00
|
|
|
|
2018-07-22 21:00:25 +03:00
|
|
|
if (!settings->SmartSizing && !settings->DynamicResolutionUpdate)
|
2015-04-14 18:59:06 +03:00
|
|
|
#endif
|
|
|
|
{
|
2015-04-16 18:29:52 +03:00
|
|
|
if (!xfc->fullscreen)
|
|
|
|
{
|
2017-11-29 12:26:04 +03:00
|
|
|
/* min == max is an hint for the WM to indicate that the window should
|
|
|
|
* not be resizable */
|
2015-04-16 18:29:52 +03:00
|
|
|
size_hints->min_width = size_hints->max_width = width;
|
|
|
|
size_hints->min_height = size_hints->max_height = height;
|
|
|
|
}
|
2011-09-06 12:22:53 +04:00
|
|
|
}
|
2015-04-14 18:59:06 +03:00
|
|
|
|
2018-07-22 21:00:25 +03:00
|
|
|
XSetWMNormalHints(xfc->display, window->handle, size_hints);
|
2015-04-14 18:59:06 +03:00
|
|
|
XFree(size_hints);
|
2011-09-06 12:22:53 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
void xf_DestroyDesktopWindow(xfContext* xfc, xfWindow* window)
|
|
|
|
{
|
|
|
|
if (!window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (xfc->window == window)
|
|
|
|
xfc->window = NULL;
|
|
|
|
|
2018-11-15 16:42:31 +03:00
|
|
|
xf_floatbar_free(window->floatbar);
|
2018-09-18 22:25:51 +03:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (window->gc)
|
|
|
|
XFreeGC(xfc->display, window->gc);
|
|
|
|
|
|
|
|
if (window->handle)
|
|
|
|
{
|
|
|
|
XUnmapWindow(xfc->display, window->handle);
|
|
|
|
XDestroyWindow(xfc->display, window->handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (window->xfwin)
|
|
|
|
munmap(0, sizeof(*window->xfwin));
|
|
|
|
|
|
|
|
if (window->shmid >= 0)
|
|
|
|
close(window->shmid);
|
|
|
|
|
|
|
|
shm_unlink(get_shm_id());
|
2019-11-06 17:24:51 +03:00
|
|
|
window->xfwin = (Window*)-1;
|
2014-11-12 06:27:33 +03:00
|
|
|
window->shmid = -1;
|
|
|
|
free(window);
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_SetWindowStyle(xfContext* xfc, xfAppWindow* appWindow, UINT32 style, UINT32 ex_style)
|
2014-11-12 06:27:33 +03:00
|
|
|
{
|
|
|
|
Atom window_type;
|
2018-09-26 12:27:57 +03:00
|
|
|
BOOL redirect = FALSE;
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2017-04-22 11:44:37 +03:00
|
|
|
if ((ex_style & WS_EX_NOACTIVATE) || (ex_style & WS_EX_TOOLWINDOW))
|
2014-11-12 06:27:33 +03:00
|
|
|
{
|
2018-09-26 12:27:57 +03:00
|
|
|
redirect = TRUE;
|
2014-11-12 06:27:33 +03:00
|
|
|
appWindow->is_transient = TRUE;
|
|
|
|
xf_SetWindowUnlisted(xfc, appWindow->handle);
|
2018-09-26 12:13:06 +03:00
|
|
|
window_type = xfc->_NET_WM_WINDOW_TYPE_DROPDOWN_MENU;
|
2014-11-12 06:27:33 +03:00
|
|
|
}
|
|
|
|
/*
|
2019-11-06 17:24:51 +03:00
|
|
|
* TOPMOST window that is not a tool window is treated like a regular window (i.e. task
|
|
|
|
* manager). Want to do this here, since the window may have type WS_POPUP
|
2014-11-12 06:27:33 +03:00
|
|
|
*/
|
|
|
|
else if (ex_style & WS_EX_TOPMOST)
|
|
|
|
{
|
|
|
|
window_type = xfc->_NET_WM_WINDOW_TYPE_NORMAL;
|
|
|
|
}
|
|
|
|
else if (style & WS_POPUP)
|
|
|
|
{
|
|
|
|
/* this includes dialogs, popups, etc, that need to be full-fledged windows */
|
|
|
|
appWindow->is_transient = TRUE;
|
|
|
|
window_type = xfc->_NET_WM_WINDOW_TYPE_DIALOG;
|
|
|
|
xf_SetWindowUnlisted(xfc, appWindow->handle);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-15 22:39:59 +03:00
|
|
|
window_type = xfc->_NET_WM_WINDOW_TYPE_NORMAL;
|
2014-11-12 06:27:33 +03:00
|
|
|
}
|
2015-10-15 22:39:59 +03:00
|
|
|
|
2018-09-26 12:27:57 +03:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Tooltips and menu items should be unmanaged windows
|
|
|
|
* (called "override redirect" in X windows parlance)
|
|
|
|
* If they are managed, there are issues with window focus that
|
|
|
|
* cause the windows to behave improperly. For example, a mouse
|
|
|
|
* press will dismiss a drop-down menu because the RDP server
|
|
|
|
* sees that as a focus out event from the window owning the
|
|
|
|
* dropdown.
|
|
|
|
*/
|
|
|
|
XSetWindowAttributes attrs;
|
|
|
|
attrs.override_redirect = redirect ? True : False;
|
2019-11-06 17:24:51 +03:00
|
|
|
XChangeWindowAttributes(xfc->display, appWindow->handle, CWOverrideRedirect, &attrs);
|
2018-09-26 12:27:57 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
XChangeProperty(xfc->display, appWindow->handle, xfc->_NET_WM_WINDOW_TYPE, XA_ATOM, 32,
|
|
|
|
PropModeReplace, (BYTE*)&window_type, 1);
|
2014-11-12 06:27:33 +03:00
|
|
|
}
|
|
|
|
|
2017-10-31 20:00:15 +03:00
|
|
|
void xf_SetWindowText(xfContext* xfc, xfAppWindow* appWindow, const char* name)
|
2014-11-12 06:27:33 +03:00
|
|
|
{
|
2017-10-31 20:00:15 +03:00
|
|
|
xf_SetWindowTitleText(xfc, appWindow->handle, name);
|
2014-11-12 06:27:33 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void xf_FixWindowCoordinates(xfContext* xfc, int* x, int* y, int* width, int* height)
|
2011-08-23 05:22:05 +04:00
|
|
|
{
|
2011-09-02 21:29:17 +04:00
|
|
|
int vscreen_width;
|
|
|
|
int vscreen_height;
|
2013-06-13 02:57:25 +04:00
|
|
|
vscreen_width = xfc->vscreen.area.right - xfc->vscreen.area.left + 1;
|
|
|
|
vscreen_height = xfc->vscreen.area.bottom - xfc->vscreen.area.top + 1;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (*x < xfc->vscreen.area.left)
|
2011-08-23 05:22:05 +04:00
|
|
|
{
|
|
|
|
*width += *x;
|
2013-06-13 02:57:25 +04:00
|
|
|
*x = xfc->vscreen.area.left;
|
2011-08-23 05:22:05 +04:00
|
|
|
}
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2014-11-12 04:26:47 +03:00
|
|
|
if (*y < xfc->vscreen.area.top)
|
2011-08-23 05:22:05 +04:00
|
|
|
{
|
|
|
|
*height += *y;
|
2013-06-13 02:57:25 +04:00
|
|
|
*y = xfc->vscreen.area.top;
|
2011-09-02 21:29:17 +04:00
|
|
|
}
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2014-11-12 04:26:47 +03:00
|
|
|
if (*width > vscreen_width)
|
2011-09-02 21:29:17 +04:00
|
|
|
{
|
|
|
|
*width = vscreen_width;
|
|
|
|
}
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2014-11-12 04:26:47 +03:00
|
|
|
if (*height > vscreen_height)
|
2011-09-02 21:29:17 +04:00
|
|
|
{
|
|
|
|
*height = vscreen_height;
|
2011-08-23 05:22:05 +04:00
|
|
|
}
|
2017-10-31 20:00:15 +03:00
|
|
|
|
2017-09-04 01:52:34 +03:00
|
|
|
if (*width < 1)
|
|
|
|
{
|
|
|
|
*width = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*height < 1)
|
|
|
|
{
|
|
|
|
*height = 1;
|
|
|
|
}
|
2011-08-23 05:22:05 +04:00
|
|
|
}
|
|
|
|
|
2014-11-13 00:42:32 +03:00
|
|
|
int xf_AppWindowInit(xfContext* xfc, xfAppWindow* appWindow)
|
2019-05-08 16:36:20 +03:00
|
|
|
{
|
|
|
|
if (!xfc || !appWindow)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
xf_SetWindowDecorations(xfc, appWindow->handle, appWindow->decorations);
|
|
|
|
xf_SetWindowStyle(xfc, appWindow, appWindow->dwStyle, appWindow->dwExStyle);
|
|
|
|
xf_SetWindowPID(xfc, appWindow->handle, 0);
|
|
|
|
xf_ShowWindow(xfc, appWindow, WINDOW_SHOW);
|
|
|
|
XClearWindow(xfc->display, appWindow->handle);
|
|
|
|
XMapWindow(xfc->display, appWindow->handle);
|
|
|
|
/* Move doesn't seem to work until window is mapped. */
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_MoveWindow(xfc, appWindow, appWindow->x, appWindow->y, appWindow->width, appWindow->height);
|
2019-05-08 16:36:20 +03:00
|
|
|
xf_SetWindowText(xfc, appWindow, appWindow->title);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xf_AppWindowCreate(xfContext* xfc, xfAppWindow* appWindow)
|
2011-08-17 10:14:02 +04:00
|
|
|
{
|
2012-09-03 00:34:06 +04:00
|
|
|
XGCValues gcv;
|
|
|
|
int input_mask;
|
2014-11-12 04:26:47 +03:00
|
|
|
XWMHints* InputModeHint;
|
|
|
|
XClassHint* class_hints;
|
2016-08-03 15:16:20 +03:00
|
|
|
xf_FixWindowCoordinates(xfc, &appWindow->x, &appWindow->y, &appWindow->width,
|
|
|
|
&appWindow->height);
|
2014-11-13 00:42:32 +03:00
|
|
|
appWindow->decorations = FALSE;
|
2014-11-12 06:27:33 +03:00
|
|
|
appWindow->fullscreen = FALSE;
|
|
|
|
appWindow->local_move.state = LMS_NOT_ACTIVE;
|
|
|
|
appWindow->is_mapped = FALSE;
|
|
|
|
appWindow->is_transient = FALSE;
|
|
|
|
appWindow->rail_state = 0;
|
|
|
|
appWindow->rail_ignore_configure = FALSE;
|
2019-11-06 17:24:51 +03:00
|
|
|
appWindow->handle = XCreateWindow(xfc->display, RootWindowOfScreen(xfc->screen), appWindow->x,
|
|
|
|
appWindow->y, appWindow->width, appWindow->height, 0,
|
|
|
|
xfc->depth, InputOutput, xfc->visual, 0, &xfc->attribs);
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (!appWindow->handle)
|
2014-11-13 00:42:32 +03:00
|
|
|
return -1;
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2013-02-15 02:43:37 +04:00
|
|
|
ZeroMemory(&gcv, sizeof(gcv));
|
2019-11-06 17:24:51 +03:00
|
|
|
appWindow->gc = XCreateGC(xfc->display, appWindow->handle, GCGraphicsExposures, &gcv);
|
2011-10-31 21:55:05 +04:00
|
|
|
class_hints = XAllocClassHint();
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (class_hints)
|
2011-10-31 21:55:05 +04:00
|
|
|
{
|
2014-11-12 04:26:47 +03:00
|
|
|
char* class = NULL;
|
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (xfc->context.settings->WmClass)
|
2013-03-29 07:34:26 +04:00
|
|
|
{
|
2016-08-03 15:16:20 +03:00
|
|
|
class_hints->res_class = xfc->context.settings->WmClass;
|
2013-03-29 07:34:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-11-12 06:27:33 +03:00
|
|
|
class = malloc(sizeof("RAIL:00000000"));
|
2019-11-06 17:24:51 +03:00
|
|
|
sprintf_s(class, sizeof("RAIL:00000000"), "RAIL:%08" PRIX64 "", appWindow->windowId);
|
2013-03-26 18:47:39 +04:00
|
|
|
class_hints->res_class = class;
|
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2011-10-31 21:55:05 +04:00
|
|
|
class_hints->res_name = "RAIL";
|
2014-11-12 06:27:33 +03:00
|
|
|
XSetClassHint(xfc->display, appWindow->handle, class_hints);
|
2011-10-31 21:55:05 +04:00
|
|
|
XFree(class_hints);
|
2015-05-11 10:07:39 +03:00
|
|
|
free(class);
|
2011-10-31 21:55:05 +04:00
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2012-09-03 00:34:06 +04:00
|
|
|
/* Set the input mode hint for the WM */
|
2014-05-23 15:09:11 +04:00
|
|
|
InputModeHint = XAllocWMHints();
|
|
|
|
InputModeHint->flags = (1L << 0);
|
|
|
|
InputModeHint->input = True;
|
2014-11-12 06:27:33 +03:00
|
|
|
XSetWMHints(xfc->display, appWindow->handle, InputModeHint);
|
2014-05-23 15:09:11 +04:00
|
|
|
XFree(InputModeHint);
|
2014-11-12 06:27:33 +03:00
|
|
|
XSetWMProtocols(xfc->display, appWindow->handle, &(xfc->WM_DELETE_WINDOW), 1);
|
2019-11-06 17:24:51 +03:00
|
|
|
input_mask = KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask |
|
|
|
|
EnterWindowMask | LeaveWindowMask | PointerMotionMask | Button1MotionMask |
|
|
|
|
Button2MotionMask | Button3MotionMask | Button4MotionMask | Button5MotionMask |
|
|
|
|
ButtonMotionMask | KeymapStateMask | ExposureMask | VisibilityChangeMask |
|
|
|
|
StructureNotifyMask | SubstructureNotifyMask | SubstructureRedirectMask |
|
|
|
|
FocusChangeMask | PropertyChangeMask | ColormapChangeMask | OwnerGrabButtonMask;
|
2014-11-12 06:27:33 +03:00
|
|
|
XSelectInput(xfc->display, appWindow->handle, input_mask);
|
2019-05-08 16:36:20 +03:00
|
|
|
|
2014-11-13 00:42:32 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_SetWindowMinMaxInfo(xfContext* xfc, xfAppWindow* appWindow, int maxWidth, int maxHeight,
|
|
|
|
int maxPosX, int maxPosY, int minTrackWidth, int minTrackHeight,
|
|
|
|
int maxTrackWidth, int maxTrackHeight)
|
2011-09-01 02:02:22 +04:00
|
|
|
{
|
2014-11-12 04:26:47 +03:00
|
|
|
XSizeHints* size_hints;
|
2011-09-02 02:08:53 +04:00
|
|
|
size_hints = XAllocSizeHints();
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (size_hints)
|
2011-09-02 02:08:53 +04:00
|
|
|
{
|
|
|
|
size_hints->flags = PMinSize | PMaxSize | PResizeInc;
|
2019-11-06 17:24:51 +03:00
|
|
|
size_hints->min_width = minTrackWidth;
|
2011-09-02 02:08:53 +04:00
|
|
|
size_hints->min_height = minTrackHeight;
|
2019-11-06 17:24:51 +03:00
|
|
|
size_hints->max_width = maxTrackWidth;
|
2011-09-02 02:08:53 +04:00
|
|
|
size_hints->max_height = maxTrackHeight;
|
2011-09-02 20:39:56 +04:00
|
|
|
/* to speedup window drawing we need to select optimal value for sizing step. */
|
2011-09-04 00:38:01 +04:00
|
|
|
size_hints->width_inc = size_hints->height_inc = 1;
|
2014-11-12 06:27:33 +03:00
|
|
|
XSetWMNormalHints(xfc->display, appWindow->handle, size_hints);
|
2011-09-02 02:08:53 +04:00
|
|
|
XFree(size_hints);
|
|
|
|
}
|
2011-09-01 02:02:22 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_StartLocalMoveSize(xfContext* xfc, xfAppWindow* appWindow, int direction, int x, int y)
|
2011-09-01 02:22:21 +04:00
|
|
|
{
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->local_move.state != LMS_NOT_ACTIVE)
|
2011-12-17 01:09:21 +04:00
|
|
|
return;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2012-05-26 02:37:38 +04:00
|
|
|
/*
|
2019-11-06 17:24:51 +03:00
|
|
|
* Save original mouse location relative to root. This will be needed
|
|
|
|
* to end local move to RDP server and/or X server
|
|
|
|
*/
|
2014-11-12 06:27:33 +03:00
|
|
|
appWindow->local_move.root_x = x;
|
|
|
|
appWindow->local_move.root_y = y;
|
|
|
|
appWindow->local_move.state = LMS_STARTING;
|
|
|
|
appWindow->local_move.direction = direction;
|
2013-06-13 02:57:25 +04:00
|
|
|
XUngrabPointer(xfc->display, CurrentTime);
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_SendClientEvent(
|
|
|
|
xfc, appWindow->handle,
|
|
|
|
xfc->_NET_WM_MOVERESIZE, /* request X window manager to initiate a local move */
|
|
|
|
5, /* 5 arguments to follow */
|
|
|
|
x, /* x relative to root window */
|
|
|
|
y, /* y relative to root window */
|
|
|
|
direction, /* extended ICCM direction flag */
|
|
|
|
1, /* simulated mouse button 1 */
|
|
|
|
1); /* 1 == application request per extended ICCM */
|
2011-09-01 02:22:21 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
void xf_EndLocalMoveSize(xfContext* xfc, xfAppWindow* appWindow)
|
2011-09-01 02:02:22 +04:00
|
|
|
{
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->local_move.state == LMS_NOT_ACTIVE)
|
2011-11-29 01:50:08 +04:00
|
|
|
return;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->local_move.state == LMS_STARTING)
|
2011-11-29 01:50:08 +04:00
|
|
|
{
|
2011-12-10 03:20:23 +04:00
|
|
|
/*
|
2011-12-17 01:09:21 +04:00
|
|
|
* The move never was property started. This can happen due to race
|
|
|
|
* conditions between the mouse button up and the communications to the
|
|
|
|
* RDP server for local moves. We must cancel the X window manager move.
|
2014-05-23 15:09:11 +04:00
|
|
|
* Per ICCM, the X client can ask to cancel an active move.
|
2011-12-10 03:20:23 +04:00
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_SendClientEvent(
|
|
|
|
xfc, appWindow->handle,
|
|
|
|
xfc->_NET_WM_MOVERESIZE, /* request X window manager to abort a local move */
|
|
|
|
5, /* 5 arguments to follow */
|
|
|
|
appWindow->local_move.root_x, /* x relative to root window */
|
|
|
|
appWindow->local_move.root_y, /* y relative to root window */
|
|
|
|
_NET_WM_MOVERESIZE_CANCEL, /* extended ICCM direction flag */
|
|
|
|
1, /* simulated mouse button 1 */
|
|
|
|
1); /* 1 == application request per extended ICCM */
|
2011-11-29 01:50:08 +04:00
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
appWindow->local_move.state = LMS_NOT_ACTIVE;
|
2011-09-01 02:02:22 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_MoveWindow(xfContext* xfc, xfAppWindow* appWindow, int x, int y, int width, int height)
|
2011-08-18 06:50:49 +04:00
|
|
|
{
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL resize = FALSE;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if ((width * height) < 1)
|
2011-08-20 06:21:09 +04:00
|
|
|
return;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if ((appWindow->width != width) || (appWindow->height != height))
|
2012-10-09 10:31:28 +04:00
|
|
|
resize = TRUE;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (appWindow->local_move.state == LMS_STARTING || appWindow->local_move.state == LMS_ACTIVE)
|
2011-12-17 01:09:21 +04:00
|
|
|
return;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
appWindow->x = x;
|
|
|
|
appWindow->y = y;
|
|
|
|
appWindow->width = width;
|
|
|
|
appWindow->height = height;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
if (resize)
|
2014-11-12 06:27:33 +03:00
|
|
|
XMoveResizeWindow(xfc->display, appWindow->handle, x, y, width, height);
|
2011-12-07 03:42:58 +04:00
|
|
|
else
|
2014-11-12 06:27:33 +03:00
|
|
|
XMoveWindow(xfc->display, appWindow->handle, x, y);
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
xf_UpdateWindowArea(xfc, appWindow, 0, 0, width, height);
|
2011-08-18 06:50:49 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
void xf_ShowWindow(xfContext* xfc, xfAppWindow* appWindow, BYTE state)
|
2011-08-22 07:15:19 +04:00
|
|
|
{
|
2014-11-12 04:26:47 +03:00
|
|
|
switch (state)
|
2011-08-22 07:15:19 +04:00
|
|
|
{
|
|
|
|
case WINDOW_HIDE:
|
2014-11-12 06:27:33 +03:00
|
|
|
XWithdrawWindow(xfc->display, appWindow->handle, xfc->screen_number);
|
2011-08-22 07:15:19 +04:00
|
|
|
break;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2011-08-22 07:15:19 +04:00
|
|
|
case WINDOW_SHOW_MINIMIZED:
|
2014-11-12 06:27:33 +03:00
|
|
|
XIconifyWindow(xfc->display, appWindow->handle, xfc->screen_number);
|
2011-08-22 07:15:19 +04:00
|
|
|
break;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2011-08-22 07:15:19 +04:00
|
|
|
case WINDOW_SHOW_MAXIMIZED:
|
2012-09-03 00:34:06 +04:00
|
|
|
/* Set the window as maximized */
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_SendClientEvent(xfc, appWindow->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_ADD,
|
|
|
|
xfc->_NET_WM_STATE_MAXIMIZED_VERT, xfc->_NET_WM_STATE_MAXIMIZED_HORZ,
|
|
|
|
0);
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2012-09-03 00:34:06 +04:00
|
|
|
/*
|
2019-11-06 17:24:51 +03:00
|
|
|
* This is a workaround for the case where the window is maximized locally before the
|
|
|
|
* rail server is told to maximize the window, this appears to be a race condition where
|
|
|
|
* the local window with incomplete data and once the window is actually maximized on
|
|
|
|
* the server
|
|
|
|
* - an update of the new areas may not happen. So, we simply to do a full update of the
|
|
|
|
* entire window once the rail server notifies us that the window is now maximized.
|
2012-09-03 00:34:06 +04:00
|
|
|
*/
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->rail_state == WINDOW_SHOW_MAXIMIZED)
|
2014-11-13 00:42:32 +03:00
|
|
|
{
|
2016-08-03 15:16:20 +03:00
|
|
|
xf_UpdateWindowArea(xfc, appWindow, 0, 0, appWindow->windowWidth,
|
|
|
|
appWindow->windowHeight);
|
2014-11-13 00:42:32 +03:00
|
|
|
}
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2011-08-22 07:15:19 +04:00
|
|
|
break;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2011-08-22 07:15:19 +04:00
|
|
|
case WINDOW_SHOW:
|
2012-09-03 00:34:06 +04:00
|
|
|
/* Ensure the window is not maximized */
|
2019-11-06 17:24:51 +03:00
|
|
|
xf_SendClientEvent(xfc, appWindow->handle, xfc->_NET_WM_STATE, 4, _NET_WM_STATE_REMOVE,
|
|
|
|
xfc->_NET_WM_STATE_MAXIMIZED_VERT, xfc->_NET_WM_STATE_MAXIMIZED_HORZ,
|
|
|
|
0);
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2012-09-03 00:34:06 +04:00
|
|
|
/*
|
|
|
|
* Ignore configure requests until both the Maximized properties have been processed
|
2019-11-06 17:24:51 +03:00
|
|
|
* to prevent condition where WM overrides size of request due to one or both of these
|
|
|
|
* properties still being set - which causes a position adjustment to be sent back to
|
|
|
|
* the server thus causing the window to not return to its original size
|
2012-09-03 00:34:06 +04:00
|
|
|
*/
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->rail_state == WINDOW_SHOW_MAXIMIZED)
|
|
|
|
appWindow->rail_ignore_configure = TRUE;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->is_transient)
|
|
|
|
xf_SetWindowUnlisted(xfc, appWindow->handle);
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2018-12-04 15:28:32 +03:00
|
|
|
XMapWindow(xfc->display, appWindow->handle);
|
2011-08-22 07:15:19 +04:00
|
|
|
break;
|
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2012-09-03 00:34:06 +04:00
|
|
|
/* Save the current rail state of this window */
|
2014-11-12 06:27:33 +03:00
|
|
|
appWindow->rail_state = state;
|
2013-06-13 02:57:25 +04:00
|
|
|
XFlush(xfc->display);
|
2011-08-22 07:15:19 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_SetWindowRects(xfContext* xfc, xfAppWindow* appWindow, RECTANGLE_16* rects, int nrects)
|
2011-08-23 00:06:12 +04:00
|
|
|
{
|
|
|
|
int i;
|
2014-11-12 04:26:47 +03:00
|
|
|
XRectangle* xrects;
|
|
|
|
|
|
|
|
if (nrects < 1)
|
2012-05-15 19:21:01 +04:00
|
|
|
return;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2015-09-19 00:14:30 +03:00
|
|
|
#ifdef WITH_XEXT
|
2019-11-06 17:24:51 +03:00
|
|
|
xrects = (XRectangle*)calloc(nrects, sizeof(XRectangle));
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
for (i = 0; i < nrects; i++)
|
2011-08-23 00:06:12 +04:00
|
|
|
{
|
|
|
|
xrects[i].x = rects[i].left;
|
|
|
|
xrects[i].y = rects[i].top;
|
2011-08-23 00:10:08 +04:00
|
|
|
xrects[i].width = rects[i].right - rects[i].left;
|
|
|
|
xrects[i].height = rects[i].bottom - rects[i].top;
|
2011-08-23 00:06:12 +04:00
|
|
|
}
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
XShapeCombineRectangles(xfc->display, appWindow->handle, ShapeBounding, 0, 0, xrects, nrects,
|
|
|
|
ShapeSet, 0);
|
2015-09-19 00:14:30 +03:00
|
|
|
free(xrects);
|
2011-08-24 06:58:36 +04:00
|
|
|
#endif
|
2011-08-23 00:06:12 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_SetWindowVisibilityRects(xfContext* xfc, xfAppWindow* appWindow, UINT32 rectsOffsetX,
|
|
|
|
UINT32 rectsOffsetY, RECTANGLE_16* rects, int nrects)
|
2011-08-09 06:24:12 +04:00
|
|
|
{
|
2011-08-30 22:21:16 +04:00
|
|
|
int i;
|
2014-11-12 04:26:47 +03:00
|
|
|
XRectangle* xrects;
|
|
|
|
|
|
|
|
if (nrects < 1)
|
2012-05-15 19:21:01 +04:00
|
|
|
return;
|
2014-11-12 04:26:47 +03:00
|
|
|
|
2015-09-19 00:14:30 +03:00
|
|
|
#ifdef WITH_XEXT
|
2019-11-06 17:24:51 +03:00
|
|
|
xrects = (XRectangle*)calloc(nrects, sizeof(XRectangle));
|
2014-11-12 04:26:47 +03:00
|
|
|
|
|
|
|
for (i = 0; i < nrects; i++)
|
2011-08-22 13:21:39 +04:00
|
|
|
{
|
2011-08-30 22:21:16 +04:00
|
|
|
xrects[i].x = rects[i].left;
|
|
|
|
xrects[i].y = rects[i].top;
|
|
|
|
xrects[i].width = rects[i].right - rects[i].left;
|
|
|
|
xrects[i].height = rects[i].bottom - rects[i].top;
|
2011-08-22 13:21:39 +04:00
|
|
|
}
|
2014-11-12 06:27:33 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
XShapeCombineRectangles(xfc->display, appWindow->handle, ShapeBounding, rectsOffsetX,
|
|
|
|
rectsOffsetY, xrects, nrects, ShapeSet, 0);
|
2015-09-19 00:14:30 +03:00
|
|
|
free(xrects);
|
2011-08-30 22:21:16 +04:00
|
|
|
#endif
|
2011-08-25 01:16:57 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
void xf_UpdateWindowArea(xfContext* xfc, xfAppWindow* appWindow, int x, int y, int width,
|
|
|
|
int height)
|
2011-09-23 05:23:01 +04:00
|
|
|
{
|
2014-11-13 00:42:32 +03:00
|
|
|
int ax, ay;
|
2017-02-17 11:38:05 +03:00
|
|
|
|
2017-08-14 11:10:53 +03:00
|
|
|
if (appWindow == NULL)
|
2017-02-17 11:38:05 +03:00
|
|
|
return;
|
|
|
|
|
2019-05-08 16:36:20 +03:00
|
|
|
if (appWindow->surfaceId < UINT16_MAX)
|
|
|
|
return;
|
|
|
|
|
2015-10-16 02:41:55 +03:00
|
|
|
ax = x + appWindow->windowOffsetX;
|
|
|
|
ay = y + appWindow->windowOffsetY;
|
2015-02-12 02:24:06 +03:00
|
|
|
|
2015-10-16 03:10:04 +03:00
|
|
|
if (ax + width > appWindow->windowOffsetX + appWindow->width)
|
|
|
|
width = (appWindow->windowOffsetX + appWindow->width - 1) - ax;
|
2016-08-03 15:16:20 +03:00
|
|
|
|
2015-10-16 03:10:04 +03:00
|
|
|
if (ay + height > appWindow->windowOffsetY + appWindow->height)
|
|
|
|
height = (appWindow->windowOffsetY + appWindow->height - 1) - ay;
|
2014-11-13 00:42:32 +03:00
|
|
|
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_lock_x11(xfc);
|
2014-11-13 00:42:32 +03:00
|
|
|
|
2016-08-03 15:16:20 +03:00
|
|
|
if (xfc->context.settings->SoftwareGdi)
|
2014-11-13 00:42:32 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
XPutImage(xfc->display, xfc->primary, appWindow->gc, xfc->image, ax, ay, ax, ay, width,
|
|
|
|
height);
|
2014-11-13 00:42:32 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
XCopyArea(xfc->display, xfc->primary, appWindow->handle, appWindow->gc, ax, ay, width, height,
|
|
|
|
x, y);
|
2014-11-13 00:42:32 +03:00
|
|
|
XFlush(xfc->display);
|
2020-03-04 13:33:06 +03:00
|
|
|
xf_unlock_x11(xfc);
|
2011-09-23 05:23:01 +04:00
|
|
|
}
|
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
void xf_DestroyWindow(xfContext* xfc, xfAppWindow* appWindow)
|
2011-08-25 01:16:57 +04:00
|
|
|
{
|
2014-11-12 06:27:33 +03:00
|
|
|
if (!appWindow)
|
2011-09-06 00:42:18 +04:00
|
|
|
return;
|
2014-06-20 21:52:13 +04:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->gc)
|
|
|
|
XFreeGC(xfc->display, appWindow->gc);
|
2014-06-20 21:52:13 +04:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->handle)
|
2011-08-30 22:21:16 +04:00
|
|
|
{
|
2014-11-12 06:27:33 +03:00
|
|
|
XUnmapWindow(xfc->display, appWindow->handle);
|
|
|
|
XDestroyWindow(xfc->display, appWindow->handle);
|
2011-08-30 22:21:16 +04:00
|
|
|
}
|
2014-06-20 21:52:13 +04:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->xfwin)
|
|
|
|
munmap(0, sizeof(*appWindow->xfwin));
|
2014-06-20 21:52:13 +04:00
|
|
|
|
2014-11-12 06:27:33 +03:00
|
|
|
if (appWindow->shmid >= 0)
|
|
|
|
close(appWindow->shmid);
|
2014-06-20 21:52:13 +04:00
|
|
|
|
2014-05-23 15:09:11 +04:00
|
|
|
shm_unlink(get_shm_id());
|
2019-11-06 17:24:51 +03:00
|
|
|
appWindow->xfwin = (Window*)-1;
|
2014-11-12 06:27:33 +03:00
|
|
|
appWindow->shmid = -1;
|
2014-11-13 01:00:57 +03:00
|
|
|
free(appWindow->title);
|
|
|
|
free(appWindow->windowRects);
|
|
|
|
free(appWindow->visibilityRects);
|
2014-11-12 06:27:33 +03:00
|
|
|
free(appWindow);
|
2011-08-09 06:24:12 +04:00
|
|
|
}
|
2012-09-19 02:57:19 +04:00
|
|
|
|
2014-11-13 00:42:32 +03:00
|
|
|
xfAppWindow* xf_AppWindowFromX11Window(xfContext* xfc, Window wnd)
|
2012-09-19 02:57:19 +04:00
|
|
|
{
|
2014-11-13 00:42:32 +03:00
|
|
|
int index;
|
|
|
|
int count;
|
|
|
|
ULONG_PTR* pKeys = NULL;
|
|
|
|
xfAppWindow* appWindow;
|
|
|
|
count = HashTable_GetKeys(xfc->railWindows, &pKeys);
|
|
|
|
|
|
|
|
for (index = 0; index < count; index++)
|
|
|
|
{
|
2019-05-08 16:36:20 +03:00
|
|
|
appWindow = xf_rail_get_window(xfc, *(UINT64*)pKeys[index]);
|
|
|
|
|
|
|
|
if (!appWindow)
|
|
|
|
return NULL;
|
2014-11-13 00:42:32 +03:00
|
|
|
|
|
|
|
if (appWindow->handle == wnd)
|
|
|
|
{
|
|
|
|
free(pKeys);
|
|
|
|
return appWindow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pKeys);
|
2012-09-19 02:57:19 +04:00
|
|
|
return NULL;
|
|
|
|
}
|