summaryrefslogtreecommitdiff
path: root/src/desktop.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-12-27 23:28:43 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-12-27 23:28:43 -0300
commitf7a827971f436d9d493cff9ecb7fe91958f71be1 (patch)
treeab8c897439934b81e038846314c65ad626928911 /src/desktop.rs
parent312a8f2e5832c06fcd228acee4945b3236841ee1 (diff)
downloaddotwm-f7a827971f436d9d493cff9ecb7fe91958f71be1.tar.gz
Fix some problems @ removing a window.
When we wanted to remove the window idx 0 within the list. the current index went to usize::max_value always. This add a check for the case when we have more than one window and removes the window 0.
Diffstat (limited to 'src/desktop.rs')
-rw-r--r--src/desktop.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/desktop.rs b/src/desktop.rs
index 520c196..8bd4a4c 100644
--- a/src/desktop.rs
+++ b/src/desktop.rs
@@ -27,6 +27,14 @@ impl Desktop {
}
}
+ /// Tells if the current index is valid for indexing the window list.
+ ///
+ /// This is a precondition that must be valid wherever one index that
+ /// list.
+ fn valid_idx(&self) -> bool {
+ self.cw_idx != usize::max_value()
+ }
+
pub fn current_window(&self) -> Option<&XWindow> {
if self.cw_idx < self.window_list.len() {
self.window_list.get(self.cw_idx)
@@ -63,7 +71,11 @@ impl Desktop {
match pos {
Some(idx) => {
- let new_idx = if idx == 0 { usize::max_value() } else { idx - 1 };
+ let new_idx = if idx == 0 {
+ if self.window_list.len() == 1 { usize::max_value() } else { 0 }
+ } else {
+ idx - 1
+ };
self.window_list.remove(idx);
self.cw_idx = new_idx;
self.focus_current_window();
@@ -93,7 +105,7 @@ impl Desktop {
/// There're 3 posibilities. There's no window, there's one window or there
/// are more windows.
pub fn focus_next(&mut self) {
- if self.window_list.len() > 0 {
+ if self.valid_idx() {
// Unfocus the current window.
let prev_win = &self.window_list[self.cw_idx];
prev_win.unfocus();