From 584656c07f9a58f41a36e7d34dbc9af155602fd2 Mon Sep 17 00:00:00 2001 From: drendog Date: Tue, 20 Aug 2024 22:02:09 +0200 Subject: [PATCH] fix: dispatch missed events --- src/windowing/mod.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/windowing/mod.rs b/src/windowing/mod.rs index 80be180..59d3f0a 100644 --- a/src/windowing/mod.rs +++ b/src/windowing/mod.rs @@ -175,17 +175,18 @@ impl WindowingSystem { pub fn run(&mut self) -> Result<()> { info!("Starting WindowingSystem main loop"); - self.state.window().render_frame_if_dirty()?; + while self.event_queue.blocking_dispatch(&mut self.state)? > 0 { + self.connection.flush()?; + self.state.window().render_frame_if_dirty()?; + } + self.setup_wayland_event_source()?; - let connection = Rc::clone(&self.connection); let event_queue = &mut self.event_queue; self.event_loop .run(None, &mut self.state, move |shared_data| { - if let Err(e) = - Self::process_events(&Rc::clone(&connection), event_queue, shared_data) - { + if let Err(e) = Self::process_events(event_queue, shared_data) { error!("Error processing events: {}", e); } }) @@ -201,7 +202,11 @@ impl WindowingSystem { .handle() .insert_source( calloop::generic::Generic::new(connection, Interest::READ, Mode::Level), - move |_, _connection, _shared_data| Ok(PostAction::Continue), + move |_, connection, _shared_data| { + connection.flush().unwrap(); + + Ok(PostAction::Continue) + }, ) .map_err(|e| anyhow::anyhow!("Failed to set up Wayland event source: {}", e))?; @@ -209,12 +214,9 @@ impl WindowingSystem { } fn process_events( - connection: &Rc, event_queue: &mut EventQueue, shared_data: &mut WindowState, ) -> Result<()> { - connection.flush()?; - if let Some(guard) = event_queue.prepare_read() { guard .read()