diff --git a/src/compositor/mod.rs b/src/compositor/mod.rs index a1529bb..f9fdb0c 100644 --- a/src/compositor/mod.rs +++ b/src/compositor/mod.rs @@ -434,6 +434,23 @@ impl + Send + unsafe { SurfaceData::::give_role_with::(surface, data) } } + /// Access the role data of a surface + /// + /// Fails and don't call the closure if the surface doesn't have this role + /// + /// If the surface is not managed by the CompositorGlobal that provided this token, this + /// will panic (having more than one compositor is not supported). + pub fn with_role_data(&self, surface: &wl_surface::WlSurface, f: F) -> Result + where + R: Role, + F: FnOnce(&mut RoleData) -> T + { + assert!( + resource_is_registered::<_, CompositorHandler>(surface, self.hid), + "Accessing the data of foreign surfaces is not supported." + ); + unsafe { SurfaceData::::with_role_data::(surface, f) } + } /// Register that this surface does not have a role any longer and retrieve the data ///