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
This commit is contained in:
Jonas Ådahl 2020-05-27 09:29:04 +02:00 committed by Georges Basile Stavracas Neto
parent 7876018755
commit 55302dbb38
7 changed files with 87 additions and 14 deletions

View File

@ -21,6 +21,8 @@
#ifndef META_BACKEND_TYPE_H #ifndef META_BACKEND_TYPE_H
#define META_BACKEND_TYPE_H #define META_BACKEND_TYPE_H
typedef struct _MetaBackend MetaBackend;
typedef struct _MetaMonitorManager MetaMonitorManager; typedef struct _MetaMonitorManager MetaMonitorManager;
typedef struct _MetaMonitorConfigManager MetaMonitorConfigManager; typedef struct _MetaMonitorConfigManager MetaMonitorConfigManager;

View File

@ -38,8 +38,21 @@
G_DEFINE_INTERFACE (MetaHwCursorInhibitor, meta_hw_cursor_inhibitor, G_DEFINE_INTERFACE (MetaHwCursorInhibitor, meta_hw_cursor_inhibitor,
G_TYPE_OBJECT) G_TYPE_OBJECT)
enum
{
PROP_0,
PROP_BACKEND,
N_PROPS
};
static GParamSpec *obj_props[N_PROPS];
struct _MetaCursorRendererPrivate struct _MetaCursorRendererPrivate
{ {
MetaBackend *backend;
float current_x; float current_x;
float current_y; float current_y;
@ -89,8 +102,7 @@ align_cursor_position (MetaCursorRenderer *renderer,
{ {
MetaCursorRendererPrivate *priv = MetaCursorRendererPrivate *priv =
meta_cursor_renderer_get_instance_private (renderer); meta_cursor_renderer_get_instance_private (renderer);
MetaBackend *backend = meta_get_backend (); ClutterActor *stage = meta_backend_get_stage (priv->backend);
ClutterActor *stage = meta_backend_get_stage (backend);
ClutterStageView *view; ClutterStageView *view;
cairo_rectangle_int_t view_layout; cairo_rectangle_int_t view_layout;
float view_scale; float view_scale;
@ -115,8 +127,7 @@ queue_redraw (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite) MetaCursorSprite *cursor_sprite)
{ {
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer); MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
MetaBackend *backend = meta_get_backend (); ClutterActor *stage = meta_backend_get_stage (priv->backend);
ClutterActor *stage = meta_backend_get_stage (backend);
CoglTexture *texture; CoglTexture *texture;
graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO; graphene_rect_t rect = GRAPHENE_RECT_INIT_ZERO;
@ -165,13 +176,54 @@ meta_cursor_renderer_real_update_cursor (MetaCursorRenderer *renderer,
return FALSE; 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 static void
meta_cursor_renderer_finalize (GObject *object) meta_cursor_renderer_finalize (GObject *object)
{ {
MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object); MetaCursorRenderer *renderer = META_CURSOR_RENDERER (object);
MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer); MetaCursorRendererPrivate *priv = meta_cursor_renderer_get_instance_private (renderer);
MetaBackend *backend = meta_get_backend (); ClutterActor *stage = meta_backend_get_stage (priv->backend);
ClutterActor *stage = meta_backend_get_stage (backend);
if (priv->stage_overlay) if (priv->stage_overlay)
meta_stage_remove_cursor_overlay (META_STAGE (stage), 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); 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; object_class->finalize = meta_cursor_renderer_finalize;
klass->update_cursor = meta_cursor_renderer_real_update_cursor; 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", signals[CURSOR_PAINTED] = g_signal_new ("cursor-painted",
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST, G_SIGNAL_RUN_LAST,
@ -273,9 +337,11 @@ meta_cursor_renderer_update_cursor (MetaCursorRenderer *renderer,
} }
MetaCursorRenderer * 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 void

View File

@ -54,7 +54,7 @@ struct _MetaCursorRendererClass
MetaCursorSprite *cursor_sprite); MetaCursorSprite *cursor_sprite);
}; };
MetaCursorRenderer * meta_cursor_renderer_new (void); MetaCursorRenderer * meta_cursor_renderer_new (MetaBackend *backend);
void meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer, void meta_cursor_renderer_set_cursor (MetaCursorRenderer *renderer,
MetaCursorSprite *cursor_sprite); MetaCursorSprite *cursor_sprite);

View File

@ -1719,8 +1719,9 @@ meta_cursor_renderer_native_new (MetaBackend *backend)
MetaCursorRendererNative *cursor_renderer_native; MetaCursorRendererNative *cursor_renderer_native;
MetaCursorRendererNativePrivate *priv; MetaCursorRendererNativePrivate *priv;
cursor_renderer_native = cursor_renderer_native = g_object_new (META_TYPE_CURSOR_RENDERER_NATIVE,
g_object_new (META_TYPE_CURSOR_RENDERER_NATIVE, NULL); "backend", backend,
NULL);
priv = priv =
meta_cursor_renderer_native_get_instance_private (cursor_renderer_native); meta_cursor_renderer_native_get_instance_private (cursor_renderer_native);

View File

@ -117,7 +117,9 @@ 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_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 * static MetaInputSettings *

View File

@ -65,7 +65,9 @@ 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_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 * static MetaInputSettings *

View File

@ -931,7 +931,7 @@ meta_wayland_tablet_tool_update (MetaWaylandTabletTool *tool,
break; break;
case CLUTTER_PROXIMITY_IN: case CLUTTER_PROXIMITY_IN:
if (!tool->cursor_renderer) if (!tool->cursor_renderer)
tool->cursor_renderer = meta_cursor_renderer_new (); tool->cursor_renderer = meta_cursor_renderer_new (meta_get_backend ());
tool->current_tablet = tool->current_tablet =
meta_wayland_tablet_seat_lookup_tablet (tool->seat, meta_wayland_tablet_seat_lookup_tablet (tool->seat,
clutter_event_get_source_device (event)); clutter_event_get_source_device (event));