mirror of
https://github.com/brl/mutter.git
synced 2024-11-12 17:27:03 -05:00
Make MetaCursorSprite a GObject
To easier track lifetime and utilize other GObject features, make MetaCursorSprite a GObject. https://bugzilla.gnome.org/show_bug.cgi?id=744932
This commit is contained in:
parent
4b667d1e09
commit
b01f95cfdd
@ -31,7 +31,8 @@
|
||||
#include <gbm.h>
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
CoglTexture2D *texture;
|
||||
int hot_x, hot_y;
|
||||
|
||||
@ -40,8 +41,9 @@ typedef struct {
|
||||
#endif
|
||||
} MetaCursorImage;
|
||||
|
||||
struct _MetaCursorSprite {
|
||||
int ref_count;
|
||||
struct _MetaCursorSprite
|
||||
{
|
||||
GObject parent;
|
||||
|
||||
int current_frame;
|
||||
XcursorImages *xcursor_images;
|
||||
|
@ -85,9 +85,9 @@ sync_cursor (MetaCursorTracker *tracker)
|
||||
if (tracker->displayed_cursor == displayed_cursor)
|
||||
return;
|
||||
|
||||
g_clear_pointer (&tracker->displayed_cursor, meta_cursor_sprite_unref);
|
||||
g_clear_object (&tracker->displayed_cursor);
|
||||
if (displayed_cursor)
|
||||
tracker->displayed_cursor = meta_cursor_sprite_ref (displayed_cursor);
|
||||
tracker->displayed_cursor = g_object_ref (displayed_cursor);
|
||||
|
||||
update_displayed_cursor (tracker);
|
||||
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
|
||||
@ -108,9 +108,9 @@ meta_cursor_tracker_finalize (GObject *object)
|
||||
MetaCursorTracker *self = META_CURSOR_TRACKER (object);
|
||||
|
||||
if (self->displayed_cursor)
|
||||
meta_cursor_sprite_unref (self->displayed_cursor);
|
||||
g_object_unref (self->displayed_cursor);
|
||||
if (self->root_cursor)
|
||||
meta_cursor_sprite_unref (self->root_cursor);
|
||||
g_object_unref (self->root_cursor);
|
||||
|
||||
G_OBJECT_CLASS (meta_cursor_tracker_parent_class)->finalize (object);
|
||||
}
|
||||
@ -160,9 +160,9 @@ set_window_cursor (MetaCursorTracker *tracker,
|
||||
gboolean has_cursor,
|
||||
MetaCursorSprite *cursor_sprite)
|
||||
{
|
||||
g_clear_pointer (&tracker->window_cursor, meta_cursor_sprite_unref);
|
||||
g_clear_object (&tracker->window_cursor);
|
||||
if (cursor_sprite)
|
||||
tracker->window_cursor = meta_cursor_sprite_ref (cursor_sprite);
|
||||
tracker->window_cursor = g_object_ref (cursor_sprite);
|
||||
tracker->has_window_cursor = has_cursor;
|
||||
sync_cursor (tracker);
|
||||
}
|
||||
@ -184,28 +184,12 @@ meta_cursor_tracker_handle_xevent (MetaCursorTracker *tracker,
|
||||
if (notify_event->subtype != XFixesDisplayCursorNotify)
|
||||
return FALSE;
|
||||
|
||||
g_clear_pointer (&tracker->xfixes_cursor, meta_cursor_sprite_unref);
|
||||
g_clear_object (&tracker->xfixes_cursor);
|
||||
g_signal_emit (tracker, signals[CURSOR_CHANGED], 0);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static MetaCursorSprite *
|
||||
meta_cursor_sprite_take_texture (CoglTexture2D *texture,
|
||||
int hot_x,
|
||||
int hot_y)
|
||||
{
|
||||
MetaCursorSprite *self;
|
||||
|
||||
self = g_slice_new0 (MetaCursorSprite);
|
||||
self->ref_count = 1;
|
||||
self->image.texture = texture;
|
||||
self->image.hot_x = hot_x;
|
||||
self->image.hot_y = hot_y;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
static void
|
||||
ensure_xfixes_cursor (MetaCursorTracker *tracker)
|
||||
{
|
||||
@ -264,9 +248,10 @@ ensure_xfixes_cursor (MetaCursorTracker *tracker)
|
||||
if (sprite != NULL)
|
||||
{
|
||||
MetaCursorSprite *cursor_sprite =
|
||||
meta_cursor_sprite_take_texture (sprite,
|
||||
meta_cursor_sprite_from_texture (sprite,
|
||||
cursor_image->xhot,
|
||||
cursor_image->yhot);
|
||||
cogl_object_unref (sprite);
|
||||
tracker->xfixes_cursor = cursor_sprite;
|
||||
}
|
||||
XFree (cursor_image);
|
||||
@ -354,9 +339,9 @@ void
|
||||
meta_cursor_tracker_set_root_cursor (MetaCursorTracker *tracker,
|
||||
MetaCursorSprite *cursor_sprite)
|
||||
{
|
||||
g_clear_pointer (&tracker->root_cursor, meta_cursor_sprite_unref);
|
||||
g_clear_object (&tracker->root_cursor);
|
||||
if (cursor_sprite)
|
||||
tracker->root_cursor = meta_cursor_sprite_ref (cursor_sprite);
|
||||
tracker->root_cursor = g_object_ref (cursor_sprite);
|
||||
|
||||
sync_cursor (tracker);
|
||||
}
|
||||
|
@ -43,14 +43,9 @@
|
||||
#include <cogl/cogl-wayland-server.h>
|
||||
#endif
|
||||
|
||||
MetaCursorSprite *
|
||||
meta_cursor_sprite_ref (MetaCursorSprite *self)
|
||||
{
|
||||
g_assert (self->ref_count > 0);
|
||||
self->ref_count++;
|
||||
GType meta_cursor_sprite_get_type (void) G_GNUC_CONST;
|
||||
|
||||
return self;
|
||||
}
|
||||
G_DEFINE_TYPE (MetaCursorSprite, meta_cursor_sprite, G_TYPE_OBJECT)
|
||||
|
||||
static void
|
||||
meta_cursor_image_free (MetaCursorImage *image)
|
||||
@ -64,24 +59,6 @@ meta_cursor_image_free (MetaCursorImage *image)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_sprite_free (MetaCursorSprite *self)
|
||||
{
|
||||
if (self->xcursor_images)
|
||||
XcursorImagesDestroy (self->xcursor_images);
|
||||
meta_cursor_image_free (&self->image);
|
||||
g_slice_free (MetaCursorSprite, self);
|
||||
}
|
||||
|
||||
void
|
||||
meta_cursor_sprite_unref (MetaCursorSprite *self)
|
||||
{
|
||||
self->ref_count--;
|
||||
|
||||
if (self->ref_count == 0)
|
||||
meta_cursor_sprite_free (self);
|
||||
}
|
||||
|
||||
static const char *
|
||||
translate_meta_cursor (MetaCursor cursor)
|
||||
{
|
||||
@ -323,9 +300,30 @@ load_cursor_image (MetaCursorSprite *self)
|
||||
MetaCursorSprite *
|
||||
meta_cursor_sprite_from_theme (MetaCursor cursor)
|
||||
{
|
||||
MetaCursorSprite *self = g_slice_new0 (MetaCursorSprite);
|
||||
self->ref_count = 1;
|
||||
MetaCursorSprite *self;
|
||||
|
||||
self = g_object_new (META_TYPE_CURSOR_SPRITE, NULL);
|
||||
|
||||
self->cursor = cursor;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
MetaCursorSprite *
|
||||
meta_cursor_sprite_from_texture (CoglTexture2D *texture,
|
||||
int hot_x,
|
||||
int hot_y)
|
||||
{
|
||||
MetaCursorSprite *self;
|
||||
|
||||
self = g_object_new (META_TYPE_CURSOR_SPRITE, NULL);
|
||||
|
||||
cogl_object_ref (texture);
|
||||
|
||||
self->image.texture = texture;
|
||||
self->image.hot_x = hot_x;
|
||||
self->image.hot_y = hot_y;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -426,8 +424,8 @@ meta_cursor_sprite_from_buffer (struct wl_resource *buffer,
|
||||
{
|
||||
MetaCursorSprite *self;
|
||||
|
||||
self = g_slice_new0 (MetaCursorSprite);
|
||||
self->ref_count = 1;
|
||||
self = g_object_new (META_TYPE_CURSOR_SPRITE, NULL);
|
||||
|
||||
meta_cursor_image_load_from_buffer (&self->image, buffer, hot_x, hot_y);
|
||||
|
||||
return self;
|
||||
@ -472,3 +470,28 @@ meta_cursor_sprite_get_meta_cursor (MetaCursorSprite *self)
|
||||
{
|
||||
return self->cursor;
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_sprite_init (MetaCursorSprite *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_sprite_finalize (GObject *object)
|
||||
{
|
||||
MetaCursorSprite *self = META_CURSOR_SPRITE (object);
|
||||
|
||||
if (self->xcursor_images)
|
||||
XcursorImagesDestroy (self->xcursor_images);
|
||||
meta_cursor_image_free (&self->image);
|
||||
|
||||
G_OBJECT_CLASS (meta_cursor_sprite_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
meta_cursor_sprite_class_init (MetaCursorSpriteClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->finalize = meta_cursor_sprite_finalize;
|
||||
}
|
||||
|
@ -22,12 +22,15 @@
|
||||
#ifndef META_CURSOR_H
|
||||
#define META_CURSOR_H
|
||||
|
||||
#include <meta/common.h>
|
||||
|
||||
typedef struct _MetaCursorSprite MetaCursorSprite;
|
||||
|
||||
MetaCursorSprite * meta_cursor_sprite_ref (MetaCursorSprite *self);
|
||||
void meta_cursor_sprite_unref (MetaCursorSprite *self);
|
||||
|
||||
#include <meta/common.h>
|
||||
#define META_TYPE_CURSOR_SPRITE (meta_cursor_sprite_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (MetaCursorSprite,
|
||||
meta_cursor_sprite,
|
||||
META, CURSOR_SPRITE,
|
||||
GObject);
|
||||
|
||||
MetaCursorSprite * meta_cursor_sprite_from_theme (MetaCursor cursor);
|
||||
|
||||
@ -40,6 +43,10 @@ MetaCursorSprite * meta_cursor_sprite_from_buffer (struct wl_resource *buffer,
|
||||
|
||||
MetaCursor meta_cursor_sprite_get_meta_cursor (MetaCursorSprite *self);
|
||||
|
||||
MetaCursorSprite * meta_cursor_sprite_from_texture (CoglTexture2D *texture,
|
||||
int hot_x,
|
||||
int hot_y);
|
||||
|
||||
Cursor meta_cursor_create_x_cursor (Display *xdisplay,
|
||||
MetaCursor cursor);
|
||||
|
||||
|
@ -1266,7 +1266,7 @@ meta_screen_update_cursor (MetaScreen *screen)
|
||||
|
||||
cursor_sprite = meta_cursor_sprite_from_theme (cursor);
|
||||
meta_cursor_tracker_set_root_cursor (tracker, cursor_sprite);
|
||||
meta_cursor_sprite_unref (cursor_sprite);
|
||||
g_object_unref (cursor_sprite);
|
||||
|
||||
/* Set a cursor for X11 applications that don't specify their own */
|
||||
xcursor = meta_display_create_x_cursor (display, cursor);
|
||||
|
@ -751,7 +751,7 @@ meta_wayland_pointer_update_cursor_surface (MetaWaylandPointer *pointer)
|
||||
cursor_sprite);
|
||||
|
||||
if (cursor_sprite)
|
||||
meta_cursor_sprite_unref (cursor_sprite);
|
||||
g_object_unref (cursor_sprite);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user