From 50c41755fd0a2f31c024d9b2dae3cce52e28503d Mon Sep 17 00:00:00 2001 From: Weird Constructor Date: Thu, 4 Mar 2021 18:00:42 +0100 Subject: [PATCH] Fix: Check for remaining events in the internal X11/xcb buffers (#86) * Fix: Check for remaining events in the internal X11/xcb buffers before going to sleep. * Also need to set the queue owner to xcb as wrl suggested. --- src/x11/window.rs | 4 ++++ src/x11/xcb_connection.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/x11/window.rs b/src/x11/window.rs index 244824f..9128f65 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -283,6 +283,10 @@ impl Window { let mut fds = [PollFd::new(xcb_fd, PollFlags::POLLIN)]; + // Check for any events in the internal buffers + // before going to sleep: + self.drain_xcb_events(handler); + // FIXME: handle errors poll(&mut fds, until_next_frame.subsec_millis() as i32).unwrap(); diff --git a/src/x11/xcb_connection.rs b/src/x11/xcb_connection.rs index 0be7aa1..66e6f8d 100644 --- a/src/x11/xcb_connection.rs +++ b/src/x11/xcb_connection.rs @@ -46,6 +46,8 @@ impl XcbConnection { pub fn new() -> Result { let (conn, xlib_display) = xcb::Connection::connect_with_xlib_display()?; + conn.set_event_queue_owner(xcb::base::EventQueueOwner::Xcb); + let (wm_protocols, wm_delete_window, wm_normal_hints) = intern_atoms!(&conn, WM_PROTOCOLS, WM_DELETE_WINDOW, WM_NORMAL_HINTS); Ok(Self {