From fe182fdfcb2b175f0a2907bd8003f92f22842da9 Mon Sep 17 00:00:00 2001 From: Ottatop Date: Tue, 18 Jun 2024 17:45:34 -0500 Subject: [PATCH] winit: Schedule render after transaction finish Fixes #255 --- src/backend/winit.rs | 21 ++++++++++++--------- src/state.rs | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 49b0884..2cad2a3 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -254,8 +254,8 @@ impl Winit { /// Render the winit window if a render has been scheduled. pub fn render_if_scheduled(&mut self, pinnacle: &mut Pinnacle) { if self.output_render_scheduled { - self.render_winit_window(pinnacle); self.output_render_scheduled = false; + self.render_winit_window(pinnacle); } } @@ -343,7 +343,11 @@ impl Winit { )); } - let mut clear_snapshots = false; + // HACK: Taking the transaction before creating render elements + // leads to a possibility where the original buffer still gets displayed. + // Need to figure that out. + // In the meantime we take the transaction afterwards and schedule another render. + let mut render_after_transaction_finish = false; self.output.with_state_mut(|state| { if state .layout_transaction @@ -351,16 +355,10 @@ impl Winit { .is_some_and(|ts| ts.ready()) { state.layout_transaction.take(); - clear_snapshots = true; + render_after_transaction_finish = true; } }); - if clear_snapshots { - for win in pinnacle.windows.iter() { - win.with_state_mut(|state| state.snapshot.take()); - } - } - let render_res = self.backend.bind().and_then(|_| { let age = if *full_redraw > 0 { 0 @@ -447,6 +445,11 @@ impl Winit { warn!("{}", err); } } + + // At the end cuz borrow checker + if render_after_transaction_finish { + self.schedule_render(); + } } } diff --git a/src/state.rs b/src/state.rs index 5535a22..feb9f5e 100644 --- a/src/state.rs +++ b/src/state.rs @@ -403,6 +403,7 @@ impl Pinnacle { pub fn shutdown(&mut self) { info!("Shutting down Pinnacle"); self.loop_signal.stop(); + self.loop_signal.wakeup(); if let Some(join_handle) = self.config.config_join_handle.take() { join_handle.abort(); }