From 4a0c56f9288785545071ea62abbb9b0e2895c73c Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 8 Dec 2020 03:38:14 +0100 Subject: [PATCH] clutter: Simplify stage state management Making this an event is overly convoluted, accounting that we emit the event, then convert it to a ClutterStage signal, then its only consumer (a11y) sets the active ATK state. Take the event out of the equation, unify activation/deactivation of the stage in MetaStage, and use it from the X11 backend too. Part-of: --- clutter/clutter/clutter-actor.c | 4 - clutter/clutter/clutter-enums.h | 15 --- clutter/clutter/clutter-event.c | 5 - clutter/clutter/clutter-event.h | 28 ----- clutter/clutter/clutter-main.c | 7 -- clutter/clutter/clutter-stage-private.h | 9 -- clutter/clutter/clutter-stage.c | 112 -------------------- src/backends/meta-stage.c | 33 +----- src/backends/x11/meta-stage-x11.c | 15 +-- src/core/events.c | 3 +- src/tests/clutter/interactive/test-events.c | 16 --- src/tests/clutter/interactive/test-grab.c | 16 --- 12 files changed, 7 insertions(+), 256 deletions(-) diff --git a/clutter/clutter/clutter-actor.c b/clutter/clutter/clutter-actor.c index 553c1450c..5deeae6d0 100644 --- a/clutter/clutter/clutter-actor.c +++ b/clutter/clutter/clutter-actor.c @@ -12272,10 +12272,6 @@ clutter_actor_event (ClutterActor *actor, signal_num = -1; detail = quark_pad; break; - case CLUTTER_STAGE_STATE: - signal_num = -1; - detail = quark_stage; - break; case CLUTTER_IM_COMMIT: case CLUTTER_IM_DELETE: case CLUTTER_IM_PREEDIT: diff --git a/clutter/clutter/clutter-enums.h b/clutter/clutter/clutter-enums.h index 527513f42..c03f47b6a 100644 --- a/clutter/clutter/clutter-enums.h +++ b/clutter/clutter/clutter-enums.h @@ -816,7 +816,6 @@ typedef enum /*< flags prefix=CLUTTER_EVENT >*/ * @CLUTTER_BUTTON_PRESS: Pointer button press event * @CLUTTER_BUTTON_RELEASE: Pointer button release event * @CLUTTER_SCROLL: Pointer scroll event - * @CLUTTER_STAGE_STATE: Stage state change event * @CLUTTER_TOUCH_BEGIN: A new touch event sequence has started; * event added in 1.10 * @CLUTTER_TOUCH_UPDATE: A touch event sequence has been updated; @@ -851,7 +850,6 @@ typedef enum /*< prefix=CLUTTER >*/ CLUTTER_BUTTON_PRESS, CLUTTER_BUTTON_RELEASE, CLUTTER_SCROLL, - CLUTTER_STAGE_STATE, CLUTTER_TOUCH_BEGIN, CLUTTER_TOUCH_UPDATE, CLUTTER_TOUCH_END, @@ -897,19 +895,6 @@ typedef enum /*< prefix=CLUTTER_SCROLL >*/ CLUTTER_SCROLL_SMOOTH } ClutterScrollDirection; -/** - * ClutterStageState: - * @CLUTTER_STAGE_STATE_ACTIVATED: Activated mask - * - * Stage state masks, used by the #ClutterEvent of type %CLUTTER_STAGE_STATE. - * - * Since: 0.4 - */ -typedef enum -{ - CLUTTER_STAGE_STATE_ACTIVATED = (1 << 3) -} ClutterStageState; - /** * ClutterFeatureFlags: * @CLUTTER_FEATURE_STAGE_STATIC: Set if stage size if fixed (i.e framebuffer) diff --git a/clutter/clutter/clutter-event.c b/clutter/clutter/clutter-event.c index 99b676589..0e5dc3530 100644 --- a/clutter/clutter/clutter-event.c +++ b/clutter/clutter/clutter-event.c @@ -384,7 +384,6 @@ clutter_event_get_position (const ClutterEvent *event, case CLUTTER_NOTHING: case CLUTTER_KEY_PRESS: case CLUTTER_KEY_RELEASE: - case CLUTTER_STAGE_STATE: case CLUTTER_EVENT_LAST: case CLUTTER_PROXIMITY_IN: case CLUTTER_PROXIMITY_OUT: @@ -460,7 +459,6 @@ clutter_event_set_coords (ClutterEvent *event, case CLUTTER_NOTHING: case CLUTTER_KEY_PRESS: case CLUTTER_KEY_RELEASE: - case CLUTTER_STAGE_STATE: case CLUTTER_EVENT_LAST: case CLUTTER_PROXIMITY_IN: case CLUTTER_PROXIMITY_OUT: @@ -1052,7 +1050,6 @@ clutter_event_set_device (ClutterEvent *event, switch (event->type) { case CLUTTER_NOTHING: - case CLUTTER_STAGE_STATE: case CLUTTER_EVENT_LAST: case CLUTTER_IM_COMMIT: case CLUTTER_IM_DELETE: @@ -1150,7 +1147,6 @@ clutter_event_get_device (const ClutterEvent *event) switch (event->type) { case CLUTTER_NOTHING: - case CLUTTER_STAGE_STATE: case CLUTTER_IM_COMMIT: case CLUTTER_IM_DELETE: case CLUTTER_IM_PREEDIT: @@ -1614,7 +1610,6 @@ clutter_event_get_axes (const ClutterEvent *event, switch (event->type) { case CLUTTER_NOTHING: - case CLUTTER_STAGE_STATE: case CLUTTER_ENTER: case CLUTTER_LEAVE: case CLUTTER_KEY_PRESS: diff --git a/clutter/clutter/clutter-event.h b/clutter/clutter/clutter-event.h index 789e3fd3c..195d8d1cc 100644 --- a/clutter/clutter/clutter-event.h +++ b/clutter/clutter/clutter-event.h @@ -112,7 +112,6 @@ typedef struct _ClutterButtonEvent ClutterButtonEvent; typedef struct _ClutterKeyEvent ClutterKeyEvent; typedef struct _ClutterMotionEvent ClutterMotionEvent; typedef struct _ClutterScrollEvent ClutterScrollEvent; -typedef struct _ClutterStageStateEvent ClutterStageStateEvent; typedef struct _ClutterCrossingEvent ClutterCrossingEvent; typedef struct _ClutterTouchEvent ClutterTouchEvent; typedef struct _ClutterTouchpadPinchEvent ClutterTouchpadPinchEvent; @@ -347,32 +346,6 @@ struct _ClutterScrollEvent ClutterScrollFinishFlags finish_flags; }; -/** - * ClutterStageStateEvent: - * @type: event type - * @time: event time - * @flags: event flags - * @stage: event source stage - * @source: event source actor (unused) - * @changed_mask: bitwise OR of the changed flags - * @new_state: bitwise OR of the current state flags - * - * Event signalling a change in the #ClutterStage state. - * - * Since: 0.2 - */ -struct _ClutterStageStateEvent -{ - ClutterEventType type; - guint32 time; - ClutterEventFlags flags; - ClutterStage *stage; - ClutterActor *source; /* XXX: should probably be the stage itself */ - - ClutterStageState changed_mask; - ClutterStageState new_state; -}; - /** * ClutterTouchEvent: * @type: event type @@ -587,7 +560,6 @@ union _ClutterEvent ClutterKeyEvent key; ClutterMotionEvent motion; ClutterScrollEvent scroll; - ClutterStageStateEvent stage_state; ClutterCrossingEvent crossing; ClutterTouchEvent touch; ClutterTouchpadPinchEvent touchpad_pinch; diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c index fc7254c25..f3475c696 100644 --- a/clutter/clutter/clutter-main.c +++ b/clutter/clutter/clutter-main.c @@ -1900,13 +1900,6 @@ _clutter_process_event_details (ClutterActor *stage, break; - case CLUTTER_STAGE_STATE: - /* focus - forward to stage */ - event->any.source = stage; - if (!_clutter_event_process_filters (event)) - clutter_stage_event (CLUTTER_STAGE (stage), event); - break; - case CLUTTER_DEVICE_ADDED: case CLUTTER_DEVICE_REMOVED: _clutter_event_process_filters (event); diff --git a/clutter/clutter/clutter-stage-private.h b/clutter/clutter/clutter-stage-private.h index 6bfdeec79..47fef4395 100644 --- a/clutter/clutter/clutter-stage-private.h +++ b/clutter/clutter/clutter-stage-private.h @@ -110,15 +110,6 @@ ClutterActor * _clutter_stage_get_touch_drag_actor (ClutterStage *st void _clutter_stage_remove_touch_drag_actor (ClutterStage *stage, ClutterEventSequence *sequence); -CLUTTER_EXPORT -ClutterStageState _clutter_stage_get_state (ClutterStage *stage); -CLUTTER_EXPORT -gboolean _clutter_stage_is_activated (ClutterStage *stage); -CLUTTER_EXPORT -gboolean _clutter_stage_update_state (ClutterStage *stage, - ClutterStageState unset_state, - ClutterStageState set_state); - void _clutter_stage_set_scale_factor (ClutterStage *stage, int factor); diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c index a7261d36d..af6c413ba 100644 --- a/clutter/clutter/clutter-stage.c +++ b/clutter/clutter/clutter-stage.c @@ -121,8 +121,6 @@ struct _ClutterStagePrivate gint sync_delay; - ClutterStageState current_state; - int update_freeze_count; gboolean needs_update_devices; @@ -1948,45 +1946,6 @@ clutter_stage_get_actor_at_pos (ClutterStage *stage, return _clutter_stage_do_pick (stage, x, y, pick_mode); } -/** - * clutter_stage_event: - * @stage: a #ClutterStage - * @event: a #ClutterEvent - * - * This function is used to emit an event on the main stage. - * - * You should rarely need to use this function, except for - * synthetised events. - * - * Return value: the return value from the signal emission - * - * Since: 0.4 - */ -gboolean -clutter_stage_event (ClutterStage *stage, - ClutterEvent *event) -{ - g_return_val_if_fail (CLUTTER_IS_STAGE (stage), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (event->type != CLUTTER_STAGE_STATE) - return FALSE; - - /* emit raw event */ - if (clutter_actor_event (CLUTTER_ACTOR (stage), event, FALSE)) - return TRUE; - - if (event->stage_state.changed_mask & CLUTTER_STAGE_STATE_ACTIVATED) - { - if (event->stage_state.new_state & CLUTTER_STAGE_STATE_ACTIVATED) - g_signal_emit (stage, stage_signals[ACTIVATE], 0); - else - g_signal_emit (stage, stage_signals[DEACTIVATE], 0); - } - - return TRUE; -} - /** * clutter_stage_set_title: * @stage: A #ClutterStage @@ -3024,77 +2983,6 @@ _clutter_stage_remove_touch_drag_actor (ClutterStage *stage, NULL); } -/*< private > - * _clutter_stage_get_state: - * @stage: a #ClutterStage - * - * Retrieves the current #ClutterStageState flags associated to the @stage. - * - * Return value: a bitwise OR of #ClutterStageState flags - */ -ClutterStageState -_clutter_stage_get_state (ClutterStage *stage) -{ - return stage->priv->current_state; -} - -/*< private > - * _clutter_stage_is_activated: - * @stage: a #ClutterStage - * - * Checks whether the @stage state includes %CLUTTER_STAGE_STATE_ACTIVATED. - * - * Return value: %TRUE if the @stage is active - */ -gboolean -_clutter_stage_is_activated (ClutterStage *stage) -{ - return (stage->priv->current_state & CLUTTER_STAGE_STATE_ACTIVATED) != 0; -} - -/*< private > - * _clutter_stage_update_state: - * @stage: a #ClutterStage - * @unset_flags: flags to unset - * @set_flags: flags to set - * - * Updates the state of @stage, by unsetting the @unset_flags and setting - * the @set_flags. - * - * If the stage state has been changed, this function will queue a - * #ClutterEvent of type %CLUTTER_STAGE_STATE. - * - * Return value: %TRUE if the state was updated, and %FALSE otherwise - */ -gboolean -_clutter_stage_update_state (ClutterStage *stage, - ClutterStageState unset_flags, - ClutterStageState set_flags) -{ - ClutterStageState new_state; - ClutterEvent *event; - - new_state = stage->priv->current_state; - new_state |= set_flags; - new_state &= ~unset_flags; - - if (new_state == stage->priv->current_state) - return FALSE; - - event = clutter_event_new (CLUTTER_STAGE_STATE); - clutter_event_set_stage (event, stage); - - event->stage_state.new_state = new_state; - event->stage_state.changed_mask = new_state ^ stage->priv->current_state; - - stage->priv->current_state = new_state; - - clutter_stage_event (stage, event); - clutter_event_free (event); - - return TRUE; -} - /** * clutter_stage_set_sync_delay: * @stage: a #ClutterStage diff --git a/src/backends/meta-stage.c b/src/backends/meta-stage.c index 277e25fd9..a08f08463 100644 --- a/src/backends/meta-stage.c +++ b/src/backends/meta-stage.c @@ -434,40 +434,13 @@ void meta_stage_set_active (MetaStage *stage, gboolean is_active) { - ClutterEvent *event; - - /* Used by the native backend to inform accessibility technologies - * about when the stage loses and gains input focus. - * - * For the X11 backend, clutter transparently takes care of this - * for us. - */ - if (stage->is_active == is_active) return; - event = clutter_event_new (CLUTTER_STAGE_STATE); - clutter_event_set_stage (event, CLUTTER_STAGE (stage)); - event->stage_state.changed_mask = CLUTTER_STAGE_STATE_ACTIVATED; - if (is_active) - event->stage_state.new_state = CLUTTER_STAGE_STATE_ACTIVATED; - - /* Emitting this StageState event will result in the stage getting - * activated or deactivated (with the activated or deactivated signal - * getting emitted from the stage) - * - * FIXME: This won't update ClutterStage's own notion of its - * activeness. For that we would need to somehow trigger a - * _clutter_stage_update_state call, which will probably - * require new API in clutter. In practice, nothing relies - * on the ClutterStage's own notion of activeness when using - * the EGL backend. - * - * See http://bugzilla.gnome.org/746670 - */ - clutter_stage_event (CLUTTER_STAGE (stage), event); - clutter_event_free (event); + g_signal_emit_by_name (CLUTTER_STAGE (stage), "activate"); + else + g_signal_emit_by_name (CLUTTER_STAGE (stage), "deactivate"); } MetaStageWatch * diff --git a/src/backends/x11/meta-stage-x11.c b/src/backends/x11/meta-stage-x11.c index 650076c74..6a836a388 100644 --- a/src/backends/x11/meta-stage-x11.c +++ b/src/backends/x11/meta-stage-x11.c @@ -26,6 +26,7 @@ #include #endif +#include "backends/meta-stage-private.h" #include "backends/x11/cm/meta-backend-x11-cm.h" #include "backends/x11/cm/meta-renderer-x11-cm.h" #include "backends/x11/meta-backend-x11.h" @@ -692,21 +693,11 @@ meta_stage_x11_translate_event (MetaStageX11 *stage_x11, break; case FocusIn: - if (!_clutter_stage_is_activated (stage_cogl->wrapper)) - { - _clutter_stage_update_state (stage_cogl->wrapper, - 0, - CLUTTER_STAGE_STATE_ACTIVATED); - } + meta_stage_set_active ((MetaStage *) stage_cogl->wrapper, TRUE); break; case FocusOut: - if (_clutter_stage_is_activated (stage_cogl->wrapper)) - { - _clutter_stage_update_state (stage_cogl->wrapper, - CLUTTER_STAGE_STATE_ACTIVATED, - 0); - } + meta_stage_set_active ((MetaStage *) stage_cogl->wrapper, FALSE); break; case Expose: diff --git a/src/core/events.c b/src/core/events.c index 8859a342f..c93e16fce 100644 --- a/src/core/events.c +++ b/src/core/events.c @@ -109,8 +109,7 @@ handle_idletime_for_event (const ClutterEvent *event) if (event->any.flags & CLUTTER_EVENT_FLAG_SYNTHETIC || event->type == CLUTTER_ENTER || - event->type == CLUTTER_LEAVE || - event->type == CLUTTER_STAGE_STATE) + event->type == CLUTTER_LEAVE) return; core_monitor = meta_idle_monitor_get_core (); diff --git a/src/tests/clutter/interactive/test-events.c b/src/tests/clutter/interactive/test-events.c index 1d1c63dd4..e8408b5e2 100644 --- a/src/tests/clutter/interactive/test-events.c +++ b/src/tests/clutter/interactive/test-events.c @@ -104,15 +104,6 @@ get_event_state_string (const ClutterEvent *event) return g_strjoinv (",", (char **) mods); } -static void -stage_state_cb (ClutterStage *stage, - gpointer data) -{ - gchar *detail = (gchar*)data; - - printf("[stage signal] %s\n", detail); -} - static gboolean red_button_cb (ClutterActor *actor, ClutterEvent *event, @@ -347,9 +338,6 @@ input_cb (ClutterActor *actor, state); } break; - case CLUTTER_STAGE_STATE: - g_print ("[%s] STAGE STATE", clutter_actor_get_name (source_actor)); - break; case CLUTTER_TOUCHPAD_PINCH: g_print ("[%s] TOUCHPAD PINCH", clutter_actor_get_name (source_actor)); break; @@ -401,10 +389,6 @@ test_events_main (int argc, char *argv[]) clutter_actor_set_name (stage, "Stage"); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); g_signal_connect (stage, "event", G_CALLBACK (input_cb), (char *) "stage"); - g_signal_connect (stage, "activate", - G_CALLBACK (stage_state_cb), (char *) "activate"); - g_signal_connect (stage, "deactivate", - G_CALLBACK (stage_state_cb), (char *) "deactivate"); focus_box = clutter_actor_new (); clutter_actor_set_background_color (focus_box, CLUTTER_COLOR_Black); diff --git a/src/tests/clutter/interactive/test-grab.c b/src/tests/clutter/interactive/test-grab.c index fc1912f9f..1de60985b 100644 --- a/src/tests/clutter/interactive/test-grab.c +++ b/src/tests/clutter/interactive/test-grab.c @@ -9,15 +9,6 @@ test_grab_main (int argc, char *argv[]); const char * test_grab_describe (void); -static void -stage_state_cb (ClutterStage *stage, - gpointer data) -{ - gchar *detail = (gchar*)data; - - printf("[stage signal] %s\n", detail); -} - static gboolean debug_event_cb (ClutterActor *actor, ClutterEvent *event, @@ -59,9 +50,6 @@ debug_event_cb (ClutterActor *actor, case CLUTTER_SCROLL: printf("[%s] BUTTON SCROLL", source); break; - case CLUTTER_STAGE_STATE: - printf("[%s] STAGE STATE", source); - break; case CLUTTER_TOUCH_BEGIN: g_print ("[%s] TOUCH BEGIN", source); break; @@ -222,10 +210,6 @@ test_grab_main (int argc, char *argv[]) g_signal_connect (stage, "destroy", G_CALLBACK (clutter_test_quit), NULL); g_signal_connect (stage, "event", G_CALLBACK (debug_event_cb), (char *) "stage"); - g_signal_connect (stage, "activate", - G_CALLBACK (stage_state_cb), (char *) "activate"); - g_signal_connect (stage, "deactivate", - G_CALLBACK (stage_state_cb), (char *) "deactivate"); actor = clutter_actor_new (); clutter_actor_set_background_color (actor, &rcol);