diff --git a/winit/src/platform_specific/wayland/event_loop/state.rs b/winit/src/platform_specific/wayland/event_loop/state.rs index 81001fac..fe6b5691 100644 --- a/winit/src/platform_specific/wayland/event_loop/state.rs +++ b/winit/src/platform_specific/wayland/event_loop/state.rs @@ -1612,7 +1612,8 @@ impl SctkState { wp_fractional_scale, wl_buffer: None, - bounds: Some(bounds), + source: None, + destination: 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 b082bf3b..2e576f4a 100644 --- a/winit/src/platform_specific/wayland/subsurface_widget.rs +++ b/winit/src/platform_specific/wayland/subsurface_widget.rs @@ -454,7 +454,8 @@ impl SubsurfaceState { wp_viewport, wp_alpha_modifier_surface, wl_buffer: None, - bounds: None, + source: None, + destination: None, wp_fractional_scale: None, transform: wl_output::Transform::Normal, z: 0, @@ -630,7 +631,8 @@ pub(crate) struct SubsurfaceInstance { pub(crate) wp_fractional_scale: Option, pub(crate) wp_alpha_modifier_surface: Option, pub(crate) wl_buffer: Option, - pub(crate) bounds: Option>, + pub(crate) source: Option>, + pub(crate) destination: Option>, pub(crate) transform: wl_output::Transform, pub(crate) z: i32, pub parent: WlSurface, @@ -677,14 +679,21 @@ impl SubsurfaceInstance { }; // XXX scale factor? - let bounds_changed = self.bounds != Some(info.bounds); + let source_changed = self.source != Some(info.source); + let destination_changed = self.destination != Some(info.destination); // wlroots seems to have issues changing buffer without running this - if bounds_changed || buffer_changed { + 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(), + ); self.wl_subsurface - .set_position(info.bounds.x as i32, info.bounds.y as i32); + .set_position(info.destination.x as i32, info.destination.y as i32); self.wp_viewport.set_destination( - info.bounds.width as i32, - info.bounds.height as i32, + info.destination.width as i32, + info.destination.height as i32, ); } let transform_changed = self.transform != info.transform; @@ -695,7 +704,7 @@ impl SubsurfaceInstance { self.wl_surface.attach(Some(&buffer), 0, 0); self.wl_surface.damage(0, 0, i32::MAX, i32::MAX); } - if buffer_changed || bounds_changed || transform_changed { + if buffer_changed || source_changed || destination_changed || transform_changed { _ = self.wl_surface.frame(&state.qh, self.wl_surface.clone()); self.wl_surface.commit(); } @@ -707,7 +716,8 @@ impl SubsurfaceInstance { } self.wl_buffer = Some(buffer); - self.bounds = Some(info.bounds); + self.source = Some(info.source); + self.destination = Some(info.destination); self.transform = info.transform; self.z = info.z; } @@ -732,7 +742,8 @@ impl Drop for SubsurfaceInstance { #[derive(Debug)] pub(crate) struct SubsurfaceInfo { pub buffer: SubsurfaceBuffer, - pub bounds: Rectangle, + pub source: Rectangle, + pub destination: Rectangle, pub alpha: f32, pub transform: wl_output::Transform, pub z: i32, @@ -839,14 +850,34 @@ 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(), - bounds: layout.bounds(), + source, + destination, alpha: self.alpha, transform: self.transform, z: self.z,