transition-group: Use macros for subclassing boilerplate

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3387>
This commit is contained in:
Bilal Elmoussaoui 2023-11-10 14:36:25 +01:00
parent dc0a4c554a
commit edfd489732
3 changed files with 23 additions and 57 deletions

View File

@ -64,7 +64,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterSwipeAction, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTapAction, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTapAction, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTextBuffer, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTextBuffer, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterText, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterText, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterTransitionGroup, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActorBox, clutter_actor_box_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActorBox, clutter_actor_box_free)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterColor, clutter_color_free) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterColor, clutter_color_free)

View File

@ -43,28 +43,28 @@
#include "clutter/clutter-private.h" #include "clutter/clutter-private.h"
#include "clutter/clutter-timeline-private.h" #include "clutter/clutter-timeline-private.h"
struct _ClutterTransitionGroupPrivate struct _ClutterTransitionGroup
{ {
ClutterTransition parent_instance;
GHashTable *transitions; GHashTable *transitions;
}; };
G_DEFINE_TYPE_WITH_PRIVATE (ClutterTransitionGroup, clutter_transition_group, CLUTTER_TYPE_TRANSITION) G_DEFINE_FINAL_TYPE (ClutterTransitionGroup, clutter_transition_group, CLUTTER_TYPE_TRANSITION)
static void static void
clutter_transition_group_new_frame (ClutterTimeline *timeline, clutter_transition_group_new_frame (ClutterTimeline *timeline,
gint elapsed) gint elapsed)
{ {
ClutterTransitionGroupPrivate *priv; ClutterTransitionGroup *transition = CLUTTER_TRANSITION_GROUP (timeline);
GHashTableIter iter; GHashTableIter iter;
gpointer element; gpointer element;
gint64 msecs; gint64 msecs;
priv = CLUTTER_TRANSITION_GROUP (timeline)->priv;
/* get the time elapsed since the last ::new-frame... */ /* get the time elapsed since the last ::new-frame... */
msecs = clutter_timeline_get_delta (timeline); msecs = clutter_timeline_get_delta (timeline);
g_hash_table_iter_init (&iter, priv->transitions); g_hash_table_iter_init (&iter, transition->transitions);
while (g_hash_table_iter_next (&iter, &element, NULL)) while (g_hash_table_iter_next (&iter, &element, NULL))
{ {
ClutterTimeline *t = element; ClutterTimeline *t = element;
@ -81,13 +81,11 @@ static void
clutter_transition_group_attached (ClutterTransition *transition, clutter_transition_group_attached (ClutterTransition *transition,
ClutterAnimatable *animatable) ClutterAnimatable *animatable)
{ {
ClutterTransitionGroupPrivate *priv; ClutterTransitionGroup *group = CLUTTER_TRANSITION_GROUP (transition);
GHashTableIter iter; GHashTableIter iter;
gpointer element; gpointer element;
priv = CLUTTER_TRANSITION_GROUP (transition)->priv; g_hash_table_iter_init (&iter, group->transitions);
g_hash_table_iter_init (&iter, priv->transitions);
while (g_hash_table_iter_next (&iter, &element, NULL)) while (g_hash_table_iter_next (&iter, &element, NULL))
{ {
ClutterTransition *t = element; ClutterTransition *t = element;
@ -100,13 +98,11 @@ static void
clutter_transition_group_detached (ClutterTransition *transition, clutter_transition_group_detached (ClutterTransition *transition,
ClutterAnimatable *animatable) ClutterAnimatable *animatable)
{ {
ClutterTransitionGroupPrivate *priv; ClutterTransitionGroup *group = CLUTTER_TRANSITION_GROUP (transition);
GHashTableIter iter; GHashTableIter iter;
gpointer element; gpointer element;
priv = CLUTTER_TRANSITION_GROUP (transition)->priv; g_hash_table_iter_init (&iter, group->transitions);
g_hash_table_iter_init (&iter, priv->transitions);
while (g_hash_table_iter_next (&iter, &element, NULL)) while (g_hash_table_iter_next (&iter, &element, NULL))
{ {
ClutterTransition *t = element; ClutterTransition *t = element;
@ -118,13 +114,11 @@ clutter_transition_group_detached (ClutterTransition *transition,
static void static void
clutter_transition_group_started (ClutterTimeline *timeline) clutter_transition_group_started (ClutterTimeline *timeline)
{ {
ClutterTransitionGroupPrivate *priv; ClutterTransitionGroup *transition = CLUTTER_TRANSITION_GROUP (timeline);
GHashTableIter iter; GHashTableIter iter;
gpointer element; gpointer element;
priv = CLUTTER_TRANSITION_GROUP (timeline)->priv; g_hash_table_iter_init (&iter, transition->transitions);
g_hash_table_iter_init (&iter, priv->transitions);
while (g_hash_table_iter_next (&iter, &element, NULL)) while (g_hash_table_iter_next (&iter, &element, NULL))
{ {
ClutterTransition *t = element; ClutterTransition *t = element;
@ -136,11 +130,9 @@ clutter_transition_group_started (ClutterTimeline *timeline)
static void static void
clutter_transition_group_finalize (GObject *gobject) clutter_transition_group_finalize (GObject *gobject)
{ {
ClutterTransitionGroupPrivate *priv; ClutterTransitionGroup *transition = CLUTTER_TRANSITION_GROUP (gobject);
priv = CLUTTER_TRANSITION_GROUP (gobject)->priv; g_hash_table_unref (transition->transitions);
g_hash_table_unref (priv->transitions);
G_OBJECT_CLASS (clutter_transition_group_parent_class)->finalize (gobject); G_OBJECT_CLASS (clutter_transition_group_parent_class)->finalize (gobject);
} }
@ -164,8 +156,7 @@ clutter_transition_group_class_init (ClutterTransitionGroupClass *klass)
static void static void
clutter_transition_group_init (ClutterTransitionGroup *self) clutter_transition_group_init (ClutterTransitionGroup *self)
{ {
self->priv = clutter_transition_group_get_instance_private (self); self->transitions =
self->priv->transitions =
g_hash_table_new_full (NULL, NULL, (GDestroyNotify) g_object_unref, NULL); g_hash_table_new_full (NULL, NULL, (GDestroyNotify) g_object_unref, NULL);
} }
@ -201,7 +192,7 @@ clutter_transition_group_add_transition (ClutterTransitionGroup *group,
g_return_if_fail (CLUTTER_IS_TRANSITION_GROUP (group)); g_return_if_fail (CLUTTER_IS_TRANSITION_GROUP (group));
g_return_if_fail (CLUTTER_IS_TRANSITION (transition)); g_return_if_fail (CLUTTER_IS_TRANSITION (transition));
g_hash_table_add (group->priv->transitions, g_object_ref (transition)); g_hash_table_add (group->transitions, g_object_ref (transition));
} }
/** /**
@ -220,7 +211,7 @@ clutter_transition_group_remove_transition (ClutterTransitionGroup *group,
{ {
g_return_if_fail (CLUTTER_IS_TRANSITION_GROUP (group)); g_return_if_fail (CLUTTER_IS_TRANSITION_GROUP (group));
g_hash_table_remove (group->priv->transitions, transition); g_hash_table_remove (group->transitions, transition);
} }
/** /**
@ -237,5 +228,5 @@ clutter_transition_group_remove_all (ClutterTransitionGroup *group)
{ {
g_return_if_fail (CLUTTER_IS_TRANSITION_GROUP (group)); g_return_if_fail (CLUTTER_IS_TRANSITION_GROUP (group));
g_hash_table_remove_all (group->priv->transitions); g_hash_table_remove_all (group->transitions);
} }

View File

@ -33,37 +33,13 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define CLUTTER_TYPE_TRANSITION_GROUP (clutter_transition_group_get_type ()) #define CLUTTER_TYPE_TRANSITION_GROUP (clutter_transition_group_get_type ())
#define CLUTTER_TRANSITION_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_TRANSITION_GROUP, ClutterTransitionGroup))
#define CLUTTER_IS_TRANSITION_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_TRANSITION_GROUP))
#define CLUTTER_TRANSITION_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_TRANSITION_GROUP, ClutterTransitionGroupClass))
#define CLUTTER_IS_TRANSITION_GROUP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_TRANSITION_GROUP))
#define CLUTTER_TRANSITION_GROUP_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_TRANSITION_GROUP, ClutterTransitionGroup))
typedef struct _ClutterTransitionGroupPrivate ClutterTransitionGroupPrivate;
typedef struct _ClutterTransitionGroupClass ClutterTransitionGroupClass;
struct _ClutterTransitionGroup
{
/*< private >*/
ClutterTransition parent_instance;
ClutterTransitionGroupPrivate *priv;
};
/**
* ClutterTransitionGroupClass:
*
* The #ClutterTransitionGroupClass structure
* contains only private data.
*/
struct _ClutterTransitionGroupClass
{
/*< private >*/
ClutterTransitionClass parent_class;
};
CLUTTER_EXPORT CLUTTER_EXPORT
GType clutter_transition_group_get_type (void) G_GNUC_CONST; G_DECLARE_FINAL_TYPE (ClutterTransitionGroup,
clutter_transition_group,
CLUTTER,
TRANSITION_GROUP,
ClutterTransition)
CLUTTER_EXPORT CLUTTER_EXPORT
ClutterTransition * clutter_transition_group_new (void); ClutterTransition * clutter_transition_group_new (void);