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
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/285>
This commit is contained in:
Carlos Garnacho 2022-01-13 14:22:16 +01:00 committed by Marge Bot
parent a870e6b38d
commit d90adfe303

View File

@ -120,6 +120,8 @@ static MetaBackend *_backend;
static gboolean stage_views_disabled = FALSE; static gboolean stage_views_disabled = FALSE;
#define HIDDEN_POINTER_TIMEOUT 300 /* ms */
/** /**
* meta_get_backend: * meta_get_backend:
* *
@ -186,6 +188,8 @@ struct _MetaBackendPrivate
guint sleep_signal_id; guint sleep_signal_id;
GCancellable *cancellable; GCancellable *cancellable;
GDBusConnection *system_bus; GDBusConnection *system_bus;
uint32_t last_pointer_motion;
}; };
typedef struct _MetaBackendPrivate MetaBackendPrivate; typedef struct _MetaBackendPrivate MetaBackendPrivate;
@ -394,7 +398,7 @@ determine_hotplug_pointer_visibility (ClutterSeat *seat)
{ {
g_autoptr (GList) devices = NULL; g_autoptr (GList) devices = NULL;
const GList *l; 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); devices = clutter_seat_list_devices (seat);
@ -410,9 +414,13 @@ determine_hotplug_pointer_visibility (ClutterSeat *seat)
if (device_type == CLUTTER_POINTER_DEVICE || if (device_type == CLUTTER_POINTER_DEVICE ||
device_type == CLUTTER_TOUCHPAD_DEVICE) device_type == CLUTTER_TOUCHPAD_DEVICE)
has_pointer = TRUE; 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 static void
@ -1006,23 +1014,39 @@ update_pointer_visibility_from_event (MetaBackend *backend,
MetaCursorTracker *cursor_tracker = priv->cursor_tracker; MetaCursorTracker *cursor_tracker = priv->cursor_tracker;
ClutterInputDevice *device; ClutterInputDevice *device;
ClutterInputDeviceType device_type; ClutterInputDeviceType device_type;
uint32_t time_ms;
device = clutter_event_get_source_device (event); device = clutter_event_get_source_device (event);
if (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_PHYSICAL) if (clutter_input_device_get_device_mode (device) != CLUTTER_INPUT_MODE_PHYSICAL)
return; return;
device_type = clutter_input_device_get_device_type (device); device_type = clutter_input_device_get_device_type (device);
time_ms = clutter_event_get_time (event);
switch (device_type) switch (device_type)
{ {
case CLUTTER_KEYBOARD_DEVICE:
break;
case CLUTTER_TOUCHSCREEN_DEVICE: case CLUTTER_TOUCHSCREEN_DEVICE:
meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE); meta_cursor_tracker_set_pointer_visible (cursor_tracker, FALSE);
break; 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); meta_cursor_tracker_set_pointer_visible (cursor_tracker, TRUE);
break; 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;
} }
} }