use crate::client::Client;
use crate::client::LookupError;
use crate::globals::Global;
use crate::globals::GlobalName;
use crate::ifs::wp_presentation_feedback::PresentationFeedback;
use crate::ifs::wp_presentation_feedback::WpPresentationFeedback;
use crate::leaks::Tracker;
use crate::object::Version;
use crate::state::State;
pub use crate::wire::WpPresentationId;
pub use crate::wire::wp_presentation::*;
use jay_proc::Global;
use jay_proc::Object;
use std::convert::Infallible;
use std::rc::Rc;
use uapi::c;
#[derive(Global)]
pub struct WpPresentationGlobal {
name: GlobalName,
}
impl WpPresentationGlobal {
pub fn new(name: GlobalName) -> Self {
Self { name }
}
fn bind_(
self: Rc<Self>,
id: WpPresentationId,
client: &Rc<Client>,
version: Version,
) -> Result<(), Infallible> {
let obj = Rc::new(WpPresentation {
id,
client: client.clone(),
tracker: Default::default(),
version,
});
track!(client, obj);
client.add_client_obj(&obj);
obj.send_clock_id();
Ok(())
}
}
impl Global for WpPresentationGlobal {
fn version(&self) -> u32 {
2
}
fn exposed(&self, state: &State) -> bool {
state.supports_presentation_feedback.get()
}
}
#[derive(Object)]
pub struct WpPresentation {
id: WpPresentationId,
client: Rc<Client>,
tracker: Tracker<Self>,
version: Version,
}
impl WpPresentation {
fn send_clock_id(&self) {
self.client.event(ClockId {
self_id: self.id,
clk_id: c::CLOCK_MONOTONIC as _,
});
}
}
impl WpPresentationRequestHandler for WpPresentation {
type Error = LookupError;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self);
Ok(())
}
fn feedback(&self, req: Feedback, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let surface = self.client.lookup(req.surface)?;
let fb = Rc::new(WpPresentationFeedback {
id: req.callback,
client: self.client.clone(),
_surface: surface.clone(),
tracker: Default::default(),
version: self.version,
});
track!(self.client, fb);
self.client.add_client_obj(&fb);
surface.add_presentation_feedback(PresentationFeedback::new(fb));
Ok(())
}
}