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::ifs::wl_seat::tablet::zwp_tablet_seat_v2::ZwpTabletSeatV2;
use crate::leaks::Tracker;
use crate::object::Version;
use crate::wire::ZwpTabletManagerV2Id;
use crate::wire::zwp_tablet_manager_v2::*;
use jay_proc::Global;
use jay_proc::Object;
use std::convert::Infallible;
use std::rc::Rc;

#[derive(Global)]
pub struct ZwpTabletManagerV2Global {
    name: GlobalName,
}

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

impl ZwpTabletManagerV2Global {
    pub fn new(name: GlobalName) -> Self {
        Self { name }
    }

    fn bind_(
        self: Rc<Self>,
        id: ZwpTabletManagerV2Id,
        client: &Rc<Client>,
        version: Version,
    ) -> Result<(), Infallible> {
        let obj = Rc::new(ZwpTabletManagerV2 {
            id,
            client: client.clone(),
            tracker: Default::default(),
            version,
        });
        track!(client, obj);
        client.add_client_obj(&obj);
        Ok(())
    }
}

impl Global for ZwpTabletManagerV2Global {
    fn version(&self) -> u32 {
        2
    }
}

impl ZwpTabletManagerV2RequestHandler for ZwpTabletManagerV2 {
    type Error = LookupError;

    fn get_tablet_seat(&self, req: GetTabletSeat, _slf: &Rc<Self>) -> Result<(), Self::Error> {
        let seat = self.client.lookup(req.seat)?.global.clone();
        let obj = Rc::new(ZwpTabletSeatV2 {
            id: req.tablet_seat,
            client: self.client.clone(),
            seat: seat.clone(),
            tracker: Default::default(),
            version: self.version,
        });
        track!(self.client, obj);
        self.client.add_client_obj(&obj);
        seat.tablet_add_seat(&obj);
        Ok(())
    }

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