From e1e773befbb4db74692c46fa8bdf00988a1f5f12 Mon Sep 17 00:00:00 2001 From: Nova Date: Mon, 4 Aug 2025 22:02:06 -0700 Subject: [PATCH] fix(wayland): double buffer frame callbacks --- src/wayland/core/surface.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wayland/core/surface.rs b/src/wayland/core/surface.rs index 2adcf91..27b7fce 100644 --- a/src/wayland/core/surface.rs +++ b/src/wayland/core/surface.rs @@ -48,6 +48,7 @@ pub struct SurfaceState { pub geometry: Option, pub min_size: Option>, pub max_size: Option>, + frame_callbacks: Registry, } impl Default for SurfaceState { fn default() -> Self { @@ -57,6 +58,7 @@ impl Default for SurfaceState { geometry: None, min_size: None, max_size: None, + frame_callbacks: Registry::new(), } } } @@ -70,7 +72,6 @@ pub struct Surface { state: Mutex>, pub message_sink: MessageSink, pub role: Mutex>, - frame_callbacks: Registry, on_commit_handlers: Mutex>, material: OnceLock>, pending_material_applications: Registry, @@ -96,7 +97,6 @@ impl Surface { state: Default::default(), message_sink: client.message_sink(), role: Mutex::new(None), - frame_callbacks: Registry::new(), on_commit_handlers: Mutex::new(Vec::new()), material: OnceLock::new(), pending_material_applications: Registry::new(), @@ -180,7 +180,7 @@ impl Surface { } #[tracing::instrument(level = "debug", skip_all)] pub fn frame_event(&self) { - for callback in self.frame_callbacks.take_valid_contents() { + for callback in self.current_state().frame_callbacks.take_valid_contents() { let _ = self.message_sink.send(Message::Frame(callback)); } } @@ -258,7 +258,7 @@ impl WlSurface for Surface { callback_id: ObjectId, ) -> Result<()> { let callback = client.insert(callback_id, Callback(callback_id)); - self.frame_callbacks.add_raw(&callback); + self.state.lock().pending.frame_callbacks.add_raw(&callback); Ok(()) } @@ -290,6 +290,7 @@ impl WlSurface for Surface { #[tracing::instrument(level = "debug", skip_all)] async fn commit(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> { self.state.lock().apply(); + self.state.lock().pending.frame_callbacks.clear(); let current_state = self.current_state(); let mut handlers = self.on_commit_handlers.lock(); handlers.retain(|f| (f)(self, ¤t_state));