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_surface::wp_linux_drm_syncobj_surface_v1::WpLinuxDrmSyncobjSurfaceV1;
use crate::ifs::wl_surface::wp_linux_drm_syncobj_surface_v1::WpLinuxDrmSyncobjSurfaceV1Error;
use crate::ifs::wp_linux_drm_syncobj_timeline_v1::WpLinuxDrmSyncobjTimelineV1;
use crate::leaks::Tracker;
use crate::object::Version;
use crate::state::State;
use crate::video::drm::syncobj::Syncobj;
use crate::wire::WpLinuxDrmSyncobjManagerV1Id;
use crate::wire::wp_linux_drm_syncobj_manager_v1::*;
use jay_proc::Global;
use jay_proc::Object;
use std::rc::Rc;
use thiserror::Error;

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

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

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

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

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

    fn exposed(&self, state: &State) -> bool {
        state.explicit_sync_enabled.get() && state.explicit_sync_supported.get()
    }
}

impl WpLinuxDrmSyncobjManagerV1RequestHandler for WpLinuxDrmSyncobjManagerV1 {
    type Error = WpLinuxDrmSyncobjManagerV1Error;

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

    fn get_surface(&self, req: GetSurface, _slf: &Rc<Self>) -> Result<(), Self::Error> {
        let surface = self.client.lookup(req.surface)?;
        let sync = Rc::new(WpLinuxDrmSyncobjSurfaceV1::new(
            req.id,
            &self.client,
            &surface,
            self.version,
        ));
        track!(self.client, sync);
        sync.install()?;
        self.client.add_client_obj(&sync);
        Ok(())
    }

    fn import_timeline(&self, req: ImportTimeline, _slf: &Rc<Self>) -> Result<(), Self::Error> {
        let syncobj = Rc::new(Syncobj::new(&req.fd));
        let sync = Rc::new(WpLinuxDrmSyncobjTimelineV1::new(
            req.id,
            &self.client,
            &syncobj,
            self.version,
        ));
        track!(self.client, sync);
        self.client.add_client_obj(&sync);
        Ok(())
    }
}

#[derive(Debug, Error)]
pub enum WpLinuxDrmSyncobjManagerV1Error {
    #[error(transparent)]
    Lookup(#[from] LookupError),
    #[error(transparent)]
    WpLinuxDrmSyncobjSurfaceV1Error(#[from] WpLinuxDrmSyncobjSurfaceV1Error),
}