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

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