summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Fourdan <ofourdan@redhat.com>2020-05-13 16:48:55 +0200
committerOlivier Fourdan <fourdan@gmail.com>2021-02-02 09:49:35 +0000
commitc7730cfe5577ebde006d408f502766d8c3a73670 (patch)
treef22716c40c8ba86b1bea9b27dd27a1128fd5ad50
parent520e7a1310ddc25b30bcaa0ea3eeaa6c4d137c8c (diff)
xwayland: Translate keyboard grabs on the root window
When an X11 client issues an active grab on the keyboard, Xwayland forward this to the Wayland compositor using the Xwayland specific protocol "xwayland-keyboard-grab" if it can find the corresponding Xwayland window. Some X11 clients (typically older games) however try to issue the keyboard grab on the X11 root window, which has obviously no matching Xwayland window. In such a case, the grab is simply ignored and the game will not work as expected. To workaround that issue, if an X11 client issues a keyboard grab on the root window, Xwayland will search for a toplevel window belonging to the same X11 client that it can use as the grab window instead. This way, the grab can be forwarded to the Wayland compositor that can either grant or deny the request based on the window and its internal policies. The heuristic picks the first realized toplevel window belonging to the client so that the Wayland compositor will send it the keyboard events, and the Xserver grab mechanism will then take care of routing the events to the expected X11 window by itself. v2: Make the test more clear (Dor Askayo <dor.askayo@gmail.com>) Signed-off-by: Olivier Fourdan <ofourdan@redhat.com> Acked-by: Jonas Ã…dahl <jadahl@gmail.com> See-also: https://gitlab.gnome.org/GNOME/mutter/-/issues/1249
-rw-r--r--hw/xwayland/xwayland-input.c30
1 files changed, 28 insertions, 2 deletions
diff --git a/hw/xwayland/xwayland-input.c b/hw/xwayland/xwayland-input.c
index 12efbe169..8e57fda1d 100644
--- a/hw/xwayland/xwayland-input.c
+++ b/hw/xwayland/xwayland-input.c
@@ -1121,17 +1121,43 @@ set_grab(struct xwl_seat *xwl_seat, struct xwl_window *xwl_window)
}
static void
+find_toplevel_callback(void *resource, XID id, void *user_data)
+{
+ WindowPtr window = resource;
+ WindowPtr *toplevel = user_data;
+
+ /* Pick the first realized toplevel we find */
+ if (*toplevel == NullWindow && window->realized && xwl_window_is_toplevel(window))
+ *toplevel = window;
+}
+
+static WindowPtr
+xwl_keyboard_search_window(ClientPtr client)
+{
+ WindowPtr window = NullWindow;
+
+ FindClientResourcesByType(client, RT_WINDOW, find_toplevel_callback, &window);
+
+ return window;
+}
+
+static void
xwl_keyboard_activate_grab(DeviceIntPtr device, GrabPtr grab, TimeStamp time, Bool passive)
{
struct xwl_seat *xwl_seat = device->public.devicePrivate;
+ WindowPtr grab_window = grab->window;
/* We are not interested in passive grabs */
if (!passive) {
/* If the device is the MASTER_KEYBOARD, we don't have an xwl_seat */
if (xwl_seat == NULL)
xwl_seat = find_matching_seat(device);
- if (xwl_seat)
- set_grab(xwl_seat, xwl_window_from_window(grab->window));
+ if (xwl_seat) {
+ if (grab_window == xwl_seat->xwl_screen->screen->root)
+ grab_window = xwl_keyboard_search_window(GetCurrentClient());
+ if (grab_window)
+ set_grab(xwl_seat, xwl_window_from_window(grab_window));
+ }
}
ActivateKeyboardGrab(device, grab, time, passive);