Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change workspace based on scroll events #123

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use cosmic::{
self,
event::wayland::{Event as WaylandEvent, LayerEvent, OutputEvent},
keyboard::key::{Key, Named},
mouse::ScrollDelta,
Size, Subscription, Task,
},
iced_core::window::Id as SurfaceId,
Expand Down Expand Up @@ -98,6 +99,7 @@ enum Msg {
Config(CosmicWorkspacesConfig),
BgConfig(cosmic_bg_config::state::State),
UpdateToplevelIcon(String, Option<PathBuf>),
OnScroll(wl_output::WlOutput, ScrollDelta),
Ignore,
}

Expand Down Expand Up @@ -536,6 +538,29 @@ impl Application for App {
}
}
}
Msg::OnScroll(output, delta) => {
// TODO assumes only one active workspace per output
let mut workspaces = self.workspaces_for_output(&output).collect::<Vec<_>>();
if let Some(workspace_idx) = workspaces.iter().position(|i| i.is_active) {
if let ScrollDelta::Pixels { x: _, y } = delta {
// XXX accumulate delta, with timer?
let workspace = if y <= -4. {
// Next workspace on output
workspaces[workspace_idx + 1..].iter().next()
} else if y >= 4. {
// Previous workspace on output
workspaces[..workspace_idx].iter().last()
} else {
None
};
if let Some(workspace) = workspace {
self.send_wayland_cmd(backend::Cmd::ActivateWorkspace(
dbg!(workspace).handle.clone(),
));
}
}
}
}
Msg::Ignore => {}
}

Expand Down
5 changes: 4 additions & 1 deletion src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ pub(crate) fn layer_surface<'a>(
.width(iced::Length::Fill),
),
};
container.into()
let output = surface.output.clone();
widget::mouse_area(container)
.on_scroll(move |delta| Msg::OnScroll(output.clone(), delta))
.into()
}

fn close_button(on_press: Msg) -> cosmic::Element<'static, Msg> {
Expand Down