clutter/actor-meta: Use G_DECLARE_DERIVABLE_TYPE

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/788
This commit is contained in:
Jonas Dreßler 2019-07-15 11:51:29 +02:00 committed by Jonas Ådahl
parent c8e12ead08
commit 8c131b32b1
3 changed files with 100 additions and 71 deletions

View File

@ -81,38 +81,47 @@ static void
on_actor_destroy (ClutterActor *actor, on_actor_destroy (ClutterActor *actor,
ClutterActorMeta *meta) ClutterActorMeta *meta)
{ {
meta->priv->actor = NULL; ClutterActorMetaPrivate *priv =
clutter_actor_meta_get_instance_private (meta);
priv->actor = NULL;
} }
static void static void
clutter_actor_meta_real_set_actor (ClutterActorMeta *meta, clutter_actor_meta_real_set_actor (ClutterActorMeta *meta,
ClutterActor *actor) ClutterActor *actor)
{ {
g_warn_if_fail (!meta->priv->actor || ClutterActorMetaPrivate *priv =
!CLUTTER_ACTOR_IN_PAINT (meta->priv->actor)); clutter_actor_meta_get_instance_private (meta);
g_warn_if_fail (!priv->actor ||
!CLUTTER_ACTOR_IN_PAINT (priv->actor));
g_warn_if_fail (!actor || !CLUTTER_ACTOR_IN_PAINT (actor)); g_warn_if_fail (!actor || !CLUTTER_ACTOR_IN_PAINT (actor));
if (meta->priv->actor == actor) if (priv->actor == actor)
return; return;
g_clear_signal_handler (&meta->priv->destroy_id, meta->priv->actor); g_clear_signal_handler (&priv->destroy_id, priv->actor);
meta->priv->actor = actor; priv->actor = actor;
if (meta->priv->actor != NULL) if (priv->actor != NULL)
meta->priv->destroy_id = g_signal_connect (meta->priv->actor, "destroy", priv->destroy_id = g_signal_connect (priv->actor, "destroy",
G_CALLBACK (on_actor_destroy), G_CALLBACK (on_actor_destroy),
meta); meta);
} }
static void static void
clutter_actor_meta_real_set_enabled (ClutterActorMeta *meta, clutter_actor_meta_real_set_enabled (ClutterActorMeta *meta,
gboolean is_enabled) gboolean is_enabled)
{ {
g_warn_if_fail (!meta->priv->actor || ClutterActorMetaPrivate *priv =
!CLUTTER_ACTOR_IN_PAINT (meta->priv->actor)); clutter_actor_meta_get_instance_private (meta);
meta->priv->is_enabled = is_enabled; g_warn_if_fail (!priv->actor ||
!CLUTTER_ACTOR_IN_PAINT (priv->actor));
priv->is_enabled = is_enabled;
g_object_notify_by_pspec (G_OBJECT (meta), obj_props[PROP_ENABLED]); g_object_notify_by_pspec (G_OBJECT (meta), obj_props[PROP_ENABLED]);
} }
@ -147,20 +156,21 @@ clutter_actor_meta_get_property (GObject *gobject,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
ClutterActorMeta *meta = CLUTTER_ACTOR_META (gobject); ClutterActorMetaPrivate *priv =
clutter_actor_meta_get_instance_private (CLUTTER_ACTOR_META (gobject));
switch (prop_id) switch (prop_id)
{ {
case PROP_ACTOR: case PROP_ACTOR:
g_value_set_object (value, meta->priv->actor); g_value_set_object (value, priv->actor);
break; break;
case PROP_NAME: case PROP_NAME:
g_value_set_string (value, meta->priv->name); g_value_set_string (value, priv->name);
break; break;
case PROP_ENABLED: case PROP_ENABLED:
g_value_set_boolean (value, meta->priv->is_enabled); g_value_set_boolean (value, priv->is_enabled);
break; break;
default: default:
@ -172,7 +182,8 @@ clutter_actor_meta_get_property (GObject *gobject,
static void static void
clutter_actor_meta_finalize (GObject *gobject) clutter_actor_meta_finalize (GObject *gobject)
{ {
ClutterActorMetaPrivate *priv = CLUTTER_ACTOR_META (gobject)->priv; ClutterActorMetaPrivate *priv =
clutter_actor_meta_get_instance_private (CLUTTER_ACTOR_META (gobject));
if (priv->actor != NULL) if (priv->actor != NULL)
g_clear_signal_handler (&priv->destroy_id, priv->actor); g_clear_signal_handler (&priv->destroy_id, priv->actor);
@ -243,9 +254,11 @@ clutter_actor_meta_class_init (ClutterActorMetaClass *klass)
void void
clutter_actor_meta_init (ClutterActorMeta *self) clutter_actor_meta_init (ClutterActorMeta *self)
{ {
self->priv = clutter_actor_meta_get_instance_private (self); ClutterActorMetaPrivate *priv =
self->priv->is_enabled = TRUE; clutter_actor_meta_get_instance_private (self);
self->priv->priority = CLUTTER_ACTOR_META_PRIORITY_DEFAULT;
priv->is_enabled = TRUE;
priv->priority = CLUTTER_ACTOR_META_PRIORITY_DEFAULT;
} }
/** /**
@ -263,13 +276,17 @@ void
clutter_actor_meta_set_name (ClutterActorMeta *meta, clutter_actor_meta_set_name (ClutterActorMeta *meta,
const gchar *name) const gchar *name)
{ {
ClutterActorMetaPrivate *priv;
g_return_if_fail (CLUTTER_IS_ACTOR_META (meta)); g_return_if_fail (CLUTTER_IS_ACTOR_META (meta));
if (g_strcmp0 (meta->priv->name, name) == 0) priv = clutter_actor_meta_get_instance_private (meta);
if (g_strcmp0 (priv->name, name) == 0)
return; return;
g_free (meta->priv->name); g_free (priv->name);
meta->priv->name = g_strdup (name); priv->name = g_strdup (name);
g_object_notify_by_pspec (G_OBJECT (meta), obj_props[PROP_NAME]); g_object_notify_by_pspec (G_OBJECT (meta), obj_props[PROP_NAME]);
} }
@ -290,9 +307,13 @@ clutter_actor_meta_set_name (ClutterActorMeta *meta,
const gchar * const gchar *
clutter_actor_meta_get_name (ClutterActorMeta *meta) clutter_actor_meta_get_name (ClutterActorMeta *meta)
{ {
ClutterActorMetaPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_ACTOR_META (meta), NULL); g_return_val_if_fail (CLUTTER_IS_ACTOR_META (meta), NULL);
return meta->priv->name; priv = clutter_actor_meta_get_instance_private (meta);
return priv->name;
} }
/** /**
@ -308,11 +329,14 @@ void
clutter_actor_meta_set_enabled (ClutterActorMeta *meta, clutter_actor_meta_set_enabled (ClutterActorMeta *meta,
gboolean is_enabled) gboolean is_enabled)
{ {
ClutterActorMetaPrivate *priv;
g_return_if_fail (CLUTTER_IS_ACTOR_META (meta)); g_return_if_fail (CLUTTER_IS_ACTOR_META (meta));
priv = clutter_actor_meta_get_instance_private (meta);
is_enabled = !!is_enabled; is_enabled = !!is_enabled;
if (meta->priv->is_enabled == is_enabled) if (priv->is_enabled == is_enabled)
return; return;
CLUTTER_ACTOR_META_GET_CLASS (meta)->set_enabled (meta, is_enabled); CLUTTER_ACTOR_META_GET_CLASS (meta)->set_enabled (meta, is_enabled);
@ -331,9 +355,13 @@ clutter_actor_meta_set_enabled (ClutterActorMeta *meta,
gboolean gboolean
clutter_actor_meta_get_enabled (ClutterActorMeta *meta) clutter_actor_meta_get_enabled (ClutterActorMeta *meta)
{ {
ClutterActorMetaPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_ACTOR_META (meta), FALSE); g_return_val_if_fail (CLUTTER_IS_ACTOR_META (meta), FALSE);
return meta->priv->is_enabled; priv = clutter_actor_meta_get_instance_private (meta);
return priv->is_enabled;
} }
/* /*
@ -369,40 +397,54 @@ _clutter_actor_meta_set_actor (ClutterActorMeta *meta,
ClutterActor * ClutterActor *
clutter_actor_meta_get_actor (ClutterActorMeta *meta) clutter_actor_meta_get_actor (ClutterActorMeta *meta)
{ {
ClutterActorMetaPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_ACTOR_META (meta), NULL); g_return_val_if_fail (CLUTTER_IS_ACTOR_META (meta), NULL);
return meta->priv->actor; priv = clutter_actor_meta_get_instance_private (meta);
return priv->actor;
} }
void void
_clutter_actor_meta_set_priority (ClutterActorMeta *meta, _clutter_actor_meta_set_priority (ClutterActorMeta *meta,
gint priority) gint priority)
{ {
ClutterActorMetaPrivate *priv;
g_return_if_fail (CLUTTER_IS_ACTOR_META (meta)); g_return_if_fail (CLUTTER_IS_ACTOR_META (meta));
priv = clutter_actor_meta_get_instance_private (meta);
/* This property shouldn't be modified after the actor meta is in /* This property shouldn't be modified after the actor meta is in
use because ClutterMetaGroup doesn't resort the list when it use because ClutterMetaGroup doesn't resort the list when it
changes. If we made the priority public then we could either make changes. If we made the priority public then we could either make
the priority a construct-only property or listen for the priority a construct-only property or listen for
notifications on the property from the ClutterMetaGroup and notifications on the property from the ClutterMetaGroup and
resort. */ resort. */
g_return_if_fail (meta->priv->actor == NULL); g_return_if_fail (priv->actor == NULL);
meta->priv->priority = priority; priv->priority = priority;
} }
gint gint
_clutter_actor_meta_get_priority (ClutterActorMeta *meta) _clutter_actor_meta_get_priority (ClutterActorMeta *meta)
{ {
ClutterActorMetaPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_ACTOR_META (meta), 0); g_return_val_if_fail (CLUTTER_IS_ACTOR_META (meta), 0);
return meta->priv->priority; priv = clutter_actor_meta_get_instance_private (meta);
return priv->priority;
} }
gboolean gboolean
_clutter_actor_meta_is_internal (ClutterActorMeta *meta) _clutter_actor_meta_is_internal (ClutterActorMeta *meta)
{ {
gint priority = meta->priv->priority; ClutterActorMetaPrivate *priv =
clutter_actor_meta_get_instance_private (meta);
gint priority = priv->priority;
return (priority <= CLUTTER_ACTOR_META_PRIORITY_INTERNAL_LOW || return (priority <= CLUTTER_ACTOR_META_PRIORITY_INTERNAL_LOW ||
priority >= CLUTTER_ACTOR_META_PRIORITY_INTERNAL_HIGH); priority >= CLUTTER_ACTOR_META_PRIORITY_INTERNAL_HIGH);
@ -449,19 +491,21 @@ void
_clutter_meta_group_add_meta (ClutterMetaGroup *group, _clutter_meta_group_add_meta (ClutterMetaGroup *group,
ClutterActorMeta *meta) ClutterActorMeta *meta)
{ {
ClutterActorMetaPrivate *priv =
clutter_actor_meta_get_instance_private (meta);
GList *prev = NULL, *l; GList *prev = NULL, *l;
if (meta->priv->actor != NULL) if (priv->actor != NULL)
{ {
g_warning ("The meta of type '%s' with name '%s' is " g_warning ("The meta of type '%s' with name '%s' is "
"already attached to actor '%s'", "already attached to actor '%s'",
G_OBJECT_TYPE_NAME (meta), G_OBJECT_TYPE_NAME (meta),
meta->priv->name != NULL priv->name != NULL
? meta->priv->name ? priv->name
: "<unknown>", : "<unknown>",
clutter_actor_get_name (meta->priv->actor) != NULL clutter_actor_get_name (priv->actor) != NULL
? clutter_actor_get_name (meta->priv->actor) ? clutter_actor_get_name (priv->actor)
: G_OBJECT_TYPE_NAME (meta->priv->actor)); : G_OBJECT_TYPE_NAME (priv->actor));
return; return;
} }
@ -497,13 +541,16 @@ void
_clutter_meta_group_remove_meta (ClutterMetaGroup *group, _clutter_meta_group_remove_meta (ClutterMetaGroup *group,
ClutterActorMeta *meta) ClutterActorMeta *meta)
{ {
if (meta->priv->actor != group->actor) ClutterActorMetaPrivate *priv =
clutter_actor_meta_get_instance_private (meta);
if (priv->actor != group->actor)
{ {
g_warning ("The meta of type '%s' with name '%s' is not " g_warning ("The meta of type '%s' with name '%s' is not "
"attached to the actor '%s'", "attached to the actor '%s'",
G_OBJECT_TYPE_NAME (meta), G_OBJECT_TYPE_NAME (meta),
meta->priv->name != NULL priv->name != NULL
? meta->priv->name ? priv->name
: "<unknown>", : "<unknown>",
clutter_actor_get_name (group->actor) != NULL clutter_actor_get_name (group->actor) != NULL
? clutter_actor_get_name (group->actor) ? clutter_actor_get_name (group->actor)
@ -646,8 +693,10 @@ _clutter_meta_group_get_meta (ClutterMetaGroup *group,
for (l = group->meta; l != NULL; l = l->next) for (l = group->meta; l != NULL; l = l->next)
{ {
ClutterActorMeta *meta = l->data; ClutterActorMeta *meta = l->data;
ClutterActorMetaPrivate *priv =
clutter_actor_meta_get_instance_private (meta);
if (g_strcmp0 (meta->priv->name, name) == 0) if (g_strcmp0 (priv->name, name) == 0)
return meta; return meta;
} }
@ -667,6 +716,8 @@ _clutter_meta_group_get_meta (ClutterMetaGroup *group,
const gchar * const gchar *
_clutter_actor_meta_get_debug_name (ClutterActorMeta *meta) _clutter_actor_meta_get_debug_name (ClutterActorMeta *meta)
{ {
return meta->priv->name != NULL ? meta->priv->name ClutterActorMetaPrivate *priv =
: G_OBJECT_TYPE_NAME (meta); clutter_actor_meta_get_instance_private (meta);
return priv->name != NULL ? priv->name : G_OBJECT_TYPE_NAME (meta);
} }

View File

@ -33,31 +33,13 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define CLUTTER_TYPE_ACTOR_META (clutter_actor_meta_get_type ()) #define CLUTTER_TYPE_ACTOR_META (clutter_actor_meta_get_type ())
#define CLUTTER_ACTOR_META(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_ACTOR_META, ClutterActorMeta))
#define CLUTTER_IS_ACTOR_META(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_ACTOR_META))
#define CLUTTER_ACTOR_META_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_ACTOR_META, ClutterActorMetaClass))
#define CLUTTER_IS_ACTOR_META_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_ACTOR_META))
#define CLUTTER_ACTOR_META_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_ACTOR_META, ClutterActorMetaClass))
typedef struct _ClutterActorMetaPrivate ClutterActorMetaPrivate; CLUTTER_EXPORT
typedef struct _ClutterActorMetaClass ClutterActorMetaClass; G_DECLARE_DERIVABLE_TYPE (ClutterActorMeta, clutter_actor_meta,
CLUTTER, ACTOR_META, GInitiallyUnowned);
/** typedef struct _ClutterActorMetaPrivate ClutterActorMetaPrivate;
* ClutterActorMeta:
*
* The #ClutterActorMeta structure contains only
* private data and should be accessed using the provided API
*
* Since: 1.4
*/
struct _ClutterActorMeta
{
/*< private >*/
GInitiallyUnowned parent_instance;
ClutterActorMetaPrivate *priv;
};
/** /**
* ClutterActorMetaClass: * ClutterActorMetaClass:
@ -99,9 +81,6 @@ struct _ClutterActorMetaClass
void (* _clutter_meta6) (void); void (* _clutter_meta6) (void);
}; };
CLUTTER_EXPORT
GType clutter_actor_meta_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT CLUTTER_EXPORT
void clutter_actor_meta_set_name (ClutterActorMeta *meta, void clutter_actor_meta_set_name (ClutterActorMeta *meta,
const gchar *name); const gchar *name);

View File

@ -32,7 +32,6 @@
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterAction, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterAction, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActor, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActor, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterActorMeta, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterAlignConstraint, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterAlignConstraint, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBackend, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBackend, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBindConstraint, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterBindConstraint, g_object_unref)