use crate::client::Client;
use crate::client::LookupError;
use crate::globals::Global;
use crate::globals::GlobalName;
use crate::ifs::zxdg_output_v1::ZxdgOutputV1;
use crate::leaks::Tracker;
use crate::object::Version;
use crate::wire::ZxdgOutputManagerV1Id;
use crate::wire::zxdg_output_manager_v1::*;
use jay_proc::Global;
use jay_proc::Object;
use std::convert::Infallible;
use std::rc::Rc;
#[derive(Global)]
pub struct ZxdgOutputManagerV1Global {
name: GlobalName,
}
#[derive(Object)]
pub struct ZxdgOutputManagerV1 {
id: ZxdgOutputManagerV1Id,
client: Rc<Client>,
version: Version,
tracker: Tracker<Self>,
}
impl ZxdgOutputManagerV1Global {
pub fn new(name: GlobalName) -> Self {
Self { name }
}
fn bind_(
self: Rc<Self>,
id: ZxdgOutputManagerV1Id,
client: &Rc<Client>,
version: Version,
) -> Result<(), Infallible> {
let obj = Rc::new(ZxdgOutputManagerV1 {
id,
client: client.clone(),
version,
tracker: Default::default(),
});
track!(client, obj);
client.add_client_obj(&obj);
Ok(())
}
}
impl ZxdgOutputManagerV1RequestHandler for ZxdgOutputManagerV1 {
type Error = LookupError;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self);
Ok(())
}
fn get_xdg_output(&self, req: GetXdgOutput, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let output = self.client.lookup(req.output)?;
let xdg_output = Rc::new(ZxdgOutputV1 {
id: req.id,
version: self.version,
client: self.client.clone(),
output: output.clone(),
tracker: Default::default(),
});
track!(self.client, xdg_output);
self.client.add_client_obj(&xdg_output);
xdg_output.send_updates(true);
output.xdg_outputs.set(req.id, xdg_output);
Ok(())
}
}
impl Global for ZxdgOutputManagerV1Global {
fn version(&self) -> u32 {
3
}
}