1
0
Fork 0
forked from wry/wry

wayland: add jay_workspace

This commit is contained in:
Julian Orth 2022-07-30 11:22:40 +02:00
parent 53ca7b5b2a
commit 83baa6aadb
10 changed files with 183 additions and 28 deletions

102
src/ifs/jay_workspace.rs Normal file
View file

@ -0,0 +1,102 @@
use {
crate::{
client::{Client, ClientError},
leaks::Tracker,
object::Object,
tree::{OutputNode, WorkspaceNode},
utils::{
buffd::{MsgParser, MsgParserError},
clonecell::CloneCell,
},
wire::{jay_workspace::*, JayWorkspaceId},
},
std::rc::Rc,
thiserror::Error,
};
pub struct JayWorkspace {
pub id: JayWorkspaceId,
pub client: Rc<Client>,
pub workspace: CloneCell<Option<Rc<WorkspaceNode>>>,
pub tracker: Tracker<Self>,
}
#[allow(dead_code)]
impl JayWorkspace {
pub fn send_linear_id(&self, ws: &WorkspaceNode) {
self.client.event(LinearId {
self_id: self.id,
linear_id: ws.id.raw(),
});
}
pub fn send_name(&self, ws: &WorkspaceNode) {
self.client.event(Name {
self_id: self.id,
name: &ws.name,
});
}
pub fn send_destroyed(&self) {
self.client.event(Destroyed { self_id: self.id });
}
pub fn send_done(&self) {
self.client.event(Done { self_id: self.id });
}
pub fn send_output(&self, output: &OutputNode) {
self.client.event(Output {
self_id: self.id,
global_name: output.global.name.raw(),
});
}
pub fn send_visible(&self, visible: bool) {
self.client.event(Visible {
self_id: self.id,
visible: visible as _,
});
}
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), JayWorkspaceError> {
let _req: Destroy = self.client.parse(self, parser)?;
self.remove_from_node();
self.client.remove_obj(self)?;
Ok(())
}
fn remove_from_node(&self) {
if let Some(ws) = self.workspace.take() {
ws.jay_workspaces.remove(&(self.client.id, self.id));
}
}
}
object_base! {
JayWorkspace;
DESTROY => destroy,
}
impl Object for JayWorkspace {
fn num_requests(&self) -> u32 {
DESTROY + 1
}
fn break_loops(&self) {
self.remove_from_node();
}
}
dedicated_add_obj!(JayWorkspace, JayWorkspaceId, jay_workspaces);
#[derive(Debug, Error)]
pub enum JayWorkspaceError {
#[error("Parsing failed")]
MsgParserError(Box<MsgParserError>),
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(JayWorkspaceError, MsgParserError);
efrom!(JayWorkspaceError, ClientError);