From b45dcdf74e8773f1fb695d11e7efaf437c2aef9b Mon Sep 17 00:00:00 2001 From: RX14 Date: Thu, 16 May 2019 22:18:43 +0100 Subject: [PATCH 1/2] Allow scrolling on the entire bar surface --- include/bar.hpp | 1 + include/modules/sway/workspaces.hpp | 3 ++- src/bar.cpp | 31 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/include/bar.hpp b/include/bar.hpp index c4cd8148..45bdf016 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -55,6 +55,7 @@ class Bar { void setMarginsAndZone(uint32_t height, uint32_t width); auto setupWidgets() -> void; void getModules(const Factory &, const std::string &); + bool handleScroll(GdkEventScroll*); void setupAltFormatKeyForModule(const std::string &module_name); void setupAltFormatKeyForModuleList(const char *module_list_name); diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index 84c2eb0e..97b82e74 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -19,6 +19,8 @@ class Workspaces : public IModule, public sigc::trackable { auto update() -> void; operator Gtk::Widget&(); + bool handleScroll(GdkEventScroll*); + private: void onCmd(const struct Ipc::ipc_response&); void onEvent(const struct Ipc::ipc_response&); @@ -27,7 +29,6 @@ class Workspaces : public IModule, public sigc::trackable { Gtk::Button& addButton(const Json::Value&); void onButtonReady(const Json::Value&, Gtk::Button&); std::string getIcon(const std::string&, const Json::Value&); - bool handleScroll(GdkEventScroll*); const std::string getCycleWorkspace(std::vector::iterator, bool prev) const; uint16_t getWorkspaceIndex(const std::string& name) const; std::string trimWorkspaceName(std::string); diff --git a/src/bar.cpp b/src/bar.cpp index 6c6de20c..cb0d01c6 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -72,6 +72,12 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) wl_surface_commit(surface); wl_display_roundtrip(client->wl_display); + + if (!config["disable-workspace-scroll"].asBool()) { + window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); + window.signal_scroll_event().connect(sigc::mem_fun(*this, &Bar::handleScroll)); + } + setupWidgets(); } @@ -217,6 +223,31 @@ void waybar::Bar::handleSignal(int signal) { } } +bool waybar::Bar::handleScroll(GdkEventScroll *e) { + std::cerr << "handleScroll" << std::endl; + + for (auto& module : modules_left_) { + if (auto workspaces = dynamic_cast(module.get())) { + workspaces->handleScroll(e); + return true; + } + } + for (auto& module : modules_center_) { + if (auto workspaces = dynamic_cast(module.get())) { + workspaces->handleScroll(e); + return true; + } + } + for (auto& module : modules_right_) { + if (auto workspaces = dynamic_cast(module.get())) { + workspaces->handleScroll(e); + return true; + } + } + + return false; +} + void waybar::Bar::layerSurfaceHandleConfigure(void* data, struct zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t width, uint32_t height) { auto o = static_cast(data); From 4d4cadb5aeb810cfa9d7c658294dd9e7d0ac1c64 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 17 May 2019 09:59:37 +0200 Subject: [PATCH 2/2] refactor: simpler code --- include/bar.hpp | 1 - include/modules/sway/workspaces.hpp | 5 ++--- src/bar.cpp | 31 ----------------------------- src/modules/sway/workspaces.cpp | 5 +++++ 4 files changed, 7 insertions(+), 35 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index 45bdf016..c4cd8148 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -55,7 +55,6 @@ class Bar { void setMarginsAndZone(uint32_t height, uint32_t width); auto setupWidgets() -> void; void getModules(const Factory &, const std::string &); - bool handleScroll(GdkEventScroll*); void setupAltFormatKeyForModule(const std::string &module_name); void setupAltFormatKeyForModuleList(const char *module_list_name); diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index 97b82e74..8c7875cc 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -7,8 +7,8 @@ #include "bar.hpp" #include "client.hpp" #include "modules/sway/ipc/client.hpp" -#include "util/sleeper_thread.hpp" #include "util/json.hpp" +#include "util/sleeper_thread.hpp" namespace waybar::modules::sway { @@ -19,8 +19,6 @@ class Workspaces : public IModule, public sigc::trackable { auto update() -> void; operator Gtk::Widget&(); - bool handleScroll(GdkEventScroll*); - private: void onCmd(const struct Ipc::ipc_response&); void onEvent(const struct Ipc::ipc_response&); @@ -32,6 +30,7 @@ class Workspaces : public IModule, public sigc::trackable { const std::string getCycleWorkspace(std::vector::iterator, bool prev) const; uint16_t getWorkspaceIndex(const std::string& name) const; std::string trimWorkspaceName(std::string); + bool handleScroll(GdkEventScroll*); const Bar& bar_; const Json::Value& config_; diff --git a/src/bar.cpp b/src/bar.cpp index cb0d01c6..6c6de20c 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -72,12 +72,6 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config) wl_surface_commit(surface); wl_display_roundtrip(client->wl_display); - - if (!config["disable-workspace-scroll"].asBool()) { - window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); - window.signal_scroll_event().connect(sigc::mem_fun(*this, &Bar::handleScroll)); - } - setupWidgets(); } @@ -223,31 +217,6 @@ void waybar::Bar::handleSignal(int signal) { } } -bool waybar::Bar::handleScroll(GdkEventScroll *e) { - std::cerr << "handleScroll" << std::endl; - - for (auto& module : modules_left_) { - if (auto workspaces = dynamic_cast(module.get())) { - workspaces->handleScroll(e); - return true; - } - } - for (auto& module : modules_center_) { - if (auto workspaces = dynamic_cast(module.get())) { - workspaces->handleScroll(e); - return true; - } - } - for (auto& module : modules_right_) { - if (auto workspaces = dynamic_cast(module.get())) { - workspaces->handleScroll(e); - return true; - } - } - - return false; -} - void waybar::Bar::layerSurfaceHandleConfigure(void* data, struct zwlr_layer_surface_v1* surface, uint32_t serial, uint32_t width, uint32_t height) { auto o = static_cast(data); diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index f379c9aa..133c81ad 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -15,6 +15,11 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent)); ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd)); ipc_.sendCmd(IPC_GET_WORKSPACES); + if (!config["disable-workspace-scroll"].asBool()) { + auto &window = const_cast(bar_).window; + window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); + window.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll)); + } // Launch worker worker(); }