compositor: give access to surface children and region metadata

This commit is contained in:
Victor Berger 2017-06-11 14:31:42 +02:00
parent a5ae27be84
commit deb072afbb
2 changed files with 31 additions and 0 deletions

View File

@ -220,6 +220,16 @@ impl<U: Send + 'static, H: Handler + Send + 'static> CompositorToken<U, H> {
unsafe { SurfaceData::<U>::get_parent(surface) } unsafe { SurfaceData::<U>::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<wl_surface::WlSurface> {
assert!(resource_is_registered::<_, CompositorHandler<U, H>>(surface, self.hid),
"Accessing the data of foreign surfaces is not supported.");
unsafe { SurfaceData::<U>::get_children(surface) }
}
/// Retrieve the role status this surface /// Retrieve the role status this surface
/// ///
/// If the surface is not managed by the CompositorGlobal that provided this token, this /// If the surface is not managed by the CompositorGlobal that provided this token, this
@ -258,6 +268,16 @@ impl<U: Send + 'static, H: Handler + Send + 'static> CompositorToken<U, H> {
"Accessing the data of foreign surfaces is not supported."); "Accessing the data of foreign surfaces is not supported.");
unsafe { SurfaceData::<U>::remove_role(surface) } unsafe { SurfaceData::<U>::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<U, H>>(region, self.hid),
"Accessing the data of foreign regions is not supported.");
unsafe { RegionData::get_attributes(region) }
}
} }
pub struct CompositorHandler<U, H> { pub struct CompositorHandler<U, H> {

View File

@ -196,6 +196,17 @@ impl<U> SurfaceData<U> {
child_guard.parent.as_ref().map(|p| p.clone_unchecked()) 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<wl_surface::WlSurface> {
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 /// Reorders a surface relative to one of its sibling
/// ///
/// Fails if `relative_to` is not a sibling or parent of `surface`. /// Fails if `relative_to` is not a sibling or parent of `surface`.