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