From 34739650914fbfaa1a4144e929e64be4ca54bf5c Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Fri, 24 Nov 2023 09:48:37 +0400 Subject: layout: Change workspace by idx functions to accept 0-based usize Makes more sense to do the converstion at the top of the call stack. --- src/input.rs | 2 ++ src/layout.rs | 19 ++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/input.rs b/src/input.rs index 347ef6c5..b7ceffd1 100644 --- a/src/input.rs +++ b/src/input.rs @@ -240,6 +240,7 @@ impl State { self.niri.queue_redraw_all(); } Action::MoveWindowToWorkspace(idx) => { + let idx = idx.saturating_sub(1) as usize; self.niri.layout.move_to_workspace(idx); // FIXME: granular self.niri.queue_redraw_all(); @@ -255,6 +256,7 @@ impl State { self.niri.queue_redraw_all(); } Action::FocusWorkspace(idx) => { + let idx = idx.saturating_sub(1) as usize; self.niri.layout.switch_workspace(idx); // FIXME: granular self.niri.queue_redraw_all(); diff --git a/src/layout.rs b/src/layout.rs index fd7bf1cf..af46a6a3 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -1007,7 +1007,7 @@ impl Layout { monitor.move_to_workspace_down(); } - pub fn move_to_workspace(&mut self, idx: u8) { + pub fn move_to_workspace(&mut self, idx: usize) { let Some(monitor) = self.active_monitor() else { return; }; @@ -1028,7 +1028,7 @@ impl Layout { monitor.switch_workspace_down(); } - pub fn switch_workspace(&mut self, idx: u8) { + pub fn switch_workspace(&mut self, idx: usize) { let Some(monitor) = self.active_monitor() else { return; }; @@ -1660,10 +1660,10 @@ impl Monitor { self.add_window(new_idx, window, true, width, is_full_width); } - pub fn move_to_workspace(&mut self, idx: u8) { + pub fn move_to_workspace(&mut self, idx: usize) { let source_workspace_idx = self.active_workspace_idx; - let new_idx = min(idx.saturating_sub(1) as usize, self.workspaces.len() - 1); + let new_idx = min(idx, self.workspaces.len() - 1); if new_idx == source_workspace_idx { return; } @@ -1698,11 +1698,8 @@ impl Monitor { )); } - pub fn switch_workspace(&mut self, idx: u8) { - self.activate_workspace(min( - idx.saturating_sub(1) as usize, - self.workspaces.len() - 1, - )); + pub fn switch_workspace(&mut self, idx: usize) { + self.activate_workspace(min(idx, self.workspaces.len() - 1)); // Don't animate this action. self.workspace_switch = None; @@ -3331,10 +3328,10 @@ mod tests { CenterColumn, FocusWorkspaceDown, FocusWorkspaceUp, - FocusWorkspace(#[proptest(strategy = "1..=5u8")] u8), + FocusWorkspace(#[proptest(strategy = "0..=4usize")] usize), MoveWindowToWorkspaceDown, MoveWindowToWorkspaceUp, - MoveWindowToWorkspace(#[proptest(strategy = "1..=5u8")] u8), + MoveWindowToWorkspace(#[proptest(strategy = "0..=4usize")] usize), MoveWorkspaceDown, MoveWorkspaceUp, MoveWindowToOutput(#[proptest(strategy = "1..=5u8")] u8), -- cgit