From c2aed1979d147a0fe64e2054ad416339a2bbffe1 Mon Sep 17 00:00:00 2001 From: Murarth Date: Wed, 11 Mar 2020 21:54:23 -0700 Subject: [PATCH] X11: Fix `ResumeTimeReached` being fired early (#1505) * X11: Fix `ResumeTimeReached` being fired early * Update CHANGELOG.md Co-authored-by: Osspial --- CHANGELOG.md | 2 ++ src/platform_impl/linux/x11/mod.rs | 54 +++++++++++------------------- 2 files changed, 21 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 832aaccba8..67a233ac42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Unreleased +- On X11, fix `ResumeTimeReached` being fired too early. + # 0.22.0 (2020-03-09) - On Windows, fix minor timing issue in wait_until_time_or_msg diff --git a/src/platform_impl/linux/x11/mod.rs b/src/platform_impl/linux/x11/mod.rs index f9e0ea569b..93a386f222 100644 --- a/src/platform_impl/linux/x11/mod.rs +++ b/src/platform_impl/linux/x11/mod.rs @@ -268,14 +268,16 @@ impl EventLoop { { let mut control_flow = ControlFlow::default(); let mut events = Events::with_capacity(8); - - callback( - crate::event::Event::NewEvents(crate::event::StartCause::Init), - &self.target, - &mut control_flow, - ); + let mut cause = StartCause::Init; loop { + sticky_exit_callback( + crate::event::Event::NewEvents(cause), + &self.target, + &mut control_flow, + &mut callback, + ); + // Process all pending events self.drain_events(&mut callback, &mut control_flow); @@ -326,7 +328,7 @@ impl EventLoop { } let start = Instant::now(); - let (mut cause, deadline, timeout); + let (deadline, timeout); match control_flow { ControlFlow::Exit => break, @@ -357,38 +359,20 @@ impl EventLoop { } } - if self.event_processor.poll() { - // If the XConnection already contains buffered events, we don't - // need to wait for data on the socket. - // However, we still need to check for user events. - self.poll - .poll(&mut events, Some(Duration::from_millis(0))) - .unwrap(); - events.clear(); - - callback( - crate::event::Event::NewEvents(cause), - &self.target, - &mut control_flow, - ); - } else { + // If the XConnection already contains buffered events, we don't + // need to wait for data on the socket. + if !self.event_processor.poll() { self.poll.poll(&mut events, timeout).unwrap(); events.clear(); + } - let wait_cancelled = deadline.map_or(false, |deadline| Instant::now() < deadline); + let wait_cancelled = deadline.map_or(false, |deadline| Instant::now() < deadline); - if wait_cancelled { - cause = StartCause::WaitCancelled { - start, - requested_resume: deadline, - }; - } - - callback( - crate::event::Event::NewEvents(cause), - &self.target, - &mut control_flow, - ); + if wait_cancelled { + cause = StartCause::WaitCancelled { + start, + requested_resume: deadline, + }; } }