use crate::client::Client;
use crate::ifs::wl_output::SEND_DONE_SINCE;
use crate::ifs::wl_output::WlOutput;
use crate::leaks::Tracker;
use crate::object::Version;
use crate::tree::TreeTimeline::LiveTL;
use crate::wire::ZxdgOutputV1Id;
use crate::wire::zxdg_output_v1::*;
use jay_proc::Object;
use std::convert::Infallible;
use std::rc::Rc;
pub const NAME_SINCE: Version = Version(2);
pub const DESCRIPTION_SINCE: Version = Version(2);
pub const NO_DONE_SINCE: Version = Version(3);
#[derive(Object)]
pub struct ZxdgOutputV1 {
pub id: ZxdgOutputV1Id,
pub version: Version,
pub client: Rc<Client>,
pub output: Rc<WlOutput>,
pub tracker: Tracker<Self>,
}
impl ZxdgOutputV1 {
fn send_logical_position(&self, mut x: i32, mut y: i32) {
logical_to_client_wire_scale!(self.client, x, y);
self.client.event(LogicalPosition {
self_id: self.id,
x,
y,
});
}
fn send_logical_size(&self, mut width: i32, mut height: i32) {
logical_to_client_wire_scale!(self.client, width, height);
self.client.event(LogicalSize {
self_id: self.id,
width,
height,
});
}
fn send_done(&self) {
self.client.event(Done { self_id: self.id });
}
fn send_name(&self, name: &str) {
self.client.event(Name {
self_id: self.id,
name,
});
}
fn send_description(&self, description: &str) {
self.client.event(Description {
self_id: self.id,
description,
});
}
pub fn send_updates(&self, initial: bool) {
let Some(node) = self.output.global.node() else {
return;
};
let global = &node.global;
let pos = node.node_state[LiveTL].pos.get();
self.send_logical_position(pos.x1(), pos.y1());
self.send_logical_size(pos.width(), pos.height());
if initial {
if self.version >= NAME_SINCE {
self.send_name(&global.connector.name);
}
if self.version >= DESCRIPTION_SINCE {
self.send_description(&global.connector.description.borrow());
}
}
if self.version >= NO_DONE_SINCE {
if self.output.version >= SEND_DONE_SINCE {
self.output.send_done();
}
} else {
self.send_done();
}
}
}
impl ZxdgOutputV1RequestHandler for ZxdgOutputV1 {
type Error = Infallible;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.output.xdg_outputs.remove(&self.id);
self.client.remove_obj(self);
Ok(())
}
}