From 5924fea0b19294206146f2255def9dbe6dca01a9 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Mon, 21 Jul 2025 13:39:18 -0700 Subject: [PATCH] Revert "subsurface_widget: Handle `viewport` and set source rectangle" This reverts commit 15547dec8f83af1ea6dbed1964302400fc17c257 from https://github.com/pop-os/iced/pull/227. This is causing issues in `cosmic-workspaces`. It seems I didn't test it properly outside the examples here... and this misinterpreted exactly what the (undocumented) `viewport` argument means (Iced's `image` widget also needed a fix to handle viewports properly since our fork: https://github.com/iced-rs/iced/pull/2752). It should be possible to fix, but revert for now. --- .../wayland/event_loop/state.rs | 3 +- .../wayland/subsurface_widget.rs | 55 ++++--------------- 2 files changed, 13 insertions(+), 45 deletions(-) diff --git a/winit/src/platform_specific/wayland/event_loop/state.rs b/winit/src/platform_specific/wayland/event_loop/state.rs index fe6b5691..81001fac 100644 --- a/winit/src/platform_specific/wayland/event_loop/state.rs +++ b/winit/src/platform_specific/wayland/event_loop/state.rs @@ -1612,8 +1612,7 @@ impl SctkState { wp_fractional_scale, wl_buffer: None, - source: None, - destination: Some(bounds), + bounds: Some(bounds), transform: cctk::wayland_client::protocol::wl_output::Transform::Normal, z: settings.z, diff --git a/winit/src/platform_specific/wayland/subsurface_widget.rs b/winit/src/platform_specific/wayland/subsurface_widget.rs index 2e576f4a..b082bf3b 100644 --- a/winit/src/platform_specific/wayland/subsurface_widget.rs +++ b/winit/src/platform_specific/wayland/subsurface_widget.rs @@ -454,8 +454,7 @@ impl SubsurfaceState { wp_viewport, wp_alpha_modifier_surface, wl_buffer: None, - source: None, - destination: None, + bounds: None, wp_fractional_scale: None, transform: wl_output::Transform::Normal, z: 0, @@ -631,8 +630,7 @@ pub(crate) struct SubsurfaceInstance { pub(crate) wp_fractional_scale: Option, pub(crate) wp_alpha_modifier_surface: Option, pub(crate) wl_buffer: Option, - pub(crate) source: Option>, - pub(crate) destination: Option>, + pub(crate) bounds: Option>, pub(crate) transform: wl_output::Transform, pub(crate) z: i32, pub parent: WlSurface, @@ -679,21 +677,14 @@ impl SubsurfaceInstance { }; // XXX scale factor? - let source_changed = self.source != Some(info.source); - let destination_changed = self.destination != Some(info.destination); + let bounds_changed = self.bounds != Some(info.bounds); // wlroots seems to have issues changing buffer without running this - if source_changed || destination_changed || buffer_changed { - self.wp_viewport.set_source( - info.source.x.into(), - info.source.y.into(), - info.source.width.into(), - info.source.height.into(), - ); + if bounds_changed || buffer_changed { self.wl_subsurface - .set_position(info.destination.x as i32, info.destination.y as i32); + .set_position(info.bounds.x as i32, info.bounds.y as i32); self.wp_viewport.set_destination( - info.destination.width as i32, - info.destination.height as i32, + info.bounds.width as i32, + info.bounds.height as i32, ); } let transform_changed = self.transform != info.transform; @@ -704,7 +695,7 @@ impl SubsurfaceInstance { self.wl_surface.attach(Some(&buffer), 0, 0); self.wl_surface.damage(0, 0, i32::MAX, i32::MAX); } - if buffer_changed || source_changed || destination_changed || transform_changed { + if buffer_changed || bounds_changed || transform_changed { _ = self.wl_surface.frame(&state.qh, self.wl_surface.clone()); self.wl_surface.commit(); } @@ -716,8 +707,7 @@ impl SubsurfaceInstance { } self.wl_buffer = Some(buffer); - self.source = Some(info.source); - self.destination = Some(info.destination); + self.bounds = Some(info.bounds); self.transform = info.transform; self.z = info.z; } @@ -742,8 +732,7 @@ impl Drop for SubsurfaceInstance { #[derive(Debug)] pub(crate) struct SubsurfaceInfo { pub buffer: SubsurfaceBuffer, - pub source: Rectangle, - pub destination: Rectangle, + pub bounds: Rectangle, pub alpha: f32, pub transform: wl_output::Transform, pub z: i32, @@ -850,34 +839,14 @@ where _style: &renderer::Style, layout: Layout<'_>, _cursor: mouse::Cursor, - viewport: &Rectangle, + _viewport: &Rectangle, ) { - let buffer_size = - Size::new(self.buffer.width() as f32, self.buffer.height() as f32); - let full_size = - self.content_fit.fit(buffer_size, layout.bounds().size()); - - let source = Rectangle { - x: viewport.x, - y: viewport.y, - width: viewport.width.min(self.buffer.width() as f32), - height: viewport.height.min(self.buffer.height() as f32), - }; - - let destination = Rectangle { - x: layout.bounds().x, - y: layout.bounds().y, - width: layout.bounds().width.min(viewport.width), - height: layout.bounds().height.min(viewport.height), - }; - // Instead of using renderer, we need to add surface to a list that is // read by the iced-sctk shell. SUBSURFACES.with(|subsurfaces| { subsurfaces.borrow_mut().push(SubsurfaceInfo { buffer: self.buffer.clone(), - source, - destination, + bounds: layout.bounds(), alpha: self.alpha, transform: self.transform, z: self.z,