From 223b523f809a9c0a1ad97dc5fd95c8f843a6ac1c Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 8 Feb 2020 08:39:27 +0300 Subject: [PATCH] anvil.window_map: add WindowMap::find --- anvil/src/window_map.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/anvil/src/window_map.rs b/anvil/src/window_map.rs index f98672b..9a8fd9f 100644 --- a/anvil/src/window_map.rs +++ b/anvil/src/window_map.rs @@ -241,6 +241,21 @@ where self.windows.clear(); } + /// Finds the toplevel corresponding to the given `WlSurface`. + pub fn find(&self, surface: &wl_surface::WlSurface) -> Option> { + 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. pub fn location(&self, toplevel: &Kind) -> Option<(i32, i32)> { self.windows