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

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