Skip to content

Commit

Permalink
fix: workspaces scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Jan 4, 2024
1 parent c112048 commit 336141e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions cosmic-applet-workspaces/src/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
tx,
running: true,
have_workspaces: false,
scroll: 0.0,
};
let loop_handle = event_loop.handle();
loop_handle
Expand All @@ -100,6 +101,14 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
}
}
Event::Msg(WorkspaceEvent::Scroll(v)) => {
// 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()
Expand All @@ -123,17 +132,18 @@ pub fn spawn_workspaces(tx: mpsc::Sender<WorkspaceList>) -> SyncSender<Workspace
})
{
let max_w = w_g.workspaces.len().wrapping_sub(1);
let d_i = if v > 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
Expand Down Expand Up @@ -181,6 +191,7 @@ pub struct State {
registry_state: RegistryState,
workspace_state: WorkspaceState,
have_workspaces: bool,
scroll: f64,
}

impl State {
Expand Down

0 comments on commit 336141e

Please sign in to comment.