pan-action: 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 15:53:21 +01:00
parent d79f0ab9f3
commit aa8ef78b17
3 changed files with 74 additions and 55 deletions

View File

@ -46,7 +46,6 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterInterval, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterKeyframeTransition, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterKeyframeTransition, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterOffscreenEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterOffscreenEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPageTurnEffect, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPageTurnEffect, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPanAction, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPropertyTransition, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterPropertyTransition, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterRotateAction, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterRotateAction, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC (ClutterScrollActor, g_object_unref)

View File

@ -84,7 +84,7 @@ typedef enum
SCROLL_PINNED_VERTICAL SCROLL_PINNED_VERTICAL
} PinState; } PinState;
struct _ClutterPanActionPrivate typedef struct _ClutterPanActionPrivate
{ {
ClutterPanAxis pan_axis; ClutterPanAxis pan_axis;
@ -108,7 +108,7 @@ struct _ClutterPanActionPrivate
guint should_interpolate : 1; guint should_interpolate : 1;
PinState pin_state; PinState pin_state;
}; } ClutterPanActionPrivate;
enum enum
{ {
@ -142,7 +142,8 @@ emit_pan (ClutterPanAction *self,
ClutterActor *actor, ClutterActor *actor,
gboolean is_interpolated) gboolean is_interpolated)
{ {
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
gboolean retval; gboolean retval;
if (priv->pin_state == SCROLL_PINNED_UNKNOWN) if (priv->pin_state == SCROLL_PINNED_UNKNOWN)
@ -181,18 +182,20 @@ static void
emit_pan_stopped (ClutterPanAction *self, emit_pan_stopped (ClutterPanAction *self,
ClutterActor *actor) ClutterActor *actor)
{ {
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
g_signal_emit (self, pan_signals[PAN_STOPPED], 0, actor); g_signal_emit (self, pan_signals[PAN_STOPPED], 0, actor);
priv->state = PAN_STATE_INACTIVE; priv->state = PAN_STATE_INACTIVE;
} }
static void static void
on_deceleration_stopped (ClutterTimeline *timeline, on_deceleration_stopped (ClutterTimeline *timeline,
gboolean is_finished, gboolean is_finished,
ClutterPanAction *self) ClutterPanAction *self)
{ {
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
ClutterActor *actor; ClutterActor *actor;
g_object_unref (timeline); g_object_unref (timeline);
@ -207,7 +210,8 @@ on_deceleration_new_frame (ClutterTimeline *timeline,
gint elapsed_time, gint elapsed_time,
ClutterPanAction *self) ClutterPanAction *self)
{ {
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
ClutterActor *actor; ClutterActor *actor;
gdouble progress; gdouble progress;
gfloat interpolated_x, interpolated_y; gfloat interpolated_x, interpolated_y;
@ -230,7 +234,8 @@ gesture_prepare (ClutterGestureAction *gesture,
ClutterActor *actor) ClutterActor *actor)
{ {
ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture); ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture);
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
if (priv->state == PAN_STATE_INTERPOLATING && priv->deceleration_timeline) if (priv->state == PAN_STATE_INTERPOLATING && priv->deceleration_timeline)
clutter_timeline_stop (priv->deceleration_timeline); clutter_timeline_stop (priv->deceleration_timeline);
@ -243,7 +248,8 @@ gesture_begin (ClutterGestureAction *gesture,
ClutterActor *actor) ClutterActor *actor)
{ {
ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture); ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture);
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
priv->pin_state = SCROLL_PINNED_UNKNOWN; priv->pin_state = SCROLL_PINNED_UNKNOWN;
priv->state = PAN_STATE_PANNING; priv->state = PAN_STATE_PANNING;
@ -269,7 +275,8 @@ gesture_cancel (ClutterGestureAction *gesture,
ClutterActor *actor) ClutterActor *actor)
{ {
ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture); ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture);
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
priv->state = PAN_STATE_INACTIVE; priv->state = PAN_STATE_INACTIVE;
} }
@ -279,7 +286,8 @@ gesture_end (ClutterGestureAction *gesture,
ClutterActor *actor) ClutterActor *actor)
{ {
ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture); ClutterPanAction *self = CLUTTER_PAN_ACTION (gesture);
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
gfloat velocity, velocity_x, velocity_y; gfloat velocity, velocity_x, velocity_y;
gfloat delta_x, delta_y; gfloat delta_x, delta_y;
gfloat tau; gfloat tau;
@ -384,7 +392,8 @@ clutter_pan_action_get_property (GObject *gobject,
GParamSpec *pspec) GParamSpec *pspec)
{ {
ClutterPanAction *self = CLUTTER_PAN_ACTION (gobject); ClutterPanAction *self = CLUTTER_PAN_ACTION (gobject);
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
switch (prop_id) switch (prop_id)
{ {
@ -392,15 +401,15 @@ clutter_pan_action_get_property (GObject *gobject,
g_value_set_enum (value, priv->pan_axis); g_value_set_enum (value, priv->pan_axis);
break; break;
case PROP_INTERPOLATE : case PROP_INTERPOLATE:
g_value_set_boolean (value, priv->should_interpolate); g_value_set_boolean (value, priv->should_interpolate);
break; break;
case PROP_DECELERATION : case PROP_DECELERATION:
g_value_set_double (value, priv->deceleration_rate); g_value_set_double (value, priv->deceleration_rate);
break; break;
case PROP_ACCELERATION_FACTOR : case PROP_ACCELERATION_FACTOR:
g_value_set_double (value, priv->acceleration_factor); g_value_set_double (value, priv->acceleration_factor);
break; break;
@ -423,7 +432,8 @@ clutter_pan_action_constructed (GObject *gobject)
static void static void
clutter_pan_action_dispose (GObject *gobject) clutter_pan_action_dispose (GObject *gobject)
{ {
ClutterPanActionPrivate *priv = CLUTTER_PAN_ACTION (gobject)->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (CLUTTER_PAN_ACTION (gobject));
g_clear_object (&priv->deceleration_timeline); g_clear_object (&priv->deceleration_timeline);
@ -435,7 +445,8 @@ clutter_pan_action_set_actor (ClutterActorMeta *meta,
ClutterActor *actor) ClutterActor *actor)
{ {
ClutterPanAction *self = CLUTTER_PAN_ACTION (meta); ClutterPanAction *self = CLUTTER_PAN_ACTION (meta);
ClutterPanActionPrivate *priv = self->priv; ClutterPanActionPrivate *priv =
clutter_pan_action_get_instance_private (self);
ClutterActor *old_actor; ClutterActor *old_actor;
old_actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (self)); old_actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (self));
@ -575,10 +586,12 @@ clutter_pan_action_class_init (ClutterPanActionClass *klass)
static void static void
clutter_pan_action_init (ClutterPanAction *self) clutter_pan_action_init (ClutterPanAction *self)
{ {
self->priv = clutter_pan_action_get_instance_private (self); ClutterPanActionPrivate *priv =
self->priv->deceleration_rate = default_deceleration_rate; clutter_pan_action_get_instance_private (self);
self->priv->acceleration_factor = default_acceleration_factor;
self->priv->state = PAN_STATE_INACTIVE; priv->deceleration_rate = default_deceleration_rate;
priv->acceleration_factor = default_acceleration_factor;
priv->state = PAN_STATE_INACTIVE;
} }
/** /**
@ -611,7 +624,7 @@ clutter_pan_action_set_pan_axis (ClutterPanAction *self,
g_return_if_fail (axis >= CLUTTER_PAN_AXIS_NONE && g_return_if_fail (axis >= CLUTTER_PAN_AXIS_NONE &&
axis <= CLUTTER_PAN_AXIS_AUTO); axis <= CLUTTER_PAN_AXIS_AUTO);
priv = self->priv; priv = clutter_pan_action_get_instance_private (self);
if (priv->pan_axis == axis) if (priv->pan_axis == axis)
return; return;
@ -632,10 +645,13 @@ clutter_pan_action_set_pan_axis (ClutterPanAction *self,
ClutterPanAxis ClutterPanAxis
clutter_pan_action_get_pan_axis (ClutterPanAction *self) clutter_pan_action_get_pan_axis (ClutterPanAction *self)
{ {
ClutterPanActionPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self),
CLUTTER_PAN_AXIS_NONE); CLUTTER_PAN_AXIS_NONE);
return self->priv->pan_axis; priv = clutter_pan_action_get_instance_private (self);
return priv->pan_axis;
} }
/** /**
@ -654,7 +670,7 @@ clutter_pan_action_set_interpolate (ClutterPanAction *self,
g_return_if_fail (CLUTTER_IS_PAN_ACTION (self)); g_return_if_fail (CLUTTER_IS_PAN_ACTION (self));
priv = self->priv; priv = clutter_pan_action_get_instance_private (self);
should_interpolate = !!should_interpolate; should_interpolate = !!should_interpolate;
@ -679,10 +695,13 @@ clutter_pan_action_set_interpolate (ClutterPanAction *self,
gboolean gboolean
clutter_pan_action_get_interpolate (ClutterPanAction *self) clutter_pan_action_get_interpolate (ClutterPanAction *self)
{ {
ClutterPanActionPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self),
FALSE); FALSE);
return self->priv->should_interpolate; priv = clutter_pan_action_get_instance_private (self);
return priv->should_interpolate;
} }
/** /**
@ -698,11 +717,14 @@ void
clutter_pan_action_set_deceleration (ClutterPanAction *self, clutter_pan_action_set_deceleration (ClutterPanAction *self,
gdouble rate) gdouble rate)
{ {
ClutterPanActionPrivate *priv;
g_return_if_fail (CLUTTER_IS_PAN_ACTION (self)); g_return_if_fail (CLUTTER_IS_PAN_ACTION (self));
g_return_if_fail (rate <= 1.0); g_return_if_fail (rate <= 1.0);
g_return_if_fail (rate > 0.0); g_return_if_fail (rate > 0.0);
self->priv->deceleration_rate = rate; priv = clutter_pan_action_get_instance_private (self);
priv->deceleration_rate = rate;
g_object_notify_by_pspec (G_OBJECT (self), pan_props[PROP_DECELERATION]); g_object_notify_by_pspec (G_OBJECT (self), pan_props[PROP_DECELERATION]);
} }
@ -717,8 +739,12 @@ clutter_pan_action_set_deceleration (ClutterPanAction *self,
gdouble gdouble
clutter_pan_action_get_deceleration (ClutterPanAction *self) clutter_pan_action_get_deceleration (ClutterPanAction *self)
{ {
ClutterPanActionPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.95); g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.95);
return self->priv->deceleration_rate;
priv = clutter_pan_action_get_instance_private (self);
return priv->deceleration_rate;
} }
/** /**
@ -733,10 +759,13 @@ void
clutter_pan_action_set_acceleration_factor (ClutterPanAction *self, clutter_pan_action_set_acceleration_factor (ClutterPanAction *self,
gdouble factor) gdouble factor)
{ {
ClutterPanActionPrivate *priv;
g_return_if_fail (CLUTTER_IS_PAN_ACTION (self)); g_return_if_fail (CLUTTER_IS_PAN_ACTION (self));
g_return_if_fail (factor >= 0.0); g_return_if_fail (factor >= 0.0);
self->priv->acceleration_factor = factor; priv = clutter_pan_action_get_instance_private (self);
priv->acceleration_factor = factor;
g_object_notify_by_pspec (G_OBJECT (self), pan_props[PROP_ACCELERATION_FACTOR]); g_object_notify_by_pspec (G_OBJECT (self), pan_props[PROP_ACCELERATION_FACTOR]);
} }
@ -751,8 +780,12 @@ clutter_pan_action_set_acceleration_factor (ClutterPanAction *self,
gdouble gdouble
clutter_pan_action_get_acceleration_factor (ClutterPanAction *self) clutter_pan_action_get_acceleration_factor (ClutterPanAction *self)
{ {
ClutterPanActionPrivate *priv;
g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 1.0); g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 1.0);
return self->priv->acceleration_factor;
priv = clutter_pan_action_get_instance_private (self);
return priv->acceleration_factor;
} }
/** /**
@ -775,7 +808,7 @@ clutter_pan_action_get_interpolated_coords (ClutterPanAction *self,
g_return_if_fail (CLUTTER_IS_PAN_ACTION (self)); g_return_if_fail (CLUTTER_IS_PAN_ACTION (self));
priv = self->priv; priv = clutter_pan_action_get_instance_private (self);
if (interpolated_x) if (interpolated_x)
*interpolated_x = priv->release_x + priv->interpolated_x; *interpolated_x = priv->release_x + priv->interpolated_x;
@ -806,7 +839,7 @@ clutter_pan_action_get_interpolated_delta (ClutterPanAction *self,
g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.0f); g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.0f);
priv = self->priv; priv = clutter_pan_action_get_instance_private (self);
if (delta_x) if (delta_x)
*delta_x = priv->dx; *delta_x = priv->dx;
@ -842,7 +875,7 @@ clutter_pan_action_get_constrained_motion_delta (ClutterPanAction *self,
g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.0f); g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.0f);
priv = self->priv; priv = clutter_pan_action_get_instance_private (self);
distance = clutter_pan_action_get_motion_delta (self, point, distance = clutter_pan_action_get_motion_delta (self, point,
&delta_x, &delta_x,
@ -905,7 +938,7 @@ clutter_pan_action_get_motion_delta (ClutterPanAction *self,
g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.0f); g_return_val_if_fail (CLUTTER_IS_PAN_ACTION (self), 0.0f);
priv = self->priv; priv = clutter_pan_action_get_instance_private (self);
switch (priv->state) switch (priv->state)
{ {
@ -955,7 +988,7 @@ clutter_pan_action_get_motion_coords (ClutterPanAction *self,
g_return_if_fail (CLUTTER_IS_PAN_ACTION (self)); g_return_if_fail (CLUTTER_IS_PAN_ACTION (self));
priv = self->priv; priv = clutter_pan_action_get_instance_private (self);
switch (priv->state) switch (priv->state)
{ {

View File

@ -41,23 +41,13 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define CLUTTER_TYPE_PAN_ACTION (clutter_pan_action_get_type ()) #define CLUTTER_TYPE_PAN_ACTION (clutter_pan_action_get_type ())
#define CLUTTER_PAN_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CLUTTER_TYPE_PAN_ACTION, ClutterPanAction))
#define CLUTTER_IS_PAN_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CLUTTER_TYPE_PAN_ACTION))
#define CLUTTER_PAN_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CLUTTER_TYPE_PAN_ACTION, ClutterPanActionClass))
#define CLUTTER_IS_PAN_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CLUTTER_TYPE_PAN_ACTION))
#define CLUTTER_PAN_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), CLUTTER_TYPE_PAN_ACTION, ClutterPanActionClass))
typedef struct _ClutterPanAction ClutterPanAction; CLUTTER_EXPORT
typedef struct _ClutterPanActionPrivate ClutterPanActionPrivate; G_DECLARE_DERIVABLE_TYPE (ClutterPanAction,
typedef struct _ClutterPanActionClass ClutterPanActionClass; clutter_pan_action,
CLUTTER,
struct _ClutterPanAction PAN_ACTION,
{ ClutterGestureAction)
/*< private >*/
ClutterGestureAction parent_instance;
ClutterPanActionPrivate *priv;
};
/** /**
* ClutterPanActionClass: * ClutterPanActionClass:
@ -77,9 +67,6 @@ struct _ClutterPanActionClass
ClutterActor *actor); ClutterActor *actor);
}; };
CLUTTER_EXPORT
GType clutter_pan_action_get_type (void) G_GNUC_CONST;
CLUTTER_EXPORT CLUTTER_EXPORT
ClutterAction * clutter_pan_action_new (void); ClutterAction * clutter_pan_action_new (void);
CLUTTER_EXPORT CLUTTER_EXPORT