clone: 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-11 19:41:48 +01:00
parent d07056992b
commit fbef2afb37
3 changed files with 31 additions and 37 deletions

View File

@ -29,7 +29,6 @@
#ifndef __GI_SCANNER__ #ifndef __GI_SCANNER__
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterClone, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInputDevice, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInputDevice, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterText, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterText, g_object_unref)

View File

@ -46,13 +46,13 @@
#include "cogl/cogl.h" #include "cogl/cogl.h"
struct _ClutterClonePrivate typedef struct _ClutterClonePrivate
{ {
ClutterActor *clone_source; ClutterActor *clone_source;
float x_scale, y_scale; float x_scale, y_scale;
gulong source_destroy_id; gulong source_destroy_id;
}; } ClutterClonePrivate;
G_DEFINE_TYPE_WITH_PRIVATE (ClutterClone, clutter_clone, CLUTTER_TYPE_ACTOR) G_DEFINE_TYPE_WITH_PRIVATE (ClutterClone, clutter_clone, CLUTTER_TYPE_ACTOR)
@ -75,7 +75,8 @@ clutter_clone_get_preferred_width (ClutterActor *self,
gfloat *min_width_p, gfloat *min_width_p,
gfloat *natural_width_p) gfloat *natural_width_p)
{ {
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv; ClutterClonePrivate *priv =
clutter_clone_get_instance_private (CLUTTER_CLONE (self));
ClutterActor *clone_source = priv->clone_source; ClutterActor *clone_source = priv->clone_source;
if (clone_source == NULL) if (clone_source == NULL)
@ -99,7 +100,8 @@ clutter_clone_get_preferred_height (ClutterActor *self,
gfloat *min_height_p, gfloat *min_height_p,
gfloat *natural_height_p) gfloat *natural_height_p)
{ {
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv; ClutterClonePrivate *priv =
clutter_clone_get_instance_private (CLUTTER_CLONE (self));
ClutterActor *clone_source = priv->clone_source; ClutterActor *clone_source = priv->clone_source;
if (clone_source == NULL) if (clone_source == NULL)
@ -121,8 +123,8 @@ static void
clutter_clone_apply_transform (ClutterActor *self, clutter_clone_apply_transform (ClutterActor *self,
graphene_matrix_t *matrix) graphene_matrix_t *matrix)
{ {
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv; ClutterClonePrivate *priv =
clutter_clone_get_instance_private (CLUTTER_CLONE (self));
if (priv->clone_source) if (priv->clone_source)
graphene_matrix_scale (matrix, priv->x_scale, priv->y_scale, 1.f); graphene_matrix_scale (matrix, priv->x_scale, priv->y_scale, 1.f);
@ -136,7 +138,7 @@ clutter_clone_paint (ClutterActor *actor,
ClutterPaintContext *paint_context) ClutterPaintContext *paint_context)
{ {
ClutterClone *self = CLUTTER_CLONE (actor); ClutterClone *self = CLUTTER_CLONE (actor);
ClutterClonePrivate *priv = self->priv; ClutterClonePrivate *priv = clutter_clone_get_instance_private (self);
gboolean was_unmapped = FALSE; gboolean was_unmapped = FALSE;
if (priv->clone_source == NULL) if (priv->clone_source == NULL)
@ -155,7 +157,7 @@ clutter_clone_paint (ClutterActor *actor,
*/ */
_clutter_actor_set_in_clone_paint (priv->clone_source, TRUE); _clutter_actor_set_in_clone_paint (priv->clone_source, TRUE);
clutter_actor_set_opacity_override (priv->clone_source, clutter_actor_set_opacity_override (priv->clone_source,
clutter_actor_get_paint_opacity (actor)); clutter_actor_get_paint_opacity (actor));
_clutter_actor_set_enable_model_view_transform (priv->clone_source, FALSE); _clutter_actor_set_enable_model_view_transform (priv->clone_source, FALSE);
if (!clutter_actor_is_mapped (priv->clone_source)) if (!clutter_actor_is_mapped (priv->clone_source))
@ -186,7 +188,8 @@ static gboolean
clutter_clone_get_paint_volume (ClutterActor *actor, clutter_clone_get_paint_volume (ClutterActor *actor,
ClutterPaintVolume *volume) ClutterPaintVolume *volume)
{ {
ClutterClonePrivate *priv = CLUTTER_CLONE (actor)->priv; ClutterClonePrivate *priv =
clutter_clone_get_instance_private (CLUTTER_CLONE (actor));
const ClutterPaintVolume *source_volume; const ClutterPaintVolume *source_volume;
/* if the source is not set the paint volume is defined to be empty */ /* if the source is not set the paint volume is defined to be empty */
@ -208,7 +211,8 @@ clutter_clone_get_paint_volume (ClutterActor *actor,
static gboolean static gboolean
clutter_clone_has_overlaps (ClutterActor *actor) clutter_clone_has_overlaps (ClutterActor *actor)
{ {
ClutterClonePrivate *priv = CLUTTER_CLONE (actor)->priv; ClutterClonePrivate *priv =
clutter_clone_get_instance_private (CLUTTER_CLONE (actor));
/* The clone has overlaps iff the source has overlaps */ /* The clone has overlaps iff the source has overlaps */
@ -222,7 +226,8 @@ static void
clutter_clone_allocate (ClutterActor *self, clutter_clone_allocate (ClutterActor *self,
const ClutterActorBox *box) const ClutterActorBox *box)
{ {
ClutterClonePrivate *priv = CLUTTER_CLONE (self)->priv; ClutterClonePrivate *priv =
clutter_clone_get_instance_private (CLUTTER_CLONE (self));
ClutterActorClass *parent_class; ClutterActorClass *parent_class;
ClutterActorBox source_box; ClutterActorBox source_box;
float x_scale, y_scale; float x_scale, y_scale;
@ -308,7 +313,8 @@ clutter_clone_get_property (GObject *gobject,
GValue *value, GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
ClutterClonePrivate *priv = CLUTTER_CLONE (gobject)->priv; ClutterClonePrivate *priv =
clutter_clone_get_instance_private (CLUTTER_CLONE (gobject));
switch (prop_id) switch (prop_id)
{ {
@ -366,10 +372,10 @@ clutter_clone_class_init (ClutterCloneClass *klass)
static void static void
clutter_clone_init (ClutterClone *self) clutter_clone_init (ClutterClone *self)
{ {
self->priv = clutter_clone_get_instance_private (self); ClutterClonePrivate *priv = clutter_clone_get_instance_private (self);
self->priv->x_scale = 1.f; priv->x_scale = 1.f;
self->priv->y_scale = 1.f; priv->y_scale = 1.f;
} }
/** /**
@ -397,7 +403,7 @@ static void
clutter_clone_set_source_internal (ClutterClone *self, clutter_clone_set_source_internal (ClutterClone *self,
ClutterActor *source) ClutterActor *source)
{ {
ClutterClonePrivate *priv = self->priv; ClutterClonePrivate *priv = clutter_clone_get_instance_private (self);
if (priv->clone_source == source) if (priv->clone_source == source)
return; return;
@ -452,7 +458,10 @@ clutter_clone_set_source (ClutterClone *self,
ClutterActor * ClutterActor *
clutter_clone_get_source (ClutterClone *self) clutter_clone_get_source (ClutterClone *self)
{ {
ClutterClonePrivate *priv;
g_return_val_if_fail (CLUTTER_IS_CLONE (self), NULL); g_return_val_if_fail (CLUTTER_IS_CLONE (self), NULL);
return self->priv->clone_source; priv = clutter_clone_get_instance_private (self);
return priv->clone_source;
} }

View File

@ -31,24 +31,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define CLUTTER_TYPE_CLONE (clutter_clone_get_type()) #define CLUTTER_TYPE_CLONE (clutter_clone_get_type ())
#define CLUTTER_CLONE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_CLONE, ClutterClone))
#define CLUTTER_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_CLONE, ClutterCloneClass))
#define CLUTTER_IS_CLONE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_CLONE))
#define CLUTTER_IS_CLONE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_CLONE))
#define CLUTTER_CLONE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_CLONE, ClutterCloneClass))
typedef struct _ClutterClone ClutterClone;
typedef struct _ClutterCloneClass ClutterCloneClass;
typedef struct _ClutterClonePrivate ClutterClonePrivate;
struct _ClutterClone
{
/*< private >*/
ClutterActor parent_instance;
ClutterClonePrivate *priv;
};
/** /**
* ClutterCloneClass: * ClutterCloneClass:
@ -62,7 +45,10 @@ struct _ClutterCloneClass
}; };
CLUTTER_EXPORT CLUTTER_EXPORT
GType clutter_clone_get_type (void) G_GNUC_CONST; G_DECLARE_DERIVABLE_TYPE (ClutterClone,
clutter_clone,
CLUTTER, CLONE,
ClutterActor)
CLUTTER_EXPORT CLUTTER_EXPORT
ClutterActor * clutter_clone_new (ClutterActor *source); ClutterActor * clutter_clone_new (ClutterActor *source);