97 lines
2.3 KiB
Rust
97 lines
2.3 KiB
Rust
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>,
|
|
}
|
|
|
|
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! {
|
|
self = JayWorkspace;
|
|
|
|
DESTROY => destroy,
|
|
}
|
|
|
|
impl Object for JayWorkspace {
|
|
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);
|