wayland: Working screencopy implementation

This commit is contained in:
Victoria Brekenfeld 2022-11-03 21:19:41 +01:00
parent 5a4df346a8
commit 9f1284b981
3 changed files with 43 additions and 17 deletions

View file

@ -41,8 +41,8 @@ use crate::{
utils::prelude::OutputExt,
wayland::protocols::{
screencopy::{
BufferInfo, BufferParams, CursorMode as ScreencopyCursorMode, CursorSession,
ScreencopyHandler, Session, SessionType,
delegate_screencopy, BufferInfo, BufferParams, CursorMode as ScreencopyCursorMode,
CursorSession, ScreencopyHandler, Session, SessionType,
},
workspace::WorkspaceHandle,
},
@ -177,14 +177,14 @@ impl ScreencopyHandler for State {
let mut formats = vec![
BufferInfo::Shm {
format: ShmFormat::Abgr8888,
format: ShmFormat::Argb8888,
size,
stride: 0,
stride: size.w as u32 * 4,
},
BufferInfo::Shm {
format: ShmFormat::Xbgr8888,
format: ShmFormat::Xrgb8888,
size,
stride: 0,
stride: size.w as u32 * 4,
},
];
@ -276,7 +276,7 @@ impl ScreencopyHandler for State {
if let Some(BufferType::Shm) = buffer_type(&params.buffer) {
if with_buffer_contents(&params.buffer, |_, info| {
info.format != ShmFormat::Abgr8888 && info.format != ShmFormat::Xbgr8888
info.format != ShmFormat::Argb8888 && info.format != ShmFormat::Xrgb8888
})
.unwrap()
{
@ -415,14 +415,14 @@ fn formats_for_output(
let mut formats = vec![
BufferInfo::Shm {
format: ShmFormat::Abgr8888,
format: ShmFormat::Argb8888,
size: mode,
stride: 0,
stride: mode.w as u32 * 4,
},
BufferInfo::Shm {
format: ShmFormat::Xbgr8888,
format: ShmFormat::Xrgb8888,
size: mode,
stride: 0,
stride: mode.w as u32 * 4,
},
];
@ -793,3 +793,5 @@ impl UserdataExt for Window {
.flatten()
}
}
delegate_screencopy!(State);

View file

@ -57,7 +57,7 @@ impl ScreencopyState {
where
D: GlobalDispatch<ZcosmicScreencopyManagerV1, ScreencopyGlobalData>
+ Dispatch<ZcosmicScreencopyManagerV1, ()>
+ Dispatch<ZcosmicScreencopySessionV1, ()>
+ Dispatch<ZcosmicScreencopySessionV1, SessionData>
+ ScreencopyHandler
+ WorkspaceHandler
+ 'static,
@ -799,15 +799,16 @@ where
data.inner.lock().unwrap().pending_buffer = Some(params);
}
zcosmic_screencopy_session_v1::Request::Commit { options } => {
{
let resource_data = data.inner.lock().unwrap();
let buffer = {
let mut resource_data = data.inner.lock().unwrap();
if resource_data.is_cursor() || resource_data.gone {
resource.failed(FailureReason::Unspec);
return;
}
}
resource_data.pending_buffer.take()
};
if let Some(buffer) = data.inner.lock().unwrap().pending_buffer.take() {
if let Some(buffer) = buffer {
let session = Session {
obj: SessionResource::Alive(resource.clone()),
data: data.clone(),
@ -889,3 +890,18 @@ fn send_formats(session: &SessionResource, formats: Vec<BufferInfo>) {
session.init_done();
}
macro_rules! delegate_screencopy {
($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => {
smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_manager_v1::ZcosmicScreencopyManagerV1: $crate::wayland::protocols::screencopy::ScreencopyGlobalData
] => $crate::wayland::protocols::screencopy::ScreencopyState);
smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_manager_v1::ZcosmicScreencopyManagerV1: ()
] => $crate::wayland::protocols::screencopy::ScreencopyState);
smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [
cosmic_protocols::screencopy::v1::server::zcosmic_screencopy_session_v1::ZcosmicScreencopySessionV1: $crate::wayland::protocols::screencopy::SessionData
] => $crate::wayland::protocols::screencopy::ScreencopyState);
};
}
pub(crate) use delegate_screencopy;