clutter: Move emitting events to ClutterActions to the stage

A fairly small refactor, move the emission of events to actions from
clutter_actor_event() to stage level.

We do this because in the future we'll need to know on stage level
whether events were handled by an actor or by an action.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2342>
This commit is contained in:
Jonas Dreßler 2022-04-04 01:18:50 +02:00 committed by Marge Bot
parent c6b3c90e41
commit d795710a14
2 changed files with 32 additions and 40 deletions

View File

@ -11842,38 +11842,6 @@ clutter_actor_set_child_at_index (ClutterActor *self,
* Event handling * Event handling
*/ */
static gboolean
clutter_actor_run_actions (ClutterActor *self,
const ClutterEvent *event,
ClutterEventPhase phase)
{
ClutterActorPrivate *priv;
const GList *actions, *l;
gboolean retval = CLUTTER_EVENT_PROPAGATE;
priv = self->priv;
if (!priv->actions)
return CLUTTER_EVENT_PROPAGATE;
actions = _clutter_meta_group_peek_metas (priv->actions);
for (l = actions; l; l = l->next)
{
ClutterAction *action = l->data;
ClutterEventPhase action_phase;
action_phase = clutter_action_get_phase (action);
if (action_phase == phase)
{
if (clutter_action_handle_event (action, event))
retval = CLUTTER_EVENT_STOP;
}
}
return retval;
}
/** /**
* clutter_actor_event: * clutter_actor_event:
* @actor: a #ClutterActor * @actor: a #ClutterActor
@ -11893,7 +11861,6 @@ clutter_actor_event (ClutterActor *actor,
const ClutterEvent *event, const ClutterEvent *event,
gboolean capture) gboolean capture)
{ {
ClutterEventPhase phase;
gboolean retval = FALSE; gboolean retval = FALSE;
gint signal_num = -1; gint signal_num = -1;
GQuark detail = 0; GQuark detail = 0;
@ -11903,11 +11870,6 @@ clutter_actor_event (ClutterActor *actor,
g_object_ref (actor); g_object_ref (actor);
phase = capture ? CLUTTER_PHASE_CAPTURE : CLUTTER_PHASE_BUBBLE;
retval = clutter_actor_run_actions (actor, event, phase);
if (retval)
goto handled;
switch (event->type) switch (event->type)
{ {
case CLUTTER_NOTHING: case CLUTTER_NOTHING:
@ -11991,7 +11953,6 @@ clutter_actor_event (ClutterActor *actor,
g_signal_emit (actor, actor_signals[signal_num], 0, event, &retval); g_signal_emit (actor, actor_signals[signal_num], 0, event, &retval);
} }
handled:
g_object_unref (actor); g_object_unref (actor);
if (event->type == CLUTTER_ENTER || event->type == CLUTTER_LEAVE) if (event->type == CLUTTER_ENTER || event->type == CLUTTER_LEAVE)

View File

@ -45,6 +45,7 @@
#include "clutter-stage.h" #include "clutter-stage.h"
#include "deprecated/clutter-container.h" #include "deprecated/clutter-container.h"
#include "clutter-action-private.h"
#include "clutter-actor-private.h" #include "clutter-actor-private.h"
#include "clutter-backend-private.h" #include "clutter-backend-private.h"
#include "clutter-cairo.h" #include "clutter-cairo.h"
@ -3423,7 +3424,8 @@ create_crossing_event (ClutterStage *stage,
typedef enum typedef enum
{ {
EVENT_NOT_HANDLED, EVENT_NOT_HANDLED,
EVENT_HANDLED_BY_ACTOR EVENT_HANDLED_BY_ACTOR,
EVENT_HANDLED_BY_ACTION
} EventHandledState; } EventHandledState;
static EventHandledState static EventHandledState
@ -3431,11 +3433,26 @@ emit_event (const ClutterEvent *event,
GPtrArray *actors) GPtrArray *actors)
{ {
int i; int i;
gboolean action_handled_event = FALSE;
/* Capture: from top-level downwards */ /* Capture: from top-level downwards */
for (i = actors->len - 1; i >= 0; i--) for (i = actors->len - 1; i >= 0; i--)
{ {
ClutterActor *actor = g_ptr_array_index (actors, i); ClutterActor *actor = g_ptr_array_index (actors, i);
const GList *l;
for (l = clutter_actor_peek_actions (actor); l; l = l->next)
{
ClutterAction *action = l->data;
if (clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (action)) &&
clutter_action_get_phase (action) == CLUTTER_PHASE_CAPTURE &&
clutter_action_handle_event (action, event))
action_handled_event = TRUE;
}
if (action_handled_event)
return EVENT_HANDLED_BY_ACTION;
if (clutter_actor_event (actor, event, TRUE)) if (clutter_actor_event (actor, event, TRUE))
return EVENT_HANDLED_BY_ACTOR; return EVENT_HANDLED_BY_ACTOR;
@ -3445,6 +3462,20 @@ emit_event (const ClutterEvent *event,
for (i = 0; i < actors->len; i++) for (i = 0; i < actors->len; i++)
{ {
ClutterActor *actor = g_ptr_array_index (actors, i); ClutterActor *actor = g_ptr_array_index (actors, i);
const GList *l;
for (l = clutter_actor_peek_actions (actor); l; l = l->next)
{
ClutterAction *action = l->data;
if (clutter_actor_meta_get_enabled (CLUTTER_ACTOR_META (action)) &&
clutter_action_get_phase (action) == CLUTTER_PHASE_BUBBLE &&
clutter_action_handle_event (action, event))
action_handled_event = TRUE;
}
if (action_handled_event)
return EVENT_HANDLED_BY_ACTION;
if (clutter_actor_event (actor, event, FALSE)) if (clutter_actor_event (actor, event, FALSE))
return EVENT_HANDLED_BY_ACTOR; return EVENT_HANDLED_BY_ACTOR;