From 336141e69d58b28bddbef944c445922b76eb9e2d Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Thu, 4 Jan 2024 11:24:00 -0500 Subject: [PATCH] fix: workspaces scrolling --- cosmic-applet-workspaces/src/wayland.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/cosmic-applet-workspaces/src/wayland.rs b/cosmic-applet-workspaces/src/wayland.rs index cf1b13da..f7c8b83b 100644 --- a/cosmic-applet-workspaces/src/wayland.rs +++ b/cosmic-applet-workspaces/src/wayland.rs @@ -79,6 +79,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender) -> SyncSender) -> SyncSender { + // reset scroll if we're scrolling in the opposite direction + if state.scroll * v < 0.0 { + state.scroll = 0.0; + } + state.scroll += v; + if state.scroll.abs() < 1.0 { + return; + } if let Some((w_g, w_i)) = state .workspace_state .workspace_groups() @@ -123,17 +132,18 @@ pub fn spawn_workspaces(tx: mpsc::Sender) -> SyncSender 0.0 { - if w_i == max_w { - 0 + let d_i = if state.scroll > 0.0 { + if w_i == 0 { + max_w } else { - w_i.wrapping_add(1) + w_i.wrapping_sub(1) } - } else if w_i == 0 { - max_w + } else if w_i == max_w { + 0 } else { - w_i.wrapping_sub(1) + w_i.wrapping_add(1) }; + state.scroll = 0.0; if let Some(w) = w_g.workspaces.get(d_i) { w.handle.activate(); state @@ -181,6 +191,7 @@ pub struct State { registry_state: RegistryState, workspace_state: WorkspaceState, have_workspaces: bool, + scroll: f64, } impl State {