1
0
Fork 0
forked from wry/wry

wayland: implement xdg-dialog-v1

This commit is contained in:
Julian Orth 2024-04-24 13:51:13 +02:00
parent 4a236b7833
commit 5dff6c38fd
9 changed files with 210 additions and 1 deletions

View file

@ -1,3 +1,5 @@
pub mod xdg_dialog_v1;
use {
crate::{
bugs,
@ -9,7 +11,10 @@ use {
ext_foreign_toplevel_list_v1::ExtForeignToplevelListV1,
wl_seat::{NodeSeatState, SeatId, WlSeatGlobal},
wl_surface::{
xdg_surface::{XdgSurface, XdgSurfaceError, XdgSurfaceExt},
xdg_surface::{
xdg_toplevel::xdg_dialog_v1::XdgDialogV1, XdgSurface, XdgSurfaceError,
XdgSurfaceExt,
},
WlSurface,
},
xdg_toplevel_drag_v1::XdgToplevelDragV1,
@ -99,6 +104,7 @@ pub struct XdgToplevel {
toplevel_data: ToplevelData,
pub drag: CloneCell<Option<Rc<XdgToplevelDragV1>>>,
is_mapped: Cell<bool>,
dialog: CloneCell<Option<Rc<XdgDialogV1>>>,
}
impl Debug for XdgToplevel {
@ -137,6 +143,7 @@ impl XdgToplevel {
),
drag: Default::default(),
is_mapped: Cell::new(false),
dialog: Default::default(),
}
}
@ -454,6 +461,7 @@ impl Object for XdgToplevel {
fn break_loops(&self) {
self.tl_destroy();
self.parent.set(None);
self.dialog.set(None);
let _children = mem::take(&mut *self.children.borrow_mut());
}
}

View file

@ -0,0 +1,73 @@
use {
crate::{
client::{Client, ClientError},
ifs::wl_surface::xdg_surface::xdg_toplevel::XdgToplevel,
leaks::Tracker,
object::{Object, Version},
wire::{xdg_dialog_v1::*, XdgDialogV1Id, XdgToplevelId},
},
std::{fmt::Debug, rc::Rc},
thiserror::Error,
};
pub struct XdgDialogV1 {
pub id: XdgDialogV1Id,
pub client: Rc<Client>,
pub toplevel: Rc<XdgToplevel>,
pub tracker: Tracker<Self>,
pub version: Version,
}
impl XdgDialogV1 {
fn detach(&self) {
self.toplevel.dialog.take();
}
pub fn install(self: &Rc<Self>) -> Result<(), XdgDialogV1Error> {
if self.toplevel.dialog.is_some() {
return Err(XdgDialogV1Error::AlreadyAttached(self.toplevel.id));
}
self.toplevel.dialog.set(Some(self.clone()));
Ok(())
}
}
impl XdgDialogV1RequestHandler for XdgDialogV1 {
type Error = XdgDialogV1Error;
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.detach();
self.client.remove_obj(self)?;
Ok(())
}
fn set_modal(&self, _req: SetModal, _slf: &Rc<Self>) -> Result<(), Self::Error> {
Ok(())
}
fn unset_modal(&self, _req: UnsetModal, _slf: &Rc<Self>) -> Result<(), Self::Error> {
Ok(())
}
}
object_base! {
self = XdgDialogV1;
version = self.version;
}
impl Object for XdgDialogV1 {
fn break_loops(&self) {
self.detach();
}
}
simple_add_obj!(XdgDialogV1);
#[derive(Debug, Error)]
pub enum XdgDialogV1Error {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Toplevel {0} already has an xdg_dialog_v1")]
AlreadyAttached(XdgToplevelId),
}
efrom!(XdgDialogV1Error, ClientError);