jay-compositor 1.15.0

The Jay compositor
use crate::client::CAP_SESSION_LOCK_MANAGER;
use crate::client::Client;
use crate::client::ClientCaps;
use crate::globals::Global;
use crate::globals::GlobalName;
use crate::ifs::ext_session_lock_v1::ExtSessionLockV1;
use crate::leaks::Tracker;
use crate::object::Version;
use crate::tree::TreeTimeline::LiveTL;
use crate::wire::ExtSessionLockManagerV1Id;
use crate::wire::ext_session_lock_manager_v1::*;
use jay_proc::Global;
use jay_proc::Object;
use std::cell::Cell;
use std::convert::Infallible;
use std::rc::Rc;

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

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

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

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

impl ExtSessionLockManagerV1RequestHandler for ExtSessionLockManagerV1 {
    type Error = Infallible;

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

    fn lock(&self, req: Lock, _slf: &Rc<Self>) -> Result<(), Self::Error> {
        let did_lock = self.client.state.lock.locked[LiveTL].get() == false;
        let new = Rc::new(ExtSessionLockV1 {
            id: req.id,
            client: self.client.clone(),
            tracker: Default::default(),
            did_lock,
            awaiting_locked: Cell::new(true),
            finished: Cell::new(false),
            version: self.version,
        });
        track!(new.client, new);
        self.client.add_client_obj(&new);
        if did_lock {
            log::info!("Client {} locks the screen", self.client.id);
            let state = &self.client.state;
            for seat in state.globals.seats.lock().values() {
                seat.prepare_for_lock();
            }
            state.set_locked(true);
            state.lock.lock.set(Some(new.clone()));
            state.tree_changed();
            state.damage_full(LiveTL);
            new.check_locked();
        } else {
            new.finish();
        }
        Ok(())
    }
}

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

    fn required_caps(&self) -> ClientCaps {
        CAP_SESSION_LOCK_MANAGER
    }
}