From c92ac695afc12f46e7a7d0b6e944fa950c6679d3 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Tue, 9 May 2017 09:20:35 -0700 Subject: [PATCH] Fix x11 poll_events to drain queue It was only processing a single event per call. The docs say > Fetches all the events that are pending, calls the callback function > for each of them, and returns. which suggests that was incorrect. --- src/platform/linux/x11/mod.rs | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/platform/linux/x11/mod.rs b/src/platform/linux/x11/mod.rs index 78eb9586..c21f6203 100644 --- a/src/platform/linux/x11/mod.rs +++ b/src/platform/linux/x11/mod.rs @@ -111,16 +111,22 @@ impl EventsLoop { let xlib = &self.display.xlib; let mut xev = unsafe { mem::uninitialized() }; - unsafe { - // Ensure XNextEvent won't block - let count = (xlib.XPending)(self.display.display); - if count == 0 { - return; + loop { + // Get next event + unsafe { + // Ensure XNextEvent won't block + let count = (xlib.XPending)(self.display.display); + if count == 0 { + break; + } + + (xlib.XNextEvent)(self.display.display, &mut xev); + } + self.process_event(&mut xev, &mut callback); + if self.interrupted.load(::std::sync::atomic::Ordering::Relaxed) { + break; } - - (xlib.XNextEvent)(self.display.display, &mut xev); } - self.process_event(&mut xev, &mut callback); } pub fn run_forever(&self, mut callback: F)