From 7a62e55c54fbaa8b6e626a7588e6f9a52457892f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 7 Sep 2022 18:23:13 +0200 Subject: [PATCH] laters: Turn into GObject Part-of: --- src/compositor/compositor.c | 2 +- src/compositor/meta-later.c | 48 ++++++++++++++++++++++++++----------- src/meta/meta-later.h | 4 ++++ 3 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/compositor/compositor.c b/src/compositor/compositor.c index 5a95fc909..a80746b80 100644 --- a/src/compositor/compositor.c +++ b/src/compositor/compositor.c @@ -1308,7 +1308,7 @@ meta_compositor_dispose (GObject *object) meta_compositor_get_instance_private (compositor); 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->before_paint_handler_id, stage); diff --git a/src/compositor/meta-later.c b/src/compositor/meta-later.c index 3713811ba..70686d03f 100644 --- a/src/compositor/meta-later.c +++ b/src/compositor/meta-later.c @@ -46,6 +46,8 @@ typedef struct _MetaLater struct _MetaLaters { + GObject parent; + MetaCompositor *compositor; unsigned int last_later_id; @@ -55,6 +57,8 @@ struct _MetaLaters gulong before_update_handler_id; }; +G_DEFINE_TYPE (MetaLaters, meta_laters, G_TYPE_OBJECT) + static MetaLater * 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: * @laters: a #MetaLaters @@ -355,7 +388,7 @@ meta_laters_new (MetaCompositor *compositor) ClutterStage *stage = meta_compositor_get_stage (compositor); MetaLaters *laters; - laters = g_new0 (MetaLaters, 1); + laters = g_object_new (META_TYPE_LATERS, NULL); laters->compositor = compositor; laters->before_update_handler_id = @@ -365,16 +398,3 @@ meta_laters_new (MetaCompositor *compositor) 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); -} diff --git a/src/meta/meta-later.h b/src/meta/meta-later.h index 1626024d3..f333f17ad 100644 --- a/src/meta/meta-later.h +++ b/src/meta/meta-later.h @@ -43,6 +43,10 @@ typedef enum META_LATER_IDLE } MetaLaterType; +#define META_TYPE_LATERS (meta_laters_get_type ()) +META_EXPORT +G_DECLARE_FINAL_TYPE (MetaLaters, meta_laters, META, LATERS, GObject) + META_EXPORT guint meta_later_add (MetaLaterType when, GSourceFunc func,