use crate::client::{Client, ClientError}; use crate::globals::{Global, GlobalName}; use crate::ifs::zxdg_toplevel_decoration_v1::ZxdgToplevelDecorationV1; use crate::leaks::Tracker; use crate::object::Object; use crate::utils::buffd::{MsgParser, MsgParserError}; use crate::wire::zxdg_decoration_manager_v1::*; use crate::wire::ZxdgDecorationManagerV1Id; use std::rc::Rc; use thiserror::Error; pub struct ZxdgDecorationManagerV1Global { name: GlobalName, } impl ZxdgDecorationManagerV1Global { pub fn new(name: GlobalName) -> Self { Self { name } } fn bind_( self: Rc, id: ZxdgDecorationManagerV1Id, client: &Rc, version: u32, ) -> Result<(), ZxdgDecorationManagerV1Error> { let obj = Rc::new(ZxdgDecorationManagerV1 { id, client: client.clone(), _version: version, tracker: Default::default(), }); track!(client, obj); client.add_client_obj(&obj)?; Ok(()) } } global_base!( ZxdgDecorationManagerV1Global, ZxdgDecorationManagerV1, ZxdgDecorationManagerV1Error ); impl Global for ZxdgDecorationManagerV1Global { fn singleton(&self) -> bool { true } fn version(&self) -> u32 { 1 } } simple_add_global!(ZxdgDecorationManagerV1Global); pub struct ZxdgDecorationManagerV1 { id: ZxdgDecorationManagerV1Id, client: Rc, _version: u32, tracker: Tracker, } impl ZxdgDecorationManagerV1 { fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), DestroyError> { let _req: Destroy = self.client.parse(self, parser)?; self.client.remove_obj(self)?; Ok(()) } fn get_toplevel_decoration( &self, parser: MsgParser<'_, '_>, ) -> Result<(), GetToplevelDecorationError> { let req: GetToplevelDecoration = self.client.parse(self, parser)?; let tl = self.client.lookup(req.toplevel)?; let obj = Rc::new(ZxdgToplevelDecorationV1::new(req.id, &self.client, &tl)); track!(self.client, obj); self.client.add_client_obj(&obj)?; obj.do_send_configure(); Ok(()) } } object_base! { ZxdgDecorationManagerV1, ZxdgDecorationManagerV1Error; DESTROY => destroy, GET_TOPLEVEL_DECORATION => get_toplevel_decoration, } impl Object for ZxdgDecorationManagerV1 { fn num_requests(&self) -> u32 { GET_TOPLEVEL_DECORATION + 1 } } simple_add_obj!(ZxdgDecorationManagerV1); #[derive(Debug, Error)] pub enum ZxdgDecorationManagerV1Error { #[error("Could not process a `destroy` request")] DestroyError(#[from] DestroyError), #[error("Could not process a `get_toplevel_decoration` request")] GetToplevelDecorationError(#[from] GetToplevelDecorationError), #[error(transparent)] ClientError(Box), } efrom!(ZxdgDecorationManagerV1Error, ClientError); #[derive(Debug, Error)] pub enum DestroyError { #[error("Parsing failed")] MsgParserError(#[source] Box), #[error(transparent)] ClientError(Box), } efrom!(DestroyError, ClientError); efrom!(DestroyError, MsgParserError); #[derive(Debug, Error)] pub enum GetToplevelDecorationError { #[error("Parsing failed")] MsgParserError(#[source] Box), #[error(transparent)] ClientError(Box), } efrom!(GetToplevelDecorationError, ClientError); efrom!(GetToplevelDecorationError, MsgParserError);