[mutter/wip/carlosg/there-can-be-only-one: 10/10] backends: Keep cursor hidden on tablet input on Wayland




commit 020d96aca12505728e1fcdc69d3895d1868c5389
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jan 13 14:22:16 2022 +0100

    backends: Keep cursor hidden on tablet input on Wayland
    
    Tablets have their own cursor, in order to avoid confusions just
    hide the regular pointer like we do on touchscreens, so there's
    the illusion that there is a single cursor.
    
    Closes: https://gitlab.gnome.org/GNOME/mutter/issues/75

 src/backends/meta-backend.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)
---
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index 0e49f59405..937c4eb1d3 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -120,6 +120,8 @@ static MetaBackend *_backend;
 
 static gboolean stage_views_disabled = FALSE;
 
+#define HIDDEN_POINTER_TIMEOUT 300 /* ms */
+
 /**
  * meta_get_backend:
  *
@@ -186,6 +188,8 @@ struct _MetaBackendPrivate
   guint sleep_signal_id;
   GCancellable *cancellable;
   GDBusConnection *system_bus;
+
+  uint32_t last_pointer_motion;
 };
 typedef struct _MetaBackendPrivate MetaBackendPrivate;
 
@@ -415,7 +419,7 @@ check_pointer_visibility (ClutterSeat *seat)
 {
   g_autoptr (GList) devices = NULL;
   const GList *l;
-  gboolean has_touchscreen = FALSE, has_pointer = FALSE;
+  gboolean has_touchscreen = FALSE, has_pointer = FALSE, has_tablet = FALSE;
 
   devices = clutter_seat_list_devices (seat);
 
@@ -431,9 +435,13 @@ check_pointer_visibility (ClutterSeat *seat)
       if (device_type == CLUTTER_POINTER_DEVICE ||
           device_type == CLUTTER_TOUCHPAD_DEVICE)
         has_pointer = TRUE;
+      if (device_type == CLUTTER_TABLET_DEVICE ||
+          device_type == CLUTTER_PEN_DEVICE ||
+          device_type == CLUTTER_ERASER_DEVICE)
+        has_tablet = TRUE;
     }
 
-  return has_pointer && !has_touchscreen;
+  return has_pointer && !has_touchscreen && !has_tablet;
 }
 
 static void
@@ -1027,23 +1035,39 @@ update_pointer_visibility_from_event (MetaBackend  *backend,
   MetaCursorTracker *cursor_tracker = priv->cursor_tracker;
   ClutterInputDevice *device;
   ClutterInputDeviceType device_type;
+  uint32_t time_ms;
 
   device = clutter_event_get_source_device (event);
   if (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_PHYSICAL)
     return;
 
   device_type = clutter_input_device_get_device_type (device);
+  time_ms = clutter_event_get_time (event);
 
   switch (device_type)
     {
-    case CLUTTER_KEYBOARD_DEVICE:
-      break;
     case CLUTTER_TOUCHSCREEN_DEVICE:
       meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE);
       break;
-    default:
+    case CLUTTER_POINTER_DEVICE:
+    case CLUTTER_TOUCHPAD_DEVICE:
+      priv->last_pointer_motion = time_ms;
       meta_cursor_tracker_set_pointer_visible (cursor_tracker, TRUE);
       break;
+    case CLUTTER_TABLET_DEVICE:
+    case CLUTTER_PEN_DEVICE:
+    case CLUTTER_ERASER_DEVICE:
+    case CLUTTER_CURSOR_DEVICE:
+      if (meta_is_wayland_compositor () &&
+          time_ms > priv->last_pointer_motion + HIDDEN_POINTER_TIMEOUT)
+        meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE);
+      break;
+    case CLUTTER_KEYBOARD_DEVICE:
+    case CLUTTER_PAD_DEVICE:
+    case CLUTTER_EXTENSION_DEVICE:
+    case CLUTTER_JOYSTICK_DEVICE:
+    default:
+      break;
     }
 }
 


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