1
0
Fork 0
forked from wry/wry

wayland: add jay_workspace_watcher

This commit is contained in:
Julian Orth 2022-07-30 11:28:46 +02:00
parent 83baa6aadb
commit 022d8d1db0
9 changed files with 145 additions and 4 deletions

View file

@ -6,7 +6,7 @@ use {
ifs::{
jay_idle::JayIdle, jay_log_file::JayLogFile, jay_output::JayOutput,
jay_pointer::JayPointer, jay_render_ctx::JayRenderCtx, jay_screenshot::JayScreenshot,
jay_seat_events::JaySeatEvents,
jay_seat_events::JaySeatEvents, jay_workspace_watcher::JayWorkspaceWatcher,
},
leaks::Tracker,
object::Object,
@ -279,6 +279,25 @@ impl JayCompositor {
ctx.send_render_ctx(rctx.as_ref());
Ok(())
}
fn watch_workspaces(&self, parser: MsgParser<'_, '_>) -> Result<(), JayCompositorError> {
let req: WatchWorkspaces = self.client.parse(self, parser)?;
let watcher = Rc::new(JayWorkspaceWatcher {
id: req.id,
client: self.client.clone(),
tracker: Default::default(),
});
track!(self.client, watcher);
self.client.add_client_obj(&watcher)?;
self.client
.state
.workspace_watchers
.set((self.client.id, req.id), watcher.clone());
for ws in self.client.state.workspaces.lock().values() {
watcher.send_workspace(ws)?;
}
Ok(())
}
}
object_base! {
@ -298,11 +317,12 @@ object_base! {
GET_OUTPUT => get_output,
GET_POINTER => get_pointer,
GET_RENDER_CTX => get_render_ctx,
WATCH_WORKSPACES => watch_workspaces,
}
impl Object for JayCompositor {
fn num_requests(&self) -> u32 {
GET_RENDER_CTX + 1
WATCH_WORKSPACES + 1
}
}

View file

@ -21,7 +21,6 @@ pub struct JayWorkspace {
pub tracker: Tracker<Self>,
}
#[allow(dead_code)]
impl JayWorkspace {
pub fn send_linear_id(&self, ws: &WorkspaceNode) {
self.client.event(LinearId {

View file

@ -0,0 +1,91 @@
use {
crate::{
client::{Client, ClientError},
ifs::jay_workspace::JayWorkspace,
leaks::Tracker,
object::Object,
tree::WorkspaceNode,
utils::{
buffd::{MsgParser, MsgParserError},
clonecell::CloneCell,
},
wire::{jay_workspace_watcher::*, JayWorkspaceWatcherId},
},
std::rc::Rc,
thiserror::Error,
};
pub struct JayWorkspaceWatcher {
pub id: JayWorkspaceWatcherId,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
}
impl JayWorkspaceWatcher {
pub fn send_workspace(&self, workspace: &Rc<WorkspaceNode>) -> Result<(), ClientError> {
let jw = Rc::new(JayWorkspace {
id: self.client.new_id()?,
client: self.client.clone(),
workspace: CloneCell::new(Some(workspace.clone())),
tracker: Default::default(),
});
track!(self.client, jw);
self.client.add_server_obj(&jw);
workspace
.jay_workspaces
.set((self.client.id, jw.id), jw.clone());
self.client.event(New {
self_id: self.id,
id: jw.id,
linear_id: workspace.id.raw(),
});
jw.send_linear_id(workspace);
jw.send_name(workspace);
jw.send_output(&workspace.output.get());
jw.send_visible(workspace.visible.get());
jw.send_done();
Ok(())
}
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), JayWorkspaceWatcherError> {
let _req: Destroy = self.client.parse(self, parser)?;
self.remove_from_state();
self.client.remove_obj(self)?;
Ok(())
}
fn remove_from_state(&self) {
self.client
.state
.workspace_watchers
.remove(&(self.client.id, self.id));
}
}
object_base! {
JayWorkspaceWatcher;
DESTROY => destroy,
}
impl Object for JayWorkspaceWatcher {
fn num_requests(&self) -> u32 {
DESTROY + 1
}
fn break_loops(&self) {
self.remove_from_state();
}
}
simple_add_obj!(JayWorkspaceWatcher);
#[derive(Debug, Error)]
pub enum JayWorkspaceWatcherError {
#[error("Parsing failed")]
MsgParserError(Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(JayWorkspaceWatcherError, MsgParserError);
efrom!(JayWorkspaceWatcherError, ClientError);