anvil.window_map: add WindowMap::find

This commit is contained in:
Ivan Molodetskikh 2020-02-08 08:39:27 +03:00
parent 6d36375f27
commit 223b523f80
No known key found for this signature in database
GPG Key ID: 02CE38DA47E9D691
1 changed files with 15 additions and 0 deletions

View File

@ -241,6 +241,21 @@ where
self.windows.clear(); self.windows.clear();
} }
/// Finds the toplevel corresponding to the given `WlSurface`.
pub fn find(&self, surface: &wl_surface::WlSurface) -> Option<Kind<R>> {
self.windows.iter().find_map(|w| {
if w.toplevel
.get_surface()
.map(|s| s.as_ref().equals(surface.as_ref()))
.unwrap_or(false)
{
Some(w.toplevel.clone())
} else {
None
}
})
}
/// Returns the location of the toplevel, if it exists. /// Returns the location of the toplevel, if it exists.
pub fn location(&self, toplevel: &Kind<R>) -> Option<(i32, i32)> { pub fn location(&self, toplevel: &Kind<R>) -> Option<(i32, i32)> {
self.windows self.windows