diff --git a/src/x11/window.rs b/src/x11/window.rs index 5a9f1b7..526370c 100644 --- a/src/x11/window.rs +++ b/src/x11/window.rs @@ -22,6 +22,8 @@ pub struct Window { frame_interval: Duration, event_loop_running: bool, + + new_size: Option<(u32, u32)> } // FIXME: move to outer crate context @@ -156,6 +158,8 @@ impl Window { frame_interval: Duration::from_millis(15), event_loop_running: false, + + new_size: None }; let mut handler = H::build(&mut window); @@ -172,9 +176,23 @@ impl Window { #[inline] fn drain_xcb_events(&mut self, handler: &mut H) { + // the X server has a tendency to send spurious/extraneous configure notify events when a + // window is resized, and we need to batch those together and just send one resize event + // when they've all been coalesced. + self.new_size = None; + while let Some(event) = self.xcb_connection.conn.poll_for_event() { self.handle_xcb_event(handler, event); } + + if let Some((width, height)) = self.new_size.take() { + self.window_info.width = width; + self.window_info.height = height; + + handler.on_event(self, Event::Window( + WindowEvent::Resized(self.window_info) + )) + } } // Event loop @@ -272,14 +290,7 @@ impl Window { xcb::CONFIGURE_NOTIFY => { let event = unsafe { xcb::cast_event::(&event) }; - if self.window_info.width != event.width() as u32 - || self.window_info.height != event.height() as u32 - { - self.window_info.width = event.width() as u32; - self.window_info.height = event.height() as u32; - - handler.on_event(self, Event::Window(WindowEvent::Resized(self.window_info))) - } + self.new_size = Some((event.width() as u32, event.height() as u32)); } ////