From 764b4ae5f84d9080d9f45cd033579fab20238686 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Wed, 15 Jan 2025 10:18:50 -0800 Subject: [PATCH] Apply screencopy `transform` to subsurfaces Fixes https://github.com/pop-os/cosmic-workspaces-epoch/issues/17. --- src/backend/mock.rs | 1 + src/backend/mod.rs | 1 + src/backend/wayland/screencopy.rs | 6 +++++- src/view/mod.rs | 7 +++++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/backend/mock.rs b/src/backend/mock.rs index 49e1f2e..3d5d69d 100644 --- a/src/backend/mock.rs +++ b/src/backend/mock.rs @@ -60,6 +60,7 @@ fn create_solid_capture_image(r: u8, g: u8, b: u8) -> CaptureImage { .into(), )) .0, + transform: wl_output::Transform::Normal, #[cfg(feature = "no-subsurfaces")] image: cosmic::widget::image::Handle::from_rgba(512, 512, [r, g, b, 255].repeat(512 * 512)), } diff --git a/src/backend/mod.rs b/src/backend/mod.rs index a0213fc..ecde02d 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -47,6 +47,7 @@ pub struct CaptureImage { pub width: u32, pub height: u32, pub wl_buffer: SubsurfaceBuffer, + pub transform: wl_output::Transform, #[cfg(feature = "no-subsurfaces")] pub image: cosmic::widget::image::Handle, } diff --git a/src/backend/wayland/screencopy.rs b/src/backend/wayland/screencopy.rs index 4af3312..257eb1a 100644 --- a/src/backend/wayland/screencopy.rs +++ b/src/backend/wayland/screencopy.rs @@ -162,7 +162,7 @@ impl ScreencopyHandler for AppData { conn: &Connection, qh: &QueueHandle, screencopy_frame: &zcosmic_screencopy_frame_v2::ZcosmicScreencopyFrameV2, - _frame: Frame, + frame: Frame, ) { let session = &screencopy_frame.data::().unwrap().session; let Some(capture) = Capture::for_session(session) else { @@ -207,6 +207,10 @@ impl ScreencopyHandler for AppData { wl_buffer: buffer, width: front.size.0, height: front.size.1, + transform: match frame.transform { + WEnum::Value(value) => value, + WEnum::Unknown(value) => panic!("invalid capture transform: {}", value), + }, #[cfg(feature = "no-subsurfaces")] image: cosmic::widget::image::Handle::from_rgba( front.size.0, diff --git a/src/view/mod.rs b/src/view/mod.rs index ce7840c..ff1eae2 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -423,12 +423,15 @@ fn capture_image(image: Option<&CaptureImage>, alpha: f32) -> cosmic::Element<'s if let Some(image) = image { #[cfg(feature = "no-subsurfaces")] { - // TODO alpha + // TODO alpha, transform widget::Image::new(image.image.clone()).into() } #[cfg(not(feature = "no-subsurfaces"))] { - Subsurface::new(image.wl_buffer.clone()).alpha(alpha).into() + Subsurface::new(image.wl_buffer.clone()) + .alpha(alpha) + .transform(image.transform) + .into() } } else { widget::Image::new(widget::image::Handle::from_rgba(1, 1, vec![0, 0, 0, 255])).into()