1
0
Fork 0
forked from wry/wry
wry/src/wl_usr/usr_ifs/usr_wl_seat.rs
2026-03-07 18:12:13 +01:00

99 lines
2.4 KiB
Rust

use {
crate::{
object::Version,
utils::clonecell::CloneCell,
wire::{WlSeatId, wl_seat::*},
wl_usr::{
UsrCon,
usr_ifs::{usr_wl_keyboard::UsrWlKeyboard, usr_wl_pointer::UsrWlPointer},
usr_object::UsrObject,
},
},
std::{cell::Cell, convert::Infallible, rc::Rc},
};
pub struct UsrWlSeat {
pub id: WlSeatId,
pub con: Rc<UsrCon>,
pub owner: CloneCell<Option<Rc<dyn UsrWlSeatOwner>>>,
pub version: Version,
}
pub trait UsrWlSeatOwner {
fn capabilities(self: Rc<Self>, value: u32) {
let _ = value;
}
fn name(&self, name: &str) {
let _ = name;
}
}
impl UsrWlSeat {
pub fn get_pointer(&self) -> Rc<UsrWlPointer> {
let ptr = Rc::new(UsrWlPointer {
id: self.con.id(),
con: self.con.clone(),
owner: Default::default(),
any_scroll_events: Cell::new(false),
pending_scroll: Default::default(),
version: self.version,
});
self.con.add_object(ptr.clone());
self.con.request(GetPointer {
self_id: self.id,
id: ptr.id,
});
ptr
}
#[expect(dead_code)]
pub fn get_keyboard(&self) -> Rc<UsrWlKeyboard> {
let kb = Rc::new(UsrWlKeyboard {
id: self.con.id(),
con: self.con.clone(),
keyboard: Default::default(),
owner: Default::default(),
version: self.version,
});
self.con.add_object(kb.clone());
self.con.request(GetKeyboard {
self_id: self.id,
id: kb.id,
});
kb
}
}
impl WlSeatEventHandler for UsrWlSeat {
type Error = Infallible;
fn capabilities(&self, ev: Capabilities, _slf: &Rc<Self>) -> Result<(), Self::Error> {
if let Some(owner) = self.owner.get() {
owner.capabilities(ev.capabilities);
}
Ok(())
}
fn name(&self, ev: Name<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
if let Some(owner) = self.owner.get() {
owner.name(ev.name);
}
Ok(())
}
}
usr_object_base! {
self = UsrWlSeat = WlSeat;
version = self.version;
}
impl UsrObject for UsrWlSeat {
fn destroy(&self) {
self.con.request(Release { self_id: self.id });
}
fn break_loops(&self) {
self.owner.take();
}
}