Blame SOURCES/add-support-for-plain-old-x-device-configuration.patch

db633a
From e9cd700f11565fd1723828a5cf77f994c8494ddd Mon Sep 17 00:00:00 2001
db633a
From: Rui Matos <tiagomatos@gmail.com>
db633a
Date: Mon, 9 Oct 2017 18:37:11 +0200
db633a
Subject: [PATCH 1/4] backends/x11: Fix a small memory leak
db633a
db633a
Introduced in "backends/x11: Support synaptics configuration".
db633a
---
db633a
 src/backends/x11/meta-input-settings-x11.c | 1 +
db633a
 1 file changed, 1 insertion(+)
db633a
db633a
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
db633a
index 75ceb0c93..cfdd2ffef 100644
db633a
--- a/src/backends/x11/meta-input-settings-x11.c
db633a
+++ b/src/backends/x11/meta-input-settings-x11.c
db633a
@@ -181,6 +181,7 @@ change_synaptics_tap_left_handed (ClutterInputDevice *device,
db633a
   buttons[0] = left_handed ? 3 : 1;
db633a
   buttons[2] = left_handed ? 1 : 3;
db633a
   XSetDeviceButtonMapping (xdisplay, xdevice, buttons, n_buttons);
db633a
+  g_free (buttons);
db633a
 
db633a
   if (display && meta_error_trap_pop_with_return (display))
db633a
     {
db633a
-- 
db633a
2.13.5
db633a
db633a
From 1df0d3b1a0d85c3a565ce6dde4faedf7c1f57930 Mon Sep 17 00:00:00 2001
db633a
From: Rui Matos <tiagomatos@gmail.com>
db633a
Date: Mon, 9 Oct 2017 18:39:52 +0200
db633a
Subject: [PATCH 2/4] backends/x11: Add a synaptics check for two finger scroll
db633a
 availability
db633a
db633a
Commit "backends/x11: Support synaptics configuration" added support
db633a
for synaptics two finger scrolling but didn't add the code to check
db633a
that it is available resulting in the upper layer always assuming it
db633a
isn't.
db633a
---
db633a
 src/backends/x11/meta-input-settings-x11.c | 11 +++++++++++
db633a
 1 file changed, 11 insertions(+)
db633a
db633a
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
db633a
index cfdd2ffef..8aa8a497b 100644
db633a
--- a/src/backends/x11/meta-input-settings-x11.c
db633a
+++ b/src/backends/x11/meta-input-settings-x11.c
db633a
@@ -546,6 +546,17 @@ meta_input_settings_x11_has_two_finger_scroll (MetaInputSettings  *settings,
db633a
   guchar *available = NULL;
db633a
   gboolean has_two_finger = TRUE;
db633a
 
db633a
+  if (is_device_synaptics (device))
db633a
+    {
db633a
+      available = get_property (device, "Synaptics Capabilities",
db633a
+                                XA_INTEGER, 8, 4);
db633a
+      if (!available || !available[3])
db633a
+          has_two_finger = FALSE;
db633a
+
db633a
+      meta_XFree (available);
db633a
+      return has_two_finger;
db633a
+    }
db633a
+
db633a
   available = get_property (device, "libinput Scroll Methods Available",
db633a
                             XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
db633a
   if (!available || !available[SCROLL_METHOD_FIELD_2FG])
db633a
-- 
db633a
2.13.5
db633a
db633a
From 05b6600752ee85e0c48d4055b3ca1c2d010d2851 Mon Sep 17 00:00:00 2001
db633a
From: Rui Matos <tiagomatos@gmail.com>
db633a
Date: Mon, 9 Oct 2017 18:55:56 +0200
db633a
Subject: [PATCH 3/4] backends/x11: Add disable while typing support for
db633a
 synaptics
db633a
db633a
This is basically a copy of the old g-s-d mouse plugin code to manage
db633a
syndaemon when the synaptics driver is being used.
db633a
---
db633a
 src/backends/x11/meta-input-settings-x11.c | 107 +++++++++++++++++++++++++++++
db633a
 1 file changed, 107 insertions(+)
db633a
db633a
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
db633a
index 8aa8a497b..d38e1b454 100644
db633a
--- a/src/backends/x11/meta-input-settings-x11.c
db633a
+++ b/src/backends/x11/meta-input-settings-x11.c
db633a
@@ -35,6 +35,9 @@
db633a
 #ifdef HAVE_LIBGUDEV
db633a
 #include <gudev/gudev.h>
db633a
 #endif
db633a
+#ifdef __linux
db633a
+#include <sys/prctl.h>
db633a
+#endif
db633a
 
db633a
 #include <meta/errors.h>
db633a
 
db633a
@@ -43,6 +46,8 @@ typedef struct _MetaInputSettingsX11Private
db633a
 #ifdef HAVE_LIBGUDEV
db633a
   GUdevClient *udev_client;
db633a
 #endif
db633a
+  gboolean syndaemon_spawned;
db633a
+  GPid syndaemon_pid;
db633a
 } MetaInputSettingsX11Private;
db633a
 
db633a
 G_DEFINE_TYPE_WITH_PRIVATE (MetaInputSettingsX11, meta_input_settings_x11,
db633a
@@ -291,6 +296,107 @@ change_synaptics_speed (ClutterInputDevice *device,
db633a
   XCloseDevice (xdisplay, xdevice);
db633a
 }
db633a
 
db633a
+/* Ensure that syndaemon dies together with us, to avoid running several of
db633a
+ * them */
db633a
+static void
db633a
+setup_syndaemon (gpointer user_data)
db633a
+{
db633a
+#ifdef __linux
db633a
+  prctl (PR_SET_PDEATHSIG, SIGHUP);
db633a
+#endif
db633a
+}
db633a
+
db633a
+static gboolean
db633a
+have_program_in_path (const char *name)
db633a
+{
db633a
+  gchar *path;
db633a
+  gboolean result;
db633a
+
db633a
+  path = g_find_program_in_path (name);
db633a
+  result = (path != NULL);
db633a
+  g_free (path);
db633a
+  return result;
db633a
+}
db633a
+
db633a
+static void
db633a
+syndaemon_died (GPid     pid,
db633a
+                gint     status,
db633a
+                gpointer user_data)
db633a
+{
db633a
+  MetaInputSettingsX11 *settings_x11 = META_INPUT_SETTINGS_X11 (user_data);
db633a
+  MetaInputSettingsX11Private *priv =
db633a
+    meta_input_settings_x11_get_instance_private (settings_x11);
db633a
+  GError *error = NULL;
db633a
+
db633a
+  if (!g_spawn_check_exit_status (status, &error))
db633a
+    {
db633a
+      if ((WIFSIGNALED (status) && WTERMSIG (status) != SIGHUP) ||
db633a
+          error->domain == G_SPAWN_EXIT_ERROR)
db633a
+        g_warning ("Syndaemon exited unexpectedly: %s", error->message);
db633a
+      g_error_free (error);
db633a
+    }
db633a
+
db633a
+  g_spawn_close_pid (pid);
db633a
+  priv->syndaemon_spawned = FALSE;
db633a
+}
db633a
+
db633a
+static void
db633a
+set_synaptics_disable_w_typing (MetaInputSettings *settings,
db633a
+                                gboolean           state)
db633a
+{
db633a
+  MetaInputSettingsX11 *settings_x11 = META_INPUT_SETTINGS_X11 (settings);
db633a
+  MetaInputSettingsX11Private *priv =
db633a
+    meta_input_settings_x11_get_instance_private (settings_x11);
db633a
+
db633a
+  if (state)
db633a
+    {
db633a
+      GError *error = NULL;
db633a
+      GPtrArray *args;
db633a
+
db633a
+      if (priv->syndaemon_spawned)
db633a
+        return;
db633a
+
db633a
+      if (!have_program_in_path ("syndaemon"))
db633a
+        return;
db633a
+
db633a
+      args = g_ptr_array_new ();
db633a
+
db633a
+      g_ptr_array_add (args, "syndaemon");
db633a
+      g_ptr_array_add (args, "-i");
db633a
+      g_ptr_array_add (args, "1.0");
db633a
+      g_ptr_array_add (args, "-t");
db633a
+      g_ptr_array_add (args, "-K");
db633a
+      g_ptr_array_add (args, "-R");
db633a
+      g_ptr_array_add (args, NULL);
db633a
+
db633a
+      /* we must use G_SPAWN_DO_NOT_REAP_CHILD to avoid
db633a
+       * double-forking, otherwise syndaemon will immediately get
db633a
+       * killed again through (PR_SET_PDEATHSIG when the intermediate
db633a
+       * process dies */
db633a
+      g_spawn_async (g_get_home_dir (), (char **) args->pdata, NULL,
db633a
+                     G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD, setup_syndaemon, NULL,
db633a
+                     &priv->syndaemon_pid, &error);
db633a
+
db633a
+      priv->syndaemon_spawned = (error == NULL);
db633a
+      g_ptr_array_free (args, TRUE);
db633a
+
db633a
+      if (error)
db633a
+        {
db633a
+          g_warning ("Failed to launch syndaemon: %s", error->message);
db633a
+          g_error_free (error);
db633a
+        }
db633a
+      else
db633a
+        {
db633a
+          g_child_watch_add (priv->syndaemon_pid, syndaemon_died, settings);
db633a
+        }
db633a
+    }
db633a
+  else if (priv->syndaemon_spawned)
db633a
+    {
db633a
+      kill (priv->syndaemon_pid, SIGHUP);
db633a
+      priv->syndaemon_spawned = FALSE;
db633a
+    }
db633a
+}
db633a
+
db633a
 static void
db633a
 meta_input_settings_x11_set_send_events (MetaInputSettings        *settings,
db633a
                                          ClutterInputDevice       *device,
db633a
@@ -303,6 +409,7 @@ meta_input_settings_x11_set_send_events (MetaInputSettings        *settings,
db633a
     {
db633a
       values[0] = mode != G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED;
db633a
       change_property (device, "Synaptics Off", XA_INTEGER, 8, &values, 1);
db633a
+      set_synaptics_disable_w_typing (settings, mode == G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED);
db633a
       return;
db633a
     }
db633a
 
db633a
-- 
db633a
2.13.5
db633a
db633a
From 94aa02bfe8364c9be9ca0251f66e8f91c38d1bdd Mon Sep 17 00:00:00 2001
db633a
From: Rui Matos <tiagomatos@gmail.com>
db633a
Date: Tue, 10 Oct 2017 19:07:27 +0200
db633a
Subject: [PATCH 4/4] backends/x11: Support plain old X device configuration
db633a
db633a
We re-use part of the code added to support synaptics and add a few
db633a
bits specific for xorg-x11-drv-evdev devices.
db633a
---
db633a
 src/backends/x11/meta-input-settings-x11.c | 97 +++++++++++++++++++++++-------
db633a
 1 file changed, 74 insertions(+), 23 deletions(-)
db633a
db633a
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
db633a
index d38e1b454..63a8fe79e 100644
db633a
--- a/src/backends/x11/meta-input-settings-x11.c
db633a
+++ b/src/backends/x11/meta-input-settings-x11.c
db633a
@@ -138,35 +138,35 @@ is_device_synaptics (ClutterInputDevice *device)
db633a
   return TRUE;
db633a
 }
db633a
 
db633a
+static gboolean
db633a
+is_device_libinput (ClutterInputDevice *device)
db633a
+{
db633a
+  guchar *has_setting;
db633a
+
db633a
+  /* We just need looking for a synaptics-specific property */
db633a
+  has_setting = get_property (device, "libinput Send Events Modes Available", XA_INTEGER, 8, 2);
db633a
+  if (!has_setting)
db633a
+    return FALSE;
db633a
+
db633a
+  meta_XFree (has_setting);
db633a
+  return TRUE;
db633a
+}
db633a
+
db633a
 static void
db633a
-change_synaptics_tap_left_handed (ClutterInputDevice *device,
db633a
-                                  gboolean            tap_enabled,
db633a
-                                  gboolean            left_handed)
db633a
+change_x_device_left_handed (ClutterInputDevice *device,
db633a
+                             gboolean            left_handed)
db633a
 {
db633a
   MetaDisplay *display = meta_get_display ();
db633a
   MetaBackend *backend = meta_get_backend ();
db633a
   Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
db633a
   XDevice *xdevice;
db633a
-  guchar *tap_action, *buttons;
db633a
+  guchar *buttons;
db633a
   guint buttons_capacity = 16, n_buttons;
db633a
 
db633a
   xdevice = XOpenDevice(xdisplay, clutter_input_device_get_device_id (device));
db633a
   if (!xdevice)
db633a
     return;
db633a
 
db633a
-  tap_action = get_property (device, "Synaptics Tap Action",
db633a
-                             XA_INTEGER, 8, 7);
db633a
-  if (!tap_action)
db633a
-    goto out;
db633a
-
db633a
-  tap_action[4] = tap_enabled ? (left_handed ? 3 : 1) : 0;
db633a
-  tap_action[5] = tap_enabled ? (left_handed ? 1 : 3) : 0;
db633a
-  tap_action[6] = tap_enabled ? 2 : 0;
db633a
-
db633a
-  change_property (device, "Synaptics Tap Action",
db633a
-                   XA_INTEGER, 8, tap_action, 7);
db633a
-  meta_XFree (tap_action);
db633a
-
db633a
   if (display)
db633a
     meta_error_trap_push (display);
db633a
   buttons = g_new (guchar, buttons_capacity);
db633a
@@ -190,17 +190,39 @@ change_synaptics_tap_left_handed (ClutterInputDevice *device,
db633a
 
db633a
   if (display && meta_error_trap_pop_with_return (display))
db633a
     {
db633a
-      g_warning ("Could not set synaptics touchpad left-handed for %s",
db633a
+      g_warning ("Could not set left-handed for %s",
db633a
                  clutter_input_device_get_device_name (device));
db633a
     }
db633a
 
db633a
- out:
db633a
   XCloseDevice (xdisplay, xdevice);
db633a
 }
db633a
 
db633a
 static void
db633a
-change_synaptics_speed (ClutterInputDevice *device,
db633a
-                        gdouble             speed)
db633a
+change_synaptics_tap_left_handed (ClutterInputDevice *device,
db633a
+                                  gboolean            tap_enabled,
db633a
+                                  gboolean            left_handed)
db633a
+{
db633a
+  guchar *tap_action;
db633a
+
db633a
+  tap_action = get_property (device, "Synaptics Tap Action",
db633a
+                             XA_INTEGER, 8, 7);
db633a
+  if (!tap_action)
db633a
+    return;
db633a
+
db633a
+  tap_action[4] = tap_enabled ? (left_handed ? 3 : 1) : 0;
db633a
+  tap_action[5] = tap_enabled ? (left_handed ? 1 : 3) : 0;
db633a
+  tap_action[6] = tap_enabled ? 2 : 0;
db633a
+
db633a
+  change_property (device, "Synaptics Tap Action",
db633a
+                   XA_INTEGER, 8, tap_action, 7);
db633a
+  meta_XFree (tap_action);
db633a
+
db633a
+  change_x_device_left_handed (device, left_handed);
db633a
+}
db633a
+
db633a
+static void
db633a
+change_x_device_speed (ClutterInputDevice *device,
db633a
+                       gdouble             speed)
db633a
 {
db633a
   MetaDisplay *display = meta_get_display ();
db633a
   MetaBackend *backend = meta_get_backend ();
db633a
@@ -296,6 +318,23 @@ change_synaptics_speed (ClutterInputDevice *device,
db633a
   XCloseDevice (xdisplay, xdevice);
db633a
 }
db633a
 
db633a
+static void
db633a
+change_x_device_scroll_button (ClutterInputDevice *device,
db633a
+                               guint               button)
db633a
+{
db633a
+  guchar value;
db633a
+
db633a
+  value = button > 0 ? 1 : 0;
db633a
+  change_property (device, "Evdev Wheel Emulation",
db633a
+                   XA_INTEGER, 8, &value, 1);
db633a
+  if (button > 0)
db633a
+    {
db633a
+      value = button;
db633a
+      change_property (device, "Evdev Wheel Emulation Button",
db633a
+                       XA_INTEGER, 8, &value, 1);
db633a
+    }
db633a
+}
db633a
+
db633a
 /* Ensure that syndaemon dies together with us, to avoid running several of
db633a
  * them */
db633a
 static void
db633a
@@ -465,9 +504,10 @@ meta_input_settings_x11_set_speed (MetaInputSettings  *settings,
db633a
   Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
db633a
   gfloat value = speed;
db633a
 
db633a
-  if (is_device_synaptics (device))
db633a
+  if (is_device_synaptics (device) ||
db633a
+      !is_device_libinput (device))
db633a
     {
db633a
-      change_synaptics_speed (device, speed);
db633a
+      change_x_device_speed (device, speed);
db633a
       return;
db633a
     }
db633a
 
db633a
@@ -494,6 +534,11 @@ meta_input_settings_x11_set_left_handed (MetaInputSettings  *settings,
db633a
       g_object_unref (settings);
db633a
       return;
db633a
     }
db633a
+  else if (!is_device_libinput (device))
db633a
+    {
db633a
+      change_x_device_left_handed (device, enabled);
db633a
+      return;
db633a
+    }
db633a
 
db633a
   change_property (device, "libinput Left Handed Enabled",
db633a
                    XA_INTEGER, 8, &value, 1);
db633a
@@ -678,6 +723,12 @@ meta_input_settings_x11_set_scroll_button (MetaInputSettings  *settings,
db633a
                                            ClutterInputDevice *device,
db633a
                                            guint               button)
db633a
 {
db633a
+  if (!is_device_libinput (device))
db633a
+    {
db633a
+      change_x_device_scroll_button (device, button);
db633a
+      return;
db633a
+    }
db633a
+
db633a
   change_property (device, "libinput Button Scrolling Button",
db633a
                    XA_INTEGER, 32, &button, 1);
db633a
 }
db633a
-- 
db633a
2.13.5
db633a