jay-compositor 1.14.0

The Jay compositor
use {
    crate::{
        client::ClientId,
        ifs::wl_seat::tablet::zwp_tablet_seat_v2::ZwpTabletSeatV2,
        utils::copyhashmap::{CopyHashMap, Locked},
        wire::ZwpTabletSeatV2Id,
    },
    derivative::Derivative,
    std::rc::Rc,
};

#[derive(Derivative)]
#[derivative(Default(bound = ""))]
pub struct TabletBindings<T> {
    bindings: CopyHashMap<(ClientId, ZwpTabletSeatV2Id), Rc<T>>,
}

impl<T> TabletBindings<T> {
    pub fn add(&self, seat: &ZwpTabletSeatV2, t: &Rc<T>) {
        self.bindings.set((seat.client.id, seat.id), t.clone());
    }

    pub fn get(&self, seat: &ZwpTabletSeatV2) -> Option<Rc<T>> {
        self.bindings.get(&(seat.client.id, seat.id))
    }

    pub fn remove(&self, seat: &ZwpTabletSeatV2) -> Option<Rc<T>> {
        self.bindings.remove(&(seat.client.id, seat.id))
    }

    pub fn lock(&self) -> Locked<'_, (ClientId, ZwpTabletSeatV2Id), Rc<T>> {
        self.bindings.lock()
    }

    pub fn clear(&self) {
        self.bindings.clear();
    }
}