diff --git a/Cargo.toml b/Cargo.toml index 1ea8a12..124621e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,6 +38,7 @@ default = ["wgpu"] wgpu = ["libcosmic/wgpu"] # Debugging features force-shm-screencopy = [] +no-subsurfaces = ["force-shm-screencopy"] [profile.dev] # Not usable at opt-level 0, at least with software renderer diff --git a/src/view/mod.rs b/src/view/mod.rs index 76d5410..afd9307 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -284,7 +284,14 @@ fn toplevel_previews<'a>( fn capture_image(image: Option<&CaptureImage>) -> cosmic::Element<'_, Msg> { if let Some(image) = image { - Subsurface::new(image.width, image.height, &image.wl_buffer).into() + #[cfg(feature = "no-subsurfaces")] + { + widget::Image::new(image.image.clone()).into() + } + #[cfg(not(feature = "no-subsurfaces"))] + { + Subsurface::new(image.width, image.height, &image.wl_buffer).into() + } } else { widget::Image::new(widget::image::Handle::from_pixels(1, 1, vec![0, 0, 0, 255])).into() } diff --git a/src/wayland/buffer.rs b/src/wayland/buffer.rs index 5827314..66e7301 100644 --- a/src/wayland/buffer.rs +++ b/src/wayland/buffer.rs @@ -69,6 +69,8 @@ pub struct Buffer { pub buffer: wl_buffer::WlBuffer, node: Option, pub size: (u32, u32), + #[cfg(feature = "no-subsurfaces")] + pub mmap: memmap2::Mmap, } impl AppData { @@ -96,6 +98,9 @@ impl AppData { pool.destroy(); + #[cfg(feature = "no-subsurfaces")] + let mmap = unsafe { memmap2::Mmap::map(&fd).unwrap() }; + Buffer { backing: Arc::new( Shmbuf { @@ -109,6 +114,8 @@ impl AppData { .into(), ), buffer, + #[cfg(feature = "no-subsurfaces")] + mmap, node: None, size: (width, height), } diff --git a/src/wayland/mod.rs b/src/wayland/mod.rs index 6468265..a7a8b0a 100644 --- a/src/wayland/mod.rs +++ b/src/wayland/mod.rs @@ -87,6 +87,8 @@ pub struct CaptureImage { pub width: u32, pub height: u32, pub wl_buffer: SubsurfaceBuffer, + #[cfg(feature = "no-subsurfaces")] + pub image: cosmic::widget::image::Handle, } pub fn subscription(conn: Connection) -> iced::Subscription { diff --git a/src/wayland/screencopy.rs b/src/wayland/screencopy.rs index d32fdba..d5f23f1 100644 --- a/src/wayland/screencopy.rs +++ b/src/wayland/screencopy.rs @@ -208,12 +208,16 @@ impl ScreencopyHandler for AppData { let front = session.buffers.as_mut().unwrap().first_mut().unwrap(); let (buffer, release) = SubsurfaceBuffer::new(front.backing.clone()); session.release = Some(release); - // let img = unsafe { front.to_image() }; - // let image = CaptureImage { img }; let image = CaptureImage { wl_buffer: buffer, width: front.size.0, height: front.size.1, + #[cfg(feature = "no-subsurfaces")] + image: cosmic::widget::image::Handle::from_pixels( + front.size.0, + front.size.1, + front.mmap.to_vec(), + ), }; match &capture.source { CaptureSource::Toplevel(toplevel) => {