1
0
Fork 0
forked from wry/wry

wl_usr: add additional interfaces

This commit is contained in:
Julian Orth 2026-02-22 00:11:31 +01:00
parent 56290d5547
commit ce30901093
16 changed files with 1062 additions and 23 deletions

View file

@ -0,0 +1,70 @@
use {
crate::{
object::Version,
utils::clonecell::CloneCell,
wire::{XdgSurfaceId, xdg_surface::*},
wl_usr::{UsrCon, usr_ifs::usr_xdg_toplevel::UsrXdgToplevel, usr_object::UsrObject},
},
std::{convert::Infallible, rc::Rc},
};
pub struct UsrXdgSurface {
pub id: XdgSurfaceId,
pub con: Rc<UsrCon>,
pub owner: CloneCell<Option<Rc<dyn UsrXdgSurfaceOwner>>>,
pub version: Version,
}
pub trait UsrXdgSurfaceOwner {
fn configure(&self) {
// nothing
}
}
impl UsrXdgSurface {
#[expect(dead_code)]
pub fn get_toplevel(&self) -> Rc<UsrXdgToplevel> {
let obj = Rc::new(UsrXdgToplevel {
id: self.con.id(),
con: self.con.clone(),
owner: Default::default(),
version: self.version,
});
self.con.request(GetToplevel {
self_id: self.id,
id: obj.id,
});
self.con.add_object(obj.clone());
obj
}
}
impl XdgSurfaceEventHandler for UsrXdgSurface {
type Error = Infallible;
fn configure(&self, ev: Configure, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.con.request(AckConfigure {
self_id: self.id,
serial: ev.serial,
});
if let Some(owner) = self.owner.get() {
owner.configure();
}
Ok(())
}
}
usr_object_base! {
self = UsrXdgSurface = XdgSurface;
version = self.version;
}
impl UsrObject for UsrXdgSurface {
fn destroy(&self) {
self.con.request(Destroy { self_id: self.id })
}
fn break_loops(&self) {
self.owner.take();
}
}