Use updated screencopy abstraction
This commit is contained in:
parent
a3be974f81
commit
4dc6f8b99f
5 changed files with 127 additions and 265 deletions
|
|
@ -26,17 +26,12 @@ use cosmic::{
|
|||
cctk::{
|
||||
self,
|
||||
cosmic_protocols::{
|
||||
self,
|
||||
image_source::v1::client::zcosmic_toplevel_image_source_manager_v1::ZcosmicToplevelImageSourceManagerV1,
|
||||
screencopy::v2::client::{
|
||||
zcosmic_screencopy_frame_v2, zcosmic_screencopy_manager_v2,
|
||||
zcosmic_screencopy_session_v2,
|
||||
},
|
||||
toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||
self, toplevel_info::v1::client::zcosmic_toplevel_handle_v1::ZcosmicToplevelHandleV1,
|
||||
},
|
||||
screencopy::{
|
||||
capture, Formats, Frame, ScreencopyFrameData, ScreencopyFrameDataExt,
|
||||
ScreencopyHandler, ScreencopySessionData, ScreencopySessionDataExt, ScreencopyState,
|
||||
CaptureFrame, CaptureOptions, CaptureSession, CaptureSource, Capturer, FailureReason,
|
||||
Formats, Frame, ScreencopyFrameData, ScreencopyFrameDataExt, ScreencopyHandler,
|
||||
ScreencopySessionData, ScreencopySessionDataExt, ScreencopyState,
|
||||
},
|
||||
sctk::shm::{Shm, ShmHandler},
|
||||
wayland_client::{
|
||||
|
|
@ -45,7 +40,7 @@ use cosmic::{
|
|||
wl_shm::{self, WlShm},
|
||||
wl_shm_pool,
|
||||
},
|
||||
Dispatch, Proxy,
|
||||
Dispatch,
|
||||
},
|
||||
},
|
||||
iced_futures::futures,
|
||||
|
|
@ -61,7 +56,7 @@ use wayland_client::{globals::registry_queue_init, Connection, QueueHandle};
|
|||
#[derive(Default)]
|
||||
struct SessionInner {
|
||||
formats: Option<Formats>,
|
||||
res: Option<Result<(), WEnum<zcosmic_screencopy_frame_v2::FailureReason>>>,
|
||||
res: Option<Result<(), WEnum<FailureReason>>>,
|
||||
}
|
||||
|
||||
// TODO: dmabuf? need to handle modifier negotation
|
||||
|
|
@ -79,13 +74,11 @@ struct SessionData {
|
|||
|
||||
struct FrameData {
|
||||
frame_data: ScreencopyFrameData,
|
||||
session: zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||
session: CaptureSession,
|
||||
}
|
||||
|
||||
impl Session {
|
||||
pub fn for_session(
|
||||
session: &zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||
) -> Option<&Self> {
|
||||
pub fn for_session(session: &CaptureSession) -> Option<&Self> {
|
||||
Some(&session.data::<SessionData>()?.session)
|
||||
}
|
||||
|
||||
|
|
@ -130,8 +123,7 @@ struct CaptureData {
|
|||
qh: QueueHandle<AppData>,
|
||||
conn: Connection,
|
||||
wl_shm: WlShm,
|
||||
screencopy_manager: zcosmic_screencopy_manager_v2::ZcosmicScreencopyManagerV2,
|
||||
toplevel_source_manager: ZcosmicToplevelImageSourceManagerV1,
|
||||
capturer: Capturer,
|
||||
}
|
||||
|
||||
impl CaptureData {
|
||||
|
|
@ -149,18 +141,18 @@ impl CaptureData {
|
|||
let overlay_cursor = if overlay_cursor { 1 } else { 0 };
|
||||
|
||||
let session = Arc::new(Session::default());
|
||||
let image_source = self
|
||||
.toplevel_source_manager
|
||||
.create_source(&source, &self.qh, ());
|
||||
let screencopy_session = self.screencopy_manager.create_session(
|
||||
&image_source,
|
||||
zcosmic_screencopy_manager_v2::Options::empty(),
|
||||
&self.qh,
|
||||
SessionData {
|
||||
session: session.clone(),
|
||||
session_data: Default::default(),
|
||||
},
|
||||
);
|
||||
let capture_session = self
|
||||
.capturer
|
||||
.create_session(
|
||||
&CaptureSource::CosmicToplevel(source),
|
||||
CaptureOptions::empty(),
|
||||
&self.qh,
|
||||
SessionData {
|
||||
session: session.clone(),
|
||||
session_data: Default::default(),
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
self.conn.flush().unwrap();
|
||||
|
||||
let formats = session
|
||||
|
|
@ -204,14 +196,13 @@ impl CaptureData {
|
|||
(),
|
||||
);
|
||||
|
||||
capture(
|
||||
&screencopy_session,
|
||||
capture_session.capture(
|
||||
&buffer,
|
||||
&[],
|
||||
&self.qh,
|
||||
FrameData {
|
||||
frame_data: Default::default(),
|
||||
session: screencopy_session.clone(),
|
||||
session: capture_session.clone(),
|
||||
},
|
||||
);
|
||||
self.conn.flush().unwrap();
|
||||
|
|
@ -306,12 +297,7 @@ impl AppData {
|
|||
qh: self.queue_handle.clone(),
|
||||
conn: self.conn.clone(),
|
||||
wl_shm: self.shm_state.wl_shm().clone(),
|
||||
screencopy_manager: self.screencopy_state.screencopy_manager.clone(),
|
||||
toplevel_source_manager: self
|
||||
.screencopy_state
|
||||
.toplevel_source_manager
|
||||
.clone()
|
||||
.unwrap(),
|
||||
capturer: self.screencopy_state.capturer().clone(),
|
||||
};
|
||||
std::thread::spawn(move || {
|
||||
use std::ffi::CStr;
|
||||
|
|
@ -509,7 +495,7 @@ impl ScreencopyHandler for AppData {
|
|||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
session: &zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||
session: &CaptureSession,
|
||||
formats: &Formats,
|
||||
) {
|
||||
Session::for_session(session).unwrap().update(|data| {
|
||||
|
|
@ -521,38 +507,30 @@ impl ScreencopyHandler for AppData {
|
|||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
screencopy_frame: &zcosmic_screencopy_frame_v2::ZcosmicScreencopyFrameV2,
|
||||
screencopy_frame: &CaptureFrame,
|
||||
_frame: Frame,
|
||||
) {
|
||||
let session = &screencopy_frame.data::<FrameData>().unwrap().session;
|
||||
Session::for_session(session).unwrap().update(|data| {
|
||||
data.res = Some(Ok(()));
|
||||
});
|
||||
session.destroy();
|
||||
}
|
||||
|
||||
fn failed(
|
||||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
screencopy_frame: &zcosmic_screencopy_frame_v2::ZcosmicScreencopyFrameV2,
|
||||
reason: WEnum<zcosmic_screencopy_frame_v2::FailureReason>,
|
||||
screencopy_frame: &CaptureFrame,
|
||||
reason: WEnum<FailureReason>,
|
||||
) {
|
||||
// TODO send message to thread
|
||||
let session = &screencopy_frame.data::<FrameData>().unwrap().session;
|
||||
Session::for_session(session).unwrap().update(|data| {
|
||||
data.res = Some(Err(reason));
|
||||
});
|
||||
session.destroy();
|
||||
}
|
||||
|
||||
fn stopped(
|
||||
&mut self,
|
||||
_conn: &Connection,
|
||||
_qh: &QueueHandle<Self>,
|
||||
_session: &zcosmic_screencopy_session_v2::ZcosmicScreencopySessionV2,
|
||||
) {
|
||||
}
|
||||
fn stopped(&mut self, _conn: &Connection, _qh: &QueueHandle<Self>, _session: &CaptureSession) {}
|
||||
}
|
||||
|
||||
impl Dispatch<wl_shm_pool::WlShmPool, ()> for AppData {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue