core: Pass MetaWindow on passive button grab machinery

In practical effects the passed Window is always window->xwindow,
so pass the MetaWindow and get the better X11 Window deep in the
call stack.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2954>
This commit is contained in:
Carlos Garnacho 2023-04-12 10:21:54 +02:00
parent e30abee5a2
commit a42bc34e4d
4 changed files with 27 additions and 22 deletions

View File

@ -237,9 +237,9 @@ GSList* meta_display_list_windows (MetaDisplay *display,
void meta_display_reload_cursor (MetaDisplay *display); void meta_display_reload_cursor (MetaDisplay *display);
void meta_display_grab_window_buttons (MetaDisplay *display, void meta_display_grab_window_buttons (MetaDisplay *display,
Window xwindow); MetaWindow *window);
void meta_display_ungrab_window_buttons (MetaDisplay *display, void meta_display_ungrab_window_buttons (MetaDisplay *display,
Window xwindow); MetaWindow *window);
void meta_display_grab_focus_window_button (MetaDisplay *display, void meta_display_grab_focus_window_button (MetaDisplay *display,
MetaWindow *window); MetaWindow *window);

View File

@ -1176,7 +1176,7 @@ calc_grab_modifiers (MetaKeyBindingManager *keys,
static void static void
meta_change_button_grab (MetaKeyBindingManager *keys, meta_change_button_grab (MetaKeyBindingManager *keys,
Window xwindow, MetaWindow *window,
gboolean grab, gboolean grab,
gboolean sync, gboolean sync,
int button, int button,
@ -1186,10 +1186,13 @@ meta_change_button_grab (MetaKeyBindingManager *keys,
Display *xdisplay; Display *xdisplay;
unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 }; unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits }; XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
Window xwindow;
GArray *mods; GArray *mods;
if (meta_is_wayland_compositor ()) if (meta_is_wayland_compositor ())
return; return;
if (window->client_type != META_WINDOW_CLIENT_TYPE_X11)
return;
backend = META_BACKEND_X11 (keys->backend); backend = META_BACKEND_X11 (keys->backend);
xdisplay = meta_backend_x11_get_xdisplay (backend); xdisplay = meta_backend_x11_get_xdisplay (backend);
@ -1202,6 +1205,8 @@ meta_change_button_grab (MetaKeyBindingManager *keys,
meta_clutter_x11_trap_x_errors (); meta_clutter_x11_trap_x_errors ();
xwindow = window->xwindow;
/* GrabModeSync means freeze until XAllowEvents */ /* GrabModeSync means freeze until XAllowEvents */
if (grab) if (grab)
XIGrabButton (xdisplay, XIGrabButton (xdisplay,
@ -1231,7 +1236,7 @@ meta_display_get_compositor_modifiers (MetaDisplay *display)
static void static void
meta_change_buttons_grab (MetaKeyBindingManager *keys, meta_change_buttons_grab (MetaKeyBindingManager *keys,
Window xwindow, MetaWindow *window,
gboolean grab, gboolean grab,
gboolean sync, gboolean sync,
int modmask) int modmask)
@ -1240,12 +1245,12 @@ meta_change_buttons_grab (MetaKeyBindingManager *keys,
int i; int i;
for (i = 1; i <= MAX_BUTTON; i++) for (i = 1; i <= MAX_BUTTON; i++)
meta_change_button_grab (keys, xwindow, grab, sync, i, modmask); meta_change_button_grab (keys, window, grab, sync, i, modmask);
} }
void void
meta_display_grab_window_buttons (MetaDisplay *display, meta_display_grab_window_buttons (MetaDisplay *display,
Window xwindow) MetaWindow *window)
{ {
MetaKeyBindingManager *keys = &display->key_binding_manager; MetaKeyBindingManager *keys = &display->key_binding_manager;
@ -1254,7 +1259,7 @@ meta_display_grab_window_buttons (MetaDisplay *display,
* Grab Alt + button3 for popping up window menu. * Grab Alt + button3 for popping up window menu.
* Grab Alt + Shift + button1 for snap-moving window. * Grab Alt + Shift + button1 for snap-moving window.
*/ */
meta_verbose ("Grabbing window buttons for 0x%lx", xwindow); meta_verbose ("Grabbing window buttons for %s", window->desc);
/* FIXME If we ignored errors here instead of spewing, we could /* FIXME If we ignored errors here instead of spewing, we could
* put one big error trap around the loop and avoid a bunch of * put one big error trap around the loop and avoid a bunch of
@ -1263,7 +1268,7 @@ meta_display_grab_window_buttons (MetaDisplay *display,
if (keys->window_grab_modifiers != 0) if (keys->window_grab_modifiers != 0)
{ {
meta_change_buttons_grab (keys, xwindow, TRUE, FALSE, meta_change_buttons_grab (keys, window, TRUE, FALSE,
keys->window_grab_modifiers); keys->window_grab_modifiers);
/* In addition to grabbing Alt+Button1 for moving the window, /* In addition to grabbing Alt+Button1 for moving the window,
@ -1272,7 +1277,7 @@ meta_display_grab_window_buttons (MetaDisplay *display,
* Shift+Alt+Button1 for some reason; so at least part of the * Shift+Alt+Button1 for some reason; so at least part of the
* order still matters, which sucks (please FIXME). * order still matters, which sucks (please FIXME).
*/ */
meta_change_button_grab (keys, xwindow, meta_change_button_grab (keys, window,
TRUE, TRUE,
FALSE, FALSE,
1, keys->window_grab_modifiers | ShiftMask); 1, keys->window_grab_modifiers | ShiftMask);
@ -1281,14 +1286,14 @@ meta_display_grab_window_buttons (MetaDisplay *display,
void void
meta_display_ungrab_window_buttons (MetaDisplay *display, meta_display_ungrab_window_buttons (MetaDisplay *display,
Window xwindow) MetaWindow *window)
{ {
MetaKeyBindingManager *keys = &display->key_binding_manager; MetaKeyBindingManager *keys = &display->key_binding_manager;
if (keys->window_grab_modifiers == 0) if (keys->window_grab_modifiers == 0)
return; return;
meta_change_buttons_grab (keys, xwindow, FALSE, FALSE, meta_change_buttons_grab (keys, window, FALSE, FALSE,
keys->window_grab_modifiers); keys->window_grab_modifiers);
} }
@ -1329,7 +1334,7 @@ meta_display_grab_focus_window_button (MetaDisplay *display,
* XSync() * XSync()
*/ */
meta_change_buttons_grab (keys, window->xwindow, TRUE, TRUE, XIAnyModifier); meta_change_buttons_grab (keys, window, TRUE, TRUE, XIAnyModifier);
window->have_focus_click_grab = TRUE; window->have_focus_click_grab = TRUE;
} }
@ -1344,7 +1349,7 @@ meta_display_ungrab_focus_window_button (MetaDisplay *display,
if (!window->have_focus_click_grab) if (!window->have_focus_click_grab)
return; return;
meta_change_buttons_grab (keys, window->xwindow, FALSE, FALSE, XIAnyModifier); meta_change_buttons_grab (keys, window, FALSE, FALSE, XIAnyModifier);
window->have_focus_click_grab = FALSE; window->have_focus_click_grab = FALSE;
} }
@ -1376,7 +1381,7 @@ prefs_changed_callback (MetaPreference pref,
for (l = windows; l; l = l->next) for (l = windows; l; l = l->next)
{ {
MetaWindow *w = l->data; MetaWindow *w = l->data;
meta_display_ungrab_window_buttons (display, w->xwindow); meta_display_ungrab_window_buttons (display, w);
} }
update_window_grab_modifiers (display); update_window_grab_modifiers (display);
@ -1385,7 +1390,7 @@ prefs_changed_callback (MetaPreference pref,
{ {
MetaWindow *w = l->data; MetaWindow *w = l->data;
if (w->type != META_WINDOW_DOCK) if (w->type != META_WINDOW_DOCK)
meta_display_grab_window_buttons (display, w->xwindow); meta_display_grab_window_buttons (display, w);
} }
g_slist_free (windows); g_slist_free (windows);

View File

@ -5194,7 +5194,7 @@ meta_window_set_focused_internal (MetaWindow *window,
meta_display_ungrab_focus_window_button (window->display, window); meta_display_ungrab_focus_window_button (window->display, window);
/* Since we ungrab with XIAnyModifier above, all button /* Since we ungrab with XIAnyModifier above, all button
grabs go way so we need to re-grab the window buttons. */ grabs go way so we need to re-grab the window buttons. */
meta_display_grab_window_buttons (window->display, window->xwindow); meta_display_grab_window_buttons (window->display, window);
} }
g_signal_emit (window, window_signals[FOCUS], 0); g_signal_emit (window, window_signals[FOCUS], 0);

View File

@ -706,7 +706,7 @@ meta_window_x11_unmanage (MetaWindow *window)
XShapeSelectInput (x11_display->xdisplay, window->xwindow, NoEventMask); XShapeSelectInput (x11_display->xdisplay, window->xwindow, NoEventMask);
meta_window_ungrab_keys (window); meta_window_ungrab_keys (window);
meta_display_ungrab_window_buttons (window->display, window->xwindow); meta_display_ungrab_window_buttons (window->display, window);
meta_display_ungrab_focus_window_button (window->display, window); meta_display_ungrab_focus_window_button (window->display, window);
meta_x11_error_trap_pop (x11_display); meta_x11_error_trap_pop (x11_display);
@ -3861,7 +3861,7 @@ meta_window_x11_new (MetaDisplay *display,
meta_window_grab_keys (window); meta_window_grab_keys (window);
if (window->type != META_WINDOW_DOCK && !window->override_redirect) if (window->type != META_WINDOW_DOCK && !window->override_redirect)
{ {
meta_display_grab_window_buttons (window->display, window->xwindow); meta_display_grab_window_buttons (window->display, window);
meta_display_grab_focus_window_button (window->display, window); meta_display_grab_focus_window_button (window->display, window);
} }