use crate::client::Client;
use crate::client::LookupError;
use crate::globals::Global;
use crate::globals::GlobalName;
use crate::ifs::ipc::zwp_primary_selection_device_v1::ZwpPrimarySelectionDeviceV1;
use crate::ifs::ipc::zwp_primary_selection_source_v1::ZwpPrimarySelectionSourceV1;
use crate::leaks::Tracker;
use crate::object::Version;
use crate::state::State;
use crate::wire::ZwpPrimarySelectionDeviceManagerV1Id;
use crate::wire::zwp_primary_selection_device_manager_v1::*;
use jay_proc::Global;
use jay_proc::Object;
use std::convert::Infallible;
use std::rc::Rc;
#[derive(Global)]
pub struct ZwpPrimarySelectionDeviceManagerV1Global {
name: GlobalName,
}
#[derive(Object)]
pub struct ZwpPrimarySelectionDeviceManagerV1 {
id: ZwpPrimarySelectionDeviceManagerV1Id,
client: Rc<Client>,
version: Version,
tracker: Tracker<Self>,
}
impl ZwpPrimarySelectionDeviceManagerV1Global {
pub fn new(name: GlobalName) -> Self {
Self { name }
}
fn bind_(
self: Rc<Self>,
id: ZwpPrimarySelectionDeviceManagerV1Id,
client: &Rc<Client>,
version: Version,
) -> Result<(), Infallible> {
let obj = Rc::new(ZwpPrimarySelectionDeviceManagerV1 {
id,
client: client.clone(),
version,
tracker: Default::default(),
});
track!(client, obj);
client.add_client_obj(&obj);
Ok(())
}
}
impl ZwpPrimarySelectionDeviceManagerV1RequestHandler for ZwpPrimarySelectionDeviceManagerV1 {
type Error = LookupError;
fn create_source(&self, req: CreateSource, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let res = Rc::new(ZwpPrimarySelectionSourceV1::new(
req.id,
&self.client,
self.version,
));
track!(self.client, res);
self.client.add_client_obj(&res);
Ok(())
}
fn get_device(&self, req: GetDevice, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let seat = self.client.lookup(req.seat)?;
let dev = Rc::new(ZwpPrimarySelectionDeviceV1::new(
req.id,
&self.client,
self.version,
&seat.global,
));
track!(self.client, dev);
seat.global.add_primary_selection_device(&dev);
self.client.add_client_obj(&dev);
Ok(())
}
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self);
Ok(())
}
}
impl Global for ZwpPrimarySelectionDeviceManagerV1Global {
fn version(&self) -> u32 {
1
}
fn exposed(&self, state: &State) -> bool {
state.enable_primary_selection.get()
}
}