Skip to content

Commit bab36d3

Browse files
committed
Wrap workspace scrolling at start and end
Matches the behavior of scrolling over the applet. Seems reasonable.
1 parent e88068a commit bab36d3

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

src/main.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -667,17 +667,22 @@ impl Application for App {
667667
// TODO assumes only one active workspace per output
668668
let workspaces = self.workspaces.for_output(&output).collect::<Vec<_>>();
669669
if let Some(workspace_idx) = workspaces.iter().position(|i| i.is_active()) {
670-
let workspace = match direction {
671-
// Next workspace on output
672-
ScrollDirection::Next => workspaces[workspace_idx + 1..].iter().next(),
673-
// Previous workspace on output
674-
ScrollDirection::Prev => workspaces[..workspace_idx].iter().last(),
670+
let new_workspace_idx = match direction {
671+
// Next workspace on output, wrapping to start
672+
ScrollDirection::Next => (workspace_idx + 1) % workspaces.len(),
673+
// Previous workspace on output, wrapping to end
674+
ScrollDirection::Prev => {
675+
if workspace_idx == 0 {
676+
workspaces.len() - 1
677+
} else {
678+
workspace_idx - 1
679+
}
680+
}
675681
};
676-
if let Some(workspace) = workspace {
677-
self.send_wayland_cmd(backend::Cmd::ActivateWorkspace(
678-
workspace.handle().clone(),
679-
));
680-
}
682+
let workspace = workspaces[new_workspace_idx];
683+
self.send_wayland_cmd(backend::Cmd::ActivateWorkspace(
684+
workspace.handle().clone(),
685+
));
681686
}
682687
}
683688
Msg::DndWorkspaceDrag => {}

0 commit comments

Comments
 (0)