Merge pull request #21 from pop-os/cosmic-screencopy-v2
cosmic-screencopy-v2
This commit is contained in:
commit
7c8fddc568
6 changed files with 511 additions and 321 deletions
578
Cargo.lock
generated
578
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -55,13 +55,13 @@ pub(crate) fn layer_surface<'a>(
|
||||||
layout,
|
layout,
|
||||||
);
|
);
|
||||||
let container = match layout {
|
let container = match layout {
|
||||||
WorkspaceLayout::Vertical => widget::cosmic_container::container(
|
WorkspaceLayout::Vertical => widget::layer_container(
|
||||||
row![sidebar, toplevels]
|
row![sidebar, toplevels]
|
||||||
.spacing(12)
|
.spacing(12)
|
||||||
.height(iced::Length::Fill)
|
.height(iced::Length::Fill)
|
||||||
.width(iced::Length::Fill),
|
.width(iced::Length::Fill),
|
||||||
),
|
),
|
||||||
WorkspaceLayout::Horizontal => widget::cosmic_container::container(
|
WorkspaceLayout::Horizontal => widget::layer_container(
|
||||||
column![sidebar, toplevels]
|
column![sidebar, toplevels]
|
||||||
.spacing(12)
|
.spacing(12)
|
||||||
.height(iced::Length::Fill)
|
.height(iced::Length::Fill)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
use cctk::{
|
use cctk::{
|
||||||
cosmic_protocols::screencopy::v1::client::zcosmic_screencopy_session_v1::BufferType,
|
screencopy::Formats,
|
||||||
screencopy::BufferInfo,
|
|
||||||
wayland_client::{
|
wayland_client::{
|
||||||
protocol::{wl_buffer, wl_shm, wl_shm_pool},
|
protocol::{wl_buffer, wl_shm, wl_shm_pool},
|
||||||
Connection, Dispatch, QueueHandle, WEnum,
|
Connection, Dispatch, QueueHandle, WEnum,
|
||||||
|
|
@ -68,34 +67,30 @@ fn create_memfile() -> rustix::io::Result<OwnedFd> {
|
||||||
pub struct Buffer {
|
pub struct Buffer {
|
||||||
pub backing: Arc<BufferSource>,
|
pub backing: Arc<BufferSource>,
|
||||||
pub buffer: wl_buffer::WlBuffer,
|
pub buffer: wl_buffer::WlBuffer,
|
||||||
pub buffer_info: BufferInfo,
|
|
||||||
node: Option<PathBuf>,
|
node: Option<PathBuf>,
|
||||||
|
pub size: (u32, u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppData {
|
impl AppData {
|
||||||
fn create_shm_buffer(&self, buffer_info: &BufferInfo) -> Buffer {
|
fn create_shm_buffer(&self, format: u32, (width, height): (u32, u32)) -> Buffer {
|
||||||
let fd = create_memfile().unwrap(); // XXX?
|
let fd = create_memfile().unwrap(); // XXX?
|
||||||
rustix::fs::ftruncate(&fd, buffer_info.stride as u64 * buffer_info.height as u64).unwrap();
|
rustix::fs::ftruncate(&fd, width as u64 * height as u64 * 4).unwrap();
|
||||||
|
|
||||||
let pool = self.shm_state.wl_shm().create_pool(
|
let pool = self.shm_state.wl_shm().create_pool(
|
||||||
fd.as_fd(),
|
fd.as_fd(),
|
||||||
buffer_info.stride as i32 * buffer_info.height as i32,
|
width as i32 * height as i32 * 4,
|
||||||
&self.qh,
|
&self.qh,
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
|
|
||||||
pool.destroy();
|
pool.destroy();
|
||||||
|
|
||||||
// XXX
|
let format = wl_shm::Format::try_from(format).unwrap();
|
||||||
let fd = rustix::fs::memfd_create("shm-buffer", rustix::fs::MemfdFlags::CLOEXEC).unwrap();
|
|
||||||
rustix::fs::ftruncate(&fd, buffer_info.stride as u64 * buffer_info.height as u64).unwrap();
|
|
||||||
|
|
||||||
let format = wl_shm::Format::try_from(buffer_info.format).unwrap();
|
|
||||||
let buffer = pool.create_buffer(
|
let buffer = pool.create_buffer(
|
||||||
0,
|
0,
|
||||||
buffer_info.width as i32,
|
width as i32,
|
||||||
buffer_info.height as i32,
|
height as i32,
|
||||||
buffer_info.stride as i32,
|
width as i32 * 4,
|
||||||
format,
|
format,
|
||||||
&self.qh,
|
&self.qh,
|
||||||
(),
|
(),
|
||||||
|
|
@ -106,23 +101,24 @@ impl AppData {
|
||||||
Shmbuf {
|
Shmbuf {
|
||||||
fd,
|
fd,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
width: buffer_info.width as i32,
|
width: width as i32,
|
||||||
height: buffer_info.height as i32,
|
height: height as i32,
|
||||||
stride: buffer_info.stride as i32,
|
stride: width as i32 * 4,
|
||||||
format,
|
format,
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
),
|
),
|
||||||
buffer,
|
buffer,
|
||||||
buffer_info: buffer_info.clone(),
|
|
||||||
node: None,
|
node: None,
|
||||||
|
size: (width, height),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn create_gbm_buffer(
|
fn create_gbm_buffer(
|
||||||
&self,
|
&self,
|
||||||
buffer_info: &BufferInfo,
|
format: u32,
|
||||||
|
(width, height): (u32, u32),
|
||||||
needs_linear: bool,
|
needs_linear: bool,
|
||||||
) -> anyhow::Result<Option<Buffer>> {
|
) -> anyhow::Result<Option<Buffer>> {
|
||||||
let (Some((node, gbm)), Some(feedback)) =
|
let (Some((node, gbm)), Some(feedback)) =
|
||||||
|
|
@ -138,7 +134,7 @@ impl AppData {
|
||||||
.flat_map(|x| &x.formats)
|
.flat_map(|x| &x.formats)
|
||||||
.filter_map(|x| formats.get(*x as usize))
|
.filter_map(|x| formats.get(*x as usize))
|
||||||
.filter(|x| {
|
.filter(|x| {
|
||||||
x.format == buffer_info.format
|
x.format == format
|
||||||
&& (!needs_linear || x.modifier == u64::from(gbm::Modifier::Linear))
|
&& (!needs_linear || x.modifier == u64::from(gbm::Modifier::Linear))
|
||||||
})
|
})
|
||||||
.filter_map(|x| gbm::Modifier::try_from(x.modifier).ok())
|
.filter_map(|x| gbm::Modifier::try_from(x.modifier).ok())
|
||||||
|
|
@ -147,21 +143,21 @@ impl AppData {
|
||||||
if modifiers.is_empty() {
|
if modifiers.is_empty() {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
let format = gbm::Format::try_from(buffer_info.format)?;
|
let gbm_format = gbm::Format::try_from(format)?;
|
||||||
//dbg!(format, modifiers);
|
//dbg!(format, modifiers);
|
||||||
let bo = if !modifiers.iter().all(|x| *x == gbm::Modifier::Invalid) {
|
let bo = if !modifiers.iter().all(|x| *x == gbm::Modifier::Invalid) {
|
||||||
gbm.create_buffer_object_with_modifiers::<()>(
|
gbm.create_buffer_object_with_modifiers::<()>(
|
||||||
buffer_info.width,
|
width,
|
||||||
buffer_info.height,
|
height,
|
||||||
format,
|
gbm_format,
|
||||||
modifiers.iter().copied(),
|
modifiers.iter().copied(),
|
||||||
)?
|
)?
|
||||||
} else {
|
} else {
|
||||||
// TODO make sure this isn't used across different GPUs
|
// TODO make sure this isn't used across different GPUs
|
||||||
gbm.create_buffer_object::<()>(
|
gbm.create_buffer_object::<()>(
|
||||||
buffer_info.width,
|
width,
|
||||||
buffer_info.height,
|
height,
|
||||||
format,
|
gbm_format,
|
||||||
gbm::BufferObjectFlags::empty(),
|
gbm::BufferObjectFlags::empty(),
|
||||||
)?
|
)?
|
||||||
};
|
};
|
||||||
|
|
@ -190,9 +186,9 @@ impl AppData {
|
||||||
}
|
}
|
||||||
let buffer = params
|
let buffer = params
|
||||||
.create_immed(
|
.create_immed(
|
||||||
buffer_info.width as i32,
|
width as i32,
|
||||||
buffer_info.height as i32,
|
height as i32,
|
||||||
buffer_info.format,
|
format,
|
||||||
zwp_linux_buffer_params_v1::Flags::empty(),
|
zwp_linux_buffer_params_v1::Flags::empty(),
|
||||||
&self.qh,
|
&self.qh,
|
||||||
)
|
)
|
||||||
|
|
@ -201,29 +197,26 @@ impl AppData {
|
||||||
Ok(Some(Buffer {
|
Ok(Some(Buffer {
|
||||||
backing: Arc::new(
|
backing: Arc::new(
|
||||||
Dmabuf {
|
Dmabuf {
|
||||||
width: buffer_info.width as i32,
|
width: width as i32,
|
||||||
height: buffer_info.height as i32,
|
height: height as i32,
|
||||||
planes,
|
planes,
|
||||||
format: buffer_info.format,
|
format,
|
||||||
modifier: modifier.into(),
|
modifier: modifier.into(),
|
||||||
}
|
}
|
||||||
.into(),
|
.into(),
|
||||||
),
|
),
|
||||||
buffer,
|
buffer,
|
||||||
buffer_info: buffer_info.clone(),
|
|
||||||
node: Some(node.clone()),
|
node: Some(node.clone()),
|
||||||
|
size: (width, height),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_buffer(&self, buffer_infos: &[BufferInfo]) -> Buffer {
|
pub fn create_buffer(&self, formats: &Formats) -> Buffer {
|
||||||
// XXX Handle other formats?
|
// XXX Handle other formats?
|
||||||
let format = wl_shm::Format::Abgr8888.into();
|
let format = u32::from(wl_shm::Format::Abgr8888);
|
||||||
|
|
||||||
if let Some(buffer_info) = buffer_infos
|
if let Some((_, modifiers)) = formats.dmabuf_formats.iter().find(|(f, _)| *f == format) {
|
||||||
.iter()
|
match self.create_gbm_buffer(format, formats.buffer_size, false) {
|
||||||
.find(|x| x.type_ == WEnum::Value(BufferType::Dmabuf) && x.format == format)
|
|
||||||
{
|
|
||||||
match self.create_gbm_buffer(buffer_info, false) {
|
|
||||||
Ok(Some(buffer)) => {
|
Ok(Some(buffer)) => {
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
@ -234,11 +227,8 @@ impl AppData {
|
||||||
|
|
||||||
// Fallback to shm buffer
|
// Fallback to shm buffer
|
||||||
// Assume format is already known to be valid
|
// Assume format is already known to be valid
|
||||||
let buffer_info = buffer_infos
|
assert!(formats.shm_formats.contains(&format));
|
||||||
.iter()
|
self.create_shm_buffer(format, formats.buffer_size)
|
||||||
.find(|x| x.type_ == WEnum::Value(BufferType::WlShm) && x.format == format)
|
|
||||||
.unwrap();
|
|
||||||
self.create_shm_buffer(buffer_info)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
use cctk::{
|
use cctk::{
|
||||||
cosmic_protocols::{
|
cosmic_protocols::{
|
||||||
screencopy::v1::client::{zcosmic_screencopy_manager_v1, zcosmic_screencopy_session_v1},
|
screencopy::v2::client::{zcosmic_screencopy_manager_v2, zcosmic_screencopy_session_v2},
|
||||||
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
|
toplevel_info::v1::client::zcosmic_toplevel_handle_v1,
|
||||||
workspace::v1::client::zcosmic_workspace_handle_v1,
|
workspace::v1::client::zcosmic_workspace_handle_v1,
|
||||||
},
|
},
|
||||||
|
screencopy::ScreencopyState,
|
||||||
wayland_client::{protocol::wl_output, Proxy, QueueHandle},
|
wayland_client::{protocol::wl_output, Proxy, QueueHandle},
|
||||||
};
|
};
|
||||||
use cosmic::cctk;
|
use cosmic::cctk;
|
||||||
|
|
@ -43,20 +44,16 @@ impl Capture {
|
||||||
// Returns `None` if capture is destroyed
|
// Returns `None` if capture is destroyed
|
||||||
// (or if `session` wasn't created with `SessionData`)
|
// (or if `session` wasn't created with `SessionData`)
|
||||||
pub fn for_session(
|
pub fn for_session(
|
||||||
session: &zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1,
|
session: &zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||||
) -> Option<Arc<Self>> {
|
) -> Option<Arc<Self>> {
|
||||||
session.data::<SessionData>()?.capture.upgrade()
|
session.data::<SessionData>()?.capture.upgrade()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start capturing frames
|
// Start capturing frames
|
||||||
pub fn start(
|
pub fn start(self: &Arc<Self>, screencopy_state: &ScreencopyState, qh: &QueueHandle<AppData>) {
|
||||||
self: &Arc<Self>,
|
|
||||||
manager: &zcosmic_screencopy_manager_v1::ZcosmicScreencopyManagerV1,
|
|
||||||
qh: &QueueHandle<AppData>,
|
|
||||||
) {
|
|
||||||
let mut session = self.session.lock().unwrap();
|
let mut session = self.session.lock().unwrap();
|
||||||
if session.is_none() {
|
if session.is_none() {
|
||||||
*session = Some(ScreencopySession::new(self, manager, qh));
|
*session = Some(ScreencopySession::new(self, screencopy_state, qh));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ impl AppData {
|
||||||
for (source, capture) in self.captures.borrow_mut().iter_mut() {
|
for (source, capture) in self.captures.borrow_mut().iter_mut() {
|
||||||
let matches = self.matches_capture_filter(source);
|
let matches = self.matches_capture_filter(source);
|
||||||
if matches {
|
if matches {
|
||||||
capture.start(&self.screencopy_state.screencopy_manager, &self.qh);
|
capture.start(&self.screencopy_state, &self.qh);
|
||||||
} else {
|
} else {
|
||||||
capture.stop();
|
capture.stop();
|
||||||
}
|
}
|
||||||
|
|
@ -167,7 +167,7 @@ impl AppData {
|
||||||
let matches = self.matches_capture_filter(&source);
|
let matches = self.matches_capture_filter(&source);
|
||||||
let capture = Capture::new(source);
|
let capture = Capture::new(source);
|
||||||
if matches {
|
if matches {
|
||||||
capture.start(&self.screencopy_state.screencopy_manager, &self.qh);
|
capture.start(&self.screencopy_state, &self.qh);
|
||||||
}
|
}
|
||||||
capture
|
capture
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,20 @@
|
||||||
use cosmic::cctk::{
|
use cosmic::cctk::{
|
||||||
self,
|
self,
|
||||||
cosmic_protocols::screencopy::v1::client::{
|
cosmic_protocols::{
|
||||||
zcosmic_screencopy_manager_v1, zcosmic_screencopy_session_v1,
|
image_source::v1::client::{
|
||||||
|
zcosmic_toplevel_image_source_manager_v1::ZcosmicToplevelImageSourceManagerV1,
|
||||||
|
zcosmic_workspace_image_source_manager_v1::ZcosmicWorkspaceImageSourceManagerV1,
|
||||||
|
},
|
||||||
|
screencopy::v2::client::{
|
||||||
|
zcosmic_screencopy_frame_v2, zcosmic_screencopy_manager_v2,
|
||||||
|
zcosmic_screencopy_session_v2,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
screencopy::{
|
screencopy::{
|
||||||
BufferInfo, ScreencopyHandler, ScreencopySessionData, ScreencopySessionDataExt,
|
capture, Formats, Frame, ScreencopyFrameData, ScreencopyFrameDataExt, ScreencopyHandler,
|
||||||
ScreencopyState,
|
ScreencopySessionData, ScreencopySessionDataExt, ScreencopyState,
|
||||||
},
|
},
|
||||||
wayland_client::{Connection, QueueHandle, WEnum},
|
wayland_client::{Connection, Proxy, QueueHandle, WEnum},
|
||||||
};
|
};
|
||||||
use cosmic::iced_sctk::subsurface_widget::{SubsurfaceBuffer, SubsurfaceBufferRelease};
|
use cosmic::iced_sctk::subsurface_widget::{SubsurfaceBuffer, SubsurfaceBufferRelease};
|
||||||
use std::{
|
use std::{
|
||||||
|
|
@ -20,8 +27,7 @@ use super::{AppData, Buffer, Capture, CaptureImage, CaptureSource, Event};
|
||||||
pub struct ScreencopySession {
|
pub struct ScreencopySession {
|
||||||
// swapchain buffers
|
// swapchain buffers
|
||||||
buffers: Option<[Buffer; 2]>,
|
buffers: Option<[Buffer; 2]>,
|
||||||
session: zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1,
|
session: zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||||
first_frame: bool,
|
|
||||||
// Future signaled when buffer is signaled.
|
// Future signaled when buffer is signaled.
|
||||||
// if triple buffer is used, will need more than one.
|
// if triple buffer is used, will need more than one.
|
||||||
release: Option<SubsurfaceBufferRelease>,
|
release: Option<SubsurfaceBufferRelease>,
|
||||||
|
|
@ -30,55 +36,69 @@ pub struct ScreencopySession {
|
||||||
impl ScreencopySession {
|
impl ScreencopySession {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
capture: &Arc<Capture>,
|
capture: &Arc<Capture>,
|
||||||
manager: &zcosmic_screencopy_manager_v1::ZcosmicScreencopyManagerV1,
|
screencopy_state: &ScreencopyState,
|
||||||
qh: &QueueHandle<AppData>,
|
qh: &QueueHandle<AppData>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
let image_source = match &capture.source {
|
||||||
|
CaptureSource::Toplevel(toplevel) => screencopy_state
|
||||||
|
.toplevel_source_manager
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.create_source(toplevel, qh, ()),
|
||||||
|
CaptureSource::Workspace(workspace, output) => screencopy_state
|
||||||
|
.workspace_source_manager
|
||||||
|
.as_ref()
|
||||||
|
.unwrap()
|
||||||
|
.create_source(
|
||||||
|
workspace,
|
||||||
|
// output,
|
||||||
|
qh,
|
||||||
|
(),
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
let udata = SessionData {
|
let udata = SessionData {
|
||||||
session_data: Default::default(),
|
session_data: Default::default(),
|
||||||
capture: Arc::downgrade(capture),
|
capture: Arc::downgrade(capture),
|
||||||
};
|
};
|
||||||
|
|
||||||
let session = match &capture.source {
|
let session = screencopy_state.screencopy_manager.create_session(
|
||||||
CaptureSource::Toplevel(toplevel) => manager.capture_toplevel(
|
&image_source,
|
||||||
toplevel,
|
zcosmic_screencopy_manager_v2::Options::empty(),
|
||||||
zcosmic_screencopy_manager_v1::CursorMode::Hidden,
|
qh,
|
||||||
qh,
|
udata,
|
||||||
udata,
|
);
|
||||||
),
|
|
||||||
CaptureSource::Workspace(workspace, output) => manager.capture_workspace(
|
|
||||||
workspace,
|
|
||||||
output,
|
|
||||||
zcosmic_screencopy_manager_v1::CursorMode::Hidden,
|
|
||||||
qh,
|
|
||||||
udata,
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
buffers: None,
|
buffers: None,
|
||||||
session,
|
session,
|
||||||
first_frame: true,
|
|
||||||
release: None,
|
release: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attach_buffer_and_commit(&mut self, _capture: &Capture, conn: &Connection) {
|
fn attach_buffer_and_commit(
|
||||||
|
&mut self,
|
||||||
|
_capture: &Capture,
|
||||||
|
conn: &Connection,
|
||||||
|
qh: &QueueHandle<AppData>,
|
||||||
|
) {
|
||||||
let Some(back) = self.buffers.as_ref().map(|x| &x[1]) else {
|
let Some(back) = self.buffers.as_ref().map(|x| &x[1]) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let node = back.node().and_then(|x| x.to_str().map(|x| x.to_string()));
|
// TODO
|
||||||
|
// let node = back.node().and_then(|x| x.to_str().map(|x| x.to_string()));
|
||||||
|
|
||||||
self.session.attach_buffer(&back.buffer, node, 0); // XXX age?
|
capture(
|
||||||
if self.first_frame {
|
&self.session,
|
||||||
self.session
|
&back.buffer,
|
||||||
.commit(zcosmic_screencopy_session_v1::Options::empty());
|
&[],
|
||||||
self.first_frame = false;
|
qh,
|
||||||
} else {
|
FrameData {
|
||||||
// TODO Not updating properly if `Options::OnDamage` is used
|
frame_data: Default::default(),
|
||||||
self.session
|
session: self.session.clone(),
|
||||||
.commit(zcosmic_screencopy_session_v1::Options::empty());
|
},
|
||||||
}
|
);
|
||||||
conn.flush().unwrap();
|
conn.flush().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -102,6 +122,17 @@ impl ScreencopySessionDataExt for SessionData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct FrameData {
|
||||||
|
frame_data: ScreencopyFrameData,
|
||||||
|
session: zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScreencopyFrameDataExt for FrameData {
|
||||||
|
fn screencopy_frame_data(&self) -> &ScreencopyFrameData {
|
||||||
|
&self.frame_data
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ScreencopyHandler for AppData {
|
impl ScreencopyHandler for AppData {
|
||||||
fn screencopy_state(&mut self) -> &mut ScreencopyState {
|
fn screencopy_state(&mut self) -> &mut ScreencopyState {
|
||||||
&mut self.screencopy_state
|
&mut self.screencopy_state
|
||||||
|
|
@ -111,8 +142,8 @@ impl ScreencopyHandler for AppData {
|
||||||
&mut self,
|
&mut self,
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
_qh: &QueueHandle<Self>,
|
_qh: &QueueHandle<Self>,
|
||||||
session: &zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1,
|
session: &zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||||
buffer_infos: &[BufferInfo],
|
formats: &Formats,
|
||||||
) {
|
) {
|
||||||
let Some(capture) = Capture::for_session(session) else {
|
let Some(capture) = Capture::for_session(session) else {
|
||||||
return;
|
return;
|
||||||
|
|
@ -122,22 +153,23 @@ impl ScreencopyHandler for AppData {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create new buffer if none, or different format
|
// Create new buffer if none
|
||||||
if !session.buffers.as_ref().map_or(false, |buffers| {
|
// XXX What if formats have changed?
|
||||||
buffer_infos.contains(&buffers[0].buffer_info)
|
if session.buffers.is_none() {
|
||||||
}) {
|
session.buffers = Some(array::from_fn(|_| self.create_buffer(formats)));
|
||||||
session.buffers = Some(array::from_fn(|_| self.create_buffer(buffer_infos)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
session.attach_buffer_and_commit(&capture, conn);
|
session.attach_buffer_and_commit(&capture, conn, &self.qh);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ready(
|
fn ready(
|
||||||
&mut self,
|
&mut self,
|
||||||
conn: &Connection,
|
conn: &Connection,
|
||||||
_qh: &QueueHandle<Self>,
|
qh: &QueueHandle<Self>,
|
||||||
session: &zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1,
|
screencopy_frame: &zcosmic_screencopy_frame_v2::ZcosmicScreencopyFrameV2,
|
||||||
|
frame: Frame,
|
||||||
) {
|
) {
|
||||||
|
let session = &screencopy_frame.data::<FrameData>().unwrap().session;
|
||||||
let Some(capture) = Capture::for_session(session) else {
|
let Some(capture) = Capture::for_session(session) else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
@ -158,6 +190,7 @@ impl ScreencopyHandler for AppData {
|
||||||
let capture_clone = capture.clone();
|
let capture_clone = capture.clone();
|
||||||
let conn = conn.clone();
|
let conn = conn.clone();
|
||||||
let release = session.release.take();
|
let release = session.release.take();
|
||||||
|
let qh = qh.clone();
|
||||||
self.scheduler
|
self.scheduler
|
||||||
.schedule(async move {
|
.schedule(async move {
|
||||||
if let Some(release) = release {
|
if let Some(release) = release {
|
||||||
|
|
@ -168,7 +201,7 @@ impl ScreencopyHandler for AppData {
|
||||||
let Some(session) = session.as_mut() else {
|
let Some(session) = session.as_mut() else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
session.attach_buffer_and_commit(&capture_clone, &conn);
|
session.attach_buffer_and_commit(&capture_clone, &conn, &qh);
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
@ -177,11 +210,10 @@ impl ScreencopyHandler for AppData {
|
||||||
session.release = Some(release);
|
session.release = Some(release);
|
||||||
// let img = unsafe { front.to_image() };
|
// let img = unsafe { front.to_image() };
|
||||||
// let image = CaptureImage { img };
|
// let image = CaptureImage { img };
|
||||||
let buffer_info = &front.buffer_info;
|
|
||||||
let image = CaptureImage {
|
let image = CaptureImage {
|
||||||
wl_buffer: buffer,
|
wl_buffer: buffer,
|
||||||
width: buffer_info.width,
|
width: front.size.0,
|
||||||
height: buffer_info.height,
|
height: front.size.1,
|
||||||
};
|
};
|
||||||
match &capture.source {
|
match &capture.source {
|
||||||
CaptureSource::Toplevel(toplevel) => {
|
CaptureSource::Toplevel(toplevel) => {
|
||||||
|
|
@ -201,15 +233,28 @@ impl ScreencopyHandler for AppData {
|
||||||
&mut self,
|
&mut self,
|
||||||
_conn: &Connection,
|
_conn: &Connection,
|
||||||
_qh: &QueueHandle<Self>,
|
_qh: &QueueHandle<Self>,
|
||||||
session: &zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1,
|
screencopy_frame: &zcosmic_screencopy_frame_v2::ZcosmicScreencopyFrameV2,
|
||||||
_reason: WEnum<zcosmic_screencopy_session_v1::FailureReason>,
|
_reason: WEnum<zcosmic_screencopy_frame_v2::FailureReason>,
|
||||||
) {
|
) {
|
||||||
// TODO
|
// TODO
|
||||||
log::error!("Screencopy failed");
|
log::error!("Screencopy failed");
|
||||||
|
let session = &screencopy_frame.data::<FrameData>().unwrap().session;
|
||||||
|
if let Some(capture) = Capture::for_session(session) {
|
||||||
|
capture.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stopped(
|
||||||
|
&mut self,
|
||||||
|
_conn: &Connection,
|
||||||
|
_qh: &QueueHandle<Self>,
|
||||||
|
session: &zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||||
|
) {
|
||||||
|
// TODO
|
||||||
if let Some(capture) = Capture::for_session(session) {
|
if let Some(capture) = Capture::for_session(session) {
|
||||||
capture.stop();
|
capture.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cctk::delegate_screencopy!(AppData, session: [SessionData]);
|
cctk::delegate_screencopy!(AppData, session: [SessionData], frame: [FrameData]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue