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

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