diff --git a/src/wayland/core/buffer.rs b/src/wayland/core/buffer.rs index eb35124..3b4557a 100644 --- a/src/wayland/core/buffer.rs +++ b/src/wayland/core/buffer.rs @@ -100,7 +100,8 @@ impl WlBuffer for Buffer { type Connection = crate::wayland::Client; /// https://wayland.app/protocols/wayland#wl_buffer:request:destroy - async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy(&self, client: &mut Client, _sender_id: ObjectId) -> WaylandResult<()> { + client.remove(self.id); tracing::info!("Destroying buffer {:?}", self.id); Ok(()) } diff --git a/src/wayland/core/compositor.rs b/src/wayland/core/compositor.rs index 8fb518d..cfec301 100644 --- a/src/wayland/core/compositor.rs +++ b/src/wayland/core/compositor.rs @@ -1,5 +1,5 @@ use super::surface::WL_SURFACE_REGISTRY; -use crate::wayland::{WaylandResult, WaylandError}; +use crate::wayland::{WaylandError, WaylandResult}; use crate::wayland::{core::surface::Surface, util::ClientExt}; use waynest::ObjectId; use waynest_protocols::server::core::wayland::wl_surface::WlSurface; @@ -35,14 +35,16 @@ impl WlCompositor for Compositor { _sender_id: ObjectId, id: ObjectId, ) -> WaylandResult<()> { - client.insert(id, Region::default()); + client.insert(id, Region { id }); Ok(()) } } -#[derive(Debug, RequestDispatcher, Default)] +#[derive(Debug, RequestDispatcher)] #[waynest(error = WaylandError)] -pub struct Region {} +pub struct Region { + id: ObjectId, +} impl WlRegion for Region { type Connection = crate::wayland::Client; @@ -73,7 +75,12 @@ impl WlRegion for Region { } /// https://wayland.app/protocols/wayland#wl_region:request:destroy - async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy( + &self, + client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } } diff --git a/src/wayland/core/data_device.rs b/src/wayland/core/data_device.rs index 87519f7..2bbdcf8 100644 --- a/src/wayland/core/data_device.rs +++ b/src/wayland/core/data_device.rs @@ -19,7 +19,7 @@ impl WlDataDeviceManager for DataDeviceManager { _sender_id: ObjectId, id: ObjectId, ) -> WaylandResult<()> { - client.insert(id, DataSource); + client.insert(id, DataSource { id }); Ok(()) } @@ -37,7 +37,9 @@ impl WlDataDeviceManager for DataDeviceManager { #[derive(Debug, waynest_server::RequestDispatcher)] #[waynest(error = crate::wayland::WaylandError)] -pub struct DataSource; +pub struct DataSource { + id: ObjectId, +} impl WlDataSource for DataSource { type Connection = Client; @@ -60,7 +62,12 @@ impl WlDataSource for DataSource { Ok(()) } - async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy( + &self, + client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } @@ -102,14 +109,20 @@ impl WlDataDevice for DataDevice { Ok(()) } - async fn release(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn release( + &self, + _client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { Ok(()) } } #[derive(Debug, waynest_server::RequestDispatcher)] #[waynest(error = crate::wayland::WaylandError)] -pub struct DataOffer; +pub struct DataOffer { + id: ObjectId, +} impl WlDataOffer for DataOffer { type Connection = Client; @@ -133,11 +146,20 @@ impl WlDataOffer for DataOffer { Ok(()) } - async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy( + &self, + client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } - async fn finish(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn finish( + &self, + _client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { Ok(()) } diff --git a/src/wayland/core/shm.rs b/src/wayland/core/shm.rs index 7a0fef9..e029efa 100644 --- a/src/wayland/core/shm.rs +++ b/src/wayland/core/shm.rs @@ -7,7 +7,11 @@ pub use waynest_protocols::server::core::wayland::wl_shm::*; #[waynest(error = crate::wayland::WaylandError)] pub struct Shm; impl Shm { - pub async fn advertise_formats(&self, client: &mut Client, sender_id: ObjectId) -> WaylandResult<()> { + pub async fn advertise_formats( + &self, + client: &mut Client, + sender_id: ObjectId, + ) -> WaylandResult<()> { self.format(client, sender_id, Format::Argb8888).await?; self.format(client, sender_id, Format::Xrgb8888).await?; @@ -26,13 +30,17 @@ impl WlShm for Shm { fd: OwnedFd, size: i32, ) -> WaylandResult<()> { - client.insert(pool_id, ShmPool::new(fd, size)?); + client.insert(pool_id, ShmPool::new(fd, size, pool_id)?); Ok(()) } /// https://wayland.app/protocols/wayland#wl_shm:request:release - async fn release(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn release( + &self, + _client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { Ok(()) } } diff --git a/src/wayland/core/shm_pool.rs b/src/wayland/core/shm_pool.rs index 328c315..03d4a81 100644 --- a/src/wayland/core/shm_pool.rs +++ b/src/wayland/core/shm_pool.rs @@ -14,11 +14,12 @@ pub use waynest_protocols::server::core::wayland::wl_shm_pool::*; #[waynest(error = crate::wayland::WaylandError)] pub struct ShmPool { inner: Mutex, + id: ObjectId, } impl ShmPool { #[tracing::instrument(level = "debug", skip_all)] - pub fn new(fd: OwnedFd, size: i32) -> WaylandResult { + pub fn new(fd: OwnedFd, size: i32, id: ObjectId) -> WaylandResult { let map = unsafe { MmapOptions::new() .len(size as usize) @@ -27,6 +28,7 @@ impl ShmPool { Ok(Self { inner: Mutex::new(map), + id, }) } @@ -79,7 +81,12 @@ impl WlShmPool for ShmPool { /// https://wayland.app/protocols/wayland#wl_shm_pool:request:destroy #[tracing::instrument(level = "debug", skip_all)] - async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy( + &self, + client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } } diff --git a/src/wayland/core/surface.rs b/src/wayland/core/surface.rs index 1c1e5e6..ba4e227 100644 --- a/src/wayland/core/surface.rs +++ b/src/wayland/core/surface.rs @@ -490,9 +490,10 @@ impl WlSurface for Surface { #[tracing::instrument(level = "debug", skip_all)] async fn destroy( &self, - _client: &mut Self::Connection, + client: &mut Self::Connection, _sender_id: ObjectId, ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } } diff --git a/src/wayland/presentation.rs b/src/wayland/presentation.rs index 81a912b..17b2e2b 100644 --- a/src/wayland/presentation.rs +++ b/src/wayland/presentation.rs @@ -34,11 +34,23 @@ impl From for MonotonicTimestamp { #[derive(Debug, waynest_server::RequestDispatcher)] #[waynest(error = crate::wayland::WaylandError)] -pub struct Presentation; +pub struct Presentation { + id: ObjectId, +} +impl Presentation { + pub fn new(id: ObjectId) -> Self { + Self { id } + } +} impl WpPresentation for Presentation { type Connection = crate::wayland::Client; - async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy( + &self, + client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } diff --git a/src/wayland/registry.rs b/src/wayland/registry.rs index ca8ebd9..c609ca2 100644 --- a/src/wayland/registry.rs +++ b/src/wayland/registry.rs @@ -168,9 +168,7 @@ impl WlRegistry for Registry { tracing::info!("Binding WM_BASE"); client.insert( new_id.object_id, - WmBase { - version: new_id.version, - }, + WmBase::new(new_id.object_id, new_id.version), ); } RegistryGlobals::SEAT => { @@ -212,12 +210,12 @@ impl WlRegistry for Registry { RegistryGlobals::PRESENTATION => { tracing::info!("Binding wp_presentation"); - client.insert(new_id.object_id, Presentation); + client.insert(new_id.object_id, Presentation::new(new_id.object_id)); } RegistryGlobals::VIEWPORTER => { tracing::info!("Binding wp_viewporter"); - client.insert(new_id.object_id, Viewporter); + client.insert(new_id.object_id, Viewporter::new(new_id.object_id)); } id => { tracing::error!(id, "Wayland: failed to bind to registry global"); diff --git a/src/wayland/viewporter.rs b/src/wayland/viewporter.rs index 796be7b..2b44d9f 100644 --- a/src/wayland/viewporter.rs +++ b/src/wayland/viewporter.rs @@ -6,14 +6,27 @@ pub use waynest_protocols::server::stable::viewporter::wp_viewporter::*; // This is a barebones/stub no-op implementation of wp_viewporter to make xwayland apps work -#[derive(Debug, waynest_server::RequestDispatcher, Default)] +#[derive(Debug, waynest_server::RequestDispatcher)] #[waynest(error = crate::wayland::WaylandError)] -pub struct Viewporter; +pub struct Viewporter { + id: ObjectId, +} + +impl Viewporter { + pub fn new(id: ObjectId) -> Self { + Self { id } + } +} impl WpViewporter for Viewporter { type Connection = crate::wayland::Client; - async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy( + &self, + client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } @@ -33,14 +46,14 @@ impl WpViewporter for Viewporter { #[derive(Debug, waynest_server::RequestDispatcher)] #[waynest(error = crate::wayland::WaylandError)] pub struct Viewport { - _id: ObjectId, + id: ObjectId, _surface_id: ObjectId, } impl Viewport { pub fn new(id: ObjectId, surface_id: ObjectId) -> Self { Self { - _id: id, + id, _surface_id: surface_id, } } @@ -49,7 +62,12 @@ impl Viewport { impl WpViewport for Viewport { type Connection = crate::wayland::Client; - async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy( + &self, + client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } diff --git a/src/wayland/xdg/popup.rs b/src/wayland/xdg/popup.rs index e2a3c02..9b5a3e8 100644 --- a/src/wayland/xdg/popup.rs +++ b/src/wayland/xdg/popup.rs @@ -16,9 +16,10 @@ pub struct Popup { version: u32, pub surface: Arc, positioner_data: Mutex, + id: ObjectId, } impl Popup { - pub fn new(version: u32, surface: Arc, positioner: &Positioner) -> Self { + pub fn new(version: u32, surface: Arc, positioner: &Positioner, id: ObjectId) -> Self { let _ = surface .wl_surface .surface_id @@ -29,6 +30,7 @@ impl Popup { version, surface, positioner_data: Mutex::new(positioner_data), + id, } } } @@ -82,7 +84,12 @@ impl XdgPopup for Popup { } /// https://wayland.app/protocols/xdg-shell#xdg_popup:request:destroy - async fn destroy(&self, _client: &mut Self::Connection, _sender_id: ObjectId) -> WaylandResult<()> { + async fn destroy( + &self, + client: &mut Self::Connection, + _sender_id: ObjectId, + ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } } diff --git a/src/wayland/xdg/positioner.rs b/src/wayland/xdg/positioner.rs index 09dff80..6cccd47 100644 --- a/src/wayland/xdg/positioner.rs +++ b/src/wayland/xdg/positioner.rs @@ -130,11 +130,13 @@ impl Default for PositionerData { #[waynest(error = crate::wayland::WaylandError)] pub struct Positioner { data: Mutex, + id: ObjectId, } -impl Default for Positioner { - fn default() -> Self { +impl Positioner { + pub fn new(id: ObjectId) -> Self { Self { data: Mutex::new(PositionerData::default()), + id, } } } @@ -253,9 +255,10 @@ impl XdgPositioner for Positioner { async fn destroy( &self, - _client: &mut Self::Connection, + client: &mut Self::Connection, _sender_id: ObjectId, ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } } diff --git a/src/wayland/xdg/surface.rs b/src/wayland/xdg/surface.rs index 94fc6ac..4fb5b39 100644 --- a/src/wayland/xdg/surface.rs +++ b/src/wayland/xdg/surface.rs @@ -44,9 +44,10 @@ impl XdgSurface for Surface { /// https://wayland.app/protocols/xdg-shell#xdg_surface:request:destroy async fn destroy( &self, - _client: &mut Self::Connection, + client: &mut Self::Connection, _sender_id: ObjectId, ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } @@ -135,7 +136,10 @@ impl XdgSurface for Surface { let surface = client.get::(self.id).unwrap(); - let popup = client.insert(popup_id, Popup::new(self.version, surface, &positioner)); + let popup = client.insert( + popup_id, + Popup::new(self.version, surface, &positioner, popup_id), + ); let positioner_geometry = positioner.data().infinite_geometry(); diff --git a/src/wayland/xdg/toplevel.rs b/src/wayland/xdg/toplevel.rs index 706a4bb..3d5a858 100644 --- a/src/wayland/xdg/toplevel.rs +++ b/src/wayland/xdg/toplevel.rs @@ -315,9 +315,10 @@ impl XdgToplevel for Toplevel { async fn destroy( &self, - _client: &mut Self::Connection, + client: &mut Self::Connection, _sender_id: ObjectId, ) -> WaylandResult<()> { + client.remove(self.id); self.mapped.lock().take(); Ok(()) } diff --git a/src/wayland/xdg/wm_base.rs b/src/wayland/xdg/wm_base.rs index be7d182..62178f7 100644 --- a/src/wayland/xdg/wm_base.rs +++ b/src/wayland/xdg/wm_base.rs @@ -4,19 +4,26 @@ use crate::wayland::{WaylandError, WaylandResult, util::ClientExt, xdg::surface: use waynest::ObjectId; pub use waynest_protocols::server::stable::xdg_shell::xdg_wm_base::*; -#[derive(Debug, waynest_server::RequestDispatcher, Default)] +#[derive(Debug, waynest_server::RequestDispatcher)] #[waynest(error = crate::wayland::WaylandError)] pub struct WmBase { - pub version: u32, + version: u32, + id: ObjectId, +} +impl WmBase { + pub fn new(id: ObjectId, version: u32) -> Self { + Self { version, id } + } } impl XdgWmBase for WmBase { type Connection = crate::wayland::Client; async fn destroy( &self, - _client: &mut Self::Connection, + client: &mut Self::Connection, _sender_id: ObjectId, ) -> WaylandResult<()> { + client.remove(self.id); Ok(()) } @@ -26,7 +33,7 @@ impl XdgWmBase for WmBase { _sender_id: ObjectId, id: ObjectId, ) -> WaylandResult<()> { - client.insert(id, Positioner::default()); + client.insert(id, Positioner::new(id)); Ok(()) }