From e9ebf1e5f44575634a2801f32f53b0c62192925e Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Mon, 7 Aug 2023 09:35:59 +0400 Subject: [PATCH] Fix event loop not waking up due to repeat source Force the wake up from the repeat source as well. Fixes: cad327755 (On Wayland, reduce amount of spurious wakeups) --- src/platform_impl/linux/wayland/event_loop/mod.rs | 2 +- src/platform_impl/linux/wayland/seat/keyboard/mod.rs | 3 +++ src/platform_impl/linux/wayland/window/mod.rs | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/platform_impl/linux/wayland/event_loop/mod.rs b/src/platform_impl/linux/wayland/event_loop/mod.rs index 28d83802..f4b8f979 100644 --- a/src/platform_impl/linux/wayland/event_loop/mod.rs +++ b/src/platform_impl/linux/wayland/event_loop/mod.rs @@ -124,7 +124,7 @@ impl EventLoop { event_loop.handle().insert_source( event_loop_awakener_source, move |_, _, winit_state: &mut WinitState| { - // No extra handling is required, we just need to wake-up. + // Mark that we have something to dispatch. winit_state.dispatched_events = true; }, )?; diff --git a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs index d9569a77..f6abf95a 100644 --- a/src/platform_impl/linux/wayland/seat/keyboard/mod.rs +++ b/src/platform_impl/linux/wayland/seat/keyboard/mod.rs @@ -151,6 +151,9 @@ impl Dispatch for WinitState { keyboard_state.repeat_token = keyboard_state .loop_handle .insert_source(timer, move |_, _, state| { + // Required to handle the wakeups from the repeat sources. + state.dispatched_events = true; + let data = wl_keyboard.data::().unwrap(); let seat_state = state.seats.get_mut(&data.seat.id()).unwrap(); diff --git a/src/platform_impl/linux/wayland/window/mod.rs b/src/platform_impl/linux/wayland/window/mod.rs index a7c7842f..a0a51b7b 100644 --- a/src/platform_impl/linux/wayland/window/mod.rs +++ b/src/platform_impl/linux/wayland/window/mod.rs @@ -287,6 +287,10 @@ impl Window { #[inline] pub fn request_redraw(&self) { + // NOTE: try to not wake up the loop when the event was already scheduled and not yet + // processed by the loop, because if at this point the value was `true` it could only + // mean that the loop still haven't dispatched the value to the client and will do + // eventually, resetting it to `false`. if self .window_requests .redraw_requested