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

23fb49
From e9cd700f11565fd1723828a5cf77f994c8494ddd 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
23fb49
index 75ceb0c93..cfdd2ffef 100644
23fb49
--- a/src/backends/x11/meta-input-settings-x11.c
23fb49
+++ b/src/backends/x11/meta-input-settings-x11.c
23fb49
@@ -181,6 +181,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
-- 
23fb49
2.13.5
23fb49
23fb49
From 1df0d3b1a0d85c3a565ce6dde4faedf7c1f57930 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
23fb49
index cfdd2ffef..8aa8a497b 100644
23fb49
--- a/src/backends/x11/meta-input-settings-x11.c
23fb49
+++ b/src/backends/x11/meta-input-settings-x11.c
23fb49
@@ -546,6 +546,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
-- 
23fb49
2.13.5
23fb49
23fb49
From 05b6600752ee85e0c48d4055b3ca1c2d010d2851 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
---
23fb49
 src/backends/x11/meta-input-settings-x11.c | 107 +++++++++++++++++++++++++++++
23fb49
 1 file changed, 107 insertions(+)
23fb49
23fb49
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
23fb49
index 8aa8a497b..d38e1b454 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>
23fb49
 
23fb49
@@ -43,6 +46,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,
23fb49
@@ -291,6 +296,107 @@ change_synaptics_speed (ClutterInputDevice *device,
23fb49
   XCloseDevice (xdisplay, xdevice);
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,
23fb49
@@ -303,6 +409,7 @@ meta_input_settings_x11_set_send_events (MetaInputSettings        *settings,
23fb49
     {
23fb49
       values[0] = mode != G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED;
23fb49
       change_property (device, "Synaptics Off", XA_INTEGER, 8, &values, 1);
23fb49
+      set_synaptics_disable_w_typing (settings, mode == G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED);
23fb49
       return;
23fb49
     }
23fb49
 
23fb49
-- 
23fb49
2.13.5
23fb49
23fb49
From 94aa02bfe8364c9be9ca0251f66e8f91c38d1bdd 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
---
23fb49
 src/backends/x11/meta-input-settings-x11.c | 97 +++++++++++++++++++++++-------
23fb49
 1 file changed, 74 insertions(+), 23 deletions(-)
23fb49
23fb49
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
23fb49
index d38e1b454..63a8fe79e 100644
23fb49
--- a/src/backends/x11/meta-input-settings-x11.c
23fb49
+++ b/src/backends/x11/meta-input-settings-x11.c
23fb49
@@ -138,35 +138,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
 
23fb49
   xdevice = XOpenDevice(xdisplay, clutter_input_device_get_device_id (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)
23fb49
-    goto out;
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);
23fb49
@@ -190,17 +190,39 @@ 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
- out:
23fb49
   XCloseDevice (xdisplay, xdevice);
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 ();
23fb49
@@ -296,6 +318,23 @@ change_synaptics_speed (ClutterInputDevice *device,
23fb49
   XCloseDevice (xdisplay, xdevice);
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
23fb49
@@ -465,9 +504,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
 
23fb49
@@ -494,6 +534,11 @@ meta_input_settings_x11_set_left_handed (MetaInputSettings  *settings,
23fb49
       g_object_unref (settings);
23fb49
       return;
23fb49
     }
23fb49
+  else if (!is_device_libinput (device))
23fb49
+    {
23fb49
+      change_x_device_left_handed (device, enabled);
23fb49
+      return;
23fb49
+    }
23fb49
 
23fb49
   change_property (device, "libinput Left Handed Enabled",
23fb49
                    XA_INTEGER, 8, &value, 1);
23fb49
@@ -678,6 +723,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
-- 
23fb49
2.13.5
23fb49