cursor-sprite: Tag each cursor sprite with a color state
So far, always set a default color state. For Wayland cursors, it will probably be more dynamic in the future. Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3433>
This commit is contained in:
parent
2a6e8f7188
commit
b0e4d7c6ad
@ -20,8 +20,10 @@
|
||||
|
||||
#include "backends/meta-cursor-sprite-xcursor.h"
|
||||
|
||||
#include "backends/meta-backend-private.h"
|
||||
#include "backends/meta-cursor.h"
|
||||
#include "backends/meta-cursor-renderer.h"
|
||||
#include "backends/meta-cursor-tracker-private.h"
|
||||
#include "clutter/clutter.h"
|
||||
#include "cogl/cogl.h"
|
||||
#include "meta/prefs.h"
|
||||
@ -364,14 +366,47 @@ meta_cursor_sprite_xcursor_invalidate (MetaCursorSprite *sprite)
|
||||
sprite_xcursor->invalidated = TRUE;
|
||||
}
|
||||
|
||||
static ClutterColorState *
|
||||
ensure_xcursor_color_state (MetaCursorTracker *cursor_tracker)
|
||||
{
|
||||
ClutterColorState *color_state;
|
||||
static GOnce quark_once = G_ONCE_INIT;
|
||||
|
||||
g_once (&quark_once, (GThreadFunc) g_quark_from_static_string,
|
||||
(gpointer) "-meta-cursor-sprite-xcursor-color-state");
|
||||
|
||||
color_state = g_object_get_qdata (G_OBJECT (cursor_tracker),
|
||||
GPOINTER_TO_INT (quark_once.retval));
|
||||
if (!color_state)
|
||||
{
|
||||
MetaBackend *backend =
|
||||
meta_cursor_tracker_get_backend (cursor_tracker);
|
||||
ClutterContext *clutter_context =
|
||||
meta_backend_get_clutter_context (backend);
|
||||
|
||||
color_state = clutter_color_state_new (clutter_context,
|
||||
CLUTTER_COLORSPACE_DEFAULT,
|
||||
CLUTTER_TRANSFER_FUNCTION_DEFAULT);
|
||||
g_object_set_qdata_full (G_OBJECT (cursor_tracker),
|
||||
GPOINTER_TO_INT (quark_once.retval),
|
||||
color_state, g_object_unref);
|
||||
}
|
||||
|
||||
return color_state;
|
||||
}
|
||||
|
||||
MetaCursorSpriteXcursor *
|
||||
meta_cursor_sprite_xcursor_new (MetaCursor cursor,
|
||||
MetaCursorTracker *cursor_tracker)
|
||||
{
|
||||
MetaCursorSpriteXcursor *sprite_xcursor;
|
||||
ClutterColorState *color_state;
|
||||
|
||||
color_state = ensure_xcursor_color_state (cursor_tracker);
|
||||
|
||||
sprite_xcursor = g_object_new (META_TYPE_CURSOR_SPRITE_XCURSOR,
|
||||
"cursor-tracker", cursor_tracker,
|
||||
"color-state", color_state,
|
||||
NULL);
|
||||
sprite_xcursor->cursor = cursor;
|
||||
|
||||
|
@ -33,6 +33,7 @@ enum
|
||||
PROP_0,
|
||||
|
||||
PROP_CURSOR_TRACKER,
|
||||
PROP_COLOR_STATE,
|
||||
|
||||
N_PROPS
|
||||
};
|
||||
@ -57,6 +58,8 @@ typedef struct _MetaCursorSpritePrivate
|
||||
MetaMonitorTransform texture_transform;
|
||||
int hot_x, hot_y;
|
||||
|
||||
ClutterColorState *color_state;
|
||||
|
||||
MetaCursorPrepareFunc prepare_func;
|
||||
gpointer prepare_func_data;
|
||||
|
||||
@ -277,6 +280,7 @@ meta_cursor_sprite_finalize (GObject *object)
|
||||
meta_cursor_sprite_get_instance_private (sprite);
|
||||
|
||||
g_clear_object (&priv->texture);
|
||||
g_clear_object (&priv->color_state);
|
||||
|
||||
meta_cursor_tracker_unregister_cursor_sprite (priv->cursor_tracker, sprite);
|
||||
g_clear_object (&priv->cursor_tracker);
|
||||
@ -299,6 +303,9 @@ meta_cursor_tracker_set_property (GObject *object,
|
||||
case PROP_CURSOR_TRACKER:
|
||||
g_set_object (&priv->cursor_tracker, g_value_get_object (value));
|
||||
break;
|
||||
case PROP_COLOR_STATE:
|
||||
g_set_object (&priv->color_state, g_value_get_object (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
@ -320,6 +327,12 @@ meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
obj_props[PROP_COLOR_STATE] =
|
||||
g_param_spec_object ("color-state", NULL, NULL,
|
||||
CLUTTER_TYPE_COLOR_STATE,
|
||||
G_PARAM_WRITABLE |
|
||||
G_PARAM_CONSTRUCT_ONLY |
|
||||
G_PARAM_STATIC_STRINGS);
|
||||
g_object_class_install_properties (object_class, N_PROPS, obj_props);
|
||||
|
||||
signals[TEXTURE_CHANGED] = g_signal_new ("texture-changed",
|
||||
@ -329,3 +342,12 @@ meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
|
||||
NULL, NULL, NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
ClutterColorState *
|
||||
meta_cursor_sprite_get_color_state (MetaCursorSprite *sprite)
|
||||
{
|
||||
MetaCursorSpritePrivate *priv =
|
||||
meta_cursor_sprite_get_instance_private (sprite);
|
||||
|
||||
return priv->color_state;
|
||||
}
|
||||
|
@ -92,3 +92,5 @@ gboolean meta_cursor_sprite_is_animated (MetaCursorSprite *sprite);
|
||||
void meta_cursor_sprite_tick_frame (MetaCursorSprite *sprite);
|
||||
|
||||
unsigned int meta_cursor_sprite_get_current_frame_time (MetaCursorSprite *sprite);
|
||||
|
||||
ClutterColorState * meta_cursor_sprite_get_color_state (MetaCursorSprite *sprite);
|
||||
|
@ -20,6 +20,8 @@
|
||||
|
||||
#include "wayland/meta-cursor-sprite-wayland.h"
|
||||
|
||||
#include "backends/meta-cursor-tracker-private.h"
|
||||
|
||||
struct _MetaCursorSpriteWayland
|
||||
{
|
||||
MetaCursorSprite parent;
|
||||
@ -63,14 +65,47 @@ meta_cursor_sprite_wayland_invalidate (MetaCursorSprite *sprite)
|
||||
sprite_wayland->invalidated = TRUE;
|
||||
}
|
||||
|
||||
static ClutterColorState *
|
||||
ensure_default_color_state (MetaCursorTracker *cursor_tracker)
|
||||
{
|
||||
ClutterColorState *color_state;
|
||||
static GOnce quark_once = G_ONCE_INIT;
|
||||
|
||||
g_once (&quark_once, (GThreadFunc) g_quark_from_static_string,
|
||||
(gpointer) "-meta-cursor-sprite-wayland-default-color-state");
|
||||
|
||||
color_state = g_object_get_qdata (G_OBJECT (cursor_tracker),
|
||||
GPOINTER_TO_INT (quark_once.retval));
|
||||
if (!color_state)
|
||||
{
|
||||
MetaBackend *backend =
|
||||
meta_cursor_tracker_get_backend (cursor_tracker);
|
||||
ClutterContext *clutter_context =
|
||||
meta_backend_get_clutter_context (backend);
|
||||
|
||||
color_state = clutter_color_state_new (clutter_context,
|
||||
CLUTTER_COLORSPACE_DEFAULT,
|
||||
CLUTTER_TRANSFER_FUNCTION_DEFAULT);
|
||||
g_object_set_qdata_full (G_OBJECT (cursor_tracker),
|
||||
GPOINTER_TO_INT (quark_once.retval),
|
||||
color_state, g_object_unref);
|
||||
}
|
||||
|
||||
return color_state;
|
||||
}
|
||||
|
||||
MetaCursorSpriteWayland *
|
||||
meta_cursor_sprite_wayland_new (MetaWaylandSurface *surface,
|
||||
MetaCursorTracker *cursor_tracker)
|
||||
{
|
||||
MetaCursorSpriteWayland *sprite_wayland;
|
||||
ClutterColorState *color_state;
|
||||
|
||||
color_state = ensure_default_color_state (cursor_tracker);
|
||||
|
||||
sprite_wayland = g_object_new (META_TYPE_CURSOR_SPRITE_WAYLAND,
|
||||
"cursor-tracker", cursor_tracker,
|
||||
"color-state", color_state,
|
||||
NULL);
|
||||
sprite_wayland->surface = surface;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user