From ec67a15775b80c35130a57e2d91ad1c6603aed0c Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Tue, 7 May 2024 17:28:32 +0200 Subject: [PATCH] Adapt to recent changes in wl_buffer protocol Destroying buffers now implicitly detaches them, so the lifetime of each buffer needs to be manually tracked. See: https://gitlab.freedesktop.org/wayland/wayland/-/merge_requests/363 --- src/main.rs | 66 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5aa41f5..14a50c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -91,6 +91,8 @@ enum DesiredTarget { struct OutputDetector; /// Related to types associated with the thumbnail window. struct Window; +#[derive(Default)] +struct Screenshot; fn main() -> anyhow::Result<()> { let cli = Cli::parse(); @@ -470,7 +472,8 @@ impl State { let detector_buffer = globals .single_pixel_manager - .create_u32_rgba_buffer(0, 0, 0, 0, qh, ()); + .create_u32_rgba_buffer(0, 0, 0, 0, qh, OutputDetector); + detector_surface.attach(Some(&detector_buffer), 0, 0); let detector = Detector { surface: detector_surface, @@ -665,17 +668,17 @@ impl State { } else { (u32::MAX / 2, u32::MAX / 2, u32::MAX / 2, u32::MAX) }; - let window_buffer = - self.globals - .single_pixel_manager - .create_u32_rgba_buffer(r, g, b, a, qh, ()); + let window_buffer = self + .globals + .single_pixel_manager + .create_u32_rgba_buffer(r, g, b, a, qh, Window); self.window_surface.attach(Some(&window_buffer), 0, 0); self.window_surface.damage_buffer(0, 0, 1, 1); self.window_viewport .set_destination(i32::try_from(width)?, i32::try_from(height)?); - window_buffer.destroy(); self.window_surface.commit(); + window_buffer.destroy(); Ok(()) } @@ -1057,17 +1060,46 @@ impl Dispatch for State { } } -impl Dispatch for State { +impl Dispatch for State { fn event( _: &mut Self, buffer: &wl_buffer::WlBuffer, event: wl_buffer::Event, - (): &(), + _: &Window, + _: &Connection, + _: &QueueHandle, + ) { + if let wl_buffer::Event::Release = event { + debug!("Buffer released: {}.", buffer.id()); + } + } +} + +impl Dispatch for State { + fn event( + _: &mut Self, + buffer: &wl_buffer::WlBuffer, + event: wl_buffer::Event, + _: &Screenshot, + _: &Connection, + _: &QueueHandle, + ) { + if let wl_buffer::Event::Release = event { + debug!("Buffer released: {}.", buffer.id()); + } + } +} + +impl Dispatch for State { + fn event( + _: &mut Self, + buffer: &wl_buffer::WlBuffer, + event: wl_buffer::Event, + _: &OutputDetector, _: &Connection, _: &QueueHandle, ) { if let wl_buffer::Event::Release = event { - debug!("Buffer released: {}, destroying it.", buffer.id()); buffer.destroy(); } } @@ -1120,11 +1152,6 @@ impl Dispatch for Sta ) { if let zwlr_layer_surface_v1::Event::Configure { serial, .. } = event { wlr_layer_surface.ack_configure(serial); - - state - .detector - .surface - .attach(Some(&state.detector.buffer), 0, 0); state.detector.surface.commit(); } } @@ -1331,9 +1358,14 @@ impl Dispatch for State { } .into(); - let (buffer, fd) = - buffers::empty_buffer(&state.globals.wl_shm, width, height, format, qh) - .unwrap(); + let (buffer, fd) = buffers::empty_buffer::<_, _, Screenshot>( + &state.globals.wl_shm, + width, + height, + format, + qh, + ) + .unwrap(); state.shot_memfile = Some(Arc::new(fd)); if state.shot_buffer.set(buffer).is_err() { -- 2.45.2