From de2a24b313276d8f59b7f9e57465203bb176f49e Mon Sep 17 00:00:00 2001 From: Bilal Elmoussaoui Date: Wed, 14 Feb 2024 14:25:38 +0100 Subject: [PATCH] window: Move keys_grabbed to WindowX11 Part-of: --- src/core/keybindings.c | 23 ++++++++++++++++------- src/core/window-private.h | 1 - src/core/window.c | 1 - src/x11/window-x11-private.h | 3 +++ src/x11/window-x11.c | 2 ++ 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/core/keybindings.c b/src/core/keybindings.c index 8a50c84bc..cfbf35d5f 100644 --- a/src/core/keybindings.c +++ b/src/core/keybindings.c @@ -46,7 +46,7 @@ #include "meta/prefs.h" #include "mtk/mtk-x11.h" #include "x11/meta-x11-display-private.h" -#include "x11/window-x11.h" +#include "x11/window-x11-private.h" #ifdef HAVE_NATIVE_BACKEND #include "backends/native/meta-backend-native.h" @@ -1601,20 +1601,22 @@ meta_window_grab_keys (MetaWindow *window) { MetaDisplay *display = window->display; MetaKeyBindingManager *keys = &display->key_binding_manager; + MetaWindowX11Private *priv; if (meta_is_wayland_compositor ()) return; + priv = meta_window_x11_get_private (META_WINDOW_X11 (window)); if (window->type == META_WINDOW_DOCK || window->override_redirect) { - if (window->keys_grabbed) + if (priv->keys_grabbed) change_window_keygrabs (keys, meta_window_x11_get_xwindow (window), FALSE); - window->keys_grabbed = FALSE; + priv->keys_grabbed = FALSE; return; } - if (window->keys_grabbed) + if (priv->keys_grabbed) { if (window->frame && !window->grab_on_frame) change_window_keygrabs (keys, meta_window_x11_get_xwindow (window), FALSE); @@ -1629,14 +1631,21 @@ meta_window_grab_keys (MetaWindow *window) meta_window_x11_get_toplevel_xwindow (window), TRUE); - window->keys_grabbed = TRUE; + priv->keys_grabbed = TRUE; window->grab_on_frame = window->frame != NULL; } void meta_window_ungrab_keys (MetaWindow *window) { - if (!meta_is_wayland_compositor () && window->keys_grabbed) + MetaWindowX11Private *priv; + + if (meta_is_wayland_compositor ()) + return; + + priv = meta_window_x11_get_private (META_WINDOW_X11 (window)); + + if (priv->keys_grabbed) { MetaDisplay *display = window->display; MetaKeyBindingManager *keys = &display->key_binding_manager; @@ -1647,7 +1656,7 @@ meta_window_ungrab_keys (MetaWindow *window) else if (!window->grab_on_frame) change_window_keygrabs (keys, meta_window_x11_get_xwindow (window), FALSE); - window->keys_grabbed = FALSE; + priv->keys_grabbed = FALSE; } } diff --git a/src/core/window-private.h b/src/core/window-private.h index 26b96a1da..58efabc0d 100644 --- a/src/core/window-private.h +++ b/src/core/window-private.h @@ -507,7 +507,6 @@ struct _MetaWindow guint constructing : 1; /* Used by keybindings.c */ - guint keys_grabbed : 1; /* normal keybindings grabbed */ guint grab_on_frame : 1; /* grabs are on the frame */ /* Set if the reason for unmanaging the window is that diff --git a/src/core/window.c b/src/core/window.c index 9bf30a791..95d1785c8 100644 --- a/src/core/window.c +++ b/src/core/window.c @@ -1059,7 +1059,6 @@ meta_window_constructed (GObject *object) window->placed = ((window->mapped && !window->hidden) || window->override_redirect); window->denied_focus_and_not_transient = FALSE; window->unmanaging = FALSE; - window->keys_grabbed = FALSE; window->grab_on_frame = FALSE; window->withdrawn = FALSE; window->initial_workspace_set = FALSE; diff --git a/src/x11/window-x11-private.h b/src/x11/window-x11-private.h index 30bde7dee..da10f6c52 100644 --- a/src/x11/window-x11-private.h +++ b/src/x11/window-x11-private.h @@ -91,6 +91,9 @@ struct _MetaWindowX11Private MetaGroup *group; MetaSyncCounter sync_counter; + + /* Used by keybindings.c */ + gboolean keys_grabbed; /* normal keybindings grabbed */ }; MetaWindowX11Private * meta_window_x11_get_private (MetaWindowX11 *window_x11); diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c index 95b6b55a0..aebf583fe 100644 --- a/src/x11/window-x11.c +++ b/src/x11/window-x11.c @@ -2087,6 +2087,8 @@ meta_window_x11_constructed (GObject *object) priv->border_width = attrs.border_width; priv->xclient_leader = None; + priv->keys_grabbed = FALSE; + g_signal_connect (window, "notify::decorated", G_CALLBACK (meta_window_x11_update_input_region), window);