diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2023-11-24 09:48:37 +0400 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2023-11-24 09:48:37 +0400 |
| commit | 34739650914fbfaa1a4144e929e64be4ca54bf5c (patch) | |
| tree | 1b3c74bd0988ee694747732bf162d4ecefc1ae40 | |
| parent | c9a79464da3245af944e692bb65db5b1f71d9ef7 (diff) | |
| download | niri-34739650914fbfaa1a4144e929e64be4ca54bf5c.tar.gz niri-34739650914fbfaa1a4144e929e64be4ca54bf5c.tar.bz2 niri-34739650914fbfaa1a4144e929e64be4ca54bf5c.zip | |
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.
| -rw-r--r-- | src/input.rs | 2 | ||||
| -rw-r--r-- | 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<W: LayoutElement> Layout<W> { 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<W: LayoutElement> Layout<W> { 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<W: LayoutElement> Monitor<W> { 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<W: LayoutElement> Monitor<W> { )); } - 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), |
