FreeRDP/client/X11/xf_event.c

1116 lines
25 KiB
C
Raw Normal View History

2011-08-07 17:52:40 +04:00
/**
2012-10-09 07:02:04 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
2011-08-07 17:52:40 +04:00
* X11 Event Handling
*
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <X11/Xlib.h>
#include <X11/Xutil.h>
2014-09-12 19:13:01 +04:00
#include <freerdp/log.h>
#include <freerdp/locale/keyboard.h>
2011-08-07 17:52:40 +04:00
#include "xf_rail.h"
#include "xf_window.h"
2011-09-23 07:37:17 +04:00
#include "xf_cliprdr.h"
#include "xf_disp.h"
#include "xf_input.h"
#include "xf_gfx.h"
2011-08-07 17:52:40 +04:00
#include "xf_event.h"
2013-04-26 03:52:17 +04:00
#include "xf_input.h"
2011-08-07 17:52:40 +04:00
2014-09-12 19:13:01 +04:00
#define TAG CLIENT_TAG("x11")
#define CLAMP_COORDINATES(x, y) if (x < 0) x = 0; if (y < 0) y = 0
2018-01-24 18:26:27 +03:00
static const char* x11_event_string(int event)
2011-08-19 19:12:30 +04:00
{
2018-01-24 18:26:27 +03:00
switch (event)
{
case KeyPress:
return "KeyPress";
case KeyRelease:
return "KeyRelease";
case ButtonPress:
return "ButtonPress";
case ButtonRelease:
return "ButtonRelease";
case MotionNotify:
return "MotionNotify";
case EnterNotify:
return "EnterNotify";
case LeaveNotify:
return "LeaveNotify";
case FocusIn:
return "FocusIn";
case FocusOut:
return "FocusOut";
case KeymapNotify:
return "KeymapNotify";
case Expose:
return "Expose";
case GraphicsExpose:
return "GraphicsExpose";
case NoExpose:
return "NoExpose";
case VisibilityNotify:
return "VisibilityNotify";
case CreateNotify:
return "CreateNotify";
case DestroyNotify:
return "DestroyNotify";
case UnmapNotify:
return "UnmapNotify";
case MapNotify:
return "MapNotify";
case MapRequest:
return "MapRequest";
case ReparentNotify:
return "ReparentNotify";
case ConfigureNotify:
return "ConfigureNotify";
case ConfigureRequest:
return "ConfigureRequest";
case GravityNotify:
return "GravityNotify";
case ResizeRequest:
return "ResizeRequest";
case CirculateNotify:
return "CirculateNotify";
case CirculateRequest:
return "CirculateRequest";
case PropertyNotify:
return "PropertyNotify";
case SelectionClear:
return "SelectionClear";
case SelectionRequest:
return "SelectionRequest";
case SelectionNotify:
return "SelectionNotify";
case ColormapNotify:
return "ColormapNotify";
case ClientMessage:
return "ClientMessage";
case MappingNotify:
return "MappingNotify";
case GenericEvent:
return "GenericEvent";
default:
return "UNKNOWN";
};
}
#ifdef WITH_DEBUG_X11
#define DEBUG_X11(...) WLog_DBG(TAG, __VA_ARGS__)
#else
#define DEBUG_X11(...) do { } while (0)
#endif
2015-05-20 20:19:50 +03:00
BOOL xf_event_action_script_init(xfContext* xfc)
{
char* xevent;
FILE* actionScript;
char buffer[1024] = { 0 };
char command[1024] = { 0 };
xfc->xevents = ArrayList_New(TRUE);
2016-07-19 17:15:38 +03:00
if (!xfc->xevents)
2015-05-20 20:19:50 +03:00
return FALSE;
2016-07-19 17:15:38 +03:00
ArrayList_Object(xfc->xevents)->fnObjectFree = free;
sprintf_s(command, sizeof(command), "%s xevent", xfc->context.settings->ActionScript);
actionScript = popen(command, "r");
if (!actionScript)
2015-05-20 20:19:50 +03:00
return FALSE;
while (fgets(buffer, sizeof(buffer), actionScript))
{
strtok(buffer, "\n");
xevent = _strdup(buffer);
2016-07-19 17:15:38 +03:00
if (!xevent || ArrayList_Add(xfc->xevents, xevent) < 0)
{
ArrayList_Free(xfc->xevents);
xfc->xevents = NULL;
2015-05-20 20:19:50 +03:00
return FALSE;
}
}
pclose(actionScript);
2015-05-20 20:19:50 +03:00
return TRUE;
}
void xf_event_action_script_free(xfContext* xfc)
{
if (xfc->xevents)
{
ArrayList_Free(xfc->xevents);
xfc->xevents = NULL;
}
}
static BOOL xf_event_execute_action_script(xfContext* xfc, XEvent* event)
{
int index;
int count;
char* name;
FILE* actionScript;
BOOL match = FALSE;
const char* xeventName;
char buffer[1024] = { 0 };
char command[1024] = { 0 };
if (!xfc->actionScriptExists || !xfc->xevents)
return FALSE;
2018-01-24 18:26:27 +03:00
if (event->type > LASTEvent)
return FALSE;
2018-01-24 18:26:27 +03:00
xeventName = x11_event_string(event->type);
count = ArrayList_Count(xfc->xevents);
for (index = 0; index < count; index++)
{
name = (char*) ArrayList_GetItem(xfc->xevents, index);
if (_stricmp(name, xeventName) == 0)
{
match = TRUE;
break;
}
}
if (!match)
return FALSE;
sprintf_s(command, sizeof(command), "%s xevent %s %lu",
xfc->context.settings->ActionScript, xeventName, (unsigned long) xfc->window->handle);
actionScript = popen(command, "r");
if (!actionScript)
return FALSE;
while (fgets(buffer, sizeof(buffer), actionScript))
{
strtok(buffer, "\n");
}
pclose(actionScript);
return TRUE;
}
2016-07-19 17:15:38 +03:00
void xf_event_adjust_coordinates(xfContext* xfc, int* x, int* y)
{
2016-07-19 17:15:38 +03:00
rdpSettings* settings;
if (!xfc || !xfc->context.settings || !y || !x)
return;
settings = xfc->context.settings;
if (!xfc->remote_app)
{
#ifdef WITH_XRENDER
2016-07-19 17:15:38 +03:00
if (xf_picture_transform_required(xfc))
{
2016-07-19 17:15:38 +03:00
double xScalingFactor = settings->DesktopWidth / (double)xfc->scaledWidth;
double yScalingFactor = settings->DesktopHeight / (double)xfc->scaledHeight;
*x = (int)((*x - xfc->offset_x) * xScalingFactor);
*y = (int)((*y - xfc->offset_y) * yScalingFactor);
}
2016-07-19 17:15:38 +03:00
#endif
}
2016-07-19 17:15:38 +03:00
CLAMP_COORDINATES(*x, *y);
}
static BOOL xf_event_Expose(xfContext* xfc, XEvent* event, BOOL app)
{
int x, y;
int w, h;
2016-07-19 17:15:38 +03:00
rdpSettings* settings = xfc->context.settings;
2016-07-19 17:15:38 +03:00
if (!app && (settings->SmartSizing || settings->MultiTouchGestures))
{
x = 0;
y = 0;
2016-07-19 17:15:38 +03:00
w = settings->DesktopWidth;
h = settings->DesktopHeight;
}
else
{
x = event->xexpose.x;
y = event->xexpose.y;
w = event->xexpose.width;
h = event->xexpose.height;
}
2014-06-05 20:36:01 +04:00
2018-02-08 15:55:36 +03:00
if (xfc->context.gdi->gfx)
{
xf_OutputExpose(xfc, x, y, w, h);
return TRUE;
}
2013-02-10 22:17:08 +04:00
if (!app)
{
xf_draw_screen(xfc, x, y, w, h);
}
else
{
xfAppWindow* appWindow;
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
if (appWindow)
{
xf_UpdateWindowArea(xfc, appWindow, x, y, w, h);
}
}
return TRUE;
}
static BOOL xf_event_VisibilityNotify(xfContext* xfc, XEvent* event, BOOL app)
{
xfc->unobscured = event->xvisibility.state == VisibilityUnobscured;
return TRUE;
}
2016-07-19 17:15:38 +03:00
BOOL xf_generic_MotionNotify(xfContext* xfc, int x, int y, int state,
Window window, BOOL app)
{
rdpInput* input;
Window childWindow;
2016-08-03 15:16:20 +03:00
input = xfc->context.input;
2016-08-03 15:16:20 +03:00
if (!xfc->context.settings->MouseMotion)
{
if ((state & (Button1Mask | Button2Mask | Button3Mask)) == 0)
return TRUE;
}
if (app)
{
/* make sure window exists */
if (!xf_AppWindowFromX11Window(xfc, window))
return TRUE;
2013-03-29 07:09:28 +04:00
/* Translate to desktop coordinates */
XTranslateCoordinates(xfc->display, window,
2016-07-19 17:15:38 +03:00
RootWindowOfScreen(xfc->screen),
x, y, &x, &y, &childWindow);
}
xf_event_adjust_coordinates(xfc, &x, &y);
2018-01-24 18:26:27 +03:00
freerdp_input_send_mouse_event(input, PTR_FLAGS_MOVE, x, y);
if (xfc->fullscreen && !app)
{
2016-07-19 17:15:38 +03:00
XSetInputFocus(xfc->display, xfc->window->handle, RevertToPointerRoot,
CurrentTime);
}
return TRUE;
2011-08-07 17:52:40 +04:00
}
static BOOL xf_event_MotionNotify(xfContext* xfc, XEvent* event, BOOL app)
{
if (xfc->use_xinput)
return TRUE;
return xf_generic_MotionNotify(xfc, event->xmotion.x, event->xmotion.y,
2016-07-19 17:15:38 +03:00
event->xmotion.state, event->xmotion.window, app);
}
2016-07-19 17:15:38 +03:00
BOOL xf_generic_ButtonPress(xfContext* xfc, int x, int y, int button,
Window window, BOOL app)
2011-08-07 17:52:40 +04:00
{
int flags;
BOOL wheel;
BOOL extended;
rdpInput* input;
Window childWindow;
wheel = FALSE;
extended = FALSE;
2016-08-03 15:16:20 +03:00
input = xfc->context.input;
switch (button)
{
case Button1:
case Button2:
case Button3:
2016-07-19 17:15:38 +03:00
flags = PTR_FLAGS_DOWN | xfc->button_map[button - BUTTON_BASE];
break;
case 4:
wheel = TRUE;
flags = PTR_FLAGS_WHEEL | 0x0078;
break;
2011-08-07 17:52:40 +04:00
case 5:
wheel = TRUE;
flags = PTR_FLAGS_WHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0078;
break;
case 8: /* back */
case 97: /* Xming */
extended = TRUE;
flags = PTR_XFLAGS_DOWN | PTR_XFLAGS_BUTTON1;
break;
case 9: /* forward */
case 112: /* Xming */
extended = TRUE;
flags = PTR_XFLAGS_DOWN | PTR_XFLAGS_BUTTON2;
break;
case 6: /* wheel left */
wheel = TRUE;
flags = PTR_FLAGS_HWHEEL | PTR_FLAGS_WHEEL_NEGATIVE | 0x0078;
break;
case 7: /* wheel right */
wheel = TRUE;
flags = PTR_FLAGS_HWHEEL | 0x0078;
break;
default:
x = 0;
y = 0;
flags = 0;
break;
}
if (flags != 0)
{
if (wheel)
{
2018-01-24 18:26:27 +03:00
freerdp_input_send_mouse_event(input, flags, 0, 0);
}
else
{
if (app)
{
/* make sure window exists */
if (!xf_AppWindowFromX11Window(xfc, window))
return TRUE;
/* Translate to desktop coordinates */
XTranslateCoordinates(xfc->display, window,
2016-07-19 17:15:38 +03:00
RootWindowOfScreen(xfc->screen),
x, y, &x, &y, &childWindow);
}
xf_event_adjust_coordinates(xfc, &x, &y);
if (extended)
2018-01-24 18:26:27 +03:00
freerdp_input_send_extended_mouse_event(input, flags, x, y);
else
2018-01-24 18:26:27 +03:00
freerdp_input_send_mouse_event(input, flags, x, y);
}
}
return TRUE;
2011-08-07 17:52:40 +04:00
}
static BOOL xf_event_ButtonPress(xfContext* xfc, XEvent* event, BOOL app)
{
if (xfc->use_xinput)
return TRUE;
return xf_generic_ButtonPress(xfc, event->xbutton.x, event->xbutton.y,
2016-07-19 17:15:38 +03:00
event->xbutton.button, event->xbutton.window, app);
}
2016-07-19 17:15:38 +03:00
BOOL xf_generic_ButtonRelease(xfContext* xfc, int x, int y, int button,
Window window, BOOL app)
2011-08-07 17:52:40 +04:00
{
int flags = 0;
BOOL extended = FALSE;
rdpInput* input;
Window childWindow;
if (!xfc || !xfc->context.input)
return FALSE;
2016-08-03 15:16:20 +03:00
input = xfc->context.input;
switch (button)
{
case Button1:
case Button2:
case Button3:
2016-07-19 17:15:38 +03:00
flags = xfc->button_map[button - BUTTON_BASE];
break;
case 6:
case 8:
case 97:
extended = TRUE;
flags = PTR_XFLAGS_BUTTON1;
break;
case 7:
case 9:
case 112:
extended = TRUE;
flags = PTR_XFLAGS_BUTTON2;
break;
default:
flags = 0;
break;
}
if (flags != 0)
{
if (app)
{
/* make sure window exists */
if (!xf_AppWindowFromX11Window(xfc, window))
return TRUE;
/* Translate to desktop coordinates */
XTranslateCoordinates(xfc->display, window,
2016-07-19 17:15:38 +03:00
RootWindowOfScreen(xfc->screen),
x, y, &x, &y, &childWindow);
}
xf_event_adjust_coordinates(xfc, &x, &y);
if (extended)
2018-01-24 18:26:27 +03:00
freerdp_input_send_extended_mouse_event(input, flags, x, y);
else
2018-01-24 18:26:27 +03:00
freerdp_input_send_mouse_event(input, flags, x, y);
}
return TRUE;
}
static BOOL xf_event_ButtonRelease(xfContext* xfc, XEvent* event, BOOL app)
{
if (xfc->use_xinput)
return TRUE;
return xf_generic_ButtonRelease(xfc, event->xbutton.x, event->xbutton.y,
2016-07-19 17:15:38 +03:00
event->xbutton.button, event->xbutton.window, app);
}
static BOOL xf_event_KeyPress(xfContext* xfc, XEvent* event, BOOL app)
{
KeySym keysym;
char str[256];
XLookupString((XKeyEvent*) event, str, sizeof(str), &keysym, NULL);
2014-03-14 05:10:22 +04:00
xf_keyboard_key_press(xfc, event->xkey.keycode, keysym);
return TRUE;
}
static BOOL xf_event_KeyRelease(xfContext* xfc, XEvent* event, BOOL app)
{
KeySym keysym;
char str[256];
XLookupString((XKeyEvent*) event, str, sizeof(str), &keysym, NULL);
xf_keyboard_key_release(xfc, event->xkey.keycode, keysym);
return TRUE;
}
static BOOL xf_event_FocusIn(xfContext* xfc, XEvent* event, BOOL app)
{
if (event->xfocus.mode == NotifyGrab)
return TRUE;
xfc->focused = TRUE;
if (xfc->mouse_active && !app)
2016-07-19 17:15:38 +03:00
XGrabKeyboard(xfc->display, xfc->window->handle, TRUE, GrabModeAsync,
GrabModeAsync, CurrentTime);
if (app)
Multiple RAIL fixes/improvements 1. Linked Window Manager Maximize/Minimize and Restore operations to those from the Server Rail Window so that they are in sync 2. Enable things like "CTRL-ALT-DELETE" and "WindowsKey-L" to show the full desktop window again since the desktop is not actively monitored since this was still trying to draw to the rail window without updating the size of the window to accomodate the full workspace area. 3. Changed local window coordinates to be based on the visibileOffsetX/Y- while moving server window based on WindowOffsetX/Y. I have seen various issues regarding this when trying to use a maximized window where this is a disconnect between local window coordinates and remote window coordinates. This change clears these things up. 4. Commented the XShapeCombineRectangles calls - this can cause issues where the entire window is not visible and it does not currently play well with the changes from #3. The gain here is greater than the loss. 5. Draw the initial workspace correctly when running across multiple monitors. The correct size was always used, but the window was only starting on the current monitor and thus could draw the window off of the viewable area. Known Issues: Although the changes for #2 worked well in the stable branch that I developed from - the desktop window shown once the rail windows are destroyed does not respond to input unless I minimize/restore the window. Once the window starts responding to input - you can hit cancel to close the desktop window and return to your rail windows again(or launch task manager, etc.). This is still a big step in the right direction as xfreerdp is now correctly acting when the rail server stops Actively Monitoring the desktop. XShapeCombineRectangles needs to be revisited, most windows applications will give you a rectangular window anyways.
2012-08-04 02:35:17 +04:00
{
xfAppWindow* appWindow;
xf_rail_send_activate(xfc, event->xany.window, TRUE);
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
/* Update the server with any window changes that occurred while the window was not focused. */
if (appWindow)
{
xf_rail_adjust_position(xfc, appWindow);
}
Multiple RAIL fixes/improvements 1. Linked Window Manager Maximize/Minimize and Restore operations to those from the Server Rail Window so that they are in sync 2. Enable things like "CTRL-ALT-DELETE" and "WindowsKey-L" to show the full desktop window again since the desktop is not actively monitored since this was still trying to draw to the rail window without updating the size of the window to accomodate the full workspace area. 3. Changed local window coordinates to be based on the visibileOffsetX/Y- while moving server window based on WindowOffsetX/Y. I have seen various issues regarding this when trying to use a maximized window where this is a disconnect between local window coordinates and remote window coordinates. This change clears these things up. 4. Commented the XShapeCombineRectangles calls - this can cause issues where the entire window is not visible and it does not currently play well with the changes from #3. The gain here is greater than the loss. 5. Draw the initial workspace correctly when running across multiple monitors. The correct size was always used, but the window was only starting on the current monitor and thus could draw the window off of the viewable area. Known Issues: Although the changes for #2 worked well in the stable branch that I developed from - the desktop window shown once the rail windows are destroyed does not respond to input unless I minimize/restore the window. Once the window starts responding to input - you can hit cancel to close the desktop window and return to your rail windows again(or launch task manager, etc.). This is still a big step in the right direction as xfreerdp is now correctly acting when the rail server stops Actively Monitoring the desktop. XShapeCombineRectangles needs to be revisited, most windows applications will give you a rectangular window anyways.
2012-08-04 02:35:17 +04:00
}
2014-03-14 05:10:22 +04:00
xf_keyboard_focus_in(xfc);
return TRUE;
}
static BOOL xf_event_FocusOut(xfContext* xfc, XEvent* event, BOOL app)
{
if (event->xfocus.mode == NotifyUngrab)
return TRUE;
xfc->focused = FALSE;
if (event->xfocus.mode == NotifyWhileGrabbed)
XUngrabKeyboard(xfc->display, CurrentTime);
xf_keyboard_release_all_keypress(xfc);
2014-03-14 05:10:22 +04:00
xf_keyboard_clear(xfc);
if (app)
xf_rail_send_activate(xfc, event->xany.window, FALSE);
return TRUE;
}
static BOOL xf_event_MappingNotify(xfContext* xfc, XEvent* event, BOOL app)
{
if (event->xmapping.request == MappingModifier)
{
2014-03-14 05:10:22 +04:00
if (xfc->modifierMap)
XFreeModifiermap(xfc->modifierMap);
2014-03-14 05:10:22 +04:00
xfc->modifierMap = XGetModifierMapping(xfc->display);
}
return TRUE;
}
static BOOL xf_event_ClientMessage(xfContext* xfc, XEvent* event, BOOL app)
{
if ((event->xclient.message_type == xfc->WM_PROTOCOLS)
&& ((Atom) event->xclient.data.l[0] == xfc->WM_DELETE_WINDOW))
{
if (app)
{
xfAppWindow* appWindow;
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
if (appWindow)
{
xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_CLOSE);
}
return TRUE;
}
else
{
2012-03-23 00:30:15 +04:00
DEBUG_X11("Main window closed");
return FALSE;
}
}
return TRUE;
2011-08-07 17:52:40 +04:00
}
static BOOL xf_event_EnterNotify(xfContext* xfc, XEvent* event, BOOL app)
2011-08-07 17:52:40 +04:00
{
2013-02-10 22:17:08 +04:00
if (!app)
{
xfc->mouse_active = TRUE;
if (xfc->fullscreen)
2016-07-19 17:15:38 +03:00
XSetInputFocus(xfc->display, xfc->window->handle, RevertToPointerRoot,
CurrentTime);
if (xfc->focused)
2016-07-19 17:15:38 +03:00
XGrabKeyboard(xfc->display, xfc->window->handle, TRUE, GrabModeAsync,
GrabModeAsync, CurrentTime);
}
else
{
xfAppWindow* appWindow;
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
/* keep track of which window has focus so that we can apply pointer updates */
if (appWindow)
{
xfc->appWindow = appWindow;
}
}
return TRUE;
2011-08-07 17:52:40 +04:00
}
static BOOL xf_event_LeaveNotify(xfContext* xfc, XEvent* event, BOOL app)
{
2013-02-10 22:17:08 +04:00
if (!app)
2011-08-19 19:12:30 +04:00
{
xfc->mouse_active = FALSE;
XUngrabKeyboard(xfc->display, CurrentTime);
2011-08-19 19:12:30 +04:00
}
return TRUE;
}
static BOOL xf_event_ConfigureNotify(xfContext* xfc, XEvent* event, BOOL app)
{
Window childWindow;
xfAppWindow* appWindow;
2016-07-19 17:15:38 +03:00
rdpSettings* settings = xfc->context.settings;
if (!app)
{
if (xfc->window->left != event->xconfigure.x)
xfc->window->left = event->xconfigure.x;
if (xfc->window->top != event->xconfigure.y)
xfc->window->top = event->xconfigure.y;
if (xfc->window->width != event->xconfigure.width ||
2016-07-19 17:15:38 +03:00
xfc->window->height != event->xconfigure.height)
{
xfc->window->width = event->xconfigure.width;
xfc->window->height = event->xconfigure.height;
#ifdef WITH_XRENDER
xfc->offset_x = 0;
xfc->offset_y = 0;
2016-07-19 17:15:38 +03:00
2016-08-03 15:16:20 +03:00
if (xfc->context.settings->SmartSizing
|| xfc->context.settings->MultiTouchGestures)
{
xfc->scaledWidth = xfc->window->width;
xfc->scaledHeight = xfc->window->height;
2016-07-19 17:15:38 +03:00
xf_draw_screen(xfc, 0, 0, settings->DesktopWidth, settings->DesktopHeight);
}
else
{
2016-07-19 17:15:38 +03:00
xfc->scaledWidth = settings->DesktopWidth;
xfc->scaledHeight = settings->DesktopHeight;
}
2016-07-19 17:15:38 +03:00
#endif
}
2016-07-19 17:15:38 +03:00
if (settings->DynamicResolutionUpdate)
{
int alignedWidth, alignedHeight;
alignedWidth = (xfc->window->width / 2) * 2;
alignedHeight = (xfc->window->height / 2) * 2;
/* ask the server to resize using the display channel */
xf_disp_handle_configureNotify(xfc, alignedWidth, alignedHeight);
}
return TRUE;
}
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
if (appWindow)
{
/*
* ConfigureNotify coordinates are expressed relative to the window parent.
* Translate these to root window coordinates.
*/
XTranslateCoordinates(xfc->display, appWindow->handle,
2016-07-19 17:15:38 +03:00
RootWindowOfScreen(xfc->screen),
0, 0, &appWindow->x, &appWindow->y, &childWindow);
appWindow->width = event->xconfigure.width;
appWindow->height = event->xconfigure.height;
/*
* Additional checks for not in a local move and not ignoring configure to send
* position update to server, also should the window not be focused then do not
* send to server yet (i.e. resizing using window decoration).
* The server will be updated when the window gets refocused.
*/
if (appWindow->decorations)
{
/* moving resizing using window decoration */
xf_rail_adjust_position(xfc, appWindow);
}
else
{
2016-07-19 17:15:38 +03:00
if ((!event->xconfigure.send_event
|| appWindow->local_move.state == LMS_NOT_ACTIVE)
&& !appWindow->rail_ignore_configure && xfc->focused)
xf_rail_adjust_position(xfc, appWindow);
}
}
return TRUE;
}
static BOOL xf_event_MapNotify(xfContext* xfc, XEvent* event, BOOL app)
{
xfAppWindow* appWindow;
2013-02-10 22:17:08 +04:00
if (!app)
gdi_send_suppress_output(xfc->context.gdi, FALSE);
2012-05-28 16:21:56 +04:00
else
{
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
2012-05-28 16:21:56 +04:00
if (appWindow)
2012-05-28 16:21:56 +04:00
{
/* local restore event */
/* This is now handled as part of the PropertyNotify
* Doing this here would inhibit the ability to restore a maximized window
* that is minimized back to the maximized state
*/
//xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_RESTORE);
appWindow->is_mapped = TRUE;
2012-05-28 16:21:56 +04:00
}
}
return TRUE;
}
static BOOL xf_event_UnmapNotify(xfContext* xfc, XEvent* event, BOOL app)
{
xfAppWindow* appWindow;
2014-03-14 05:10:22 +04:00
xf_keyboard_release_all_keypress(xfc);
2013-02-10 22:17:08 +04:00
if (!app)
gdi_send_suppress_output(xfc->context.gdi, TRUE);
2012-05-28 16:21:56 +04:00
else
{
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
2012-05-28 16:21:56 +04:00
if (appWindow)
2012-05-28 16:21:56 +04:00
{
appWindow->is_mapped = FALSE;
2012-05-28 16:21:56 +04:00
}
}
return TRUE;
}
static BOOL xf_event_PropertyNotify(xfContext* xfc, XEvent* event, BOOL app)
2011-09-23 07:37:17 +04:00
{
/*
* This section handles sending the appropriate commands to the rail server
* when the window has been minimized, maximized, restored locally
* ie. not using the buttons on the rail window itself
*/
2018-01-24 18:26:27 +03:00
if ((((Atom) event->xproperty.atom == xfc->_NET_WM_STATE)
&& (event->xproperty.state != PropertyDelete)) ||
(((Atom) event->xproperty.atom == xfc->WM_STATE)
&& (event->xproperty.state != PropertyDelete)))
Multiple RAIL fixes/improvements 1. Linked Window Manager Maximize/Minimize and Restore operations to those from the Server Rail Window so that they are in sync 2. Enable things like "CTRL-ALT-DELETE" and "WindowsKey-L" to show the full desktop window again since the desktop is not actively monitored since this was still trying to draw to the rail window without updating the size of the window to accomodate the full workspace area. 3. Changed local window coordinates to be based on the visibileOffsetX/Y- while moving server window based on WindowOffsetX/Y. I have seen various issues regarding this when trying to use a maximized window where this is a disconnect between local window coordinates and remote window coordinates. This change clears these things up. 4. Commented the XShapeCombineRectangles calls - this can cause issues where the entire window is not visible and it does not currently play well with the changes from #3. The gain here is greater than the loss. 5. Draw the initial workspace correctly when running across multiple monitors. The correct size was always used, but the window was only starting on the current monitor and thus could draw the window off of the viewable area. Known Issues: Although the changes for #2 worked well in the stable branch that I developed from - the desktop window shown once the rail windows are destroyed does not respond to input unless I minimize/restore the window. Once the window starts responding to input - you can hit cancel to close the desktop window and return to your rail windows again(or launch task manager, etc.). This is still a big step in the right direction as xfreerdp is now correctly acting when the rail server stops Actively Monitoring the desktop. XShapeCombineRectangles needs to be revisited, most windows applications will give you a rectangular window anyways.
2012-08-04 02:35:17 +04:00
{
2018-01-24 18:26:27 +03:00
int i;
BOOL status;
BOOL maxVert = FALSE;
BOOL maxHorz = FALSE;
BOOL minimized = FALSE;
BOOL minimizedChanged = FALSE;
unsigned long nitems;
unsigned long bytes;
unsigned char* prop;
xfAppWindow* appWindow = NULL;
if (app)
{
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
if (!appWindow)
return TRUE;
}
2018-01-24 18:26:27 +03:00
if ((Atom) event->xproperty.atom == xfc->_NET_WM_STATE)
2016-07-19 17:15:38 +03:00
{
2018-01-24 18:26:27 +03:00
status = xf_GetWindowProperty(xfc, event->xproperty.window,
xfc->_NET_WM_STATE, 12, &nitems, &bytes, &prop);
Multiple RAIL fixes/improvements 1. Linked Window Manager Maximize/Minimize and Restore operations to those from the Server Rail Window so that they are in sync 2. Enable things like "CTRL-ALT-DELETE" and "WindowsKey-L" to show the full desktop window again since the desktop is not actively monitored since this was still trying to draw to the rail window without updating the size of the window to accomodate the full workspace area. 3. Changed local window coordinates to be based on the visibileOffsetX/Y- while moving server window based on WindowOffsetX/Y. I have seen various issues regarding this when trying to use a maximized window where this is a disconnect between local window coordinates and remote window coordinates. This change clears these things up. 4. Commented the XShapeCombineRectangles calls - this can cause issues where the entire window is not visible and it does not currently play well with the changes from #3. The gain here is greater than the loss. 5. Draw the initial workspace correctly when running across multiple monitors. The correct size was always used, but the window was only starting on the current monitor and thus could draw the window off of the viewable area. Known Issues: Although the changes for #2 worked well in the stable branch that I developed from - the desktop window shown once the rail windows are destroyed does not respond to input unless I minimize/restore the window. Once the window starts responding to input - you can hit cancel to close the desktop window and return to your rail windows again(or launch task manager, etc.). This is still a big step in the right direction as xfreerdp is now correctly acting when the rail server stops Actively Monitoring the desktop. XShapeCombineRectangles needs to be revisited, most windows applications will give you a rectangular window anyways.
2012-08-04 02:35:17 +04:00
2018-01-24 18:26:27 +03:00
if (status)
{
for (i = 0; i < nitems; i++)
2013-03-29 07:09:28 +04:00
{
2018-01-24 18:26:27 +03:00
if ((Atom)((UINT16**) prop)[i] == XInternAtom(xfc->display,
"_NET_WM_STATE_MAXIMIZED_VERT", False))
2013-03-29 07:09:28 +04:00
{
2018-01-24 18:26:27 +03:00
maxVert = TRUE;
2013-03-29 07:09:28 +04:00
}
2018-01-24 18:26:27 +03:00
if ((Atom)((UINT16**) prop)[i] == XInternAtom(xfc->display,
"_NET_WM_STATE_MAXIMIZED_HORZ", False))
{
maxHorz = TRUE;
}
2013-03-29 07:09:28 +04:00
}
2018-01-24 18:26:27 +03:00
XFree(prop);
2016-07-19 17:15:38 +03:00
}
2018-01-24 18:26:27 +03:00
}
2018-01-24 18:26:27 +03:00
if ((Atom) event->xproperty.atom == xfc->WM_STATE)
{
status = xf_GetWindowProperty(xfc, event->xproperty.window,
xfc->WM_STATE, 1, &nitems, &bytes, &prop);
if (status)
2016-07-19 17:15:38 +03:00
{
2018-01-24 18:26:27 +03:00
/* If the window is in the iconic state */
if (((UINT32) *prop == 3))
minimized = TRUE;
else
minimized = FALSE;
minimizedChanged = TRUE;
XFree(prop);
}
}
2013-03-29 07:09:28 +04:00
2018-01-24 18:26:27 +03:00
if (app)
{
2016-07-19 17:15:38 +03:00
if (maxVert && maxHorz && !minimized
&& (appWindow->rail_state != WINDOW_SHOW_MAXIMIZED))
{
appWindow->rail_state = WINDOW_SHOW_MAXIMIZED;
xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_MAXIMIZE);
}
else if (minimized && (appWindow->rail_state != WINDOW_SHOW_MINIMIZED))
{
appWindow->rail_state = WINDOW_SHOW_MINIMIZED;
xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_MINIMIZE);
}
else if (!minimized && !maxVert && !maxHorz
&& (appWindow->rail_state != WINDOW_SHOW))
{
appWindow->rail_state = WINDOW_SHOW;
xf_rail_send_client_system_command(xfc, appWindow->windowId, SC_RESTORE);
}
}
2018-01-24 18:26:27 +03:00
else if (minimizedChanged)
gdi_send_suppress_output(xfc->context.gdi, minimized);
2016-07-19 17:15:38 +03:00
}
2011-09-23 07:37:17 +04:00
return TRUE;
2011-09-23 07:37:17 +04:00
}
2016-07-19 17:15:38 +03:00
static BOOL xf_event_suppress_events(xfContext* xfc, xfAppWindow* appWindow,
XEvent* event)
{
if (!xfc->remote_app)
return FALSE;
switch (appWindow->local_move.state)
{
case LMS_NOT_ACTIVE:
2016-07-19 17:15:38 +03:00
/* No local move in progress, nothing to do */
/* Prevent Configure from happening during indeterminant state of Horz or Vert Max only */
2016-07-19 17:15:38 +03:00
if ((event->type == ConfigureNotify) && appWindow->rail_ignore_configure)
{
appWindow->rail_ignore_configure = FALSE;
return TRUE;
}
Multiple RAIL fixes/improvements 1. Linked Window Manager Maximize/Minimize and Restore operations to those from the Server Rail Window so that they are in sync 2. Enable things like "CTRL-ALT-DELETE" and "WindowsKey-L" to show the full desktop window again since the desktop is not actively monitored since this was still trying to draw to the rail window without updating the size of the window to accomodate the full workspace area. 3. Changed local window coordinates to be based on the visibileOffsetX/Y- while moving server window based on WindowOffsetX/Y. I have seen various issues regarding this when trying to use a maximized window where this is a disconnect between local window coordinates and remote window coordinates. This change clears these things up. 4. Commented the XShapeCombineRectangles calls - this can cause issues where the entire window is not visible and it does not currently play well with the changes from #3. The gain here is greater than the loss. 5. Draw the initial workspace correctly when running across multiple monitors. The correct size was always used, but the window was only starting on the current monitor and thus could draw the window off of the viewable area. Known Issues: Although the changes for #2 worked well in the stable branch that I developed from - the desktop window shown once the rail windows are destroyed does not respond to input unless I minimize/restore the window. Once the window starts responding to input - you can hit cancel to close the desktop window and return to your rail windows again(or launch task manager, etc.). This is still a big step in the right direction as xfreerdp is now correctly acting when the rail server stops Actively Monitoring the desktop. XShapeCombineRectangles needs to be revisited, most windows applications will give you a rectangular window anyways.
2012-08-04 02:35:17 +04:00
break;
case LMS_STARTING:
2016-07-19 17:15:38 +03:00
/* Local move initiated by RDP server, but we have not yet seen any updates from the X server */
switch (event->type)
{
case ConfigureNotify:
/* Starting to see move events from the X server. Local move is now in progress. */
appWindow->local_move.state = LMS_ACTIVE;
/* Allow these events to be processed during move to keep our state up to date. */
break;
2016-07-19 17:15:38 +03:00
case ButtonPress:
case ButtonRelease:
case KeyPress:
case KeyRelease:
case UnmapNotify:
2016-07-19 17:15:38 +03:00
/*
* A button release event means the X window server did not grab the
* mouse before the user released it. In this case we must cancel the
* local move. The event will be processed below as normal, below.
*/
break;
case VisibilityNotify:
case PropertyNotify:
case Expose:
/* Allow these events to pass */
break;
2016-07-19 17:15:38 +03:00
default:
/* Eat any other events */
return TRUE;
}
2016-07-19 17:15:38 +03:00
break;
case LMS_ACTIVE:
2016-07-19 17:15:38 +03:00
/* Local move is in progress */
switch (event->type)
{
case ConfigureNotify:
case VisibilityNotify:
case PropertyNotify:
case Expose:
Multiple RAIL fixes/improvements 1. Linked Window Manager Maximize/Minimize and Restore operations to those from the Server Rail Window so that they are in sync 2. Enable things like "CTRL-ALT-DELETE" and "WindowsKey-L" to show the full desktop window again since the desktop is not actively monitored since this was still trying to draw to the rail window without updating the size of the window to accomodate the full workspace area. 3. Changed local window coordinates to be based on the visibileOffsetX/Y- while moving server window based on WindowOffsetX/Y. I have seen various issues regarding this when trying to use a maximized window where this is a disconnect between local window coordinates and remote window coordinates. This change clears these things up. 4. Commented the XShapeCombineRectangles calls - this can cause issues where the entire window is not visible and it does not currently play well with the changes from #3. The gain here is greater than the loss. 5. Draw the initial workspace correctly when running across multiple monitors. The correct size was always used, but the window was only starting on the current monitor and thus could draw the window off of the viewable area. Known Issues: Although the changes for #2 worked well in the stable branch that I developed from - the desktop window shown once the rail windows are destroyed does not respond to input unless I minimize/restore the window. Once the window starts responding to input - you can hit cancel to close the desktop window and return to your rail windows again(or launch task manager, etc.). This is still a big step in the right direction as xfreerdp is now correctly acting when the rail server stops Actively Monitoring the desktop. XShapeCombineRectangles needs to be revisited, most windows applications will give you a rectangular window anyways.
2012-08-04 02:35:17 +04:00
case GravityNotify:
/* Keep us up to date on position */
break;
2016-07-19 17:15:38 +03:00
default:
/* Any other event terminates move */
xf_rail_end_local_move(xfc, appWindow);
break;
}
2016-07-19 17:15:38 +03:00
break;
case LMS_TERMINATING:
/* Already sent RDP end move to server. Allow events to pass. */
break;
}
return FALSE;
}
BOOL xf_event_process(freerdp* instance, XEvent* event)
{
BOOL status = TRUE;
xfAppWindow* appWindow;
xfContext* xfc = (xfContext*) instance->context;
2017-12-21 13:04:50 +03:00
rdpSettings* settings = xfc->context.settings;
if (xfc->remote_app)
{
appWindow = xf_AppWindowFromX11Window(xfc, event->xany.window);
if (appWindow)
{
/* Update "current" window for cursor change orders */
xfc->appWindow = appWindow;
if (xf_event_suppress_events(xfc, appWindow, event))
return TRUE;
}
}
xf_event_execute_action_script(xfc, event);
2011-08-19 19:12:30 +04:00
if (event->type != MotionNotify)
2018-01-24 18:26:27 +03:00
{
DEBUG_X11("%s Event(%d): wnd=0x%08lX", x11_event_string(event->type),
event->type, (unsigned long) event->xany.window);
2018-01-24 18:26:27 +03:00
}
2011-08-19 19:12:30 +04:00
switch (event->type)
{
case Expose:
status = xf_event_Expose(xfc, event, xfc->remote_app);
break;
case VisibilityNotify:
status = xf_event_VisibilityNotify(xfc, event, xfc->remote_app);
break;
case MotionNotify:
status = xf_event_MotionNotify(xfc, event, xfc->remote_app);
break;
case ButtonPress:
status = xf_event_ButtonPress(xfc, event, xfc->remote_app);
break;
case ButtonRelease:
status = xf_event_ButtonRelease(xfc, event, xfc->remote_app);
break;
case KeyPress:
status = xf_event_KeyPress(xfc, event, xfc->remote_app);
break;
case KeyRelease:
status = xf_event_KeyRelease(xfc, event, xfc->remote_app);
break;
case FocusIn:
status = xf_event_FocusIn(xfc, event, xfc->remote_app);
break;
case FocusOut:
status = xf_event_FocusOut(xfc, event, xfc->remote_app);
break;
case EnterNotify:
status = xf_event_EnterNotify(xfc, event, xfc->remote_app);
break;
case LeaveNotify:
status = xf_event_LeaveNotify(xfc, event, xfc->remote_app);
break;
case NoExpose:
break;
case GraphicsExpose:
break;
case ConfigureNotify:
status = xf_event_ConfigureNotify(xfc, event, xfc->remote_app);
break;
case MapNotify:
status = xf_event_MapNotify(xfc, event, xfc->remote_app);
break;
case UnmapNotify:
status = xf_event_UnmapNotify(xfc, event, xfc->remote_app);
break;
case ReparentNotify:
break;
case MappingNotify:
status = xf_event_MappingNotify(xfc, event, xfc->remote_app);
break;
case ClientMessage:
status = xf_event_ClientMessage(xfc, event, xfc->remote_app);
break;
2011-09-23 07:37:17 +04:00
case PropertyNotify:
status = xf_event_PropertyNotify(xfc, event, xfc->remote_app);
2011-09-23 07:37:17 +04:00
break;
default:
if (settings->SupportDisplayControl && xfc->xfDisp)
xf_disp_handle_xevent(xfc, event);
2017-12-21 13:04:50 +03:00
break;
}
xf_cliprdr_handle_xevent(xfc, event);
xf_input_handle_event(xfc, event);
XSync(xfc->display, FALSE);
return status;
}