From 4ce398bc190b6460f9e6feffc7bb6872f5d751d7 Mon Sep 17 00:00:00 2001 From: Timmy Xiao <34635512+tzx@users.noreply.github.com> Date: Sun, 7 Jan 2024 02:07:30 -0500 Subject: [PATCH] A window renders now --- window/src/os/wayland/connection.rs | 8 +++++++- window/src/os/wayland/window.rs | 15 ++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/window/src/os/wayland/connection.rs b/window/src/os/wayland/connection.rs index 8a855d1d6..e08f1af24 100644 --- a/window/src/os/wayland/connection.rs +++ b/window/src/os/wayland/connection.rs @@ -206,7 +206,13 @@ impl CompositorHandler for WaylandState { time: u32, ) { log::trace!("frame: CompositorHandler"); - todo!() + let surface_data = SurfaceUserData::from_wl(surface); + let window_id = surface_data.window_id; + + WaylandConnection::with_window_inner(window_id, |inner| { + inner.next_frame_is_ready(); + Ok(()) + }); } } diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index d4314be79..a6873ee40 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -547,16 +547,10 @@ impl WaylandWindowInner { let conn = WaylandConnection::get().unwrap().wayland(); let qh = conn.event_queue.borrow().handle(); - // TODO: is this the current udata to pass in?, just following examples + let callback = self.surface().frame(&qh, self.surface().clone()); log::trace!("do_paint - callback: {:?}", callback); - // callback.quick_assign(move |_source, _event, _data| { - // WaylandConnection::with_window_inner(window_id, |inner| { - // inner.next_frame_is_ready(); - // Ok(()) - // }); - // }); self.frame_callback.replace(callback); // The repaint has the side of effect of committing the surface, @@ -576,6 +570,13 @@ impl WaylandWindowInner { .expect("Window should exist") .wl_surface() } + + pub(crate) fn next_frame_is_ready(&mut self) { + self.frame_callback.take(); + if self.invalidated { + self.do_paint().ok(); + } + } } unsafe impl HasRawDisplayHandle for WaylandWindowInner {