From 1d3588ba48175b42dfa836c363b1b58409d71a6b Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 10 Jul 2020 23:28:50 +0200 Subject: [PATCH] backends: Add meta_backend_get_cursor_renderer_for_device() Different devices may get standalone cursor renderers, add this API to adapt slowly to this. The meta_backend_get_cursor_renderer() call still exists, but shortcuts to the mouse pointer's renderer (as it actually did before). https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1403 --- src/backends/meta-backend-private.h | 5 ++- src/backends/meta-backend.c | 40 ++++++++++++++++--- src/backends/native/meta-backend-native.c | 12 ++++-- src/backends/native/meta-seat-native.c | 22 ++++++++++ src/backends/native/meta-seat-native.h | 5 +++ src/backends/x11/cm/meta-backend-x11-cm.c | 20 +++++++--- .../x11/nested/meta-backend-x11-nested.c | 22 +++++++--- 7 files changed, 106 insertions(+), 20 deletions(-) diff --git a/src/backends/meta-backend-private.h b/src/backends/meta-backend-private.h index 2c02350bf..9ac20eec8 100644 --- a/src/backends/meta-backend-private.h +++ b/src/backends/meta-backend-private.h @@ -67,7 +67,8 @@ struct _MetaBackendClass MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend, GError **error); - MetaCursorRenderer * (* create_cursor_renderer) (MetaBackend *backend); + MetaCursorRenderer * (* get_cursor_renderer) (MetaBackend *backend, + ClutterInputDevice *device); MetaCursorTracker * (* create_cursor_tracker) (MetaBackend *backend); MetaRenderer * (* create_renderer) (MetaBackend *backend, GError **error); @@ -131,6 +132,8 @@ META_EXPORT_TEST MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend); MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend); MetaCursorTracker * meta_backend_get_cursor_tracker (MetaBackend *backend); +MetaCursorRenderer * meta_backend_get_cursor_renderer_for_device (MetaBackend *backend, + ClutterInputDevice *device); MetaCursorRenderer * meta_backend_get_cursor_renderer (MetaBackend *backend); META_EXPORT_TEST MetaRenderer * meta_backend_get_renderer (MetaBackend *backend); diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c index 9a85bb901..7a72d068d 100644 --- a/src/backends/meta-backend.c +++ b/src/backends/meta-backend.c @@ -120,7 +120,7 @@ struct _MetaBackendPrivate MetaMonitorManager *monitor_manager; MetaOrientationManager *orientation_manager; MetaCursorTracker *cursor_tracker; - MetaCursorRenderer *cursor_renderer; + GHashTable *cursor_renderers; MetaInputSettings *input_settings; MetaRenderer *renderer; #ifdef HAVE_EGL @@ -213,6 +213,8 @@ meta_backend_finalize (GObject *object) g_clear_pointer (&priv->wacom_db, libwacom_database_destroy); #endif + g_hash_table_unref (priv->cursor_renderers); + if (priv->sleep_signal_id) g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id); if (priv->upower_watch_id) @@ -264,6 +266,19 @@ reset_pointer_position (MetaBackend *backend) primary->rect.y + primary->rect.height * 0.9); } +static void +update_cursors (MetaBackend *backend) +{ + MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); + MetaCursorRenderer *renderer; + GHashTableIter iter; + + g_hash_table_iter_init (&iter, priv->cursor_renderers); + + while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &renderer)) + meta_cursor_renderer_force_update (renderer); +} + void meta_backend_monitors_changed (MetaBackend *backend) { @@ -289,7 +304,7 @@ meta_backend_monitors_changed (MetaBackend *backend) } } - meta_cursor_renderer_force_update (priv->cursor_renderer); + update_cursors (backend); } void @@ -520,8 +535,6 @@ meta_backend_real_post_init (MetaBackend *backend) meta_backend_sync_screen_size (backend); - priv->cursor_renderer = META_BACKEND_GET_CLASS (backend)->create_cursor_renderer (backend); - priv->device_monitors = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref); @@ -1083,8 +1096,25 @@ MetaCursorRenderer * meta_backend_get_cursor_renderer (MetaBackend *backend) { MetaBackendPrivate *priv = meta_backend_get_instance_private (backend); + ClutterInputDevice *pointer; + ClutterSeat *seat; - return priv->cursor_renderer; + seat = clutter_backend_get_default_seat (priv->clutter_backend); + pointer = clutter_seat_get_pointer (seat); + + return meta_backend_get_cursor_renderer_for_device (backend, pointer); +} + +MetaCursorRenderer * +meta_backend_get_cursor_renderer_for_device (MetaBackend *backend, + ClutterInputDevice *device) +{ + g_return_val_if_fail (META_IS_BACKEND (backend), NULL); + g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), NULL); + g_return_val_if_fail (clutter_input_device_get_device_type (device) != + CLUTTER_KEYBOARD_DEVICE, NULL); + + return META_BACKEND_GET_CLASS (backend)->get_cursor_renderer (backend, device); } /** diff --git a/src/backends/native/meta-backend-native.c b/src/backends/native/meta-backend-native.c index ab69a380e..36e56d48d 100644 --- a/src/backends/native/meta-backend-native.c +++ b/src/backends/native/meta-backend-native.c @@ -49,7 +49,6 @@ #include "backends/meta-settings-private.h" #include "backends/meta-stage-private.h" #include "backends/native/meta-clutter-backend-native.h" -#include "backends/native/meta-cursor-renderer-native.h" #include "backends/native/meta-event-native.h" #include "backends/native/meta-input-settings-native.h" #include "backends/native/meta-kms.h" @@ -143,9 +142,14 @@ meta_backend_native_create_monitor_manager (MetaBackend *backend, } static MetaCursorRenderer * -meta_backend_native_create_cursor_renderer (MetaBackend *backend) +meta_backend_native_get_cursor_renderer (MetaBackend *backend, + ClutterInputDevice *device) { - return META_CURSOR_RENDERER (meta_cursor_renderer_native_new (backend)); + ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); + MetaSeatNative *seat = + META_SEAT_NATIVE (clutter_backend_get_default_seat (clutter_backend)); + + return meta_seat_native_get_cursor_renderer (seat, device); } static MetaRenderer * @@ -473,7 +477,7 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass) backend_class->post_init = meta_backend_native_post_init; backend_class->create_monitor_manager = meta_backend_native_create_monitor_manager; - backend_class->create_cursor_renderer = meta_backend_native_create_cursor_renderer; + backend_class->get_cursor_renderer = meta_backend_native_get_cursor_renderer; backend_class->create_renderer = meta_backend_native_create_renderer; backend_class->create_input_settings = meta_backend_native_create_input_settings; diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c index 6ab562386..2a7f6b850 100644 --- a/src/backends/native/meta-seat-native.c +++ b/src/backends/native/meta-seat-native.c @@ -2600,6 +2600,7 @@ meta_seat_native_finalize (GObject *object) if (seat->touch_states) g_hash_table_destroy (seat->touch_states); + g_object_unref (seat->cursor_renderer); g_object_unref (seat->udev_client); meta_event_source_free (seat->event_source); @@ -3258,3 +3259,24 @@ meta_seat_native_set_pointer_constraint (MetaSeatNative *seat, meta_pointer_constraint_impl_ensure_constrained (impl, seat->core_pointer); } } + +MetaCursorRenderer * +meta_seat_native_get_cursor_renderer (MetaSeatNative *seat, + ClutterInputDevice *device) +{ + if (device == seat->core_pointer) + { + if (!seat->cursor_renderer) + { + MetaCursorRendererNative *renderer_native; + + renderer_native = + meta_cursor_renderer_native_new (meta_get_backend ()); + seat->cursor_renderer = META_CURSOR_RENDERER (renderer_native); + } + + return seat->cursor_renderer; + } + + return NULL; +} diff --git a/src/backends/native/meta-seat-native.h b/src/backends/native/meta-seat-native.h index a104c158b..6fada5956 100644 --- a/src/backends/native/meta-seat-native.h +++ b/src/backends/native/meta-seat-native.h @@ -28,6 +28,7 @@ #include #include "backends/native/meta-barrier-native.h" +#include "backends/native/meta-cursor-renderer-native.h" #include "backends/native/meta-keymap-native.h" #include "backends/native/meta-pointer-constraint-native.h" #include "backends/native/meta-xkb-utils.h" @@ -61,6 +62,7 @@ struct _MetaSeatNative ClutterInputDevice *core_keyboard; GHashTable *touch_states; + GHashTable *cursor_renderers; struct xkb_state *xkb; xkb_led_index_t caps_lock_led; @@ -82,6 +84,7 @@ struct _MetaSeatNative MetaPointerConstraintImpl *pointer_constraint; MetaKeymapNative *keymap; + MetaCursorRenderer *cursor_renderer; GUdevClient *udev_client; guint tablet_mode_switch_state : 1; @@ -255,5 +258,7 @@ MetaBarrierManagerNative * meta_seat_native_get_barrier_manager (MetaSeatNative void meta_seat_native_set_pointer_constraint (MetaSeatNative *seat, MetaPointerConstraintImpl *impl); +MetaCursorRenderer * meta_seat_native_get_cursor_renderer (MetaSeatNative *seat, + ClutterInputDevice *device); #endif /* META_SEAT_NATIVE_H */ diff --git a/src/backends/x11/cm/meta-backend-x11-cm.c b/src/backends/x11/cm/meta-backend-x11-cm.c index 28726f7d7..b00f1ca06 100644 --- a/src/backends/x11/cm/meta-backend-x11-cm.c +++ b/src/backends/x11/cm/meta-backend-x11-cm.c @@ -41,6 +41,7 @@ struct _MetaBackendX11Cm { MetaBackendX11 parent; + MetaCursorRenderer *cursor_renderer; char *keymap_layouts; char *keymap_variants; char *keymap_options; @@ -116,11 +117,20 @@ meta_backend_x11_cm_create_monitor_manager (MetaBackend *backend, } static MetaCursorRenderer * -meta_backend_x11_cm_create_cursor_renderer (MetaBackend *backend) +meta_backend_x11_cm_get_cursor_renderer (MetaBackend *backend, + ClutterInputDevice *device) { - return g_object_new (META_TYPE_CURSOR_RENDERER_X11, - "backend", backend, - NULL); + MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (backend); + + if (!x11_cm->cursor_renderer) + { + x11_cm->cursor_renderer = + g_object_new (META_TYPE_CURSOR_RENDERER_X11, + "backend", backend, + NULL); + } + + return x11_cm->cursor_renderer; } static MetaCursorTracker * @@ -444,7 +454,7 @@ meta_backend_x11_cm_class_init (MetaBackendX11CmClass *klass) backend_class->post_init = meta_backend_x11_cm_post_init; backend_class->create_renderer = meta_backend_x11_cm_create_renderer; backend_class->create_monitor_manager = meta_backend_x11_cm_create_monitor_manager; - backend_class->create_cursor_renderer = meta_backend_x11_cm_create_cursor_renderer; + backend_class->get_cursor_renderer = meta_backend_x11_cm_get_cursor_renderer; backend_class->create_cursor_tracker = meta_backend_x11_cm_create_cursor_tracker; backend_class->create_input_settings = meta_backend_x11_cm_create_input_settings; backend_class->update_screen_size = meta_backend_x11_cm_update_screen_size; diff --git a/src/backends/x11/nested/meta-backend-x11-nested.c b/src/backends/x11/nested/meta-backend-x11-nested.c index 009a80978..27143ce14 100644 --- a/src/backends/x11/nested/meta-backend-x11-nested.c +++ b/src/backends/x11/nested/meta-backend-x11-nested.c @@ -31,6 +31,7 @@ typedef struct _MetaBackendX11NestedPrivate { MetaGpu *gpu; + MetaCursorRenderer *cursor_renderer; } MetaBackendX11NestedPrivate; static GInitableIface *initable_parent_iface; @@ -63,11 +64,22 @@ meta_backend_x11_nested_create_monitor_manager (MetaBackend *backend, } static MetaCursorRenderer * -meta_backend_x11_nested_create_cursor_renderer (MetaBackend *backend) +meta_backend_x11_nested_get_cursor_renderer (MetaBackend *backend, + ClutterInputDevice *device) { - return g_object_new (META_TYPE_CURSOR_RENDERER_X11_NESTED, - "backend", backend, - NULL); + MetaBackendX11Nested *backend_x11_nested = META_BACKEND_X11_NESTED (backend); + MetaBackendX11NestedPrivate *priv = + meta_backend_x11_nested_get_instance_private (backend_x11_nested); + + if (!priv->cursor_renderer) + { + priv->cursor_renderer = + g_object_new (META_TYPE_CURSOR_RENDERER_X11_NESTED, + "backend", backend, + NULL); + } + + return priv->cursor_renderer; } static MetaInputSettings * @@ -275,7 +287,7 @@ meta_backend_x11_nested_class_init (MetaBackendX11NestedClass *klass) backend_class->post_init = meta_backend_x11_nested_post_init; backend_class->create_renderer = meta_backend_x11_nested_create_renderer; backend_class->create_monitor_manager = meta_backend_x11_nested_create_monitor_manager; - backend_class->create_cursor_renderer = meta_backend_x11_nested_create_cursor_renderer; + backend_class->get_cursor_renderer = meta_backend_x11_nested_get_cursor_renderer; backend_class->create_input_settings = meta_backend_x11_nested_create_input_settings; backend_class->update_screen_size = meta_backend_x11_nested_update_screen_size; backend_class->select_stage_events = meta_backend_x11_nested_select_stage_events;