From c9cc07fd3adce271f5e980b758bc651130d30489 Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Mon, 13 May 2019 11:07:29 +0200 Subject: [PATCH] =?UTF-8?q?settings:=20Slack=20off=20=E2=80=9Cxwayland-all?= =?UTF-8?q?ow-grabs=E2=80=9D=20setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To emulate X11 grabs, mutter as a Wayland compositor would disable its own keyboard shortcuts and when the X11 window is an override redirect window (which never receives focus), it also forces keyboard focus onto that X11 O-R window so that all keyboard events are routed to the window, just like an X11 server would. But that's a bit of a “all-or-nothing” approach which prevents applications that would legitimately grab the keyboard under X11 (like virtual machine viewers) to work by default. Change “xwayland-allow-grabs” to control whether the keyboard focus should be locked onto override redirect windows in case of an X11 grab. For stringent needs, careful users can still use the blacklisting feature (i.e. a list containing “!*”) to prevent grabs from any X11 applications to affect other Wayland native applications. https://gitlab.gnome.org/GNOME/mutter/issues/597 --- data/org.gnome.mutter.wayland.gschema.xml.in | 13 +++++++++--- src/wayland/meta-xwayland-grab-keyboard.c | 22 ++++++++++++++++---- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/data/org.gnome.mutter.wayland.gschema.xml.in b/data/org.gnome.mutter.wayland.gschema.xml.in index 48241296e..bd41e9f18 100644 --- a/data/org.gnome.mutter.wayland.gschema.xml.in +++ b/data/org.gnome.mutter.wayland.gschema.xml.in @@ -61,10 +61,17 @@ false - Allow grabs with Xwayland + Allow X11 grabs to lock keyboard focus with Xwayland - Allow keyboard grabs issued by X11 applications running in Xwayland - to be taken into account. + Allow all keyboard events to be routed to X11 “override redirect” + windows with a grab when running in Xwayland. + + This option is to support X11 clients which map an “override redirect” + window (which do not receive keyboard focus) and issue a keyboard + grab to force all keyboard events to that window. + + This option is seldom used and has no effect on regular X11 windows + which can receive keyboard focus under normal circumstances. For a X11 grab to be taken into account under Wayland, the client must also either send a specific X11 ClientMessage to the root window or be diff --git a/src/wayland/meta-xwayland-grab-keyboard.c b/src/wayland/meta-xwayland-grab-keyboard.c index db2d5f0bd..5724e63a2 100644 --- a/src/wayland/meta-xwayland-grab-keyboard.c +++ b/src/wayland/meta-xwayland-grab-keyboard.c @@ -193,8 +193,6 @@ meta_xwayland_grab_is_granted (MetaWindow *window) backend = meta_get_backend (); settings = meta_backend_get_settings (backend); - if (!meta_settings_are_xwayland_grabs_allowed (settings)) - return FALSE; /* Check whether the window is blacklisted */ meta_settings_get_xwayland_grab_patterns (settings, &whitelist, &blacklist); @@ -214,6 +212,22 @@ meta_xwayland_grab_is_granted (MetaWindow *window) return FALSE; } +static gboolean +meta_xwayland_grab_should_lock_focus (MetaWindow *window) +{ + MetaBackend *backend; + MetaSettings *settings; + + /* Lock focus applies to O-R windows which never receive keyboard focus otherwise */ + if (!window->override_redirect) + return FALSE; + + backend = meta_get_backend (); + settings = meta_backend_get_settings (backend); + + return meta_settings_are_xwayland_grabs_allowed (settings); +} + static void meta_xwayland_keyboard_grab_activate (MetaXwaylandKeyboardActiveGrab *active_grab) { @@ -225,8 +239,8 @@ meta_xwayland_keyboard_grab_activate (MetaXwaylandKeyboardActiveGrab *active_gra { meta_verbose ("XWayland window %s has a grab granted", window->desc); meta_wayland_surface_inhibit_shortcuts (surface, seat); - /* Use a grab for O-R windows which never receive keyboard focus otherwise */ - if (window->override_redirect) + + if (meta_xwayland_grab_should_lock_focus (window)) meta_wayland_keyboard_start_grab (seat->keyboard, &active_grab->keyboard_grab); } if (active_grab->window_associate_handler)