[mutter/wip/carlosg/pointers-and-touch] backends/native: Disable touch-mode with pointer presence




commit dbc59b55956b8aa30b11a0078b63611a8a41d02f
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Feb 5 00:33:56 2021 +0100

    backends/native: Disable touch-mode with pointer presence
    
    The original implementation of ::touch-mode tested for keyboard
    presence to know whether the OSK and other touch-only features were
    enabled.
    
    However that didn't pan out, every webcam, card reader and kitchen
    sink like to live a second life as EV_KEY devices. This made the
    detection of actual external keyboards a much harder task than it
    sounds, and was thus removed in commit f8e2234ce59fbb.
    
    Try a different approach here, and test for pointer devices, it
    doesn't matter if internal or external devices, the rationales:
    
    - It is significantly easier to get this right, there's virtually
      no devices with abs/rel axes that don't try to be a real input
      device of some sorts.
    - It's not as good as testing for keyboard presence, but it's the
      next best thing. These usually come in pairs, except in weird
      setups.
    - It is better than not having anything for a number of situations:
      - Non-convertible laptops with a touchscreen will get touch-mode
        disabled due to touchpad presence (plus keyboard). There's
        been complains about OSK triggering with those.
      - Same for desktop machines with USB touchscreens, the mouse
        (and presumably keyboard) attached would make touch-mode
        get in the middle.
      - Convertible laptops with a broken tablet-mode switch get a
        chance to work on tablet modes that do disable input devices
        (e.g. detachable keyboards, or via firmware)
      - Kiosk machines, tablets, and other devices that have a
        touchscreen but will not regularly have a mouse/keyboard
        will get the touch-mode enabled.
    
    All in all, this seems to cover more situations the way we expect it,
    there's only one situation that the OSK would show where it might
    not be desirable, and one that might not show when it better should:
    
    - Tablets and kiosk machines that get one keyboard plugged, but not a
      mouse, will still show the OSK, despite being able to type right
      away.
    - Convertible laptops with broken/unreliable tablet-mode switch (e.g.
      ignored by the kernel) rely entirely on the device/firmware
      characteristics to work. If after folding into tablet mode the
      touchpad remains active, touch-mode will not turn on.
      Fixing the tablet-mode switch on these devices should be preferred,
      as that'll also make libinput magically disable the touchpad.
    
    The latter can be worked around with the a11y toggle. The former is
    merely inconvenient, and nothing prevents the user from plugging a mouse
    in addition.

 src/backends/native/meta-seat-impl.c | 42 ++++++++++++++++++++++++++++++------
 src/backends/native/meta-seat-impl.h |  1 +
 2 files changed, 36 insertions(+), 7 deletions(-)
---
diff --git a/src/backends/native/meta-seat-impl.c b/src/backends/native/meta-seat-impl.c
index 6dd5bfc4db..46bad60812 100644
--- a/src/backends/native/meta-seat-impl.c
+++ b/src/backends/native/meta-seat-impl.c
@@ -63,6 +63,9 @@
 #define BTN_STYLUS3 0x149 /* Linux 4.15 */
 #endif
 
+#define IS_POINTER(type) \
+  (type == CLUTTER_POINTER_DEVICE || type == CLUTTER_TOUCHPAD_DEVICE)
+
 struct _MetaEventSource
 {
   GSource source;
@@ -1490,6 +1493,23 @@ has_touchscreen (MetaSeatImpl *seat_impl)
   return FALSE;
 }
 
+static gboolean
+has_pointer (MetaSeatImpl *seat_impl)
+{
+  GSList *l;
+
+  for (l = seat_impl->devices; l; l = l->next)
+    {
+      ClutterInputDeviceType device_type;
+
+      device_type = clutter_input_device_get_device_type (l->data);
+      if (IS_POINTER (device_type))
+        return TRUE;
+    }
+
+  return FALSE;
+}
+
 static gboolean
 device_is_tablet_switch (MetaInputDeviceNative *device_native)
 {
@@ -1529,11 +1549,14 @@ update_touch_mode (MetaSeatImpl *seat_impl)
   /* If we have a tablet mode switch, honor it being unset */
   else if (seat_impl->has_tablet_switch && !seat_impl->tablet_mode_switch_state)
     touch_mode = FALSE;
-  /* If tablet mode is enabled, or if there is no tablet mode switch
-   * (eg. kiosk machines), assume touch-mode.
+  /* If tablet mode is enabled, go for it */
+  else if (seat_impl->has_tablet_switch && seat_impl->tablet_mode_switch_state)
+    touch_mode = TRUE;
+  /* If there is no tablet mode switch (eg. kiosk machines),
+   * assume touch-mode is mutually exclusive with pointers.
    */
   else
-    touch_mode = TRUE;
+    touch_mode = !seat_impl->has_pointer;
 
   if (seat_impl->touch_mode != touch_mode)
     {
@@ -1553,7 +1576,7 @@ evdev_add_device (MetaSeatImpl           *seat_impl,
 {
   ClutterInputDeviceType type;
   ClutterInputDevice *device;
-  gboolean is_touchscreen, is_tablet_switch;
+  gboolean is_touchscreen, is_tablet_switch, is_pointer;
 
   device = meta_input_device_native_new_in_impl (seat_impl, libinput_device);
 
@@ -1566,11 +1589,13 @@ evdev_add_device (MetaSeatImpl           *seat_impl,
   is_touchscreen = type == CLUTTER_TOUCHSCREEN_DEVICE;
   is_tablet_switch =
     device_is_tablet_switch (META_INPUT_DEVICE_NATIVE (device));
+  is_pointer = IS_POINTER (type);
 
   seat_impl->has_touchscreen |= is_touchscreen;
   seat_impl->has_tablet_switch |= is_tablet_switch;
+  seat_impl->has_pointer |= is_pointer;
 
-  if (is_touchscreen || is_tablet_switch)
+  if (is_touchscreen || is_tablet_switch || is_pointer)
     update_touch_mode (seat_impl);
 
   return device;
@@ -1582,7 +1607,7 @@ evdev_remove_device (MetaSeatImpl          *seat_impl,
 {
   ClutterInputDevice *device;
   ClutterInputDeviceType device_type;
-  gboolean is_touchscreen, is_tablet_switch;
+  gboolean is_touchscreen, is_tablet_switch, is_pointer;
 
   device = CLUTTER_INPUT_DEVICE (device_native);
   seat_impl->devices = g_slist_remove (seat_impl->devices, device);
@@ -1591,13 +1616,16 @@ evdev_remove_device (MetaSeatImpl          *seat_impl,
 
   is_touchscreen = device_type == CLUTTER_TOUCHSCREEN_DEVICE;
   is_tablet_switch = device_is_tablet_switch (device_native);
+  is_pointer = IS_POINTER (device_type);
 
   if (is_touchscreen)
     seat_impl->has_touchscreen = has_touchscreen (seat_impl);
   if (is_tablet_switch)
     seat_impl->has_tablet_switch = has_tablet_switch (seat_impl);
+  if (is_pointer)
+    seat_impl->has_pointer = has_pointer (seat_impl);
 
-  if (is_touchscreen || is_tablet_switch)
+  if (is_touchscreen || is_tablet_switch || is_pointer)
     update_touch_mode (seat_impl);
 
   if (seat_impl->repeat_source && seat_impl->repeat_device == device)
diff --git a/src/backends/native/meta-seat-impl.h b/src/backends/native/meta-seat-impl.h
index bd48f549ad..ec78a9414c 100644
--- a/src/backends/native/meta-seat-impl.h
+++ b/src/backends/native/meta-seat-impl.h
@@ -99,6 +99,7 @@ struct _MetaSeatImpl
   gboolean tablet_mode_switch_state;
   gboolean has_touchscreen;
   gboolean has_tablet_switch;
+  gboolean has_pointer;
   gboolean touch_mode;
   gboolean input_thread_initialized;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]