Blame SOURCES/0001-backends-x11-Preserve-XI1-XDevice-throughout-Clutter.patch

e47e58
From bc17d94ef058564c1a1adf28a8696164455fea1b Mon Sep 17 00:00:00 2001
e47e58
From: Carlos Garnacho <carlosg@gnome.org>
e47e58
Date: Tue, 30 Jan 2018 13:07:32 +0100
e47e58
Subject: [PATCH] backends/x11: Preserve XI1 XDevice throughout
e47e58
 ClutterInputDevice lifetime
e47e58
e47e58
Opening and closing the device may result into XI2 grabs being cut short,
e47e58
resulting into pad buttons being rendered ineffective, and other possible
e47e58
misbehaviors. This is an XInput flaw that fell in the gap between XI1 and
e47e58
XI2, and has no easy fix. It pays us for mixing both versions, I guess...
e47e58
e47e58
Work this around by keeping the XI1 XDevice attached to the
e47e58
ClutterInputDevice, this way it will live long enough that this is not
e47e58
a concern.
e47e58
e47e58
Investigation of this bug was mostly carried by Peter Hutterer, I'm just
e47e58
the executing hand.
e47e58
e47e58
https://gitlab.gnome.org/GNOME/mutter/issues/7
e47e58
e47e58
Closes: #7
e47e58
---
e47e58
 src/backends/x11/meta-input-settings-x11.c | 48 ++++++++++++++++++++++++++----
e47e58
 1 file changed, 42 insertions(+), 6 deletions(-)
e47e58
e47e58
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
e47e58
index d1ee37a..7a876ef 100644
e47e58
--- a/src/backends/x11/meta-input-settings-x11.c
e47e58
+++ b/src/backends/x11/meta-input-settings-x11.c
e47e58
@@ -55,6 +55,46 @@ enum {
e47e58
   SCROLL_METHOD_NUM_FIELDS
e47e58
 };
e47e58
 
e47e58
+static void
e47e58
+device_free_xdevice (gpointer user_data)
e47e58
+{
e47e58
+  MetaDisplay *display = meta_get_display ();
e47e58
+  MetaBackend *backend = meta_get_backend ();
e47e58
+  Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
e47e58
+  XDevice *xdev = user_data;
e47e58
+
e47e58
+  meta_error_trap_push (display);
e47e58
+  XCloseDevice (xdisplay, xdev);
e47e58
+  meta_error_trap_pop (display);
e47e58
+}
e47e58
+
e47e58
+static XDevice *
e47e58
+device_ensure_xdevice (ClutterInputDevice *device)
e47e58
+{
e47e58
+  MetaDisplay *display = meta_get_display ();
e47e58
+  MetaBackend *backend = meta_get_backend ();
e47e58
+  Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
e47e58
+  int device_id = clutter_input_device_get_device_id (device);
e47e58
+  XDevice *xdev = NULL;
e47e58
+
e47e58
+  xdev = g_object_get_data (G_OBJECT (device), "meta-input-settings-xdevice");
e47e58
+  if (xdev)
e47e58
+    return xdev;
e47e58
+
e47e58
+  meta_error_trap_push (display);
e47e58
+  xdev = XOpenDevice (xdisplay, device_id);
e47e58
+  meta_error_trap_pop (display);
e47e58
+
e47e58
+  if (xdev)
e47e58
+    {
e47e58
+      g_object_set_data_full (G_OBJECT (device),
e47e58
+                              "meta-input-settings-xdevice",
e47e58
+                              xdev, (GDestroyNotify) device_free_xdevice);
e47e58
+    }
e47e58
+
e47e58
+  return xdev;
e47e58
+}
e47e58
+
e47e58
 static void *
e47e58
 get_property (ClutterInputDevice *device,
e47e58
               const gchar        *property,
e47e58
@@ -540,7 +580,6 @@ meta_input_settings_x11_set_tablet_mapping (MetaInputSettings     *settings,
e47e58
   MetaDisplay *display = meta_get_display ();
e47e58
   MetaBackend *backend = meta_get_backend ();
e47e58
   Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
e47e58
-  int device_id = clutter_input_device_get_device_id (device);
e47e58
   XDevice *xdev;
e47e58
 
e47e58
   if (!display)
e47e58
@@ -548,13 +587,12 @@ meta_input_settings_x11_set_tablet_mapping (MetaInputSettings     *settings,
e47e58
 
e47e58
   /* Grab the puke bucket! */
e47e58
   meta_error_trap_push (display);
e47e58
-  xdev = XOpenDevice (xdisplay, device_id);
e47e58
+  xdev = device_ensure_xdevice (device);
e47e58
   if (xdev)
e47e58
     {
e47e58
       XSetDeviceMode (xdisplay, xdev,
e47e58
                       mapping == G_DESKTOP_TABLET_MAPPING_ABSOLUTE ?
e47e58
                       Absolute : Relative);
e47e58
-      XCloseDevice (xdisplay, xdev);
e47e58
     }
e47e58
 
e47e58
   if (meta_error_trap_pop_with_return (display))
e47e58
@@ -737,7 +775,6 @@ meta_input_settings_x11_set_stylus_button_map (MetaInputSettings          *setti
e47e58
   MetaDisplay *display = meta_get_display ();
e47e58
   MetaBackend *backend = meta_get_backend ();
e47e58
   Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
e47e58
-  int device_id = clutter_input_device_get_device_id (device);
e47e58
   XDevice *xdev;
e47e58
 
e47e58
   if (!display)
e47e58
@@ -745,7 +782,7 @@ meta_input_settings_x11_set_stylus_button_map (MetaInputSettings          *setti
e47e58
 
e47e58
   /* Grab the puke bucket! */
e47e58
   meta_error_trap_push (display);
e47e58
-  xdev = XOpenDevice (xdisplay, device_id);
e47e58
+  xdev = device_ensure_xdevice (device);
e47e58
   if (xdev)
e47e58
     {
e47e58
       guchar map[3] = {
e47e58
@@ -755,7 +792,6 @@ meta_input_settings_x11_set_stylus_button_map (MetaInputSettings          *setti
e47e58
       };
e47e58
 
e47e58
       XSetDeviceButtonMapping (xdisplay, xdev, map, G_N_ELEMENTS (map));
e47e58
-      XCloseDevice (xdisplay, xdev);
e47e58
     }
e47e58
 
e47e58
   if (meta_error_trap_pop_with_return (display))
e47e58
-- 
e47e58
1.8.3.1
e47e58