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

hyprland/workspaces: Add enable-bar-scroll option #3088

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Workspaces : public AModule, public EventHandler {
auto activeOnly() const -> bool { return m_activeOnly; }
auto specialVisibleOnly() const -> bool { return m_specialVisibleOnly; }
auto moveToMonitor() const -> bool { return m_moveToMonitor; }
auto barScroll() const -> bool { return m_barScroll; }

auto getBarOutput() const -> std::string { return m_bar.output->name; }

Expand Down Expand Up @@ -93,6 +94,9 @@ class Workspaces : public AModule, public EventHandler {

int windowRewritePriorityFunction(std::string const& window_rule);

// scroll events
bool handleScroll(GdkEventScroll* e) override;

// Update methods
void doUpdate();
void removeWorkspacesToRemove();
Expand All @@ -114,6 +118,7 @@ class Workspaces : public AModule, public EventHandler {
bool m_activeOnly = false;
bool m_specialVisibleOnly = false;
bool m_moveToMonitor = false;
bool m_barScroll = false;
Json::Value m_persistentWorkspaceConfig;

// Map for windows stored in workspaces not present in the current bar.
Expand Down
5 changes: 5 additions & 0 deletions man/waybar-hyprland-workspaces.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ Addressed by *hyprland/workspaces*
Otherwise, the workspace will open on the monitor where it was previously assigned.
Analog to using `focusworkspaceoncurrentmonitor` dispatcher instead of `workspace` in Hyprland.

*enable-bar-scroll*: ++
typeof: bool ++
default: false ++
If set to false, you can't scroll to cycle throughout workspaces from the entire bar. If set to true this behaviour is enabled.

*ignore-workspaces*: ++
typeof: array ++
default: [] ++
Expand Down
35 changes: 35 additions & 0 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ void Workspaces::init() {
m_activeWorkspaceName = (gIPC->getSocket1JsonReply("activeworkspace"))["name"].asString();

initializeWorkspaces();

if (barScroll()) {
auto &window = const_cast<Bar &>(m_bar).window;
window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
window.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll));
}

dp.emit();
}

Expand Down Expand Up @@ -575,6 +582,7 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void {
populateBoolConfig(config, "special-visible-only", m_specialVisibleOnly);
populateBoolConfig(config, "active-only", m_activeOnly);
populateBoolConfig(config, "move-to-monitor", m_moveToMonitor);
populateBoolConfig(config, "enable-bar-scroll", m_barScroll);

m_persistentWorkspaceConfig = config.get("persistent-workspaces", Json::Value());
populateSortByConfig(config);
Expand Down Expand Up @@ -905,4 +913,31 @@ int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) {
return 0;
}

bool Workspaces::handleScroll(GdkEventScroll *e) {
// Ignore emulated scroll events on window
if (gdk_event_get_pointer_emulated((GdkEvent *)e)) {
return false;
}
auto dir = AModule::getScrollDir(e);
if (dir == SCROLL_DIR::NONE) {
return true;
}

if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) {
if (allOutputs()) {
gIPC->getSocket1Reply("dispatch workspace e+1");
} else {
gIPC->getSocket1Reply("dispatch workspace m+1");
}
} else if (dir == SCROLL_DIR::UP || dir == SCROLL_DIR::LEFT) {
if (allOutputs()) {
gIPC->getSocket1Reply("dispatch workspace e-1");
} else {
gIPC->getSocket1Reply("dispatch workspace m-1");
}
}

return true;
}

} // namespace waybar::modules::hyprland
Loading