jay-compositor 1.15.0

The Jay compositor
use crate::client::Client;
use crate::fixed::Fixed;
use crate::ifs::wl_seat::WlSeatGlobal;
use crate::ifs::wl_surface::WlSurface;
use crate::leaks::Tracker;
use crate::object::BreakLoops;
use crate::object::Version;
use crate::wire::ZwpPointerGesturePinchV1Id;
use crate::wire::zwp_pointer_gesture_pinch_v1::*;
use jay_proc::Object;
use std::convert::Infallible;
use std::rc::Rc;

#[derive(Object)]
#[break_loops]
pub struct ZwpPointerGesturePinchV1 {
    pub id: ZwpPointerGesturePinchV1Id,
    pub client: Rc<Client>,
    pub seat: Rc<WlSeatGlobal>,
    pub tracker: Tracker<Self>,
    pub version: Version,
}

impl ZwpPointerGesturePinchV1 {
    fn detach(&self) {
        self.seat.pinch_bindings.remove(&self.client, self);
    }

    pub fn send_pinch_begin(&self, n: &WlSurface, serial: u64, time_usec: u64, finger_count: u32) {
        self.client.event(Begin {
            self_id: self.id,
            serial: serial as _,
            time: (time_usec / 1000) as u32,
            surface: n.id,
            fingers: finger_count,
        });
    }

    pub fn send_pinch_update(
        &self,
        time_usec: u64,
        dx: Fixed,
        dy: Fixed,
        scale: Fixed,
        rotation: Fixed,
    ) {
        self.client.event(Update {
            self_id: self.id,
            time: (time_usec / 1000) as u32,
            dx,
            dy,
            scale,
            rotation,
        });
    }

    pub fn send_pinch_end(&self, serial: u64, time_usec: u64, cancelled: bool) {
        self.client.event(End {
            self_id: self.id,
            serial: serial as _,
            time: (time_usec / 1000) as u32,
            cancelled: cancelled as _,
        });
    }
}

impl ZwpPointerGesturePinchV1RequestHandler for ZwpPointerGesturePinchV1 {
    type Error = Infallible;

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

impl BreakLoops for ZwpPointerGesturePinchV1 {
    fn break_loops(self: Rc<Self>) {
        self.detach();
    }
}