Skip to content
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
2 changes: 2 additions & 0 deletions include/modules/ext/workspace_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class WorkspaceManager final : public AModule {

// wl requests
void commit() const;
bool handleScroll(GdkEventScroll* e) override;

private:
void update() override;
Expand Down Expand Up @@ -100,6 +101,7 @@ class Workspace {
std::vector<u_int32_t>& coordinates() { return coordinates_; }
Gtk::Button& button() { return button_; }
void update();
bool is_active() const { return has_state(EXT_WORKSPACE_HANDLE_V1_STATE_ACTIVE); }

// wl events
void handle_id(const std::string& id);
Expand Down
10 changes: 10 additions & 0 deletions man/waybar-ext-workspaces.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ Addressed by *ext/workspaces*
default: false ++
If set to true only active or urgent workspaces will be shown.

*disable-scroll*: ++
typeof: bool ++
default: false ++
If set to true, scrolling is disabled for this module.

*enable-bar-scroll*: ++
typeof: bool ++
default: false ++
If set to true, scrolling anywhere on the bar switches to the previous or next workspace. By default, scrolling only works when the pointer is over the workspaces module

*ignore-hidden*: ++
typeof: bool ++
default: true ++
Expand Down
49 changes: 48 additions & 1 deletion src/modules/ext/workspace_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ std::map<std::string, std::string> Workspace::icon_map_;

WorkspaceManager::WorkspaceManager(const std::string& id, const waybar::Bar& bar,
const Json::Value& config)
: waybar::AModule(config, "workspaces", id, false, false), bar_(bar), box_(bar.orientation, 0) {
: waybar::AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()),
bar_(bar),
box_(bar.orientation, 0) {
add_registry_listener(this);

// parse configuration
Expand Down Expand Up @@ -61,6 +63,11 @@ WorkspaceManager::WorkspaceManager(const std::string& id, const waybar::Bar& bar
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);
if (!config_["disable-scroll"].asBool() && config_["enable-bar-scroll"].asBool()) {
auto& window = const_cast<Bar&>(bar_).window;
window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
window.signal_scroll_event().connect(sigc::mem_fun(*this, &WorkspaceManager::handleScroll));
}

spdlog::debug("[ext/workspaces]: Workspace manager created");
}
Expand Down Expand Up @@ -147,6 +154,46 @@ void WorkspaceManager::commit() const {
if (ext_manager_) ext_workspace_manager_v1_commit(ext_manager_);
}

bool WorkspaceManager::handleScroll(GdkEventScroll* e) {
if (gdk_event_get_pointer_emulated(reinterpret_cast<GdkEvent*>(e)) != 0) {
return false;
}

const auto dir = getScrollDir(e);
if (dir == SCROLL_DIR::NONE) {
return true;
}

auto active = std::find_if(workspaces_.begin(), workspaces_.end(), [](const auto& workspace) {
return workspace->is_active() && workspace->button().get_visible();
});
if (active == workspaces_.end()) {
return true;
}

auto target = active;
do {
if (dir == SCROLL_DIR::DOWN || dir == SCROLL_DIR::RIGHT) {
++target;
if (target == workspaces_.end()) {
target = workspaces_.begin();
}
} else {
if (target == workspaces_.begin()) {
target = workspaces_.end();
}
--target;
}
} while (target != active && !(*target)->button().get_visible());

if (target != active) {
ext_workspace_handle_v1_activate((*target)->handle());
commit();
}

return true;
}

void WorkspaceManager::update() {
spdlog::debug("[ext/workspaces]: Updating state");

Expand Down
Loading