clutter: Replace ClutterActors resource-scale property with a signal

We're going to refactor resource scales, making the notification of
changes to the resource scale a lot more important than it is right now
(we won't guarantee queried scales are correct outside the paint cycle
anymore).

Having a separate signal/vfunc for this will make the difference between
the new clutter_actor_get_resource_scale() API (which can return a
guessed value) and the notification of changes to the resource scale
(which will be guaranteed to return an up-to-date value) more obvious.

So replace the "resource-scale" property of ClutterActor with a
"resource-scale-changed" signal that's emitted when the resource scale
is recalculated.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1276
This commit is contained in:
Jonas Dreßler 2020-04-10 14:16:53 +02:00 committed by Jonas Ådahl
parent 9823a0f6c9
commit 162aec7802
3 changed files with 32 additions and 46 deletions

View File

@ -924,7 +924,6 @@ enum
PROP_SCALE_X,
PROP_SCALE_Y,
PROP_SCALE_Z,
PROP_RESOURCE_SCALE,
PROP_ROTATION_ANGLE_X, /* XXX:2.0 rename to rotation-x */
PROP_ROTATION_ANGLE_Y, /* XXX:2.0 rename to rotation-y */
@ -1005,6 +1004,7 @@ enum
TOUCH_EVENT,
TRANSITION_STOPPED,
STAGE_VIEWS_CHANGED,
RESOURCE_SCALE_CHANGED,
LAST_SIGNAL
};
@ -5375,16 +5375,6 @@ clutter_actor_get_property (GObject *object,
}
break;
case PROP_RESOURCE_SCALE:
if (priv->needs_compute_resource_scale)
{
if (!clutter_actor_update_resource_scale (actor))
g_warning ("Getting invalid resource scale property");
}
g_value_set_float (value, priv->resource_scale);
break;
case PROP_REACTIVE:
g_value_set_boolean (value, clutter_actor_get_reactive (actor));
break;
@ -6678,19 +6668,6 @@ clutter_actor_class_init (ClutterActorClass *klass)
G_PARAM_STATIC_STRINGS |
CLUTTER_PARAM_ANIMATABLE);
/**
* ClutterActor:resource-scale:
*
* The resource-scale of the #ClutterActor if any or -1 if not available
*/
obj_props[PROP_RESOURCE_SCALE] =
g_param_spec_float ("resource-scale",
P_("Resource Scale"),
P_("The Scaling factor for resources painting"),
-1.0f, G_MAXFLOAT,
1.0f,
CLUTTER_PARAM_READABLE);
/**
* ClutterActor:rotation-angle-x:
*
@ -7981,6 +7958,23 @@ clutter_actor_class_init (ClutterActorClass *klass)
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* ClutterActor::resource-scale-changed:
* @actor: a #ClutterActor
*
* The ::resource-scale-changed signal is emitted when the resource scale
* value returned by clutter_actor_get_resource_scale() changes.
*
* This signal can be used to get notified about the correct resource scale
* when the scale had to be queried outside of the paint cycle.
*/
actor_signals[RESOURCE_SCALE_CHANGED] =
g_signal_new (I_("resource-scale-changed"),
G_TYPE_FROM_CLASS (object_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET (ClutterActorClass, resource_scale_changed),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
}
static void
@ -16126,7 +16120,7 @@ clutter_actor_ensure_resource_scale (ClutterActor *self)
return;
if (clutter_actor_update_resource_scale (self))
g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_RESOURCE_SCALE]);
g_signal_emit (self, actor_signals[RESOURCE_SCALE_CHANGED], 0);
}
gboolean

View File

@ -296,6 +296,7 @@ struct _ClutterActorClass
gboolean (* touch_event) (ClutterActor *self,
ClutterTouchEvent *event);
gboolean (* has_accessible) (ClutterActor *self);
void (* resource_scale_changed) (ClutterActor *self);
/*< private >*/
/* padding for future expansion */

View File

@ -187,9 +187,6 @@ struct _ClutterTextPrivate
ClutterInputContentHintFlags input_hints;
ClutterInputContentPurpose input_purpose;
/* Signal handler for when the :resource-scale changes */
gulong resource_scale_changed_id;
/* bitfields */
guint alignment : 2;
guint wrap : 1;
@ -922,18 +919,6 @@ clutter_text_direction_changed_cb (GObject *gobject,
/* no need to queue a relayout: set_text_direction() will do that for us */
}
static void
clutter_text_resource_scale_changed_cb (GObject *gobject,
GParamSpec *pspec)
{
ClutterText *self = CLUTTER_TEXT (gobject);
ClutterTextPrivate *priv = self->priv;
g_clear_pointer (&priv->effective_attrs, pango_attr_list_unref);
clutter_text_dirty_cache (self);
clutter_actor_queue_relayout (CLUTTER_ACTOR (gobject));
}
/*
* clutter_text_create_layout:
* @text: a #ClutterText
@ -1776,7 +1761,6 @@ clutter_text_dispose (GObject *gobject)
clutter_text_dirty_cache (self);
g_clear_signal_handler (&priv->direction_changed_id, self);
g_clear_signal_handler (&priv->resource_scale_changed_id, self);
g_clear_signal_handler (&priv->settings_changed_id,
clutter_get_default_backend ());
@ -3066,6 +3050,17 @@ clutter_text_has_overlaps (ClutterActor *self)
return clutter_text_should_draw_cursor ((ClutterText *) self);
}
static void
clutter_text_resource_scale_changed (ClutterActor *actor)
{
ClutterText *self = CLUTTER_TEXT (actor);
ClutterTextPrivate *priv = self->priv;
g_clear_pointer (&priv->effective_attrs, pango_attr_list_unref);
clutter_text_dirty_cache (self);
clutter_actor_queue_relayout (actor);
}
static void
clutter_text_im_focus (ClutterText *text)
{
@ -3814,6 +3809,7 @@ clutter_text_class_init (ClutterTextClass *klass)
actor_class->key_focus_in = clutter_text_key_focus_in;
actor_class->key_focus_out = clutter_text_key_focus_out;
actor_class->has_overlaps = clutter_text_has_overlaps;
actor_class->resource_scale_changed = clutter_text_resource_scale_changed;
/**
* ClutterText:buffer:
@ -4621,11 +4617,6 @@ clutter_text_init (ClutterText *self)
NULL);
priv->input_focus = clutter_text_input_focus_new (self);
priv->resource_scale_changed_id =
g_signal_connect (self, "notify::resource-scale",
G_CALLBACK (clutter_text_resource_scale_changed_cb),
NULL);
}
/**