Blame SOURCES/legacy-x11-input-configuration.patch

8a83d7
From 22fe64732e11199901d4a35f9d3c63d5d6deb3a3 Mon Sep 17 00:00:00 2001
f7d48e
From: Carlos Garnacho <carlosg@gnome.org>
f7d48e
Date: Tue, 1 Jun 2021 11:44:20 +0200
f7d48e
Subject: [PATCH 1/6] backends/x11: Support synaptics configuration
f7d48e
f7d48e
The code is taken mostly as-is from g-s-d, so we can drag the
f7d48e
dead horse a bit longer.
f7d48e
---
8a83d7
 src/backends/x11/meta-input-settings-x11.c | 274 +++++++++++++++++++++
8a83d7
 1 file changed, 274 insertions(+)
f7d48e
f7d48e
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
8a83d7
index 371e2f60e..426056390 100644
f7d48e
--- a/src/backends/x11/meta-input-settings-x11.c
f7d48e
+++ b/src/backends/x11/meta-input-settings-x11.c
f7d48e
@@ -26,6 +26,7 @@
f7d48e
 #include "backends/x11/meta-input-settings-x11.h"
f7d48e
 
f7d48e
 #include <gdk/gdkx.h>
f7d48e
+#include <stdlib.h>
f7d48e
 #include <string.h>
f7d48e
 #include <X11/Xatom.h>
f7d48e
 #include <X11/extensions/XInput2.h>
8a83d7
@@ -165,6 +166,183 @@ change_property (ClutterInputDevice *device,
f7d48e
   meta_XFree (data_ret);
f7d48e
 }
f7d48e
 
f7d48e
+static gboolean
f7d48e
+is_device_synaptics (ClutterInputDevice *device)
f7d48e
+{
f7d48e
+  guchar *has_setting;
f7d48e
+
f7d48e
+  /* We just need looking for a synaptics-specific property */
f7d48e
+  has_setting = get_property (device, "Synaptics Off", XA_INTEGER, 8, 1);
f7d48e
+  if (!has_setting)
f7d48e
+    return FALSE;
f7d48e
+
f7d48e
+  meta_XFree (has_setting);
f7d48e
+  return TRUE;
f7d48e
+}
f7d48e
+
f7d48e
+static void
f7d48e
+change_synaptics_tap_left_handed (ClutterInputDevice *device,
f7d48e
+                                  gboolean            tap_enabled,
f7d48e
+                                  gboolean            left_handed)
f7d48e
+{
f7d48e
+  MetaDisplay *display = meta_get_display ();
f7d48e
+  MetaBackend *backend = meta_get_backend ();
f7d48e
+  Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
f7d48e
+  int device_id;
f7d48e
+  XDevice *xdevice;
f7d48e
+  guchar *tap_action, *buttons;
f7d48e
+  guint buttons_capacity = 16, n_buttons;
f7d48e
+
f7d48e
+  device_id = meta_input_device_x11_get_device_id (device);
f7d48e
+  xdevice = XOpenDevice (xdisplay, device_id);
f7d48e
+  if (!xdevice)
f7d48e
+    return;
f7d48e
+
f7d48e
+  tap_action = get_property (device, "Synaptics Tap Action",
f7d48e
+                             XA_INTEGER, 8, 7);
f7d48e
+  if (!tap_action)
f7d48e
+    goto out;
f7d48e
+
f7d48e
+  tap_action[4] = tap_enabled ? (left_handed ? 3 : 1) : 0;
f7d48e
+  tap_action[5] = tap_enabled ? (left_handed ? 1 : 3) : 0;
f7d48e
+  tap_action[6] = tap_enabled ? 2 : 0;
f7d48e
+
f7d48e
+  change_property (device, "Synaptics Tap Action",
f7d48e
+                   XA_INTEGER, 8, tap_action, 7);
f7d48e
+  meta_XFree (tap_action);
f7d48e
+
8a83d7
+  clutter_x11_trap_x_errors();
f7d48e
+  buttons = g_new (guchar, buttons_capacity);
f7d48e
+  n_buttons = XGetDeviceButtonMapping (xdisplay, xdevice,
f7d48e
+                                       buttons, buttons_capacity);
f7d48e
+
f7d48e
+  while (n_buttons > buttons_capacity)
f7d48e
+    {
f7d48e
+      buttons_capacity = n_buttons;
f7d48e
+      buttons = (guchar *) g_realloc (buttons,
f7d48e
+                                      buttons_capacity * sizeof (guchar));
f7d48e
+
f7d48e
+      n_buttons = XGetDeviceButtonMapping (xdisplay, xdevice,
f7d48e
+                                           buttons, buttons_capacity);
f7d48e
+    }
f7d48e
+
f7d48e
+  buttons[0] = left_handed ? 3 : 1;
f7d48e
+  buttons[2] = left_handed ? 1 : 3;
f7d48e
+  XSetDeviceButtonMapping (xdisplay, xdevice, buttons, n_buttons);
f7d48e
+  g_free (buttons);
f7d48e
+
8a83d7
+  if (clutter_x11_untrap_x_errors())
f7d48e
+    {
f7d48e
+      g_warning ("Could not set synaptics touchpad left-handed for %s",
f7d48e
+                 clutter_input_device_get_device_name (device));
f7d48e
+    }
f7d48e
+
f7d48e
+ out:
f7d48e
+  XCloseDevice (xdisplay, xdevice);
f7d48e
+}
f7d48e
+
f7d48e
+static void
f7d48e
+change_synaptics_speed (ClutterInputDevice *device,
f7d48e
+                        gdouble             speed)
f7d48e
+{
f7d48e
+  MetaDisplay *display = meta_get_display ();
f7d48e
+  MetaBackend *backend = meta_get_backend ();
f7d48e
+  Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
f7d48e
+  int device_id;
f7d48e
+  XDevice *xdevice;
f7d48e
+  XPtrFeedbackControl feedback;
f7d48e
+  XFeedbackState *states, *state;
f7d48e
+  int i, num_feedbacks, motion_threshold, numerator, denominator;
f7d48e
+  gfloat motion_acceleration;
f7d48e
+
f7d48e
+  device_id = meta_input_device_x11_get_device_id (device);
f7d48e
+  xdevice = XOpenDevice (xdisplay, device_id);
f7d48e
+  if (!xdevice)
f7d48e
+    return;
f7d48e
+  /* Get the list of feedbacks for the device */
8a83d7
+  clutter_x11_trap_x_errors();
f7d48e
+  states = XGetFeedbackControl (xdisplay, xdevice, &num_feedbacks);
8a83d7
+  if (clutter_x11_untrap_x_errors())
8a83d7
+    return;
f7d48e
+  if (!states)
f7d48e
+    return;
f7d48e
+
f7d48e
+  /* Calculate acceleration and threshold */
f7d48e
+  motion_acceleration = (speed + 1) * 5; /* speed is [-1..1], map to [0..10] */
f7d48e
+  motion_threshold = CLAMP (10 - floor (motion_acceleration), 1, 10);
f7d48e
+
f7d48e
+  if (motion_acceleration >= 1.0)
f7d48e
+    {
f7d48e
+      /* we want to get the acceleration, with a resolution of 0.5
f7d48e
+       */
f7d48e
+      if ((motion_acceleration - floor (motion_acceleration)) < 0.25)
f7d48e
+        {
f7d48e
+          numerator = floor (motion_acceleration);
f7d48e
+          denominator = 1;
f7d48e
+        }
f7d48e
+      else if ((motion_acceleration - floor (motion_acceleration)) < 0.5)
f7d48e
+        {
f7d48e
+          numerator = ceil (2.0 * motion_acceleration);
f7d48e
+          denominator = 2;
f7d48e
+        }
f7d48e
+      else if ((motion_acceleration - floor (motion_acceleration)) < 0.75)
f7d48e
+        {
f7d48e
+          numerator = floor (2.0 *motion_acceleration);
f7d48e
+          denominator = 2;
f7d48e
+        }
f7d48e
+      else
f7d48e
+        {
f7d48e
+          numerator = ceil (motion_acceleration);
f7d48e
+          denominator = 1;
f7d48e
+        }
f7d48e
+    }
f7d48e
+  else if (motion_acceleration < 1.0 && motion_acceleration > 0)
f7d48e
+    {
f7d48e
+      /* This we do to 1/10ths */
f7d48e
+      numerator = floor (motion_acceleration * 10) + 1;
f7d48e
+      denominator= 10;
f7d48e
+    }
f7d48e
+  else
f7d48e
+    {
f7d48e
+      numerator = -1;
f7d48e
+      denominator = -1;
f7d48e
+    }
f7d48e
+
8a83d7
+  clutter_x11_trap_x_errors();
f7d48e
+
f7d48e
+  state = (XFeedbackState *) states;
f7d48e
+
f7d48e
+  for (i = 0; i < num_feedbacks; i++)
f7d48e
+    {
f7d48e
+      if (state->class == PtrFeedbackClass)
f7d48e
+        {
f7d48e
+          /* And tell the device */
f7d48e
+          feedback.class      = PtrFeedbackClass;
f7d48e
+          feedback.length     = sizeof (XPtrFeedbackControl);
f7d48e
+          feedback.id         = state->id;
f7d48e
+          feedback.threshold  = motion_threshold;
f7d48e
+          feedback.accelNum   = numerator;
f7d48e
+          feedback.accelDenom = denominator;
f7d48e
+
f7d48e
+          XChangeFeedbackControl (xdisplay, xdevice,
f7d48e
+                                  DvAccelNum | DvAccelDenom | DvThreshold,
f7d48e
+                                  (XFeedbackControl *) &feedback);
f7d48e
+          break;
f7d48e
+        }
f7d48e
+
f7d48e
+      state = (XFeedbackState *) ((char *) state + state->length);
f7d48e
+    }
f7d48e
+
8a83d7
+  if (clutter_x11_untrap_x_errors())
f7d48e
+    {
f7d48e
+      g_warning ("Could not set synaptics touchpad acceleration for %s",
f7d48e
+                 clutter_input_device_get_device_name (device));
f7d48e
+    }
f7d48e
+
f7d48e
+  XFreeFeedbackList (states);
f7d48e
+  XCloseDevice (xdisplay, xdevice);
f7d48e
+}
f7d48e
+
f7d48e
 static void
f7d48e
 meta_input_settings_x11_set_send_events (MetaInputSettings        *settings,
f7d48e
                                          ClutterInputDevice       *device,
8a83d7
@@ -173,6 +351,13 @@ meta_input_settings_x11_set_send_events (MetaInputSettings        *settings,
f7d48e
   guchar values[2] = { 0 }; /* disabled, disabled-on-external-mouse */
f7d48e
   guchar *available;
f7d48e
 
f7d48e
+  if (is_device_synaptics (device))
f7d48e
+    {
f7d48e
+      values[0] = mode != G_DESKTOP_DEVICE_SEND_EVENTS_ENABLED;
f7d48e
+      change_property (device, "Synaptics Off", XA_INTEGER, 8, &values, 1);
f7d48e
+      return;
f7d48e
+    }
f7d48e
+
f7d48e
   available = get_property (device, "libinput Send Events Modes Available",
f7d48e
                             XA_INTEGER, 8, 2);
f7d48e
   if (!available)
8a83d7
@@ -225,6 +410,12 @@ meta_input_settings_x11_set_speed (MetaInputSettings  *settings,
f7d48e
   Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
f7d48e
   gfloat value = speed;
f7d48e
 
f7d48e
+  if (is_device_synaptics (device))
f7d48e
+    {
f7d48e
+      change_synaptics_speed (device, speed);
f7d48e
+      return;
f7d48e
+    }
f7d48e
+
f7d48e
   change_property (device, "libinput Accel Speed",
f7d48e
                    XInternAtom (xdisplay, "FLOAT", False),
f7d48e
                    32, &value, 1);
8a83d7
@@ -251,6 +442,19 @@ meta_input_settings_x11_set_left_handed (MetaInputSettings  *settings,
f7d48e
   else
f7d48e
     {
f7d48e
       value = enabled ? 1 : 0;
f7d48e
+
f7d48e
+      if (is_device_synaptics (device))
f7d48e
+        {
f7d48e
+          GSettings *settings;
f7d48e
+
f7d48e
+          settings = g_settings_new ("org.gnome.desktop.peripherals.touchpad");
f7d48e
+          change_synaptics_tap_left_handed (device,
f7d48e
+                                            g_settings_get_boolean (settings, "tap-to-click"),
f7d48e
+                                            enabled);
f7d48e
+          g_object_unref (settings);
f7d48e
+          return;
f7d48e
+        }
f7d48e
+
f7d48e
       change_property (device, "libinput Left Handed Enabled",
f7d48e
                        XA_INTEGER, 8, &value, 1);
f7d48e
     }
8a83d7
@@ -274,6 +478,20 @@ meta_input_settings_x11_set_tap_enabled (MetaInputSettings  *settings,
f7d48e
 {
f7d48e
   guchar value = (enabled) ? 1 : 0;
f7d48e
 
f7d48e
+  if (is_device_synaptics (device))
f7d48e
+    {
f7d48e
+      GDesktopTouchpadHandedness handedness;
f7d48e
+      GSettings *settings;
f7d48e
+
f7d48e
+      settings = g_settings_new ("org.gnome.desktop.peripherals.touchpad");
f7d48e
+      handedness = g_settings_get_enum (settings, "left-handed");
f7d48e
+      g_object_unref (settings);
f7d48e
+
f7d48e
+      change_synaptics_tap_left_handed (device, enabled,
f7d48e
+                                        handedness == G_DESKTOP_TOUCHPAD_HANDEDNESS_LEFT);
f7d48e
+      return;
f7d48e
+    }
f7d48e
+
f7d48e
   change_property (device, "libinput Tapping Enabled",
f7d48e
                    XA_INTEGER, 8, &value, 1);
f7d48e
 }
8a83d7
@@ -307,6 +525,27 @@ meta_input_settings_x11_set_invert_scroll (MetaInputSettings  *settings,
f7d48e
 {
f7d48e
   guchar value = (inverted) ? 1 : 0;
f7d48e
 
f7d48e
+  if (is_device_synaptics (device))
f7d48e
+    {
f7d48e
+      gint32 *scrolling_distance;
f7d48e
+
f7d48e
+      scrolling_distance = get_property (device, "Synaptics Scrolling Distance",
f7d48e
+                                         XA_INTEGER, 32, 2);
f7d48e
+      if (scrolling_distance)
f7d48e
+        {
f7d48e
+          scrolling_distance[0] = inverted ?
f7d48e
+            -abs (scrolling_distance[0]) : abs (scrolling_distance[0]);
f7d48e
+          scrolling_distance[1] = inverted ?
f7d48e
+            -abs (scrolling_distance[1]) : abs (scrolling_distance[1]);
f7d48e
+
f7d48e
+          change_property (device, "Synaptics Scrolling Distance",
f7d48e
+                           XA_INTEGER, 32, scrolling_distance, 2);
f7d48e
+          meta_XFree (scrolling_distance);
f7d48e
+        }
f7d48e
+
f7d48e
+      return;
f7d48e
+    }
f7d48e
+
f7d48e
   change_property (device, "libinput Natural Scrolling Enabled",
f7d48e
                    XA_INTEGER, 8, &value, 1);
f7d48e
 }
8a83d7
@@ -320,6 +559,41 @@ change_scroll_method (ClutterInputDevice           *device,
f7d48e
   guchar *current = NULL;
f7d48e
   guchar *available = NULL;
f7d48e
 
f7d48e
+  if (is_device_synaptics (device))
f7d48e
+    {
f7d48e
+      switch (method)
f7d48e
+        {
f7d48e
+        case SCROLL_METHOD_FIELD_EDGE:
f7d48e
+          current = get_property (device, "Synaptics Edge Scrolling",
f7d48e
+                                  XA_INTEGER, 8, 3);
f7d48e
+          if (current)
f7d48e
+            {
f7d48e
+              current[0] = enabled;
f7d48e
+              current[1] = enabled;
f7d48e
+              change_property (device, "Synaptics Edge Scrolling",
f7d48e
+                               XA_INTEGER, 8, current, 3);
f7d48e
+              meta_XFree (current);
f7d48e
+            }
f7d48e
+          break;
f7d48e
+        case SCROLL_METHOD_FIELD_2FG:
f7d48e
+          current = get_property (device, "Synaptics Two-Finger Scrolling",
f7d48e
+                                  XA_INTEGER, 8, 2);
f7d48e
+          if (current)
f7d48e
+            {
f7d48e
+              current[0] = enabled;
f7d48e
+              current[1] = enabled;
f7d48e
+              change_property (device, "Synaptics Two-Finger Scrolling",
f7d48e
+                               XA_INTEGER, 8, current, 2);
f7d48e
+              meta_XFree (current);
f7d48e
+            }
f7d48e
+          break;
f7d48e
+        default:
f7d48e
+          break;
f7d48e
+        }
f7d48e
+
f7d48e
+      return;
f7d48e
+    }
f7d48e
+
f7d48e
   available = get_property (device, "libinput Scroll Methods Available",
f7d48e
                             XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
f7d48e
   if (!available || !available[method])
f7d48e
-- 
8a83d7
2.36.1
f7d48e
f7d48e
8a83d7
From 963ff120898e7e42d80d5761753e76adcf16c132 Mon Sep 17 00:00:00 2001
f7d48e
From: Carlos Garnacho <carlosg@gnome.org>
f7d48e
Date: Tue, 13 Feb 2018 11:44:40 +0100
f7d48e
Subject: [PATCH 2/6] clutter: Extend touchpad device property check for
f7d48e
 Synaptics
f7d48e
f7d48e
So we reliably get CLUTTER_TOUCHPAD_DEVICE for those. The other heuristics
f7d48e
to get the device type may fall short.
f7d48e
---
f7d48e
 src/backends/x11/meta-seat-x11.c | 17 +++++++++++++++--
f7d48e
 1 file changed, 15 insertions(+), 2 deletions(-)
f7d48e
f7d48e
diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c
8a83d7
index d43834bd7..73938e22e 100644
f7d48e
--- a/src/backends/x11/meta-seat-x11.c
f7d48e
+++ b/src/backends/x11/meta-seat-x11.c
f7d48e
@@ -246,7 +246,8 @@ is_touch_device (XIAnyClassInfo         **classes,
f7d48e
 }
f7d48e
 
f7d48e
 static gboolean
f7d48e
-is_touchpad_device (XIDeviceInfo *info)
f7d48e
+query_exists_device_property (XIDeviceInfo *info,
f7d48e
+                              const char   *property)
f7d48e
 {
f7d48e
   gulong nitems, bytes_after;
f7d48e
   uint32_t *data = NULL;
f7d48e
@@ -254,7 +255,7 @@ is_touchpad_device (XIDeviceInfo *info)
f7d48e
   Atom type;
f7d48e
   Atom prop;
f7d48e
 
f7d48e
-  prop = XInternAtom (clutter_x11_get_default_display (), "libinput Tapping Enabled", True);
f7d48e
+  prop = XInternAtom (clutter_x11_get_default_display (), property, True);
f7d48e
   if (prop == None)
f7d48e
     return FALSE;
f7d48e
 
f7d48e
@@ -275,6 +276,18 @@ is_touchpad_device (XIDeviceInfo *info)
f7d48e
   return TRUE;
f7d48e
 }
f7d48e
 
f7d48e
+static gboolean
f7d48e
+is_touchpad_device (XIDeviceInfo *info)
f7d48e
+{
f7d48e
+  if (query_exists_device_property (info, "libinput Tapping Enabled"))
f7d48e
+    return TRUE;
f7d48e
+
f7d48e
+  if (query_exists_device_property (info, "Synaptics Off"))
f7d48e
+    return TRUE;
f7d48e
+
f7d48e
+  return FALSE;
f7d48e
+}
f7d48e
+
f7d48e
 static gboolean
f7d48e
 get_device_ids (XIDeviceInfo  *info,
f7d48e
                 char         **vendor_id,
f7d48e
-- 
8a83d7
2.36.1
f7d48e
f7d48e
8a83d7
From 86cc1b46dae01da619980af826eb9bf81cf31143 Mon Sep 17 00:00:00 2001
f7d48e
From: Rui Matos <tiagomatos@gmail.com>
f7d48e
Date: Mon, 9 Oct 2017 18:39:52 +0200
f7d48e
Subject: [PATCH 3/6] backends/x11: Add a synaptics check for two finger scroll
f7d48e
 availability
f7d48e
f7d48e
Commit "backends/x11: Support synaptics configuration" added support
f7d48e
for synaptics two finger scrolling but didn't add the code to check
f7d48e
that it is available resulting in the upper layer always assuming it
f7d48e
isn't.
f7d48e
---
f7d48e
 src/backends/x11/meta-input-settings-x11.c | 11 +++++++++++
f7d48e
 1 file changed, 11 insertions(+)
f7d48e
f7d48e
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
8a83d7
index 426056390..db2b2a4fb 100644
f7d48e
--- a/src/backends/x11/meta-input-settings-x11.c
f7d48e
+++ b/src/backends/x11/meta-input-settings-x11.c
8a83d7
@@ -637,6 +637,17 @@ meta_input_settings_x11_has_two_finger_scroll (MetaInputSettings  *settings,
f7d48e
   guchar *available = NULL;
f7d48e
   gboolean has_two_finger = TRUE;
f7d48e
 
f7d48e
+  if (is_device_synaptics (device))
f7d48e
+    {
f7d48e
+      available = get_property (device, "Synaptics Capabilities",
f7d48e
+                                XA_INTEGER, 8, 4);
f7d48e
+      if (!available || !available[3])
f7d48e
+          has_two_finger = FALSE;
f7d48e
+
f7d48e
+      meta_XFree (available);
f7d48e
+      return has_two_finger;
f7d48e
+    }
f7d48e
+
f7d48e
   available = get_property (device, "libinput Scroll Methods Available",
f7d48e
                             XA_INTEGER, 8, SCROLL_METHOD_NUM_FIELDS);
f7d48e
   if (!available || !available[SCROLL_METHOD_FIELD_2FG])
f7d48e
-- 
8a83d7
2.36.1
f7d48e
f7d48e
8a83d7
From 32e2da07eeb1f9edcf03751285a756ab1acca6a8 Mon Sep 17 00:00:00 2001
f7d48e
From: Rui Matos <tiagomatos@gmail.com>
f7d48e
Date: Mon, 9 Oct 2017 18:55:56 +0200
f7d48e
Subject: [PATCH 4/6] backends/x11: Add disable while typing support for
f7d48e
 synaptics
f7d48e
f7d48e
This is basically a copy of the old g-s-d mouse plugin code to manage
f7d48e
syndaemon when the synaptics driver is being used.
f7d48e
---
f7d48e
 src/backends/x11/meta-input-settings-x11.c | 112 +++++++++++++++++++++
f7d48e
 1 file changed, 112 insertions(+)
f7d48e
f7d48e
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
8a83d7
index db2b2a4fb..bf9d769e9 100644
f7d48e
--- a/src/backends/x11/meta-input-settings-x11.c
f7d48e
+++ b/src/backends/x11/meta-input-settings-x11.c
f7d48e
@@ -35,6 +35,9 @@
f7d48e
 #ifdef HAVE_LIBGUDEV
f7d48e
 #include <gudev/gudev.h>
f7d48e
 #endif
f7d48e
+#ifdef __linux
f7d48e
+#include <sys/prctl.h>
f7d48e
+#endif
f7d48e
 
f7d48e
 #include "backends/x11/meta-backend-x11.h"
f7d48e
 #include "backends/x11/meta-input-device-x11.h"
f7d48e
@@ -46,6 +49,8 @@ typedef struct _MetaInputSettingsX11Private
f7d48e
 #ifdef HAVE_LIBGUDEV
f7d48e
   GUdevClient *udev_client;
f7d48e
 #endif
f7d48e
+  gboolean syndaemon_spawned;
f7d48e
+  GPid syndaemon_pid;
f7d48e
 } MetaInputSettingsX11Private;
f7d48e
 
f7d48e
 G_DEFINE_TYPE_WITH_PRIVATE (MetaInputSettingsX11, meta_input_settings_x11,
8a83d7
@@ -343,6 +348,107 @@ change_synaptics_speed (ClutterInputDevice *device,
f7d48e
   XCloseDevice (xdisplay, xdevice);
f7d48e
 }
f7d48e
 
f7d48e
+/* Ensure that syndaemon dies together with us, to avoid running several of
f7d48e
+ * them */
f7d48e
+static void
f7d48e
+setup_syndaemon (gpointer user_data)
f7d48e
+{
f7d48e
+#ifdef __linux
f7d48e
+  prctl (PR_SET_PDEATHSIG, SIGHUP);
f7d48e
+#endif
f7d48e
+}
f7d48e
+
f7d48e
+static gboolean
f7d48e
+have_program_in_path (const char *name)
f7d48e
+{
f7d48e
+  gchar *path;
f7d48e
+  gboolean result;
f7d48e
+
f7d48e
+  path = g_find_program_in_path (name);
f7d48e
+  result = (path != NULL);
f7d48e
+  g_free (path);
f7d48e
+  return result;
f7d48e
+}
f7d48e
+
f7d48e
+static void
f7d48e
+syndaemon_died (GPid     pid,
f7d48e
+                gint     status,
f7d48e
+                gpointer user_data)
f7d48e
+{
f7d48e
+  MetaInputSettingsX11 *settings_x11 = META_INPUT_SETTINGS_X11 (user_data);
f7d48e
+  MetaInputSettingsX11Private *priv =
f7d48e
+    meta_input_settings_x11_get_instance_private (settings_x11);
f7d48e
+  GError *error = NULL;
f7d48e
+
f7d48e
+  if (!g_spawn_check_exit_status (status, &error))
f7d48e
+    {
f7d48e
+      if ((WIFSIGNALED (status) && WTERMSIG (status) != SIGHUP) ||
f7d48e
+          error->domain == G_SPAWN_EXIT_ERROR)
f7d48e
+        g_warning ("Syndaemon exited unexpectedly: %s", error->message);
f7d48e
+      g_error_free (error);
f7d48e
+    }
f7d48e
+
f7d48e
+  g_spawn_close_pid (pid);
f7d48e
+  priv->syndaemon_spawned = FALSE;
f7d48e
+}
f7d48e
+
f7d48e
+static void
f7d48e
+set_synaptics_disable_w_typing (MetaInputSettings *settings,
f7d48e
+                                gboolean           state)
f7d48e
+{
f7d48e
+  MetaInputSettingsX11 *settings_x11 = META_INPUT_SETTINGS_X11 (settings);
f7d48e
+  MetaInputSettingsX11Private *priv =
f7d48e
+    meta_input_settings_x11_get_instance_private (settings_x11);
f7d48e
+
f7d48e
+  if (state)
f7d48e
+    {
f7d48e
+      GError *error = NULL;
f7d48e
+      GPtrArray *args;
f7d48e
+
f7d48e
+      if (priv->syndaemon_spawned)
f7d48e
+        return;
f7d48e
+
f7d48e
+      if (!have_program_in_path ("syndaemon"))
f7d48e
+        return;
f7d48e
+
f7d48e
+      args = g_ptr_array_new ();
f7d48e
+
f7d48e
+      g_ptr_array_add (args, (gpointer)"syndaemon");
f7d48e
+      g_ptr_array_add (args, (gpointer)"-i");
f7d48e
+      g_ptr_array_add (args, (gpointer)"1.0");
f7d48e
+      g_ptr_array_add (args, (gpointer)"-t");
f7d48e
+      g_ptr_array_add (args, (gpointer)"-K");
f7d48e
+      g_ptr_array_add (args, (gpointer)"-R");
f7d48e
+      g_ptr_array_add (args, NULL);
f7d48e
+
f7d48e
+      /* we must use G_SPAWN_DO_NOT_REAP_CHILD to avoid
f7d48e
+       * double-forking, otherwise syndaemon will immediately get
f7d48e
+       * killed again through (PR_SET_PDEATHSIG when the intermediate
f7d48e
+       * process dies */
f7d48e
+      g_spawn_async (g_get_home_dir (), (char **) args->pdata, NULL,
f7d48e
+                     G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD, setup_syndaemon, NULL,
f7d48e
+                     &priv->syndaemon_pid, &error);
f7d48e
+
f7d48e
+      priv->syndaemon_spawned = (error == NULL);
f7d48e
+      g_ptr_array_free (args, TRUE);
f7d48e
+
f7d48e
+      if (error)
f7d48e
+        {
f7d48e
+          g_warning ("Failed to launch syndaemon: %s", error->message);
f7d48e
+          g_error_free (error);
f7d48e
+        }
f7d48e
+      else
f7d48e
+        {
f7d48e
+          g_child_watch_add (priv->syndaemon_pid, syndaemon_died, settings);
f7d48e
+        }
f7d48e
+    }
f7d48e
+  else if (priv->syndaemon_spawned)
f7d48e
+    {
f7d48e
+      kill (priv->syndaemon_pid, SIGHUP);
f7d48e
+      priv->syndaemon_spawned = FALSE;
f7d48e
+    }
f7d48e
+}
f7d48e
+
f7d48e
 static void
f7d48e
 meta_input_settings_x11_set_send_events (MetaInputSettings        *settings,
f7d48e
                                          ClutterInputDevice       *device,
8a83d7
@@ -467,6 +573,12 @@ meta_input_settings_x11_set_disable_while_typing (MetaInputSettings  *settings,
f7d48e
 {
f7d48e
   guchar value = (enabled) ? 1 : 0;
f7d48e
 
f7d48e
+  if (is_device_synaptics (device))
f7d48e
+    {
f7d48e
+      set_synaptics_disable_w_typing (settings, enabled);
f7d48e
+      return;
f7d48e
+    }
f7d48e
+
f7d48e
   change_property (device, "libinput Disable While Typing Enabled",
f7d48e
                    XA_INTEGER, 8, &value, 1);
f7d48e
 }
f7d48e
-- 
8a83d7
2.36.1
f7d48e
f7d48e
8a83d7
From 6da0bfe86f416d3cfc5cc6993e8e2f6ca255e85a Mon Sep 17 00:00:00 2001
f7d48e
From: Carlos Garnacho <carlosg@gnome.org>
f7d48e
Date: Wed, 13 Jun 2018 13:48:24 +0200
f7d48e
Subject: [PATCH 5/6] clutter: Only reset scroll axes on slave devices
f7d48e
f7d48e
As a plus, unknown source device IDs will just warn instead of crash.
f7d48e
---
f7d48e
 src/backends/x11/meta-seat-x11.c | 4 +++-
f7d48e
 1 file changed, 3 insertions(+), 1 deletion(-)
f7d48e
f7d48e
diff --git a/src/backends/x11/meta-seat-x11.c b/src/backends/x11/meta-seat-x11.c
8a83d7
index 73938e22e..6d2c7d374 100644
f7d48e
--- a/src/backends/x11/meta-seat-x11.c
f7d48e
+++ b/src/backends/x11/meta-seat-x11.c
f7d48e
@@ -2362,7 +2362,9 @@ meta_seat_x11_translate_event (MetaSeatX11  *seat,
f7d48e
               seat->has_pointer_focus = FALSE;
f7d48e
           }
f7d48e
 
f7d48e
-        meta_input_device_x11_reset_scroll_info (source_device);
f7d48e
+        if (clutter_input_device_get_device_mode (source_device) ==
f7d48e
+            CLUTTER_INPUT_MODE_PHYSICAL)
f7d48e
+          meta_input_device_x11_reset_scroll_info (source_device);
f7d48e
 
f7d48e
         clutter_event_set_device (event, device);
f7d48e
         clutter_event_set_source_device (event, source_device);
f7d48e
-- 
8a83d7
2.36.1
f7d48e
f7d48e
8a83d7
From da60cf38c7fcec68f8e79a8a3a174e551c07a64a Mon Sep 17 00:00:00 2001
f7d48e
From: Rui Matos <tiagomatos@gmail.com>
f7d48e
Date: Tue, 10 Oct 2017 19:07:27 +0200
f7d48e
Subject: [PATCH 6/6] backends/x11: Support plain old X device configuration
f7d48e
f7d48e
We re-use part of the code added to support synaptics and add a few
f7d48e
bits specific for xorg-x11-drv-evdev devices.
f7d48e
---
f7d48e
 src/backends/x11/meta-input-settings-x11.c | 98 +++++++++++++++++-----
f7d48e
 1 file changed, 75 insertions(+), 23 deletions(-)
f7d48e
f7d48e
diff --git a/src/backends/x11/meta-input-settings-x11.c b/src/backends/x11/meta-input-settings-x11.c
8a83d7
index bf9d769e9..49dcb74f1 100644
f7d48e
--- a/src/backends/x11/meta-input-settings-x11.c
f7d48e
+++ b/src/backends/x11/meta-input-settings-x11.c
8a83d7
@@ -185,17 +185,30 @@ is_device_synaptics (ClutterInputDevice *device)
f7d48e
   return TRUE;
f7d48e
 }
f7d48e
 
f7d48e
+static gboolean
f7d48e
+is_device_libinput (ClutterInputDevice *device)
f7d48e
+{
f7d48e
+  guchar *has_setting;
f7d48e
+
f7d48e
+  /* We just need looking for a synaptics-specific property */
f7d48e
+  has_setting = get_property (device, "libinput Send Events Modes Available", XA_INTEGER, 8, 2);
f7d48e
+  if (!has_setting)
f7d48e
+    return FALSE;
f7d48e
+
f7d48e
+  meta_XFree (has_setting);
f7d48e
+  return TRUE;
f7d48e
+}
f7d48e
+
f7d48e
 static void
f7d48e
-change_synaptics_tap_left_handed (ClutterInputDevice *device,
f7d48e
-                                  gboolean            tap_enabled,
f7d48e
-                                  gboolean            left_handed)
f7d48e
+change_x_device_left_handed (ClutterInputDevice *device,
f7d48e
+                             gboolean            left_handed)
f7d48e
 {
f7d48e
   MetaDisplay *display = meta_get_display ();
8a83d7
   MetaBackend *backend = meta_get_backend ();
f7d48e
   Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
f7d48e
   int device_id;
f7d48e
   XDevice *xdevice;
f7d48e
-  guchar *tap_action, *buttons;
f7d48e
+  guchar *buttons;
f7d48e
   guint buttons_capacity = 16, n_buttons;
f7d48e
 
f7d48e
   device_id = meta_input_device_x11_get_device_id (device);
8a83d7
@@ -203,19 +216,6 @@ change_synaptics_tap_left_handed (ClutterInputDevice *device,
f7d48e
   if (!xdevice)
f7d48e
     return;
f7d48e
 
f7d48e
-  tap_action = get_property (device, "Synaptics Tap Action",
f7d48e
-                             XA_INTEGER, 8, 7);
f7d48e
-  if (!tap_action)
f7d48e
-    goto out;
f7d48e
-
f7d48e
-  tap_action[4] = tap_enabled ? (left_handed ? 3 : 1) : 0;
f7d48e
-  tap_action[5] = tap_enabled ? (left_handed ? 1 : 3) : 0;
f7d48e
-  tap_action[6] = tap_enabled ? 2 : 0;
f7d48e
-
f7d48e
-  change_property (device, "Synaptics Tap Action",
f7d48e
-                   XA_INTEGER, 8, tap_action, 7);
f7d48e
-  meta_XFree (tap_action);
f7d48e
-
8a83d7
   clutter_x11_trap_x_errors();
f7d48e
   buttons = g_new (guchar, buttons_capacity);
8a83d7
   n_buttons = XGetDeviceButtonMapping (xdisplay, xdevice,
8a83d7
@@ -238,17 +238,39 @@ change_synaptics_tap_left_handed (ClutterInputDevice *device,
f7d48e
 
8a83d7
   if (clutter_x11_untrap_x_errors())
f7d48e
     {
f7d48e
-      g_warning ("Could not set synaptics touchpad left-handed for %s",
f7d48e
+      g_warning ("Could not set left-handed for %s",
f7d48e
                  clutter_input_device_get_device_name (device));
f7d48e
     }
f7d48e
 
f7d48e
- out:
f7d48e
   XCloseDevice (xdisplay, xdevice);
f7d48e
 }
f7d48e
 
f7d48e
 static void
f7d48e
-change_synaptics_speed (ClutterInputDevice *device,
f7d48e
-                        gdouble             speed)
f7d48e
+change_synaptics_tap_left_handed (ClutterInputDevice *device,
f7d48e
+                                  gboolean            tap_enabled,
f7d48e
+                                  gboolean            left_handed)
f7d48e
+{
f7d48e
+  guchar *tap_action;
f7d48e
+
f7d48e
+  tap_action = get_property (device, "Synaptics Tap Action",
f7d48e
+                             XA_INTEGER, 8, 7);
f7d48e
+  if (!tap_action)
f7d48e
+    return;
f7d48e
+
f7d48e
+  tap_action[4] = tap_enabled ? (left_handed ? 3 : 1) : 0;
f7d48e
+  tap_action[5] = tap_enabled ? (left_handed ? 1 : 3) : 0;
f7d48e
+  tap_action[6] = tap_enabled ? 2 : 0;
f7d48e
+
f7d48e
+  change_property (device, "Synaptics Tap Action",
f7d48e
+                   XA_INTEGER, 8, tap_action, 7);
f7d48e
+  meta_XFree (tap_action);
f7d48e
+
f7d48e
+  change_x_device_left_handed (device, left_handed);
f7d48e
+}
f7d48e
+
f7d48e
+static void
f7d48e
+change_x_device_speed (ClutterInputDevice *device,
f7d48e
+                       gdouble             speed)
f7d48e
 {
f7d48e
   MetaDisplay *display = meta_get_display ();
8a83d7
   MetaBackend *backend = meta_get_backend ();
8a83d7
@@ -348,6 +370,23 @@ change_synaptics_speed (ClutterInputDevice *device,
f7d48e
   XCloseDevice (xdisplay, xdevice);
f7d48e
 }
f7d48e
 
f7d48e
+static void
f7d48e
+change_x_device_scroll_button (ClutterInputDevice *device,
f7d48e
+                               guint               button)
f7d48e
+{
f7d48e
+  guchar value;
f7d48e
+
f7d48e
+  value = button > 0 ? 1 : 0;
f7d48e
+  change_property (device, "Evdev Wheel Emulation",
f7d48e
+                   XA_INTEGER, 8, &value, 1);
f7d48e
+  if (button > 0)
f7d48e
+    {
f7d48e
+      value = button;
f7d48e
+      change_property (device, "Evdev Wheel Emulation Button",
f7d48e
+                       XA_INTEGER, 8, &value, 1);
f7d48e
+    }
f7d48e
+}
f7d48e
+
f7d48e
 /* Ensure that syndaemon dies together with us, to avoid running several of
f7d48e
  * them */
f7d48e
 static void
8a83d7
@@ -516,9 +555,10 @@ meta_input_settings_x11_set_speed (MetaInputSettings  *settings,
f7d48e
   Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
f7d48e
   gfloat value = speed;
f7d48e
 
f7d48e
-  if (is_device_synaptics (device))
f7d48e
+  if (is_device_synaptics (device) ||
f7d48e
+      !is_device_libinput (device))
f7d48e
     {
f7d48e
-      change_synaptics_speed (device, speed);
f7d48e
+      change_x_device_speed (device, speed);
f7d48e
       return;
f7d48e
     }
f7d48e
 
8a83d7
@@ -560,6 +600,11 @@ meta_input_settings_x11_set_left_handed (MetaInputSettings  *settings,
f7d48e
           g_object_unref (settings);
f7d48e
           return;
f7d48e
         }
f7d48e
+      else if (!is_device_libinput (device) && device_type != CLUTTER_PAD_DEVICE)
f7d48e
+        {
f7d48e
+          change_x_device_left_handed (device, enabled);
f7d48e
+          return;
f7d48e
+        }
f7d48e
 
f7d48e
       change_property (device, "libinput Left Handed Enabled",
f7d48e
                        XA_INTEGER, 8, &value, 1);
8a83d7
@@ -777,7 +822,14 @@ meta_input_settings_x11_set_scroll_button (MetaInputSettings  *settings,
f7d48e
 {
f7d48e
   gchar lock = button_lock;
f7d48e
 
f7d48e
+  if (!is_device_libinput (device))
f7d48e
+    {
f7d48e
+      change_x_device_scroll_button (device, button);
f7d48e
+      return;
f7d48e
+    }
f7d48e
+
f7d48e
   change_scroll_method (device, SCROLL_METHOD_FIELD_BUTTON, button != 0);
f7d48e
+
f7d48e
   change_property (device, "libinput Button Scrolling Button",
f7d48e
                    XA_CARDINAL, 32, &button, 1);
f7d48e
   change_property (device, "libinput Button Scrolling Button Lock Enabled",
f7d48e
-- 
8a83d7
2.36.1
f7d48e