use {
    crate::{
        object::Version,
        wire::{XdgWmBaseId, xdg_wm_base::*},
        wl_usr::{UsrCon, usr_object::UsrObject},
    },
    std::{convert::Infallible, rc::Rc},
};

pub struct UsrXdgWmBase {
    pub id: XdgWmBaseId,
    pub con: Rc<UsrCon>,
    pub version: Version,
}

impl XdgWmBaseEventHandler for UsrXdgWmBase {
    type Error = Infallible;

    fn ping(&self, ev: Ping, _slf: &Rc<Self>) -> Result<(), Self::Error> {
        self.con.request(Pong {
            self_id: self.id,
            serial: ev.serial,
        });
        Ok(())
    }
}

usr_object_base! {
    self = UsrXdgWmBase = XdgWmBase;
    version = self.version;
}

impl UsrObject for UsrXdgWmBase {
    fn destroy(&self) {
        self.con.request(Destroy { self_id: self.id })
    }
}
