laters: Turn into GObject

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2718>
This commit is contained in:
Jonas Ådahl 2022-09-07 18:23:13 +02:00 committed by Robert Mader
parent 4b3cab2cca
commit 7a62e55c54
3 changed files with 39 additions and 15 deletions

View File

@ -1308,7 +1308,7 @@ meta_compositor_dispose (GObject *object)
meta_compositor_get_instance_private (compositor); meta_compositor_get_instance_private (compositor);
ClutterActor *stage = meta_backend_get_stage (priv->backend); ClutterActor *stage = meta_backend_get_stage (priv->backend);
g_clear_pointer (&priv->laters, meta_laters_free); g_clear_object (&priv->laters);
g_clear_signal_handler (&priv->stage_presented_id, stage); g_clear_signal_handler (&priv->stage_presented_id, stage);
g_clear_signal_handler (&priv->before_paint_handler_id, stage); g_clear_signal_handler (&priv->before_paint_handler_id, stage);

View File

@ -46,6 +46,8 @@ typedef struct _MetaLater
struct _MetaLaters struct _MetaLaters
{ {
GObject parent;
MetaCompositor *compositor; MetaCompositor *compositor;
unsigned int last_later_id; unsigned int last_later_id;
@ -55,6 +57,8 @@ struct _MetaLaters
gulong before_update_handler_id; gulong before_update_handler_id;
}; };
G_DEFINE_TYPE (MetaLaters, meta_laters, G_TYPE_OBJECT)
static MetaLater * static MetaLater *
meta_later_ref (MetaLater *later) meta_later_ref (MetaLater *later)
{ {
@ -210,6 +214,35 @@ invoke_later_idle (gpointer data)
} }
} }
static void
meta_laters_finalize (GObject *object)
{
MetaLaters *laters = META_LATERS (object);
ClutterStage *stage = meta_compositor_get_stage (laters->compositor);
unsigned int i;
for (i = 0; i < G_N_ELEMENTS (laters->laters); i++)
g_slist_free_full (laters->laters[i], (GDestroyNotify) meta_later_unref);
g_clear_signal_handler (&laters->before_update_handler_id, stage);
G_OBJECT_CLASS (meta_laters_parent_class)->finalize (object);
}
static void
meta_laters_class_init (MetaLatersClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->finalize = meta_laters_finalize;
}
static void
meta_laters_init (MetaLaters *laters)
{
}
/** /**
* meta_laters_add: * meta_laters_add:
* @laters: a #MetaLaters * @laters: a #MetaLaters
@ -355,7 +388,7 @@ meta_laters_new (MetaCompositor *compositor)
ClutterStage *stage = meta_compositor_get_stage (compositor); ClutterStage *stage = meta_compositor_get_stage (compositor);
MetaLaters *laters; MetaLaters *laters;
laters = g_new0 (MetaLaters, 1); laters = g_object_new (META_TYPE_LATERS, NULL);
laters->compositor = compositor; laters->compositor = compositor;
laters->before_update_handler_id = laters->before_update_handler_id =
@ -365,16 +398,3 @@ meta_laters_new (MetaCompositor *compositor)
return laters; return laters;
} }
void
meta_laters_free (MetaLaters *laters)
{
ClutterStage *stage = meta_compositor_get_stage (laters->compositor);
unsigned int i;
for (i = 0; i < G_N_ELEMENTS (laters->laters); i++)
g_slist_free_full (laters->laters[i], (GDestroyNotify) meta_later_unref);
g_clear_signal_handler (&laters->before_update_handler_id, stage);
g_free (laters);
}

View File

@ -43,6 +43,10 @@ typedef enum
META_LATER_IDLE META_LATER_IDLE
} MetaLaterType; } MetaLaterType;
#define META_TYPE_LATERS (meta_laters_get_type ())
META_EXPORT
G_DECLARE_FINAL_TYPE (MetaLaters, meta_laters, META, LATERS, GObject)
META_EXPORT META_EXPORT
guint meta_later_add (MetaLaterType when, guint meta_later_add (MetaLaterType when,
GSourceFunc func, GSourceFunc func,