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

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