1
0
Fork 0
forked from wry/wry

portal: implement workspace capture

This commit is contained in:
Julian Orth 2024-04-20 13:48:12 +02:00
parent c6864a6d85
commit 33a0a40857
23 changed files with 518 additions and 50 deletions

View file

@ -4,6 +4,7 @@ pub mod usr_jay_pointer;
pub mod usr_jay_render_ctx;
pub mod usr_jay_screencast;
pub mod usr_jay_select_toplevel;
pub mod usr_jay_select_workspace;
pub mod usr_jay_toplevel;
pub mod usr_jay_workspace;
pub mod usr_jay_workspace_watcher;

View file

@ -11,6 +11,7 @@ use {
usr_jay_output::UsrJayOutput, usr_jay_pointer::UsrJayPointer,
usr_jay_render_ctx::UsrJayRenderCtx, usr_jay_screencast::UsrJayScreencast,
usr_jay_select_toplevel::UsrJaySelectToplevel,
usr_jay_select_workspace::UsrJaySelectWorkspace,
usr_jay_workspace_watcher::UsrJayWorkspaceWatcher, usr_wl_output::UsrWlOutput,
usr_wl_seat::UsrWlSeat,
},
@ -25,7 +26,13 @@ pub struct UsrJayCompositor {
pub id: JayCompositorId,
pub con: Rc<UsrCon>,
pub owner: CloneCell<Option<Rc<dyn UsrJayCompositorOwner>>>,
pub caps: UsrJayCompositorCaps,
}
#[derive(Default)]
pub struct UsrJayCompositorCaps {
pub window_capture: Cell<bool>,
pub select_workspace: Cell<bool>,
}
pub trait UsrJayCompositorOwner {
@ -129,6 +136,21 @@ impl UsrJayCompositor {
sc
}
pub fn select_workspace(&self, seat: &UsrWlSeat) -> Rc<UsrJaySelectWorkspace> {
let sc = Rc::new(UsrJaySelectWorkspace {
id: self.con.id(),
con: self.con.clone(),
owner: Default::default(),
});
self.con.request(SelectWorkspace {
self_id: self.id,
id: sc.id,
seat: seat.id,
});
self.con.add_object(sc.clone());
sc
}
fn client_id(&self, parser: MsgParser<'_, '_>) -> Result<(), MsgParserError> {
let ev: ClientId = self.con.parse(self, parser)?;
if let Some(owner) = self.owner.get() {
@ -150,7 +172,8 @@ impl UsrJayCompositor {
for &cap in ev.cap {
match cap {
Cap::NONE => {}
Cap::WINDOW_CAPTURE => self.window_capture.set(true),
Cap::WINDOW_CAPTURE => self.caps.window_capture.set(true),
Cap::SELECT_WORKSPACE => self.caps.select_workspace.set(true),
_ => {}
}
}

View file

@ -1,7 +1,6 @@
use {
crate::{
format::formats,
ifs::jay_workspace::JayWorkspace,
utils::{
buffd::{MsgParser, MsgParserError},
clonecell::CloneCell,
@ -9,7 +8,10 @@ use {
video::dmabuf::{DmaBuf, DmaBufPlane, PlaneVec},
wire::{jay_screencast::*, JayScreencastId},
wl_usr::{
usr_ifs::{usr_jay_output::UsrJayOutput, usr_jay_toplevel::UsrJayToplevel},
usr_ifs::{
usr_jay_output::UsrJayOutput, usr_jay_toplevel::UsrJayToplevel,
usr_jay_workspace::UsrJayWorkspace,
},
usr_object::UsrObject,
UsrCon,
},
@ -78,8 +80,7 @@ impl UsrJayScreencast {
});
}
#[allow(dead_code)]
pub fn allow_workspace(&self, ws: &JayWorkspace) {
pub fn allow_workspace(&self, ws: &UsrJayWorkspace) {
self.con.request(AllowWorkspace {
self_id: self.id,
workspace: ws.id,

View file

@ -0,0 +1,72 @@
use {
crate::{
utils::{
buffd::{MsgParser, MsgParserError},
clonecell::CloneCell,
},
wire::{jay_select_workspace::*, JaySelectWorkspaceId},
wl_usr::{usr_ifs::usr_jay_workspace::UsrJayWorkspace, usr_object::UsrObject, UsrCon},
},
std::rc::Rc,
thiserror::Error,
};
pub struct UsrJaySelectWorkspace {
pub id: JaySelectWorkspaceId,
pub con: Rc<UsrCon>,
pub owner: CloneCell<Option<Rc<dyn UsrJaySelectWorkspaceOwner>>>,
}
pub trait UsrJaySelectWorkspaceOwner {
fn done(&self, output: u32, ws: Option<Rc<UsrJayWorkspace>>);
}
impl UsrJaySelectWorkspace {
fn cancelled(&self, parser: MsgParser<'_, '_>) -> Result<(), UsrJaySelectWorkspaceError> {
let _ev: Cancelled = self.con.parse(self, parser)?;
if let Some(owner) = self.owner.get() {
owner.done(0, None);
}
self.con.remove_obj(self);
Ok(())
}
fn selected(&self, parser: MsgParser<'_, '_>) -> Result<(), UsrJaySelectWorkspaceError> {
let ev: Selected = self.con.parse(self, parser)?;
let tl = Rc::new(UsrJayWorkspace {
id: ev.id,
con: self.con.clone(),
owner: Default::default(),
});
self.con.add_object(tl.clone());
match self.owner.get() {
Some(owner) => owner.done(ev.output, Some(tl)),
_ => self.con.remove_obj(&*tl),
}
self.con.remove_obj(self);
Ok(())
}
}
usr_object_base! {
UsrJaySelectWorkspace, JaySelectWorkspace;
CANCELLED => cancelled,
SELECTED => selected,
}
impl UsrObject for UsrJaySelectWorkspace {
fn destroy(&self) {
// nothing
}
fn break_loops(&self) {
self.owner.take();
}
}
#[derive(Debug, Error)]
pub enum UsrJaySelectWorkspaceError {
#[error("Parsing failed")]
MsgParserError(#[from] MsgParserError),
}