clutter/stage: Add is-grabbed property

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3185>
This commit is contained in:
Jonas Ådahl 2023-08-16 00:08:31 +02:00 committed by Marge Bot
parent 587c31b611
commit 03ee48094e

View File

@ -164,6 +164,8 @@ enum
PROP_PERSPECTIVE, PROP_PERSPECTIVE,
PROP_TITLE, PROP_TITLE,
PROP_KEY_FOCUS, PROP_KEY_FOCUS,
PROP_IS_GRABBED,
PROP_LAST PROP_LAST
}; };
@ -1226,6 +1228,10 @@ clutter_stage_get_property (GObject *gobject,
g_value_set_object (value, priv->key_focused_actor); g_value_set_object (value, priv->key_focused_actor);
break; break;
case PROP_IS_GRABBED:
g_value_set_boolean (value, !!priv->topmost_grab);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
break; break;
@ -1412,6 +1418,17 @@ clutter_stage_class_init (ClutterStageClass *klass)
CLUTTER_PARAM_READWRITE | CLUTTER_PARAM_READWRITE |
G_PARAM_EXPLICIT_NOTIFY); G_PARAM_EXPLICIT_NOTIFY);
/**
* ClutterStage:is-grabbed:
*
* %TRUE if there is currently an active grab on the stage.
*/
obj_props[PROP_IS_GRABBED] =
g_param_spec_boolean ("is-grabbed", NULL, NULL,
FALSE,
CLUTTER_PARAM_READABLE |
G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, PROP_LAST, obj_props); g_object_class_install_properties (gobject_class, PROP_LAST, obj_props);
/** /**
@ -3898,6 +3915,7 @@ clutter_stage_grab_full (ClutterStage *stage,
{ {
ClutterStagePrivate *priv; ClutterStagePrivate *priv;
ClutterGrab *grab; ClutterGrab *grab;
gboolean was_grabbed;
g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL); g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL);
g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL); g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
@ -3924,6 +3942,8 @@ clutter_stage_grab_full (ClutterStage *stage,
grab->prev = NULL; grab->prev = NULL;
grab->next = priv->topmost_grab; grab->next = priv->topmost_grab;
was_grabbed = !!priv->topmost_grab;
if (priv->topmost_grab) if (priv->topmost_grab)
priv->topmost_grab->prev = grab; priv->topmost_grab->prev = grab;
@ -3945,6 +3965,9 @@ clutter_stage_grab_full (ClutterStage *stage,
clutter_actor_attach_grab (actor, grab); clutter_actor_attach_grab (actor, grab);
clutter_stage_notify_grab (stage, grab, grab->next); clutter_stage_notify_grab (stage, grab, grab->next);
if (was_grabbed != !!priv->topmost_grab)
g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_IS_GRABBED]);
return grab; return grab;
} }
@ -3991,6 +4014,7 @@ clutter_stage_unlink_grab (ClutterStage *stage,
{ {
ClutterStagePrivate *priv = stage->priv; ClutterStagePrivate *priv = stage->priv;
ClutterGrab *prev, *next; ClutterGrab *prev, *next;
gboolean was_grabbed;
/* This grab is already detached */ /* This grab is already detached */
if (!grab->prev && !grab->next && priv->topmost_grab != grab) if (!grab->prev && !grab->next && priv->topmost_grab != grab)
@ -4004,6 +4028,8 @@ clutter_stage_unlink_grab (ClutterStage *stage,
if (next) if (next)
next->prev = prev; next->prev = prev;
was_grabbed = !!priv->topmost_grab;
if (priv->topmost_grab == grab) if (priv->topmost_grab == grab)
{ {
/* This is the active grab */ /* This is the active grab */
@ -4026,6 +4052,9 @@ clutter_stage_unlink_grab (ClutterStage *stage,
priv->grab_state = CLUTTER_GRAB_STATE_NONE; priv->grab_state = CLUTTER_GRAB_STATE_NONE;
} }
if (was_grabbed != !!priv->topmost_grab)
g_object_notify_by_pspec (G_OBJECT (stage), obj_props[PROP_IS_GRABBED]);
if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_GRABS)) if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_GRABS))
{ {
unsigned int n_grabs = 0; unsigned int n_grabs = 0;