anvil: split `bring_nth_window_to_top` to separate fn

This commit is contained in:
Poly 2021-07-31 22:36:55 +02:00
parent 3721b515f7
commit 524501b2e8
1 changed files with 21 additions and 28 deletions

View File

@ -300,17 +300,8 @@ impl WindowMap {
None None
} }
pub fn bring_surface_to_top(&mut self, surface: &WlSurface) { fn bring_nth_window_to_top(&mut self, id: usize) {
let found = self.windows.iter().enumerate().find(|(_, w)| { let winner = self.windows.remove(id);
if let Some(s) = w.toplevel.get_surface() {
s.as_ref().equals(surface.as_ref())
} else {
false
}
});
if let Some((i, _)) = found {
let winner = self.windows.remove(i);
// Take activation away from all the windows // Take activation away from all the windows
for window in self.windows.iter() { for window in self.windows.iter() {
@ -321,6 +312,18 @@ impl WindowMap {
winner.toplevel.set_activated(true); winner.toplevel.set_activated(true);
self.windows.insert(0, winner); self.windows.insert(0, winner);
} }
pub fn bring_surface_to_top(&mut self, surface: &WlSurface) {
let found = self.windows.iter().enumerate().find(|(_, w)| {
w.toplevel
.get_surface()
.map(|s| s.as_ref().equals(surface.as_ref()))
.unwrap_or(false)
});
if let Some((id, _)) = found {
self.bring_nth_window_to_top(id);
}
} }
pub fn get_surface_and_bring_to_top( pub fn get_surface_and_bring_to_top(
@ -334,18 +337,8 @@ impl WindowMap {
break; break;
} }
} }
if let Some((i, surface)) = found { if let Some((id, surface)) = found {
let winner = self.windows.remove(i); self.bring_nth_window_to_top(id);
// Take activation away from all the windows
for window in self.windows.iter() {
window.toplevel.set_activated(false);
}
// Give activation to our winner
winner.toplevel.set_activated(true);
self.windows.insert(0, winner);
Some(surface) Some(surface)
} else { } else {
None None