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

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