kathenas / rpms / mutter

Forked from rpms/mutter 5 years ago
Clone

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

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