diff --git a/src/compositor/mod.rs b/src/compositor/mod.rs index 084330c..7757352 100644 --- a/src/compositor/mod.rs +++ b/src/compositor/mod.rs @@ -220,6 +220,16 @@ impl CompositorToken { unsafe { SurfaceData::::get_parent(surface) } } + /// Retrieve the children of this surface + /// + /// 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 get_children(&self, surface: &wl_surface::WlSurface) -> Vec { + assert!(resource_is_registered::<_, CompositorHandler>(surface, self.hid), + "Accessing the data of foreign surfaces is not supported."); + unsafe { SurfaceData::::get_children(surface) } + } + /// Retrieve the role status this surface /// /// If the surface is not managed by the CompositorGlobal that provided this token, this @@ -258,6 +268,16 @@ impl CompositorToken { "Accessing the data of foreign surfaces is not supported."); unsafe { SurfaceData::::remove_role(surface) } } + + /// Retrieve the metadata associated with a wl_region + /// + /// If the region is not managed by the CompositorGlobal that provided this token, this + /// will panic (having more than one compositor is not supported). + pub fn get_region_attributes(&self, region: &wl_region::WlRegion) -> RegionAttributes { + assert!(resource_is_registered::<_, CompositorHandler>(region, self.hid), + "Accessing the data of foreign regions is not supported."); + unsafe { RegionData::get_attributes(region) } + } } pub struct CompositorHandler { diff --git a/src/compositor/tree.rs b/src/compositor/tree.rs index 2bca930..a78558f 100644 --- a/src/compositor/tree.rs +++ b/src/compositor/tree.rs @@ -196,6 +196,17 @@ impl SurfaceData { child_guard.parent.as_ref().map(|p| p.clone_unchecked()) } + /// Retrieve the parent surface (if any) of this surface + pub unsafe fn get_children(child: &wl_surface::WlSurface) -> Vec { + let child_mutex = Self::get_data(child); + let child_guard = child_mutex.lock().unwrap(); + child_guard + .children + .iter() + .map(|p| p.clone_unchecked()) + .collect() + } + /// Reorders a surface relative to one of its sibling /// /// Fails if `relative_to` is not a sibling or parent of `surface`.