From 5623bbecfe118ace2387c9f33c8ac1f2e0f7fa8c Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 2 May 2019 16:56:45 +0200 Subject: [PATCH] feat(idle_inhibitor): pass status to click events exec --- include/ALabel.hpp | 1 + src/ALabel.cpp | 18 +++++++++++------- src/modules/idle_inhibitor.cpp | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index cf8e5619..a6a9a5f1 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -23,6 +23,7 @@ class ALabel : public IModule { Gtk::Label label_; const Json::Value & config_; std::string format_; + std::string click_param; std::mutex mutex_; const std::chrono::seconds interval_; bool alt_ = false; diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 5e90ce73..9787367c 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -1,7 +1,6 @@ #include "ALabel.hpp" #include - -#include +#include waybar::ALabel::ALabel(const Json::Value& config, const std::string& format, uint16_t interval) : config_(config), @@ -50,16 +49,21 @@ auto waybar::ALabel::update() -> void { } bool waybar::ALabel::handleToggle(GdkEventButton* const& e) { + std::string format; if (config_["on-click"].isString() && e->button == 1) { - pid_.push_back(waybar::util::command::forkExec(config_["on-click"].asString())); + format = config_["on-click"].asString(); } else if (config_["on-click-middle"].isString() && e->button == 2) { - pid_.push_back(waybar::util::command::forkExec(config_["on-click-middle"].asString())); + format = config_["on-click-middle"].asString(); } else if (config_["on-click-right"].isString() && e->button == 3) { - pid_.push_back(waybar::util::command::forkExec(config_["on-click-right"].asString())); + format = config_["on-click-right"].asString(); } else if (config_["on-click-forward"].isString() && e->button == 8) { - pid_.push_back(waybar::util::command::forkExec(config_["on-click-backward"].asString())); + format = config_["on-click-backward"].asString(); } else if (config_["on-click-backward"].isString() && e->button == 9) { - pid_.push_back(waybar::util::command::forkExec(config_["on-click-forward"].asString())); + format = config_["on-click-forward"].asString(); + } + if (!format.empty()) { + pid_.push_back( + waybar::util::command::forkExec(fmt::format(format, fmt::arg("arg", click_param)))); } if (config_["format-alt-click"].isUInt() && e->button == config_["format-alt-click"].asUInt()) { alt_ = !alt_; diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index 7f745709..de294722 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -50,6 +50,7 @@ bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { waybar::Client::inst()->idle_inhibit_manager, bar_.surface); status_ = "activated"; } + click_param = status_; } else { ALabel::handleToggle(e); }