aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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();