From edc226a04d75d23189232ed69d73b6a20c69da58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Date: Sat, 5 Nov 2022 21:16:20 +0100 Subject: [PATCH] clutter: Process device removing events immediately when they come in Having the stage device list be responsible for delivering the same events twice (first immediately to clients, then later to Clutter) was expected to be tricky, a sneaky problem with it right now is the following case: While collecting events for a stage update cycle, we get three touch events from the backend: TOUCH_BEGIN(seq=1) -> TOUCH_END(seq=1) -> TOUCH_BEGIN(seq=1) What we do right now when we see a TOUCH_BEGIN event is adding a device to the stage right when it comes in from the backend. And when we see a TOUCH_END, we remove the device from the stage not immediately but only after it went through the queue. In the case of the three events mentioned above, with the current behavior, this will happen when they come in from the backend: - TOUCH_BEGIN(seq=1): device gets added to the stage with seq 1, event gets queued - TOUCH_END(seq=1): Nothing happens, event gets queued - TOUCH_BEGIN(seq=1): we try to add device to the stage, but seq 1 is already there, event gets queued Now when we go through the queue and see the TOUCH_END, the device with seq 1 gets removed, but on the subsequent TOUCH_BEGIN, we won't add a new device, so this event (and all events with seq=1 that are still in the queue) is now ignored by Clutter because it has no device. What we want to do here is to cut short once the TOUCH_END event comes in: Process queued events immediately and make sure the device is removed from the stage list before a new device can be added. Same goes for any other events that will lead to devices getting removed. Small note: Since this leads to clutter_stage_get_device_actor() returning NULL, I was wondering why we never crash because of this: Turns out _clutter_actor_handle_event() handles self = NULL just fine without crashing... Part-of: --- clutter/clutter/clutter-main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/clutter/clutter/clutter-main.c b/clutter/clutter/clutter-main.c index ab59048e1..c87bf2c10 100644 --- a/clutter/clutter/clutter-main.c +++ b/clutter/clutter/clutter-main.c @@ -823,6 +823,11 @@ clutter_do_event (ClutterEvent *event) * will occur before drawing the frame. */ _clutter_stage_queue_event (event->any.stage, event, TRUE); + + if (event->type == CLUTTER_TOUCH_END || + event->type == CLUTTER_TOUCH_CANCEL || + event->type == CLUTTER_DEVICE_REMOVED) + _clutter_stage_process_queued_events (event->any.stage); } static void