jay-compositor 1.15.0

The Jay compositor
use crate::client::Client;
use crate::client::LookupError;
use crate::globals::Global;
use crate::globals::GlobalName;
use crate::globals::RemovableWaylandGlobal;
use crate::ifs::wl_output::OutputGlobalOpt;
use crate::ifs::wl_surface::tray::jay_tray_item_v1::JayTrayItemV1;
use crate::ifs::wl_surface::tray::jay_tray_item_v1::JayTrayItemV1Error;
use crate::leaks::Tracker;
use crate::object::Version;
use crate::wire::JayTrayV1Id;
use crate::wire::jay_tray_v1::*;
use jay_proc::Global;
use jay_proc::Object;
use std::rc::Rc;
use thiserror::Error;

#[derive(Global)]
pub struct JayTrayV1Global {
    pub name: GlobalName,
    pub output: Rc<OutputGlobalOpt>,
}

#[derive(Object)]
pub struct JayTrayV1 {
    id: JayTrayV1Id,
    client: Rc<Client>,
    tracker: Tracker<Self>,
    version: Version,
    output: Rc<OutputGlobalOpt>,
}

impl JayTrayV1Global {
    fn bind_(
        self: Rc<Self>,
        id: JayTrayV1Id,
        client: &Rc<Client>,
        version: Version,
    ) -> Result<(), JayTrayManagerV1Error> {
        let obj = Rc::new(JayTrayV1 {
            id,
            client: client.clone(),
            tracker: Default::default(),
            version,
            output: self.output.clone(),
        });
        track!(client, obj);
        client.add_client_obj(&obj);
        Ok(())
    }
}

impl Global for JayTrayV1Global {
    fn version(&self) -> u32 {
        1
    }
}

impl RemovableWaylandGlobal for JayTrayV1Global {
    fn create_replacement(self: Rc<Self>) -> Rc<dyn Global> {
        self
    }
}

impl JayTrayV1RequestHandler for JayTrayV1 {
    type Error = JayTrayManagerV1Error;

    fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
        self.client.remove_obj(self);
        Ok(())
    }

    fn get_tray_item(&self, req: GetTrayItem, _slf: &Rc<Self>) -> Result<(), Self::Error> {
        let surface = self.client.lookup(req.surface)?;
        let fs = Rc::new(JayTrayItemV1::new(
            req.id,
            self.version,
            &surface,
            &self.output,
        ));
        track!(self.client, fs);
        fs.install()?;
        self.client.add_client_obj(&fs);
        Ok(())
    }
}

#[derive(Debug, Error)]
pub enum JayTrayManagerV1Error {
    #[error(transparent)]
    Lookup(#[from] LookupError),
    #[error(transparent)]
    ExtTrayItemV1Error(#[from] JayTrayItemV1Error),
}