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

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