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 {
240 self.niri.queue_redraw_all();240 self.niri.queue_redraw_all();
241 }241 }
242 Action::MoveWindowToWorkspace(idx) => {242 Action::MoveWindowToWorkspace(idx) => {
243+ let idx = idx.saturating_sub(1) as usize;
243 self.niri.layout.move_to_workspace(idx);244 self.niri.layout.move_to_workspace(idx);
244 // FIXME: granular245 // FIXME: granular
245 self.niri.queue_redraw_all();246 self.niri.queue_redraw_all();
@@ -255,6 +256,7 @@ impl State {
255 self.niri.queue_redraw_all();256 self.niri.queue_redraw_all();
256 }257 }
257 Action::FocusWorkspace(idx) => {258 Action::FocusWorkspace(idx) => {
259+ let idx = idx.saturating_sub(1) as usize;
258 self.niri.layout.switch_workspace(idx);260 self.niri.layout.switch_workspace(idx);
259 // FIXME: granular261 // FIXME: granular
260 self.niri.queue_redraw_all();262 self.niri.queue_redraw_all();
src/layout.rsmodified+8 -11
@@ -1007,7 +1007,7 @@ impl<W: LayoutElement> Layout<W> {
1007 monitor.move_to_workspace_down();1007 monitor.move_to_workspace_down();
1008 }1008 }
1009 1009
1010- pub fn move_to_workspace(&mut self, idx: u8) {1010+ pub fn move_to_workspace(&mut self, idx: usize) {
1011 let Some(monitor) = self.active_monitor() else {1011 let Some(monitor) = self.active_monitor() else {
1012 return;1012 return;
1013 };1013 };
@@ -1028,7 +1028,7 @@ impl<W: LayoutElement> Layout<W> {
1028 monitor.switch_workspace_down();1028 monitor.switch_workspace_down();
1029 }1029 }
1030 1030
1031- pub fn switch_workspace(&mut self, idx: u8) {1031+ pub fn switch_workspace(&mut self, idx: usize) {
1032 let Some(monitor) = self.active_monitor() else {1032 let Some(monitor) = self.active_monitor() else {
1033 return;1033 return;
1034 };1034 };
@@ -1660,10 +1660,10 @@ impl<W: LayoutElement> Monitor<W> {
1660 self.add_window(new_idx, window, true, width, is_full_width);1660 self.add_window(new_idx, window, true, width, is_full_width);
1661 }1661 }
1662 1662
1663- pub fn move_to_workspace(&mut self, idx: u8) {1663+ pub fn move_to_workspace(&mut self, idx: usize) {
1664 let source_workspace_idx = self.active_workspace_idx;1664 let source_workspace_idx = self.active_workspace_idx;
1665 1665
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);
1667 if new_idx == source_workspace_idx {1667 if new_idx == source_workspace_idx {
1668 return;1668 return;
1669 }1669 }
@@ -1698,11 +1698,8 @@ impl<W: LayoutElement> Monitor<W> {
1698 ));1698 ));
1699 }1699 }
1700 1700
1701- pub fn switch_workspace(&mut self, idx: u8) {1701+ pub fn switch_workspace(&mut self, idx: usize) {
1702- self.activate_workspace(min(1702+ self.activate_workspace(min(idx, self.workspaces.len() - 1));
1703- idx.saturating_sub(1) as usize,
1704- self.workspaces.len() - 1,
1705- ));
1706 // Don't animate this action.1703 // Don't animate this action.
1707 self.workspace_switch = None;1704 self.workspace_switch = None;
1708 1705
@@ -3331,10 +3328,10 @@ mod tests {
3331 CenterColumn,3328 CenterColumn,
3332 FocusWorkspaceDown,3329 FocusWorkspaceDown,
3333 FocusWorkspaceUp,3330 FocusWorkspaceUp,
3334- FocusWorkspace(#[proptest(strategy = "1..=5u8")] u8),3331+ FocusWorkspace(#[proptest(strategy = "0..=4usize")] usize),
3335 MoveWindowToWorkspaceDown,3332 MoveWindowToWorkspaceDown,
3336 MoveWindowToWorkspaceUp,3333 MoveWindowToWorkspaceUp,
3337- MoveWindowToWorkspace(#[proptest(strategy = "1..=5u8")] u8),3334+ MoveWindowToWorkspace(#[proptest(strategy = "0..=4usize")] usize),
3338 MoveWorkspaceDown,3335 MoveWorkspaceDown,
3339 MoveWorkspaceUp,3336 MoveWorkspaceUp,
3340 MoveWindowToOutput(#[proptest(strategy = "1..=5u8")] u8),3337 MoveWindowToOutput(#[proptest(strategy = "1..=5u8")] u8),