From 55302dbb38b70649ab8b8583c5d50c918f0a9389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 27 May 2020 09:29:04 +0200 Subject: [PATCH] cursor-renderer: Pass backend to constructor Then use the backend passed instead of the global singleton. https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1289 --- src/backends/meta-backend-types.h | 2 + src/backends/meta-cursor-renderer.c | 82 +++++++++++++++++-- src/backends/meta-cursor-renderer.h | 2 +- .../native/meta-cursor-renderer-native.c | 5 +- src/backends/x11/cm/meta-backend-x11-cm.c | 4 +- .../x11/nested/meta-backend-x11-nested.c | 4 +- src/wayland/meta-wayland-tablet-tool.c | 2 +- 7 files changed, 87 insertions(+), 14 deletions(-) diff --git a/src/backends/meta-backend-types.h b/src/backends/meta-backend-types.h index 2961a8b20..a88d8e1af 100644 --- a/src/backends/meta-backend-types.h +++ b/src/backends/meta-backend-types.h @@ -21,6 +21,8 @@ #ifndef META_BACKEND_TYPE_H #define META_BACKEND_TYPE_H +typedef struct _MetaBackend MetaBackend; + typedef struct _MetaMonitorManager MetaMonitorManager; typedef struct _MetaMonitorConfigManager MetaMonitorConfigManager; diff --git a/src/backends/meta-cursor-renderer.c b/src/backends/meta-cursor-renderer.c index b342a98f3..485e96a8d 100644 --- a/src/backends/meta-cursor-renderer.c +++ b/src/backends/meta-cursor-renderer.c @@ -38,8 +38,21 @@ G_DEFINE_INTERFACE (MetaHwCursorInhibitor, meta_hw_cursor_inhibitor, G_TYPE_OBJECT) +enum +{ + PROP_0, + + PROP_BACKEND, + + N_PROPS +}; + +static GParamSpec *obj_props[N_PROPS]; + struct _MetaCursorRendererPrivate { + MetaBackend *backend; + float current_x; float current_y; @@ -89,8 +102,7 @@ align_cursor_position (MetaCursorRenderer *renderer, { MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer); - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage = meta_backend_get_stage (backend); + ClutterActor *stage = meta_backend_get_stage (priv->backend); ClutterStageView *view; cairo_rectangle_int_t view_layout; float view_scale; @@ -115,8 +127,7 @@ queue_redraw (MetaCursorRenderer *renderer, MetaCursorSprite *cursor_sprite) { MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer); - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage = meta_backend_get_stage (backend); + ClutterActor *stage = meta_backend_get_stage (priv->backend); CoglTexture *texture; graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO; @@ -165,13 +176,54 @@ meta_cursor_renderer_real_update_cursor (MetaCursorRenderer *renderer, return FALSE; } +static void +meta_cursor_renderer_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object); + MetaCursorRendererPrivate *priv = + meta_cursor_renderer_get_instance_private (renderer); + + switch (prop_id) + { + case PROP_BACKEND: + g_value_set_object (value, priv->backend); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + +static void +meta_cursor_renderer_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object); + MetaCursorRendererPrivate *priv = + meta_cursor_renderer_get_instance_private (renderer); + + switch (prop_id) + { + case PROP_BACKEND: + priv->backend = g_value_get_object (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); + break; + } +} + static void meta_cursor_renderer_finalize (GObject *object) { MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object); MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer); - MetaBackend *backend = meta_get_backend (); - ClutterActor *stage = meta_backend_get_stage (backend); + ClutterActor *stage = meta_backend_get_stage (priv->backend); if (priv->stage_overlay) meta_stage_remove_cursor_overlay (META_STAGE (stage), priv->stage_overlay); @@ -186,9 +238,21 @@ meta_cursor_renderer_class_init (MetaCursorRendererClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->get_property = meta_cursor_renderer_get_property; + object_class->set_property = meta_cursor_renderer_set_property; object_class->finalize = meta_cursor_renderer_finalize; klass->update_cursor = meta_cursor_renderer_real_update_cursor; + obj_props[PROP_BACKEND] = + g_param_spec_object ("backend", + "backend", + "MetaBackend", + META_TYPE_BACKEND, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS); + g_object_class_install_properties (object_class, N_PROPS, obj_props); + signals[CURSOR_PAINTED] = g_signal_new ("cursor-painted", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST, @@ -273,9 +337,11 @@ meta_cursor_renderer_update_cursor (MetaCursorRenderer *renderer, } MetaCursorRenderer * -meta_cursor_renderer_new (void) +meta_cursor_renderer_new (MetaBackend *backend) { - return g_object_new (META_TYPE_CURSOR_RENDERER, NULL); + return g_object_new (META_TYPE_CURSOR_RENDERER, + "backend", backend, + NULL); } void diff --git a/src/backends/meta-cursor-renderer.h b/src/backends/meta-cursor-renderer.h index 852551355..15b2bfca6 100644 --- a/src/backends/meta-cursor-renderer.h +++ b/src/backends/meta-cursor-renderer.h @@ -54,7 +54,7 @@ struct _MetaCursorRendererClass MetaCursorSprite *cursor_sprite); }; -MetaCursorRenderer * meta_cursor_renderer_new (void); +MetaCursorRenderer * meta_cursor_renderer_new (MetaBackend *backend); void meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer, MetaCursorSprite *cursor_sprite); diff --git a/src/backends/native/meta-cursor-renderer-native.c b/src/backends/native/meta-cursor-renderer-native.c index 578a9a0a0..8875ce15f 100644 --- a/src/backends/native/meta-cursor-renderer-native.c +++ b/src/backends/native/meta-cursor-renderer-native.c @@ -1719,8 +1719,9 @@ meta_cursor_renderer_native_new (MetaBackend *backend) MetaCursorRendererNative *cursor_renderer_native; MetaCursorRendererNativePrivate *priv; - cursor_renderer_native = - g_object_new (META_TYPE_CURSOR_RENDERER_NATIVE, NULL); + cursor_renderer_native = g_object_new (META_TYPE_CURSOR_RENDERER_NATIVE, + "backend", backend, + NULL); priv = meta_cursor_renderer_native_get_instance_private (cursor_renderer_native); diff --git a/src/backends/x11/cm/meta-backend-x11-cm.c b/src/backends/x11/cm/meta-backend-x11-cm.c index e5ebd68f2..35f1fd4c2 100644 --- a/src/backends/x11/cm/meta-backend-x11-cm.c +++ b/src/backends/x11/cm/meta-backend-x11-cm.c @@ -117,7 +117,9 @@ meta_backend_x11_cm_create_monitor_manager (MetaBackend *backend, static MetaCursorRenderer * meta_backend_x11_cm_create_cursor_renderer (MetaBackend *backend) { - return g_object_new (META_TYPE_CURSOR_RENDERER_X11, NULL); + return g_object_new (META_TYPE_CURSOR_RENDERER_X11, + "backend", backend, + NULL); } static MetaInputSettings * diff --git a/src/backends/x11/nested/meta-backend-x11-nested.c b/src/backends/x11/nested/meta-backend-x11-nested.c index def74bb74..37d611eb3 100644 --- a/src/backends/x11/nested/meta-backend-x11-nested.c +++ b/src/backends/x11/nested/meta-backend-x11-nested.c @@ -65,7 +65,9 @@ meta_backend_x11_nested_create_monitor_manager (MetaBackend *backend, static MetaCursorRenderer * meta_backend_x11_nested_create_cursor_renderer (MetaBackend *backend) { - return g_object_new (META_TYPE_CURSOR_RENDERER_X11_NESTED, NULL); + return g_object_new (META_TYPE_CURSOR_RENDERER_X11_NESTED, + "backend", backend, + NULL); } static MetaInputSettings * diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c index e960cc63b..677ccdd30 100644 --- a/src/wayland/meta-wayland-tablet-tool.c +++ b/src/wayland/meta-wayland-tablet-tool.c @@ -931,7 +931,7 @@ meta_wayland_tablet_tool_update (MetaWaylandTabletTool *tool, break; case CLUTTER_PROXIMITY_IN: if (!tool->cursor_renderer) - tool->cursor_renderer = meta_cursor_renderer_new (); + tool->cursor_renderer = meta_cursor_renderer_new (meta_get_backend ()); tool->current_tablet = meta_wayland_tablet_seat_lookup_tablet (tool->seat, clutter_event_get_source_device (event));