From 88a7790d4436765ad9a2de5058955433b96d2ea7 Mon Sep 17 00:00:00 2001 From: "Owen W. Taylor" Date: Fri, 11 Jul 2014 13:32:07 -0400 Subject: [PATCH] MetaDisplay: remove meta_display_grab()/ungrab() Now that we have two connections to the X server, the idea of a ref-counted server grab that might be held across extended portions of code is very dangerous since we might try to use the backend connection while the frontend connection is grabbed. Replace the only usage (which was local) with direct XGrabServer/XUngrabServer usage and remove the meta_display_grab() API. https://bugzilla.gnome.org/show_bug.cgi?id=733068 --- src/core/display-private.h | 4 --- src/core/display.c | 50 +++----------------------------------- 2 files changed, 3 insertions(+), 51 deletions(-) diff --git a/src/core/display-private.h b/src/core/display-private.h index 034b44723..6ebf78806 100644 --- a/src/core/display-private.h +++ b/src/core/display-private.h @@ -146,8 +146,6 @@ struct _MetaDisplay GHashTable *xids; GHashTable *wayland_windows; - int server_grab_count; - /* serials of leave/unmap events that may * correspond to an enter event we should * ignore @@ -314,8 +312,6 @@ struct _MetaDisplayClass gboolean meta_display_open (void); void meta_display_close (MetaDisplay *display, guint32 timestamp); -void meta_display_grab (MetaDisplay *display); -void meta_display_ungrab (MetaDisplay *display); void meta_display_unmanage_windows_for_screen (MetaDisplay *display, MetaScreen *screen, diff --git a/src/core/display.c b/src/core/display.c index a4bf820fd..4a12e9c6f 100644 --- a/src/core/display.c +++ b/src/core/display.c @@ -512,7 +512,6 @@ meta_display_open (void) */ the_display->name = g_strdup (XDisplayName (NULL)); the_display->xdisplay = xdisplay; - the_display->server_grab_count = 0; the_display->display_opening = TRUE; the_display->pending_pings = NULL; @@ -1076,50 +1075,6 @@ meta_display_close (MetaDisplay *display, meta_quit (META_EXIT_SUCCESS); } -/* Grab/ungrab routines taken from fvwm. - * Calling this function will cause X to ignore all other clients until - * you ungrab. This may not be quite as bad as it sounds, yet there is - * agreement that avoiding server grabs except when they are clearly needed - * is a good thing. - * - * If you do use such grabs, please clearly explain the necessity for their - * usage in a comment. Try to keep their scope extremely limited. In - * particular, try to avoid emitting any signals or notifications while - * a grab is active (if the signal receiver tries to block on an X request - * from another client at this point, you will have a deadlock). - */ -void -meta_display_grab (MetaDisplay *display) -{ - if (display->server_grab_count == 0) - { - XGrabServer (display->xdisplay); - } - display->server_grab_count += 1; - meta_verbose ("Grabbing display, grab count now %d\n", - display->server_grab_count); -} - -void -meta_display_ungrab (MetaDisplay *display) -{ - if (display->server_grab_count == 0) - meta_bug ("Ungrabbed non-grabbed server\n"); - - display->server_grab_count -= 1; - if (display->server_grab_count == 0) - { - /* FIXME we want to purge all pending "queued" stuff - * at this point, such as window hide/show - */ - XUngrabServer (display->xdisplay); - XFlush (display->xdisplay); - } - - meta_verbose ("Ungrabbing display, grab count now %d\n", - display->server_grab_count); -} - /** * meta_display_for_x_display: * @xdisplay: An X display @@ -1554,7 +1509,7 @@ request_xserver_input_focus_change (MetaDisplay *display, * we know which is which by making two requests that the server will * process at the same time. */ - meta_display_grab (display); + XGrabServer (display->xdisplay); serial = XNextRequest (display->xdisplay); @@ -1567,7 +1522,8 @@ request_xserver_input_focus_change (MetaDisplay *display, display->atom__MUTTER_FOCUS_SET, XA_STRING, 8, PropModeAppend, NULL, 0); - meta_display_ungrab (display); + XUngrabServer (display->xdisplay); + XFlush (display->xdisplay); meta_display_update_focus_window (display, meta_window,