Skip to content

Commit

Permalink
hyprland/workspaces: Add enable-bar-scroll option
Browse files Browse the repository at this point in the history
  • Loading branch information
VAWVAW committed Apr 18, 2024
1 parent 8ef4ddd commit 99ceaae
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/modules/hyprland/workspaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Workspaces : public AModule, public EventHandler {
auto showSpecial() const -> bool { return m_showSpecial; }
auto activeOnly() const -> bool { return m_activeOnly; }
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 @@ -181,6 +182,9 @@ class Workspaces : public AModule, public EventHandler {
void loadPersistentWorkspacesFromConfig(Json::Value const& clientsJson);
void loadPersistentWorkspacesFromWorkspaceRules(const Json::Value& clientsJson);

bool handleScroll(GdkEventScroll*) override;

Check warning on line 185 in include/modules/hyprland/workspaces.hpp

View workflow job for this annotation

GitHub Actions / build

include/modules/hyprland/workspaces.hpp:185:36 [readability-named-parameter]

all parameters should be named in a function

bool m_barScroll = false;

Check warning on line 187 in include/modules/hyprland/workspaces.hpp

View workflow job for this annotation

GitHub Actions / build

include/modules/hyprland/workspaces.hpp:187:8 [readability-identifier-naming]

invalid case style for private member 'm_barScroll'
bool m_allOutputs = false;

Check warning on line 188 in include/modules/hyprland/workspaces.hpp

View workflow job for this annotation

GitHub Actions / build

include/modules/hyprland/workspaces.hpp:188:8 [readability-identifier-naming]

invalid case style for private member 'm_allOutputs'
bool m_showSpecial = false;
bool m_activeOnly = false;
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 @@ -47,6 +47,11 @@ Addressed by *hyprland/workspaces*
default: false ++
If set to false workspaces group will be shown only in assigned output. Otherwise, all workspace groups are shown.

*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.

*active-only*: ++
typeof: bool ++
default: false ++
Expand Down
42 changes: 42 additions & 0 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void {
m_moveToMonitor = configMoveToMonitor.asBool();
}

auto configBarScroll = config_["enable-bar-scroll"];
if (configBarScroll.isBool()) {
m_barScroll = configBarScroll.asBool();
}

auto configSortBy = config_["sort-by"];
if (configSortBy.isString()) {
auto sortByStr = configSortBy.asString();
Expand Down Expand Up @@ -803,6 +808,12 @@ void Workspaces::initializeWorkspaces() {
auto const workspacesJson = gIPC->getSocket1JsonReply("workspaces");
auto const clientsJson = gIPC->getSocket1JsonReply("clients");

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));
}

for (Json::Value workspaceJson : workspacesJson) {
std::string workspaceName = workspaceJson["name"].asString();
if ((allOutputs() || m_bar.output->name == workspaceJson["monitor"].asString()) &&
Expand Down Expand Up @@ -1196,4 +1207,35 @@ void WindowCreationPayload::moveToWorksace(std::string &new_workspace_name) {
m_workspaceName = new_workspace_name;
}

bool Workspaces::handleScroll(GdkEventScroll *e) {
if (gdk_event_get_pointer_emulated((GdkEvent *)e)) {

Check warning on line 1211 in src/modules/hyprland/workspaces.cpp

View workflow job for this annotation

GitHub Actions / build

src/modules/hyprland/workspaces.cpp:1211:7 [readability-implicit-bool-conversion]

implicit conversion 'gboolean' (aka 'int') -> bool
/**
* Ignore emulated scroll events on window
*/
return false;
}
auto dir = AModule::getScrollDir(e);
if (dir == SCROLL_DIR::NONE) {
return true;
}

bool increase;

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

0 comments on commit 99ceaae

Please sign in to comment.