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

e3f29c
From 81986e9b3c16efa170b2bb4fe2af05a30b9386b3 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
e3f29c
index 467a9b7..27995c8 100644
db633a
--- a/src/backends/x11/meta-input-settings-x11.c
db633a
+++ b/src/backends/x11/meta-input-settings-x11.c
e3f29c
@@ -222,6 +222,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
-- 
e3f29c
1.8.3.1
db633a
e3f29c
e3f29c
From c3f4dc97cdb4f1b63e43e38daf02e676d207ad37 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
e3f29c
index 27995c8..4c2709c 100644
db633a
--- a/src/backends/x11/meta-input-settings-x11.c
db633a
+++ b/src/backends/x11/meta-input-settings-x11.c
e3f29c
@@ -621,6 +621,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
-- 
e3f29c
1.8.3.1
e3f29c
db633a
e3f29c
From fd94f5fd842f0f0f9e4a28e69716a30669e2e848 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
---
e3f29c
 src/backends/x11/meta-input-settings-x11.c | 112 +++++++++++++++++++++++++++++
e3f29c
 1 file changed, 112 insertions(+)
db633a
db633a
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
e3f29c
index 4c2709c..9a85f94 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>
e3f29c
 #include "backends/meta-logical-monitor.h"
e3f29c
@@ -44,6 +47,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,
e3f29c
@@ -328,6 +333,107 @@ change_synaptics_speed (ClutterInputDevice *device,
e3f29c
   XFreeFeedbackList (states);
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,
e3f29c
@@ -452,6 +558,12 @@ meta_input_settings_x11_set_disable_while_typing (MetaInputSettings  *settings,
e3f29c
 {
e3f29c
   guchar value = (enabled) ? 1 : 0;
db633a
 
e3f29c
+  if (is_device_synaptics (device))
e3f29c
+    {
e3f29c
+      set_synaptics_disable_w_typing (settings, enabled);
e3f29c
+      return;
e3f29c
+    }
e3f29c
+
e3f29c
   change_property (device, "libinput Disable While Typing Enabled",
e3f29c
                    XA_INTEGER, 8, &value, 1);
e3f29c
 }
db633a
-- 
e3f29c
1.8.3.1
e3f29c
db633a
e3f29c
From f5f9195fe23c0af8a498a13ca6bc5521a0c9e6ce 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
---
e3f29c
 src/backends/x11/meta-input-settings-x11.c | 96 +++++++++++++++++++++++-------
e3f29c
 1 file changed, 74 insertions(+), 22 deletions(-)
db633a
db633a
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
e3f29c
index 9a85f94..cb4eb00 100644
db633a
--- a/src/backends/x11/meta-input-settings-x11.c
db633a
+++ b/src/backends/x11/meta-input-settings-x11.c
e3f29c
@@ -179,35 +179,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
 
e3f29c
   xdevice = device_ensure_xdevice (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)
e3f29c
-    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
   if (display)
db633a
     meta_error_trap_push (display);
db633a
   buttons = g_new (guchar, buttons_capacity);
e3f29c
@@ -231,14 +231,37 @@ 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
 
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 ();
e3f29c
@@ -333,6 +356,23 @@ change_synaptics_speed (ClutterInputDevice *device,
e3f29c
   XFreeFeedbackList (states);
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
e3f29c
@@ -501,9 +541,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
 
e3f29c
@@ -545,6 +586,11 @@ meta_input_settings_x11_set_left_handed (MetaInputSettings  *settings,
e3f29c
           g_object_unref (settings);
e3f29c
           return;
e3f29c
         }
e3f29c
+      else if (!is_device_libinput (device))
e3f29c
+        {
e3f29c
+          change_x_device_left_handed (device, enabled);
e3f29c
+          return;
e3f29c
+        }
db633a
 
e3f29c
       change_property (device, "libinput Left Handed Enabled",
e3f29c
                        XA_INTEGER, 8, &value, 1);
e3f29c
@@ -758,6 +804,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
-- 
e3f29c
1.8.3.1
db633a