forge
Explore
Log in

Don't you dare go Hollow

layout: Change workspace by idx functions to accept 0-based usize

Browse files at this commit

34739650914fbfaa1a4144e929e64be4ca54bf5cIvan MolodetskikhParent: c9a7946
Makes more sense to do the converstion at the top of the call stack.
src/input.rsmodified+2 -0
@@ -240,6 +240,7 @@ impl State {
240240 self.niri.queue_redraw_all();
241241 }
242242 Action::MoveWindowToWorkspace(idx) => {
243+ let idx = idx.saturating_sub(1) as usize;
243244 self.niri.layout.move_to_workspace(idx);
244245 // FIXME: granular
245246 self.niri.queue_redraw_all();
@@ -255,6 +256,7 @@ impl State {
255256 self.niri.queue_redraw_all();
256257 }
257258 Action::FocusWorkspace(idx) => {
259+ let idx = idx.saturating_sub(1) as usize;
258260 self.niri.layout.switch_workspace(idx);
259261 // FIXME: granular
260262 self.niri.queue_redraw_all();
src/layout.rsmodified+8 -11
@@ -1007,7 +1007,7 @@ impl<W: LayoutElement> Layout<W> {
10071007 monitor.move_to_workspace_down();
10081008 }
10091009
1010- pub fn move_to_workspace(&mut self, idx: u8) {
1010+ pub fn move_to_workspace(&mut self, idx: usize) {
10111011 let Some(monitor) = self.active_monitor() else {
10121012 return;
10131013 };
@@ -1028,7 +1028,7 @@ impl<W: LayoutElement> Layout<W> {
10281028 monitor.switch_workspace_down();
10291029 }
10301030
1031- pub fn switch_workspace(&mut self, idx: u8) {
1031+ pub fn switch_workspace(&mut self, idx: usize) {
10321032 let Some(monitor) = self.active_monitor() else {
10331033 return;
10341034 };
@@ -1660,10 +1660,10 @@ impl<W: LayoutElement> Monitor<W> {
16601660 self.add_window(new_idx, window, true, width, is_full_width);
16611661 }
16621662
1663- pub fn move_to_workspace(&mut self, idx: u8) {
1663+ pub fn move_to_workspace(&mut self, idx: usize) {
16641664 let source_workspace_idx = self.active_workspace_idx;
16651665
1666- let new_idx = min(idx.saturating_sub(1) as usize, self.workspaces.len() - 1);
1666+ let new_idx = min(idx, self.workspaces.len() - 1);
16671667 if new_idx == source_workspace_idx {
16681668 return;
16691669 }
@@ -1698,11 +1698,8 @@ impl<W: LayoutElement> Monitor<W> {
16981698 ));
16991699 }
17001700
1701- pub fn switch_workspace(&mut self, idx: u8) {
1702- self.activate_workspace(min(
1703- idx.saturating_sub(1) as usize,
1704- self.workspaces.len() - 1,
1705- ));
1701+ pub fn switch_workspace(&mut self, idx: usize) {
1702+ self.activate_workspace(min(idx, self.workspaces.len() - 1));
17061703 // Don't animate this action.
17071704 self.workspace_switch = None;
17081705
@@ -3331,10 +3328,10 @@ mod tests {
33313328 CenterColumn,
33323329 FocusWorkspaceDown,
33333330 FocusWorkspaceUp,
3334- FocusWorkspace(#[proptest(strategy = "1..=5u8")] u8),
3331+ FocusWorkspace(#[proptest(strategy = "0..=4usize")] usize),
33353332 MoveWindowToWorkspaceDown,
33363333 MoveWindowToWorkspaceUp,
3337- MoveWindowToWorkspace(#[proptest(strategy = "1..=5u8")] u8),
3334+ MoveWindowToWorkspace(#[proptest(strategy = "0..=4usize")] usize),
33383335 MoveWorkspaceDown,
33393336 MoveWorkspaceUp,
33403337 MoveWindowToOutput(#[proptest(strategy = "1..=5u8")] u8),