From 9e72e4917ca31baf4010496bf7f4aaf78d34d236 Mon Sep 17 00:00:00 2001 From: Stephan <55782191+iciclejj@users.noreply.github.com> Date: Fri, 11 Sep 2026 13:58:30 +0200 Subject: [PATCH] Fix screencopy buffers when buffer-size != shm-pool-size (#4566) * screencopy: allow buffer-size != shm-pool-size * screencopy: add helper for advertised buffer stride --- src/protocols/screencopy.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/protocols/screencopy.rs b/src/protocols/screencopy.rs index c6e61ce5..1596e6ef 100644 --- a/src/protocols/screencopy.rs +++ b/src/protocols/screencopy.rs @@ -29,6 +29,10 @@ use crate::utils::{get_credentials_for_client, get_monotonic_time, CastSessionId const VERSION: u32 = 3; +fn screencopy_shm_buffer_stride(size: Size) -> i32 { + size.w * 4 +} + /// Inactivity timeout for considering a screencopy cast as stopped. /// /// xdg-desktop-portal-wlr keeps the screencopy manager alive across casts, so there's no way to @@ -416,7 +420,7 @@ where Format::Xrgb8888, buffer_size.w as u32, buffer_size.h as u32, - buffer_size.w as u32 * 4, + screencopy_shm_buffer_stride(buffer_size) as u32, ); if frame.version() >= 3 { @@ -550,12 +554,11 @@ where ); return; } - } else if shm::with_buffer_contents(&buffer, |_, shm_len, buffer_data| { + } else if shm::with_buffer_contents(&buffer, |_, _, buffer_data| { buffer_data.format == Format::Xrgb8888 && buffer_data.width == size.w && buffer_data.height == size.h - && buffer_data.stride == size.w * 4 - && shm_len == buffer_data.stride as usize * buffer_data.height as usize + && buffer_data.stride == screencopy_shm_buffer_stride(size) }) .unwrap_or(false) {