From 6ff5492866490be859f23db01541df0ec67dcc3b Mon Sep 17 00:00:00 2001 From: crimist Date: Mon, 22 Jun 2026 03:01:02 -0700 Subject: [PATCH] wayland: fix protocol error when buffer size isn't a multiple of buffer_scale (#7746) ref: #7333 --- window/src/os/wayland/window.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index 9c2a11c4f..b0b8fc984 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -653,11 +653,15 @@ impl WaylandWindowInner { .ok_or(anyhow!("Window does not exist"))?; let object_id = window.wl_surface().id(); - wegl_surface = Some(WlEglSurface::new( - object_id, - self.dimensions.pixel_width as i32, - self.dimensions.pixel_height as i32, - )?); + // Align pixel dimensions to the integer buffer scale factor + // to satisfy the Wayland protocol requirement that buffer + // dimensions must be an integer multiple of the buffer_scale. + let surface_udata = SurfaceUserData::from_wl(window.wl_surface()); + let scale = surface_udata.surface_data.scale_factor(); + let pixel_width = (self.dimensions.pixel_width as i32 / scale) * scale; + let pixel_height = (self.dimensions.pixel_height as i32 / scale) * scale; + + wegl_surface = Some(WlEglSurface::new(object_id, pixel_width, pixel_height)?); log::trace!("WEGL Surface here {:?}", wegl_surface); @@ -885,6 +889,13 @@ impl WaylandWindowInner { } } + // Align pixel dimensions to the integer buffer scale factor + // to satisfy the Wayland protocol requirement that buffer + // dimensions must be an integer multiple of the buffer_scale. + let scale = factor as i32; + pixel_width = (pixel_width / scale) * scale; + pixel_height = (pixel_height / scale) * scale; + log::trace!("Resizing frame"); if !self.window_frame.is_hidden() { // Clamp the size to at least one surface heigh/width.