Allow scrolling on the entire bar surface

This commit is contained in:
RX14 2019-05-16 22:18:43 +01:00
parent a1ffa7fa9f
commit b45dcdf74e
No known key found for this signature in database
GPG Key ID: CEF2BBFE18BD0E67
3 changed files with 34 additions and 1 deletions

View File

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

View File

@ -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<Json::Value>::iterator, bool prev) const;
uint16_t getWorkspaceIndex(const std::string& name) const;
std::string trimWorkspaceName(std::string);

View File

@ -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<waybar::modules::sway::Workspaces*>(module.get())) {
workspaces->handleScroll(e);
return true;
}
}
for (auto& module : modules_center_) {
if (auto workspaces = dynamic_cast<waybar::modules::sway::Workspaces*>(module.get())) {
workspaces->handleScroll(e);
return true;
}
}
for (auto& module : modules_right_) {
if (auto workspaces = dynamic_cast<waybar::modules::sway::Workspaces*>(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<waybar::Bar*>(data);