Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ sctk = { package = "smithay-client-toolkit", version = "0.20.0" }
[patch."https://github.com/pop-os/cosmic-protocols"]
cosmic-protocols = { git = "https://github.com/pop-os/cosmic-protocols//", branch = "main" }
cosmic-client-toolkit = { git = "https://github.com/pop-os/cosmic-protocols//", branch = "main" }

[patch."https://github.com/pop-os/libcosmic"]
libcosmic = { git = "https://github.com/pop-os/libcosmic//", branch = "discrete-scroll" }
cosmic-config = { git = "https://github.com/pop-os/libcosmic//", branch = "discrete-scroll" }
iced_futures = { git = "https://github.com/pop-os/libcosmic//", branch = "discrete-scroll" }
73 changes: 17 additions & 56 deletions cosmic-applet-workspaces/src/components/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use cosmic::{
widget::{button, column, row},
},
iced_core::{Background, Border},
scroll::DiscreteScrollState,
surface,
widget::{Id, autosize, container, horizontal_space, vertical_space},
};
Expand All @@ -31,11 +32,7 @@ use crate::{
wayland_subscription::{WorkspacesUpdate, workspaces},
};

use std::{
process::Command as ShellCommand,
sync::LazyLock,
time::{Duration, Instant},
};
use std::{process::Command as ShellCommand, sync::LazyLock};

static AUTOSIZE_MAIN_ID: LazyLock<Id> = LazyLock::new(|| Id::new("autosize-main"));

Expand All @@ -54,9 +51,7 @@ struct IcedWorkspacesApplet {
workspaces: Vec<Workspace>,
workspace_tx: Option<SyncSender<WorkspaceEvent>>,
layout: Layout,
scroll: f64,
next_scroll: Option<Instant>,
last_scroll: Instant,
scroll: DiscreteScrollState,
}

impl IcedWorkspacesApplet {
Expand Down Expand Up @@ -111,9 +106,7 @@ impl cosmic::Application for IcedWorkspacesApplet {
core,
workspaces: Vec::new(),
workspace_tx: Option::default(),
scroll: 0.0,
next_scroll: None,
last_scroll: Instant::now(),
scroll: DiscreteScrollState::default(),
},
Task::none(),
)
Expand Down Expand Up @@ -148,53 +141,21 @@ impl cosmic::Application for IcedWorkspacesApplet {
}
}
Message::WheelScrolled(delta) => {
let (delta, debounce) = match delta {
ScrollDelta::Lines { x, y } => ((x + y) as f64, false),
ScrollDelta::Pixels { x, y } => ((x + y) as f64, true),
};
let discrete_delta = self.scroll.update(delta);
if discrete_delta.y != 0 {
if let Some(w_i) = self
.workspaces
.iter()
.position(|w| w.state.contains(ext_workspace_handle_v1::State::Active))
{
let d_i = (w_i as isize - discrete_delta.y)
.rem_euclid(self.workspaces.len() as isize)
as usize;

let dur = if debounce {
Duration::from_millis(350)
} else {
Duration::from_millis(200)
};
if self.last_scroll.elapsed() > Duration::from_millis(100)
|| self.scroll * delta < 0.0
{
self.next_scroll = None;
self.scroll = 0.0;
}
self.last_scroll = Instant::now();

self.scroll += delta;
if let Some(next) = self.next_scroll {
if next > Instant::now() {
return cosmic::iced::Task::none();
}
self.next_scroll = None;
}

if self.scroll.abs() < 1.0 {
return cosmic::iced::Task::none();
}
self.next_scroll = Some(Instant::now() + dur);
if let Some(w_i) = self
.workspaces
.iter()
.position(|w| w.state.contains(ext_workspace_handle_v1::State::Active))
{
let max_w = self.workspaces.len().wrapping_sub(1);
let d_i = if self.scroll > 0.0 {
if w_i == 0 { max_w } else { w_i.wrapping_sub(1) }
} else if w_i == max_w {
0
} else {
w_i.wrapping_add(1)
};
self.scroll = 0.0;
if let Some(w) = self.workspaces.get(d_i) {
if let Some(tx) = self.workspace_tx.as_mut() {
let _ = tx.try_send(WorkspaceEvent::Activate(w.handle.clone()));
let _ = tx.try_send(WorkspaceEvent::Activate(
self.workspaces[d_i].handle.clone(),
));
}
}
}
Expand Down
Loading