File mutter-SLE-bsc984738-grab-display.patch of Package mutter-federico

From 147d0d2033fb748dee260c3a24680e3c88766feb Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Thu, 17 Oct 2019 08:35:23 -0500
Subject: [PATCH 1/7] MetaX11Display: Add a server_grab_count field

---
 src/x11/meta-x11-display-private.h | 2 ++
 src/x11/meta-x11-display.c         | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h
index 7c61d7b0d..c52bfec25 100644
--- a/src/x11/meta-x11-display-private.h
+++ b/src/x11/meta-x11-display-private.h
@@ -62,6 +62,8 @@ struct _MetaX11Display
 
   guint32 timestamp;
 
+  guint server_grab_count;
+
   /* Pull in all the names of atoms as fields; we will intern them when the
    * class is constructed.
    */
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index 3ae5b3d8d..0ac350b4c 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -1176,6 +1176,8 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
   x11_display->xdisplay = xdisplay;
   x11_display->xroot = xroot;
 
+  x11_display->server_grab_count = 0;
+
   x11_display->name = g_strdup (XDisplayName (NULL));
   x11_display->screen_name = get_screen_name (xdisplay, number);
   x11_display->default_xvisual = DefaultVisualOfScreen (xscreen);
-- 
2.20.1


From 5794f63b8e6cdf3755644c6885e1c4b1be90a8de Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Thu, 17 Oct 2019 08:48:52 -0500
Subject: [PATCH 2/7] Add back meta_x11_display_grab()/ungrab()

---
 src/x11/meta-x11-display-private.h |  3 +++
 src/x11/meta-x11-display.c         | 34 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h
index c52bfec25..4ba4b10da 100644
--- a/src/x11/meta-x11-display-private.h
+++ b/src/x11/meta-x11-display-private.h
@@ -187,6 +187,9 @@ struct _MetaX11Display
 
 MetaX11Display *meta_x11_display_new (MetaDisplay *display, GError **error);
 
+void meta_x11_display_grab (MetaX11Display *x11_display);
+void meta_x11_display_ungrab (MetaX11Display *x11_display);
+
 void meta_x11_display_restore_active_workspace (MetaX11Display *x11_display);
 
 Window meta_x11_display_create_offscreen_window (MetaX11Display *x11_display,
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index 0ac350b4c..72b479398 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -1366,6 +1366,40 @@ meta_x11_display_new (MetaDisplay *display, GError **error)
   return x11_display;
 }
 
+void
+meta_x11_display_grab (MetaX11Display *x11_display)
+{
+  g_return_if_fail (META_IS_X11_DISPLAY (x11_display));
+
+  if (x11_display->server_grab_count == 0)
+    {
+      XGrabServer (x11_display->xdisplay);
+    }
+
+  x11_display->server_grab_count += 1;
+  meta_verbose ("Grabbing X display, grab count now %d\n", x11_display->server_grab_count);
+}
+
+void
+meta_x11_display_ungrab (MetaX11Display *x11_display)
+{
+  g_return_if_fail (META_IS_X11_DISPLAY (x11_display));
+
+  if (x11_display->server_grab_count == 0)
+    {
+      meta_bug ("Tried to ungrab non-grabbbed X server\n");
+    }
+
+  x11_display->server_grab_count -= 1;
+  if (x11_display->server_grab_count == 0)
+    {
+      XUngrabServer (x11_display->xdisplay);
+      XFlush (x11_display->xdisplay);
+    }
+
+  meta_verbose ("Ungrabbing X display, grab count now %d\n", x11_display->server_grab_count);
+}
+
 void
 meta_x11_display_restore_active_workspace (MetaX11Display *x11_display)
 {
-- 
2.20.1


From 74b58cdfc271ac781a9f274dead3d798415611eb Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Thu, 17 Oct 2019 10:26:14 -0500
Subject: [PATCH 3/7] Add meta_display_grab()/ungrab()

---
 src/core/display-private.h |  3 +++
 src/core/display.c         | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/src/core/display-private.h b/src/core/display-private.h
index ae8bb2ba6..24bcb5e35 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -268,6 +268,9 @@ void meta_display_manage_all_xwindows (MetaDisplay *display);
 void meta_display_unmanage_windows   (MetaDisplay *display,
                                       guint32      timestamp);
 
+void meta_display_grab (MetaDisplay *display);
+void meta_display_ungrab (MetaDisplay *display);
+
 /* Utility function to compare the stacking of two windows */
 int           meta_display_stack_cmp           (const void *a,
                                                 const void *b);
diff --git a/src/core/display.c b/src/core/display.c
index 82c9cd108..d259afddc 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -2524,6 +2524,24 @@ meta_display_unmanage_windows (MetaDisplay *display,
   g_slist_free (winlist);
 }
 
+void
+meta_display_grab (MetaDisplay *display)
+{
+  if (display->x11_display)
+    {
+      meta_x11_display_grab (display->x11_display);
+    }
+}
+
+void
+meta_display_ungrab (MetaDisplay *display)
+{
+  if (display->x11_display)
+    {
+      meta_x11_display_ungrab (display->x11_display);
+    }
+}
+
 int
 meta_display_stack_cmp (const void *a,
                         const void *b)
-- 
2.20.1


From be447bac4a52346d6bc86e68d89a3e7a92ebc383 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Thu, 17 Oct 2019 11:56:26 -0500
Subject: [PATCH 4/7] Add is_grabbed functions for MetaDisplay and
 MetaX11Display

---
 src/core/display-private.h         |  1 +
 src/core/display.c                 | 13 +++++++++++++
 src/x11/meta-x11-display-private.h |  1 +
 src/x11/meta-x11-display.c         |  8 ++++++++
 4 files changed, 23 insertions(+)

diff --git a/src/core/display-private.h b/src/core/display-private.h
index 24bcb5e35..cc3e6158a 100644
--- a/src/core/display-private.h
+++ b/src/core/display-private.h
@@ -270,6 +270,7 @@ void meta_display_unmanage_windows   (MetaDisplay *display,
 
 void meta_display_grab (MetaDisplay *display);
 void meta_display_ungrab (MetaDisplay *display);
+gboolean meta_display_is_grabbed (MetaDisplay *display);
 
 /* Utility function to compare the stacking of two windows */
 int           meta_display_stack_cmp           (const void *a,
diff --git a/src/core/display.c b/src/core/display.c
index d259afddc..520b746e7 100644
--- a/src/core/display.c
+++ b/src/core/display.c
@@ -2542,6 +2542,19 @@ meta_display_ungrab (MetaDisplay *display)
     }
 }
 
+gboolean
+meta_display_is_grabbed (MetaDisplay *display)
+{
+  if (display->x11_display)
+    {
+      return meta_x11_display_is_grabbed (display->x11_display);
+    }
+  else
+    {
+      return FALSE;
+    }
+}
+
 int
 meta_display_stack_cmp (const void *a,
                         const void *b)
diff --git a/src/x11/meta-x11-display-private.h b/src/x11/meta-x11-display-private.h
index 4ba4b10da..d0639a9d8 100644
--- a/src/x11/meta-x11-display-private.h
+++ b/src/x11/meta-x11-display-private.h
@@ -189,6 +189,7 @@ MetaX11Display *meta_x11_display_new (MetaDisplay *display, GError **error);
 
 void meta_x11_display_grab (MetaX11Display *x11_display);
 void meta_x11_display_ungrab (MetaX11Display *x11_display);
+gboolean meta_x11_display_is_grabbed (MetaX11Display *x11_display);
 
 void meta_x11_display_restore_active_workspace (MetaX11Display *x11_display);
 
diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index 72b479398..dfdbd8503 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -1400,6 +1400,14 @@ meta_x11_display_ungrab (MetaX11Display *x11_display)
   meta_verbose ("Ungrabbing X display, grab count now %d\n", x11_display->server_grab_count);
 }
 
+gboolean
+meta_x11_display_is_grabbed (MetaX11Display *x11_display)
+{
+  g_return_val_if_fail (META_IS_X11_DISPLAY (x11_display), FALSE);
+
+  return x11_display->server_grab_count > 0;
+}
+
 void
 meta_x11_display_restore_active_workspace (MetaX11Display *x11_display)
 {
-- 
2.20.1


From 71a64a8104c106ba752ece6ea86fbadb5a3a9378 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Thu, 17 Oct 2019 12:07:17 -0500
Subject: [PATCH 5/7] MetaX11Display: use own functions instead of
 XGrabServer() internally

This leaves meta-monitor-manager-xrandr doing its own server grab (on
its own display connection!?), but I don't know how to handle that yet.
---
 src/x11/meta-x11-display.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/src/x11/meta-x11-display.c b/src/x11/meta-x11-display.c
index dfdbd8503..6713c13fd 100644
--- a/src/x11/meta-x11-display.c
+++ b/src/x11/meta-x11-display.c
@@ -1926,7 +1926,7 @@ meta_x11_display_set_input_focus_internal (MetaX11Display *x11_display,
    * we know which is which by making two requests that the server will
    * process at the same time.
    */
-  XGrabServer (x11_display->xdisplay);
+  meta_x11_display_grab (x11_display);
 
   XSetInputFocus (x11_display->xdisplay,
                   xwindow,
@@ -1938,8 +1938,7 @@ meta_x11_display_set_input_focus_internal (MetaX11Display *x11_display,
                    x11_display->atom__MUTTER_FOCUS_SET,
                    XA_STRING, 8, PropModeAppend, NULL, 0);
 
-  XUngrabServer (x11_display->xdisplay);
-  XFlush (x11_display->xdisplay);
+  meta_x11_display_ungrab (x11_display);
 
   meta_x11_error_trap_pop (x11_display);
 }
-- 
2.20.1


From a61823d13f6d46a9feeff1e7e9c344f3da4a1892 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Thu, 17 Oct 2019 12:12:15 -0500
Subject: [PATCH 6/7] No-op if the display is grabbed for the grab-the-buttons
 functions

meta_display_grab_window_buttons
meta_display_ungrab_window_buttons
meta_display_grab_focus_window_button
meta_display_ungrab_focus_window_button
meta_window_grab_keys
meta_window_ungrab_keys
---
 src/core/keybindings.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/core/keybindings.c b/src/core/keybindings.c
index b86272541..017c76cfd 100644
--- a/src/core/keybindings.c
+++ b/src/core/keybindings.c
@@ -1242,6 +1242,9 @@ meta_display_grab_window_buttons (MetaDisplay *display,
 {
   MetaKeyBindingManager *keys = &display->key_binding_manager;
 
+  if (meta_display_is_grabbed (display))
+    return;
+
   /* Grab Alt + button1 for moving window.
    * Grab Alt + button2 for resizing window.
    * Grab Alt + button3 for popping up window menu.
@@ -1278,6 +1281,9 @@ meta_display_ungrab_window_buttons (MetaDisplay *display,
 {
   MetaKeyBindingManager *keys = &display->key_binding_manager;
 
+  if (meta_display_is_grabbed (display))
+    return;
+
   if (keys->window_grab_modifiers == 0)
     return;
 
@@ -1303,6 +1309,9 @@ meta_display_grab_focus_window_button (MetaDisplay *display,
 {
   MetaKeyBindingManager *keys = &display->key_binding_manager;
 
+  if (meta_display_is_grabbed (display))
+    return;
+
   /* Grab button 1 for activating unfocused windows */
   meta_verbose ("Grabbing unfocused window buttons for %s\n", window->desc);
 
@@ -1327,6 +1336,9 @@ meta_display_ungrab_focus_window_button (MetaDisplay *display,
 {
   MetaKeyBindingManager *keys = &display->key_binding_manager;
 
+  if (meta_display_is_grabbed (display))
+    return;
+
   meta_verbose ("Ungrabbing unfocused window buttons for %s\n", window->desc);
 
   if (!window->have_focus_click_grab)
@@ -1572,6 +1584,10 @@ meta_window_grab_keys (MetaWindow  *window)
 
   if (meta_is_wayland_compositor ())
     return;
+
+  if (meta_display_is_grabbed (display))
+    return;
+
   if (window->all_keys_grabbed)
     return;
 
@@ -1606,9 +1622,16 @@ meta_window_grab_keys (MetaWindow  *window)
 void
 meta_window_ungrab_keys (MetaWindow  *window)
 {
-  if (!meta_is_wayland_compositor () && window->keys_grabbed)
+  MetaDisplay *display = window->display;
+
+  if (meta_is_wayland_compositor ())
+    return;
+
+  if (meta_display_is_grabbed (display))
+    return;
+
+  if (window->keys_grabbed)
     {
-      MetaDisplay *display = window->display;
       MetaKeyBindingManager *keys = &display->key_binding_manager;
 
       if (window->grab_on_frame &&
-- 
2.20.1


From 82afe7b68b867e85d095239eb2a5ebd1a23c0df7 Mon Sep 17 00:00:00 2001
From: Federico Mena Quintero <federico@gnome.org>
Date: Thu, 17 Oct 2019 14:22:02 -0500
Subject: [PATCH 7/7] meta_window_x11_manage(): Grab/ungrab the server

---
 src/x11/window-x11.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/x11/window-x11.c b/src/x11/window-x11.c
index 31635a2f5..7b6c78702 100644
--- a/src/x11/window-x11.c
+++ b/src/x11/window-x11.c
@@ -513,6 +513,8 @@ meta_window_x11_manage (MetaWindow *window)
 
   meta_icon_cache_init (&priv->icon_cache);
 
+  meta_display_grab (display);
+
   meta_x11_display_register_x_window (display->x11_display,
                                       &window->xwindow,
                                       window);
@@ -573,6 +575,8 @@ meta_window_x11_manage (MetaWindow *window)
 
   meta_window_x11_update_shape_region (window);
   meta_window_x11_update_input_region (window);
+
+  meta_display_ungrab (display);
 }
 
 static void
-- 
2.20.1

openSUSE Build Service is sponsored by