From bd9e031912b6d3e0806aca858fa41db477ea856f Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Thu, 9 Oct 2025 19:41:32 -0700 Subject: [PATCH] Wrap workspace scrolling at start and end Matches the behavior of scrolling over the applet. Seems reasonable. --- src/main.rs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index bbdd06b..ce6cc6c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -719,17 +719,22 @@ impl Application for App { // TODO assumes only one active workspace per output let workspaces = self.workspaces.for_output(&output).collect::>(); if let Some(workspace_idx) = workspaces.iter().position(|i| i.is_active()) { - let workspace = match direction { - // Next workspace on output - ScrollDirection::Next => workspaces[workspace_idx + 1..].iter().next(), - // Previous workspace on output - ScrollDirection::Prev => workspaces[..workspace_idx].iter().last(), + let new_workspace_idx = match direction { + // Next workspace on output, wrapping to start + ScrollDirection::Next => (workspace_idx + 1) % workspaces.len(), + // Previous workspace on output, wrapping to end + ScrollDirection::Prev => { + if workspace_idx == 0 { + workspaces.len() - 1 + } else { + workspace_idx - 1 + } + } }; - if let Some(workspace) = workspace { - self.send_wayland_cmd(backend::Cmd::ActivateWorkspace( - workspace.handle().clone(), - )); - } + let workspace = workspaces[new_workspace_idx]; + self.send_wayland_cmd(backend::Cmd::ActivateWorkspace( + workspace.handle().clone(), + )); } } Msg::DndWorkspaceDrag => {}