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
This commit is contained in:
Carlos Garnacho 2020-07-10 23:28:50 +02:00
parent 16317cec12
commit 1d3588ba48
7 changed files with 106 additions and 20 deletions

View File

@ -67,7 +67,8 @@ struct _MetaBackendClass
MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend, MetaMonitorManager * (* create_monitor_manager) (MetaBackend *backend,
GError **error); GError **error);
MetaCursorRenderer * (* create_cursor_renderer) (MetaBackend *backend); MetaCursorRenderer * (* get_cursor_renderer) (MetaBackend *backend,
ClutterInputDevice *device);
MetaCursorTracker * (* create_cursor_tracker) (MetaBackend *backend); MetaCursorTracker * (* create_cursor_tracker) (MetaBackend *backend);
MetaRenderer * (* create_renderer) (MetaBackend *backend, MetaRenderer * (* create_renderer) (MetaBackend *backend,
GError **error); GError **error);
@ -131,6 +132,8 @@ META_EXPORT_TEST
MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend); MetaMonitorManager * meta_backend_get_monitor_manager (MetaBackend *backend);
MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend); MetaOrientationManager * meta_backend_get_orientation_manager (MetaBackend *backend);
MetaCursorTracker * meta_backend_get_cursor_tracker (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); MetaCursorRenderer * meta_backend_get_cursor_renderer (MetaBackend *backend);
META_EXPORT_TEST META_EXPORT_TEST
MetaRenderer * meta_backend_get_renderer (MetaBackend *backend); MetaRenderer * meta_backend_get_renderer (MetaBackend *backend);

View File

@ -120,7 +120,7 @@ struct _MetaBackendPrivate
MetaMonitorManager *monitor_manager; MetaMonitorManager *monitor_manager;
MetaOrientationManager *orientation_manager; MetaOrientationManager *orientation_manager;
MetaCursorTracker *cursor_tracker; MetaCursorTracker *cursor_tracker;
MetaCursorRenderer *cursor_renderer; GHashTable *cursor_renderers;
MetaInputSettings *input_settings; MetaInputSettings *input_settings;
MetaRenderer *renderer; MetaRenderer *renderer;
#ifdef HAVE_EGL #ifdef HAVE_EGL
@ -213,6 +213,8 @@ meta_backend_finalize (GObject *object)
g_clear_pointer (&priv->wacom_db, libwacom_database_destroy); g_clear_pointer (&priv->wacom_db, libwacom_database_destroy);
#endif #endif
g_hash_table_unref (priv->cursor_renderers);
if (priv->sleep_signal_id) if (priv->sleep_signal_id)
g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id); g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id);
if (priv->upower_watch_id) if (priv->upower_watch_id)
@ -264,6 +266,19 @@ reset_pointer_position (MetaBackend *backend)
primary->rect.y + primary->rect.height * 0.9); 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 void
meta_backend_monitors_changed (MetaBackend *backend) 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 void
@ -520,8 +535,6 @@ meta_backend_real_post_init (MetaBackend *backend)
meta_backend_sync_screen_size (backend); meta_backend_sync_screen_size (backend);
priv->cursor_renderer = META_BACKEND_GET_CLASS (backend)->create_cursor_renderer (backend);
priv->device_monitors = priv->device_monitors =
g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref); g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref);
@ -1083,8 +1096,25 @@ MetaCursorRenderer *
meta_backend_get_cursor_renderer (MetaBackend *backend) meta_backend_get_cursor_renderer (MetaBackend *backend)
{ {
MetaBackendPrivate *priv = meta_backend_get_instance_private (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);
} }
/** /**

View File

@ -49,7 +49,6 @@
#include "backends/meta-settings-private.h" #include "backends/meta-settings-private.h"
#include "backends/meta-stage-private.h" #include "backends/meta-stage-private.h"
#include "backends/native/meta-clutter-backend-native.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-event-native.h"
#include "backends/native/meta-input-settings-native.h" #include "backends/native/meta-input-settings-native.h"
#include "backends/native/meta-kms.h" #include "backends/native/meta-kms.h"
@ -143,9 +142,14 @@ meta_backend_native_create_monitor_manager (MetaBackend *backend,
} }
static MetaCursorRenderer * 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 * static MetaRenderer *
@ -473,7 +477,7 @@ meta_backend_native_class_init (MetaBackendNativeClass *klass)
backend_class->post_init = meta_backend_native_post_init; backend_class->post_init = meta_backend_native_post_init;
backend_class->create_monitor_manager = meta_backend_native_create_monitor_manager; 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_renderer = meta_backend_native_create_renderer;
backend_class->create_input_settings = meta_backend_native_create_input_settings; backend_class->create_input_settings = meta_backend_native_create_input_settings;

View File

@ -2600,6 +2600,7 @@ meta_seat_native_finalize (GObject *object)
if (seat->touch_states) if (seat->touch_states)
g_hash_table_destroy (seat->touch_states); g_hash_table_destroy (seat->touch_states);
g_object_unref (seat->cursor_renderer);
g_object_unref (seat->udev_client); g_object_unref (seat->udev_client);
meta_event_source_free (seat->event_source); 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); 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;
}

View File

@ -28,6 +28,7 @@
#include <linux/input-event-codes.h> #include <linux/input-event-codes.h>
#include "backends/native/meta-barrier-native.h" #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-keymap-native.h"
#include "backends/native/meta-pointer-constraint-native.h" #include "backends/native/meta-pointer-constraint-native.h"
#include "backends/native/meta-xkb-utils.h" #include "backends/native/meta-xkb-utils.h"
@ -61,6 +62,7 @@ struct _MetaSeatNative
ClutterInputDevice *core_keyboard; ClutterInputDevice *core_keyboard;
GHashTable *touch_states; GHashTable *touch_states;
GHashTable *cursor_renderers;
struct xkb_state *xkb; struct xkb_state *xkb;
xkb_led_index_t caps_lock_led; xkb_led_index_t caps_lock_led;
@ -82,6 +84,7 @@ struct _MetaSeatNative
MetaPointerConstraintImpl *pointer_constraint; MetaPointerConstraintImpl *pointer_constraint;
MetaKeymapNative *keymap; MetaKeymapNative *keymap;
MetaCursorRenderer *cursor_renderer;
GUdevClient *udev_client; GUdevClient *udev_client;
guint tablet_mode_switch_state : 1; 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, void meta_seat_native_set_pointer_constraint (MetaSeatNative *seat,
MetaPointerConstraintImpl *impl); MetaPointerConstraintImpl *impl);
MetaCursorRenderer * meta_seat_native_get_cursor_renderer (MetaSeatNative *seat,
ClutterInputDevice *device);
#endif /* META_SEAT_NATIVE_H */ #endif /* META_SEAT_NATIVE_H */

View File

@ -41,6 +41,7 @@ struct _MetaBackendX11Cm
{ {
MetaBackendX11 parent; MetaBackendX11 parent;
MetaCursorRenderer *cursor_renderer;
char *keymap_layouts; char *keymap_layouts;
char *keymap_variants; char *keymap_variants;
char *keymap_options; char *keymap_options;
@ -116,11 +117,20 @@ meta_backend_x11_cm_create_monitor_manager (MetaBackend *backend,
} }
static MetaCursorRenderer * 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, MetaBackendX11Cm *x11_cm = META_BACKEND_X11_CM (backend);
"backend", backend,
NULL); 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 * 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->post_init = meta_backend_x11_cm_post_init;
backend_class->create_renderer = meta_backend_x11_cm_create_renderer; 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_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_cursor_tracker = meta_backend_x11_cm_create_cursor_tracker;
backend_class->create_input_settings = meta_backend_x11_cm_create_input_settings; backend_class->create_input_settings = meta_backend_x11_cm_create_input_settings;
backend_class->update_screen_size = meta_backend_x11_cm_update_screen_size; backend_class->update_screen_size = meta_backend_x11_cm_update_screen_size;

View File

@ -31,6 +31,7 @@
typedef struct _MetaBackendX11NestedPrivate typedef struct _MetaBackendX11NestedPrivate
{ {
MetaGpu *gpu; MetaGpu *gpu;
MetaCursorRenderer *cursor_renderer;
} MetaBackendX11NestedPrivate; } MetaBackendX11NestedPrivate;
static GInitableIface *initable_parent_iface; static GInitableIface *initable_parent_iface;
@ -63,11 +64,22 @@ meta_backend_x11_nested_create_monitor_manager (MetaBackend *backend,
} }
static MetaCursorRenderer * 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, MetaBackendX11Nested *backend_x11_nested = META_BACKEND_X11_NESTED (backend);
"backend", backend, MetaBackendX11NestedPrivate *priv =
NULL); 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 * 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->post_init = meta_backend_x11_nested_post_init;
backend_class->create_renderer = meta_backend_x11_nested_create_renderer; 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_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->create_input_settings = meta_backend_x11_nested_create_input_settings;
backend_class->update_screen_size = meta_backend_x11_nested_update_screen_size; backend_class->update_screen_size = meta_backend_x11_nested_update_screen_size;
backend_class->select_stage_events = meta_backend_x11_nested_select_stage_events; backend_class->select_stage_events = meta_backend_x11_nested_select_stage_events;