From 2937bd454b52886927a80c90ab83389ea04f85ea Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Sat, 4 Jun 2016 16:33:19 -0300 Subject: Fix unfocused window bug. --- src/desktop.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/desktop.rs b/src/desktop.rs index aac472f..454c05b 100644 --- a/src/desktop.rs +++ b/src/desktop.rs @@ -62,16 +62,23 @@ impl Desktop { self.window_list.push(w); // Last windows get focus. self.focus_current_window(); + } else { + println!("XWindow::new responded None"); } } - /// Remove a window. + /// Remove a window focusing the previous one on the list. pub fn remove_window(&mut self, w: xlib::Window) { + // Get the position of this window. let pos = self.window_list.iter().position(|xw| xw.inner == w); + // Only remove it if we found the position of the window. if let Some(idx) = pos { + // Get the index of the previous window. Keep it in 0 if it's the + // first window. + // NOTE: maybe we should do something if the window_list.len() is 1 let new_idx = if idx == 0 { - if self.window_list.len() == 1 { usize::max_value() } else { 0 } + 0 } else { idx - 1 }; -- cgit v1.2.3-70-g09d2