From 82dcd9a46a661cf495c1cf673a9f23229e51c84f Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 7 May 2026 15:02:16 -0700 Subject: [PATCH] image-copy: Don't send 0x0 buffer params for cursor capture Fixes panics in `xdg-desktop-portal-cosmic` when it tries to use cursor capture, and an application hides the cursor. --- src/input/mod.rs | 16 +++++++++++++--- .../handlers/image_copy_capture/render.rs | 6 +++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/input/mod.rs b/src/input/mod.rs index 13b39c20..519c54d0 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -64,7 +64,7 @@ use smithay::{ protocol::{wl_shm::Format as ShmFormat, wl_surface::WlSurface}, }, }, - utils::{Logical, Point, Rectangle, SERIAL_COUNTER, Serial}, + utils::{Logical, Point, Rectangle, SERIAL_COUNTER, Serial, Size}, wayland::{ compositor::CompositorHandler, image_copy_capture::{BufferConstraints, CursorSessionRef}, @@ -654,8 +654,13 @@ impl State { .map(|constraint| constraint.size != geometry.size) .unwrap_or(true) { + let mut cursor_size = geometry.size; + // Client shouldn't try to allocate 0x0 buffer + if cursor_size == Size::new(0, 0) { + cursor_size = Size::new(1, 1); + } session.update_constraints(BufferConstraints { - size: geometry.size, + size: cursor_size, shm: vec![ShmFormat::Argb8888], dma: None, }); @@ -718,8 +723,13 @@ impl State { .map(|constraint| constraint.size != geometry.size) .unwrap_or(true) { + let mut cursor_size = geometry.size; + // Client shouldn't try to allocate 0x0 buffer + if cursor_size == Size::new(0, 0) { + cursor_size = Size::new(1, 1); + } session.update_constraints(BufferConstraints { - size: geometry.size, + size: cursor_size, shm: vec![ShmFormat::Argb8888], dma: None, }); diff --git a/src/wayland/handlers/image_copy_capture/render.rs b/src/wayland/handlers/image_copy_capture/render.rs index 28ccd1cb..21370f31 100644 --- a/src/wayland/handlers/image_copy_capture/render.rs +++ b/src/wayland/handlers/image_copy_capture/render.rs @@ -753,11 +753,15 @@ pub fn render_cursor_to_buffer( seat: &Seat, ) { let buffer = frame.buffer(); - let cursor_size = seat + let mut cursor_size = seat .cursor_geometry((0.0, 0.0), state.common.clock.now()) .map(|(geo, _hotspot)| geo.size) .unwrap_or_else(|| Size::from((64, 64))); let buffer_size = buffer_dimensions(&buffer).unwrap(); + // Client shouldn't try to allocate 0x0 buffer + if cursor_size == Size::new(0, 0) { + cursor_size = Size::new(1, 1); + } if buffer_size != cursor_size { let constraints = BufferConstraints { size: cursor_size,