diff --git a/include/ALabel.hpp b/include/ALabel.hpp index 2baf0b10..00daf3c8 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -18,9 +18,6 @@ class ALabel : public IModule { Gtk::Label label_; const Json::Value& config_; std::string format_; - std::string button_press_cmd_ = ""; - std::string scroll_up_cmd_ = ""; - std::string scroll_down_cmd_ = ""; std::mutex mutex_; private: diff --git a/include/util/command.hpp b/include/util/command.hpp index 8ff42bed..5d3692e7 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -35,7 +35,6 @@ inline struct res exec(const std::string cmd) inline bool forkExec(std::string cmd) { if (cmd == "") return true; - printf("fork exec command %s\n", cmd.c_str()); int32_t pid = fork(); if (pid < 0) { diff --git a/resources/config b/resources/config index 43f247ad..ba9c945d 100644 --- a/resources/config +++ b/resources/config @@ -69,7 +69,8 @@ "portable": "", "car": "", "default": ["", ""] - } + }, + "on-click": "pavucontrol" }, "custom/spotify": { "format": " {}", diff --git a/resources/mediaplayer.sh b/resources/custom_modules/mediaplayer.sh similarity index 100% rename from resources/mediaplayer.sh rename to resources/custom_modules/mediaplayer.sh diff --git a/src/ALabel.cpp b/src/ALabel.cpp index cb9448bf..9dd590e5 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -21,28 +21,19 @@ waybar::ALabel::ALabel(const Json::Value& config, const std::string format) // configure events' user commands if (config_["on-click"].isString()) { - std::string cmd = config_["on-click"].asString(); event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.signal_button_press_event().connect( sigc::mem_fun(*this, &ALabel::handleToggle)); - - button_press_cmd_ = cmd; } if (config_["on-scroll-up"].isString()) { - std::string cmd = config_["on-scroll-up"].asString(); event_box_.add_events(Gdk::SCROLL_MASK); event_box_.signal_scroll_event().connect( sigc::mem_fun(*this, &ALabel::handleScroll)); - - scroll_up_cmd_ = cmd; } if (config_["on-scroll-down"].isString()) { - std::string cmd = config_["on-scroll-down"].asString(); event_box_.add_events(Gdk::SCROLL_MASK); event_box_.signal_scroll_event().connect( sigc::mem_fun(*this, &ALabel::handleScroll)); - - scroll_down_cmd_ = cmd; } } @@ -51,8 +42,8 @@ auto waybar::ALabel::update() -> void { } bool waybar::ALabel::handleToggle(GdkEventButton* const& e) { - if (button_press_cmd_ != "" && e->button == 1) { - waybar::util::command::forkExec(button_press_cmd_); + if (config_["on-click"].isString() && e->button == 1) { + waybar::util::command::forkExec(config_["on-click"].asString()); } else { alt = !alt; if (alt) { @@ -69,35 +60,31 @@ bool waybar::ALabel::handleToggle(GdkEventButton* const& e) { bool waybar::ALabel::handleScroll(GdkEventScroll* e) { // Avoid concurrent scroll event - { - std::lock_guard lock(mutex_); - bool direction_up = false; + std::lock_guard lock(mutex_); + bool direction_up = false; - if (e->direction == GDK_SCROLL_UP) { + if (e->direction == GDK_SCROLL_UP) { + direction_up = true; + } + if (e->direction == GDK_SCROLL_DOWN) { + direction_up = false; + } + if (e->direction == GDK_SCROLL_SMOOTH) { + gdouble delta_x, delta_y; + gdk_event_get_scroll_deltas(reinterpret_cast(e), + &delta_x, &delta_y); + if (delta_y < 0) { direction_up = true; - } - if (e->direction == GDK_SCROLL_DOWN) { + } else if (delta_y > 0) { direction_up = false; } - if (e->direction == GDK_SCROLL_SMOOTH) { - gdouble delta_x, delta_y; - gdk_event_get_scroll_deltas(reinterpret_cast(e), - &delta_x, &delta_y); - if (delta_y < 0) { - direction_up = true; - } else if (delta_y > 0) { - direction_up = false; - } - } - - if (direction_up) - waybar::util::command::forkExec(scroll_up_cmd_); - else - waybar::util::command::forkExec(scroll_down_cmd_); - - dp.emit(); } - + if (direction_up && config_["on-scroll-up"].isString()) { + waybar::util::command::forkExec(config_["on-scroll-up"].asString()); + } else if (config_["on-scroll-down"].isString()) { + waybar::util::command::forkExec(config_["on-scroll-down"].asString()); + } + dp.emit(); return true; }