From 9d4048983db4dd1e7224ce9b34ca4853570cae85 Mon Sep 17 00:00:00 2001 From: Alexis Date: Thu, 1 Nov 2018 09:27:00 +0100 Subject: [PATCH] refactor: remove useless tmp variable --- include/ALabel.hpp | 3 - include/util/command.hpp | 1 - resources/config | 3 +- resources/{ => custom_modules}/mediaplayer.sh | 0 src/ALabel.cpp | 57 +++++++------------ 5 files changed, 24 insertions(+), 40 deletions(-) rename resources/{ => custom_modules}/mediaplayer.sh (100%) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index 2baf0b1..00daf3c 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 8ff42be..5d3692e 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 43f247a..ba9c945 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 cb9448b..9dd590e 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; }