From c8b685ddbc0ac7d2a122ae47d6ecea968c1ecae5 Mon Sep 17 00:00:00 2001 From: Pavel Strakhov Date: Wed, 20 Sep 2023 12:15:28 +0100 Subject: [PATCH] On X11, fix WaitUntil and Poll behavior Co-authored-by: Kirill Chibisov --- CHANGELOG.md | 1 + src/platform_impl/linux/x11/mod.rs | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 785bdd48..8a1881bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ And please only add new entries to the top of this list, right below the `# Unre - **Breaking:** Moved `ControlFlow::Exit` to `EventLoopWindowTarget::exit()` and `EventLoopWindowTarget::exiting()` and removed `ControlFlow::ExitWithCode(_)` entirely. - On Web, add `EventLoopWindowTargetExtWebSys` and `PollStrategy`, which allows to set different strategies for `ControlFlow::Poll`. By default the Prioritized Task Scheduling API is used, but an option to use `Window.requestIdleCallback` is available as well. Both use `setTimeout()`, with a trick to circumvent throttling to 4ms, as a fallback. - Implement `PartialOrd` and `Ord` for `MouseButton`. +- On X11, fix event loop not waking up on `ControlFlow::Poll` and `ControlFlow::WaitUntil`. # 0.29.1-beta diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index 6be64782..266d4b45 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -505,18 +505,6 @@ impl EventLoop { return; } - // False positive / spurious wake ups could lead to us spamming - // redundant iterations of the event loop with no new events to - // dispatch. - // - // If there's no readable event source then we just double check if we - // have any pending `_receiver` events and if not we return without - // running a loop iteration. - // If we don't have any pending `_receiver` - if !self.has_pending() && !self.state.x11_readiness.readable { - return; - } - // NB: `StartCause::Init` is handled as a special case and doesn't need // to be considered here let cause = match self.control_flow() { @@ -540,6 +528,23 @@ impl EventLoop { } }; + // False positive / spurious wake ups could lead to us spamming + // redundant iterations of the event loop with no new events to + // dispatch. + // + // If there's no readable event source then we just double check if we + // have any pending `_receiver` events and if not we return without + // running a loop iteration. + // If we don't have any pending `_receiver` + if !self.has_pending() + && !matches!( + &cause, + StartCause::ResumeTimeReached { .. } | StartCause::Poll + ) + { + return; + } + self.single_iteration(&mut callback, cause); }