From 62bd0359a9534609a0fef82bfc49f8a1725d6aa2 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 1 Mar 2022 23:13:02 +0100 Subject: [PATCH] clutter: Add clutter_stage_get_event_actor() API call This is a small helper to retrieve the actor that is currently beneath the device/sequence, meant to replace clutter_event_get_source(). Part-of: --- clutter/clutter/clutter-stage.c | 67 +++++++++++++++++++++++++++++++++ clutter/clutter/clutter-stage.h | 3 ++ meson.build | 1 - 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c index 6503f973b..09a56e8a7 100644 --- a/clutter/clutter/clutter-stage.c +++ b/clutter/clutter/clutter-stage.c @@ -3921,3 +3921,70 @@ clutter_stage_get_grab_actor (ClutterStage *stage) /* Return active grab */ return priv->topmost_grab->actor; } + +/** + * clutter_stage_get_event_actor: + * @stage: a #ClutterStage + * @event: an event received on the stage + * + * Retrieves the current focus actor for an event. This is + * the key focus for key events and other events directed + * to the key focus, or the actor directly under the + * coordinates of a device or touch sequence. + * + * The actor is looked up at the time of calling this function, + * and may differ from the actor that the stage originally + * delivered the event to. + * + * Return value: (transfer none): a pointer to the #ClutterActor or %NULL + **/ +ClutterActor * +clutter_stage_get_event_actor (ClutterStage *stage, + const ClutterEvent *event) +{ + ClutterInputDevice *device; + ClutterEventSequence *sequence; + + g_return_val_if_fail (CLUTTER_IS_STAGE (stage), NULL); + g_return_val_if_fail (event != NULL, NULL); + + switch (event->type) + { + case CLUTTER_KEY_PRESS: + case CLUTTER_KEY_RELEASE: + case CLUTTER_PAD_BUTTON_PRESS: + case CLUTTER_PAD_BUTTON_RELEASE: + case CLUTTER_PAD_RING: + case CLUTTER_PAD_STRIP: + case CLUTTER_IM_COMMIT: + case CLUTTER_IM_DELETE: + case CLUTTER_IM_PREEDIT: + return clutter_stage_get_key_focus (stage); + case CLUTTER_MOTION: + case CLUTTER_ENTER: + case CLUTTER_LEAVE: + case CLUTTER_BUTTON_PRESS: + case CLUTTER_BUTTON_RELEASE: + case CLUTTER_SCROLL: + case CLUTTER_TOUCH_BEGIN: + case CLUTTER_TOUCH_UPDATE: + case CLUTTER_TOUCH_END: + case CLUTTER_TOUCH_CANCEL: + case CLUTTER_TOUCHPAD_PINCH: + case CLUTTER_TOUCHPAD_SWIPE: + case CLUTTER_TOUCHPAD_HOLD: + case CLUTTER_PROXIMITY_IN: + case CLUTTER_PROXIMITY_OUT: + device = clutter_event_get_device (event); + sequence = clutter_event_get_event_sequence (event); + + return clutter_stage_get_device_actor (stage, device, sequence); + case CLUTTER_DEVICE_ADDED: + case CLUTTER_DEVICE_REMOVED: + case CLUTTER_NOTHING: + case CLUTTER_EVENT_LAST: + g_warn_if_reached (); + } + + return NULL; +} diff --git a/clutter/clutter/clutter-stage.h b/clutter/clutter/clutter-stage.h index 6c1f5ff96..5412c4d72 100644 --- a/clutter/clutter/clutter-stage.h +++ b/clutter/clutter/clutter-stage.h @@ -250,6 +250,9 @@ CLUTTER_EXPORT ClutterActor * clutter_stage_get_device_actor (ClutterStage *stage, ClutterInputDevice *device, ClutterEventSequence *sequence); +CLUTTER_EXPORT +ClutterActor * clutter_stage_get_event_actor (ClutterStage *stage, + const ClutterEvent *event); CLUTTER_EXPORT ClutterGrab * clutter_stage_grab (ClutterStage *stage, diff --git a/meson.build b/meson.build index 2f7e40c6b..faa38a84f 100644 --- a/meson.build +++ b/meson.build @@ -338,7 +338,6 @@ if have_tests ], exe_wrapper: [ default_test_wrappers, - find_program('catchsegv'), find_program('xvfb-run'), '-a', '-s', '+iglx -noreset', ], timeout_multiplier: 10,