Blame SOURCES/0001-clutter-Backport-of-touch-mode.patch

ebfe55
From 2a2e870c139e2130b00d582546616269bca27458 Mon Sep 17 00:00:00 2001
ebfe55
From: Carlos Garnacho <carlosg@gnome.org>
ebfe55
Date: Fri, 4 Sep 2020 17:11:36 +0200
ebfe55
Subject: [PATCH] clutter: Backport of ::touch-mode
ebfe55
ebfe55
In upstream/master this is a ClutterSeat readonly property. Add it to
ebfe55
ClutterDeviceManager here, the mechanism and triggering is the same
ebfe55
though.
ebfe55
---
ebfe55
 clutter/clutter/clutter-device-manager.c      |  24 +++
ebfe55
 clutter/clutter/clutter-device-manager.h      |   2 +
ebfe55
 .../evdev/clutter-device-manager-evdev.c      | 179 ++++++++++++++++++
ebfe55
 3 files changed, 205 insertions(+)
ebfe55
ebfe55
diff --git a/clutter/clutter/clutter-device-manager.c b/clutter/clutter/clutter-device-manager.c
ebfe55
index c676384..e1cc455 100644
ebfe55
--- a/clutter/clutter/clutter-device-manager.c
ebfe55
+++ b/clutter/clutter/clutter-device-manager.c
ebfe55
@@ -62,6 +62,7 @@ enum
ebfe55
   PROP_0,
ebfe55
 
ebfe55
   PROP_BACKEND,
ebfe55
+  PROP_TOUCH_MODE,
ebfe55
 
ebfe55
   PROP_LAST
ebfe55
 };
ebfe55
@@ -108,6 +109,7 @@ clutter_device_manager_set_property (GObject      *gobject,
ebfe55
       priv->backend = g_value_get_object (value);
ebfe55
       break;
ebfe55
 
ebfe55
+    case PROP_TOUCH_MODE:
ebfe55
     default:
ebfe55
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
ebfe55
     }
ebfe55
@@ -127,6 +129,10 @@ clutter_device_manager_get_property (GObject    *gobject,
ebfe55
       g_value_set_object (value, priv->backend);
ebfe55
       break;
ebfe55
 
ebfe55
+    case PROP_TOUCH_MODE:
ebfe55
+      g_value_set_boolean (value, FALSE);
ebfe55
+      break;
ebfe55
+
ebfe55
     default:
ebfe55
       G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
ebfe55
     }
ebfe55
@@ -143,6 +149,12 @@ clutter_device_manager_class_init (ClutterDeviceManagerClass *klass)
ebfe55
                          P_("The ClutterBackend of the device manager"),
ebfe55
                          CLUTTER_TYPE_BACKEND,
ebfe55
                          CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
ebfe55
+  obj_props[PROP_TOUCH_MODE] =
ebfe55
+    g_param_spec_boolean ("touch-mode",
ebfe55
+			  P_("Touch mode"),
ebfe55
+			  P_("Touch mode"),
ebfe55
+			  FALSE,
ebfe55
+			  CLUTTER_PARAM_READABLE);
ebfe55
 
ebfe55
   gobject_class->set_property = clutter_device_manager_set_property;
ebfe55
   gobject_class->get_property = clutter_device_manager_get_property;
ebfe55
@@ -579,3 +591,15 @@ clutter_device_manager_get_kbd_a11y_settings (ClutterDeviceManager   *device_man
ebfe55
 
ebfe55
   *settings = device_manager->priv->kbd_a11y_settings;
ebfe55
 }
ebfe55
+
ebfe55
+gboolean
ebfe55
+clutter_device_manager_get_touch_mode (ClutterDeviceManager *device_manager)
ebfe55
+{
ebfe55
+  gboolean touch_mode;
ebfe55
+
ebfe55
+  g_return_val_if_fail (CLUTTER_IS_DEVICE_MANAGER (device_manager), FALSE);
ebfe55
+
ebfe55
+  g_object_get (G_OBJECT (device_manager), "touch-mode", &touch_mode, NULL);
ebfe55
+
ebfe55
+  return touch_mode;
ebfe55
+}
ebfe55
diff --git a/clutter/clutter/clutter-device-manager.h b/clutter/clutter/clutter-device-manager.h
ebfe55
index 1cbf030..a4a6271 100644
ebfe55
--- a/clutter/clutter/clutter-device-manager.h
ebfe55
+++ b/clutter/clutter/clutter-device-manager.h
ebfe55
@@ -155,6 +155,8 @@ void clutter_device_manager_set_kbd_a11y_settings (ClutterDeviceManager   *devic
ebfe55
 CLUTTER_EXPORT
ebfe55
 void clutter_device_manager_get_kbd_a11y_settings (ClutterDeviceManager   *device_manager,
ebfe55
                                                    ClutterKbdA11ySettings *settings);
ebfe55
+CLUTTER_EXPORT
ebfe55
+gboolean clutter_device_manager_get_touch_mode (ClutterDeviceManager *device_manager);
ebfe55
 
ebfe55
 G_END_DECLS
ebfe55
 
ebfe55
diff --git a/clutter/clutter/evdev/clutter-device-manager-evdev.c b/clutter/clutter/evdev/clutter-device-manager-evdev.c
ebfe55
index 84b0aad..78b5b64 100644
ebfe55
--- a/clutter/clutter/evdev/clutter-device-manager-evdev.c
ebfe55
+++ b/clutter/clutter/evdev/clutter-device-manager-evdev.c
ebfe55
@@ -108,6 +108,19 @@ struct _ClutterDeviceManagerEvdevPrivate
ebfe55
 
ebfe55
   gint device_id_next;
ebfe55
   GList *free_device_ids;
ebfe55
+
ebfe55
+  guint tablet_mode_switch_state : 1;
ebfe55
+  guint has_touchscreen          : 1;
ebfe55
+  guint has_tablet_switch        : 1;
ebfe55
+  guint has_pointer              : 1;
ebfe55
+  guint touch_mode               : 1;
ebfe55
+};
ebfe55
+
ebfe55
+enum
ebfe55
+{
ebfe55
+  PROP_0,
ebfe55
+  PROP_TOUCH_MODE,
ebfe55
+  N_PROPS
ebfe55
 };
ebfe55
 
ebfe55
 static void clutter_device_manager_evdev_event_extender_init (ClutterEventExtenderInterface *iface);
ebfe55
@@ -765,6 +778,34 @@ clutter_event_source_free (ClutterEventSource *source)
ebfe55
   g_source_unref (g_source);
ebfe55
 }
ebfe55
 
ebfe55
+static void
ebfe55
+update_touch_mode (ClutterDeviceManagerEvdev *manager_evdev)
ebfe55
+{
ebfe55
+  ClutterDeviceManagerEvdevPrivate *priv = manager_evdev->priv;
ebfe55
+  gboolean touch_mode;
ebfe55
+
ebfe55
+  /* No touch mode if we don't have a touchscreen, easy */
ebfe55
+  if (!priv->has_touchscreen)
ebfe55
+    touch_mode = FALSE;
ebfe55
+  /* If we have a tablet mode switch, honor it being unset */
ebfe55
+  else if (priv->has_tablet_switch && !priv->tablet_mode_switch_state)
ebfe55
+    touch_mode = FALSE;
ebfe55
+  /* If tablet mode is enabled, go for it */
ebfe55
+  else if (priv->has_tablet_switch && priv->tablet_mode_switch_state)
ebfe55
+    touch_mode = TRUE;
ebfe55
+  /* If there is no tablet mode switch (eg. kiosk machines),
ebfe55
+   * assume touch-mode is mutually exclusive with pointers.
ebfe55
+   */
ebfe55
+  else
ebfe55
+    touch_mode = !priv->has_pointer;
ebfe55
+
ebfe55
+  if (priv->touch_mode != touch_mode)
ebfe55
+    {
ebfe55
+      priv->touch_mode = touch_mode;
ebfe55
+      g_object_notify (G_OBJECT (manager_evdev), "touch-mode");
ebfe55
+    }
ebfe55
+}
ebfe55
+
ebfe55
 static void
ebfe55
 evdev_add_device (ClutterDeviceManagerEvdev *manager_evdev,
ebfe55
                   struct libinput_device    *libinput_device)
ebfe55
@@ -942,19 +983,81 @@ flush_event_queue (void)
ebfe55
     }
ebfe55
 }
ebfe55
 
ebfe55
+static gboolean
ebfe55
+has_touchscreen (ClutterDeviceManagerEvdev *manager_evdev)
ebfe55
+{
ebfe55
+  ClutterDeviceManagerEvdevPrivate *priv = manager_evdev->priv;
ebfe55
+  GSList *l;
ebfe55
+
ebfe55
+  for (l = priv->devices; l; l = l->next)
ebfe55
+    {
ebfe55
+      ClutterInputDeviceType device_type;
ebfe55
+
ebfe55
+      device_type = clutter_input_device_get_device_type (l->data);
ebfe55
+
ebfe55
+      if (device_type == CLUTTER_TOUCHSCREEN_DEVICE)
ebfe55
+        return TRUE;
ebfe55
+    }
ebfe55
+
ebfe55
+  return FALSE;
ebfe55
+}
ebfe55
+
ebfe55
+static gboolean
ebfe55
+device_type_is_pointer (ClutterInputDeviceType device_type)
ebfe55
+{
ebfe55
+  return (device_type == CLUTTER_POINTER_DEVICE ||
ebfe55
+          device_type == CLUTTER_TOUCHPAD_DEVICE);
ebfe55
+}
ebfe55
+
ebfe55
+static gboolean
ebfe55
+has_pointer (ClutterDeviceManagerEvdev *manager_evdev)
ebfe55
+{
ebfe55
+  ClutterDeviceManagerEvdevPrivate *priv = manager_evdev->priv;
ebfe55
+  GSList *l;
ebfe55
+
ebfe55
+  for (l = priv->devices; l; l = l->next)
ebfe55
+    {
ebfe55
+      ClutterInputDeviceType device_type;
ebfe55
+
ebfe55
+      device_type = clutter_input_device_get_device_type (l->data);
ebfe55
+
ebfe55
+      if (device_type_is_pointer (device_type))
ebfe55
+        return TRUE;
ebfe55
+    }
ebfe55
+
ebfe55
+  return FALSE;
ebfe55
+}
ebfe55
+
ebfe55
 static gboolean
ebfe55
 process_base_event (ClutterDeviceManagerEvdev *manager_evdev,
ebfe55
                     struct libinput_event *event)
ebfe55
 {
ebfe55
+  ClutterDeviceManagerEvdevPrivate *priv = manager_evdev->priv;
ebfe55
   ClutterInputDevice *device;
ebfe55
   struct libinput_device *libinput_device;
ebfe55
   gboolean handled = TRUE;
ebfe55
+  gboolean check_touch_mode;
ebfe55
 
ebfe55
   switch (libinput_event_get_type (event))
ebfe55
     {
ebfe55
     case LIBINPUT_EVENT_DEVICE_ADDED:
ebfe55
       libinput_device = libinput_event_get_device (event);
ebfe55
 
ebfe55
+      priv->has_touchscreen |=
ebfe55
+        libinput_device_has_capability (libinput_device, LIBINPUT_DEVICE_CAP_TOUCH);
ebfe55
+      priv->has_pointer |=
ebfe55
+        libinput_device_has_capability (libinput_device, LIBINPUT_DEVICE_CAP_POINTER);
ebfe55
+      check_touch_mode = priv->has_touchscreen | priv->has_pointer;
ebfe55
+
ebfe55
+      if (libinput_device_has_capability (libinput_device,
ebfe55
+                                          LIBINPUT_DEVICE_CAP_SWITCH) &&
ebfe55
+          libinput_device_switch_has_switch (libinput_device,
ebfe55
+                                             LIBINPUT_SWITCH_TABLET_MODE))
ebfe55
+        {
ebfe55
+          priv->has_tablet_switch = TRUE;
ebfe55
+          check_touch_mode = TRUE;
ebfe55
+        }
ebfe55
+
ebfe55
       evdev_add_device (manager_evdev, libinput_device);
ebfe55
       break;
ebfe55
 
ebfe55
@@ -966,7 +1069,17 @@ process_base_event (ClutterDeviceManagerEvdev *manager_evdev,
ebfe55
 
ebfe55
       libinput_device = libinput_event_get_device (event);
ebfe55
 
ebfe55
+      check_touch_mode =
ebfe55
+        libinput_device_has_capability (libinput_device, LIBINPUT_DEVICE_CAP_TOUCH);
ebfe55
       device = libinput_device_get_user_data (libinput_device);
ebfe55
+      if (check_touch_mode)
ebfe55
+        priv->has_touchscreen = has_touchscreen (manager_evdev);
ebfe55
+      if (device_type_is_pointer (clutter_input_device_get_device_type (device)))
ebfe55
+        {
ebfe55
+          priv->has_pointer = has_pointer (manager_evdev);
ebfe55
+          check_touch_mode = TRUE;
ebfe55
+        }
ebfe55
+
ebfe55
       evdev_remove_device (manager_evdev,
ebfe55
                            CLUTTER_INPUT_DEVICE_EVDEV (device));
ebfe55
       break;
ebfe55
@@ -975,6 +1088,9 @@ process_base_event (ClutterDeviceManagerEvdev *manager_evdev,
ebfe55
       handled = FALSE;
ebfe55
     }
ebfe55
 
ebfe55
+  if (check_touch_mode)
ebfe55
+    update_touch_mode (manager_evdev);
ebfe55
+
ebfe55
   return handled;
ebfe55
 }
ebfe55
 
ebfe55
@@ -1752,6 +1868,23 @@ process_device_event (ClutterDeviceManagerEvdev *manager_evdev,
ebfe55
         notify_pad_ring (device, time, number, source, group, mode, angle);
ebfe55
         break;
ebfe55
       }
ebfe55
+    case LIBINPUT_EVENT_SWITCH_TOGGLE:
ebfe55
+      {
ebfe55
+        ClutterDeviceManagerEvdevPrivate *priv = manager_evdev->priv;
ebfe55
+        struct libinput_event_switch *switch_event =
ebfe55
+          libinput_event_get_switch_event (event);
ebfe55
+        enum libinput_switch sw =
ebfe55
+          libinput_event_switch_get_switch (switch_event);
ebfe55
+        enum libinput_switch_state state =
ebfe55
+          libinput_event_switch_get_switch_state (switch_event);
ebfe55
+
ebfe55
+        if (sw == LIBINPUT_SWITCH_TABLET_MODE)
ebfe55
+          {
ebfe55
+            priv->tablet_mode_switch_state = (state == LIBINPUT_SWITCH_STATE_ON);
ebfe55
+            update_touch_mode (manager_evdev);
ebfe55
+          }
ebfe55
+        break;
ebfe55
+      }
ebfe55
     default:
ebfe55
       handled = FALSE;
ebfe55
     }
ebfe55
@@ -1967,6 +2100,10 @@ clutter_device_manager_evdev_constructed (GObject *gobject)
ebfe55
 
ebfe55
   source = clutter_event_source_new (manager_evdev);
ebfe55
   priv->event_source = source;
ebfe55
+
ebfe55
+  priv->has_touchscreen = has_touchscreen (manager_evdev);
ebfe55
+  priv->has_pointer = has_pointer (manager_evdev);
ebfe55
+  update_touch_mode (manager_evdev);
ebfe55
 }
ebfe55
 
ebfe55
 static void
ebfe55
@@ -2001,6 +2138,43 @@ clutter_device_manager_evdev_dispose (GObject *object)
ebfe55
   G_OBJECT_CLASS (clutter_device_manager_evdev_parent_class)->dispose (object);
ebfe55
 }
ebfe55
 
ebfe55
+static void
ebfe55
+clutter_device_manager_evdev_set_property (GObject      *object,
ebfe55
+                                           guint         prop_id,
ebfe55
+                                           const GValue *value,
ebfe55
+                                           GParamSpec   *pspec)
ebfe55
+{
ebfe55
+  switch (prop_id)
ebfe55
+    {
ebfe55
+    case PROP_TOUCH_MODE:
ebfe55
+    default:
ebfe55
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
ebfe55
+    }
ebfe55
+}
ebfe55
+
ebfe55
+static void
ebfe55
+clutter_device_manager_evdev_get_property (GObject    *object,
ebfe55
+                                           guint       prop_id,
ebfe55
+                                           GValue     *value,
ebfe55
+                                           GParamSpec *pspec)
ebfe55
+{
ebfe55
+  ClutterDeviceManagerEvdev *manager_evdev;
ebfe55
+  ClutterDeviceManagerEvdevPrivate *priv;
ebfe55
+
ebfe55
+  manager_evdev = CLUTTER_DEVICE_MANAGER_EVDEV (object);
ebfe55
+  priv = manager_evdev->priv;
ebfe55
+
ebfe55
+  switch (prop_id)
ebfe55
+    {
ebfe55
+    case PROP_TOUCH_MODE:
ebfe55
+      g_value_set_boolean (value, priv->touch_mode);
ebfe55
+      break;
ebfe55
+    default:
ebfe55
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
ebfe55
+    }
ebfe55
+}
ebfe55
+
ebfe55
+
ebfe55
 static void
ebfe55
 clutter_device_manager_evdev_finalize (GObject *object)
ebfe55
 {
ebfe55
@@ -2036,6 +2210,8 @@ clutter_device_manager_evdev_class_init (ClutterDeviceManagerEvdevClass *klass)
ebfe55
   gobject_class->constructed = clutter_device_manager_evdev_constructed;
ebfe55
   gobject_class->finalize = clutter_device_manager_evdev_finalize;
ebfe55
   gobject_class->dispose = clutter_device_manager_evdev_dispose;
ebfe55
+  gobject_class->set_property = clutter_device_manager_evdev_set_property;
ebfe55
+  gobject_class->get_property = clutter_device_manager_evdev_get_property;
ebfe55
 
ebfe55
   manager_class = CLUTTER_DEVICE_MANAGER_CLASS (klass);
ebfe55
   manager_class->add_device = clutter_device_manager_evdev_add_device;
ebfe55
@@ -2047,6 +2223,9 @@ clutter_device_manager_evdev_class_init (ClutterDeviceManagerEvdevClass *klass)
ebfe55
   manager_class->get_supported_virtual_device_types = clutter_device_manager_evdev_get_supported_virtual_device_types;
ebfe55
   manager_class->compress_motion = clutter_device_manager_evdev_compress_motion;
ebfe55
   manager_class->apply_kbd_a11y_settings = clutter_device_manager_evdev_apply_kbd_a11y_settings;
ebfe55
+
ebfe55
+  g_object_class_override_property (gobject_class, PROP_TOUCH_MODE,
ebfe55
+                                    "touch-mode");
ebfe55
 }
ebfe55
 
ebfe55
 static void
ebfe55
-- 
ebfe55
2.29.2
ebfe55