feat(idle_inhibitor): pass status to click events exec

This commit is contained in:
Alex 2019-05-02 16:56:45 +02:00
parent 1e871b2353
commit 5623bbecfe
3 changed files with 13 additions and 7 deletions

View File

@ -23,6 +23,7 @@ class ALabel : public IModule {
Gtk::Label label_; Gtk::Label label_;
const Json::Value & config_; const Json::Value & config_;
std::string format_; std::string format_;
std::string click_param;
std::mutex mutex_; std::mutex mutex_;
const std::chrono::seconds interval_; const std::chrono::seconds interval_;
bool alt_ = false; bool alt_ = false;

View File

@ -1,7 +1,6 @@
#include "ALabel.hpp" #include "ALabel.hpp"
#include <util/command.hpp> #include <util/command.hpp>
#include <fmt/format.h>
#include <iostream>
waybar::ALabel::ALabel(const Json::Value& config, const std::string& format, uint16_t interval) waybar::ALabel::ALabel(const Json::Value& config, const std::string& format, uint16_t interval)
: config_(config), : config_(config),
@ -50,16 +49,21 @@ auto waybar::ALabel::update() -> void {
} }
bool waybar::ALabel::handleToggle(GdkEventButton* const& e) { bool waybar::ALabel::handleToggle(GdkEventButton* const& e) {
std::string format;
if (config_["on-click"].isString() && e->button == 1) { 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) { } 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) { } 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) { } 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) { } 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()) { if (config_["format-alt-click"].isUInt() && e->button == config_["format-alt-click"].asUInt()) {
alt_ = !alt_; alt_ = !alt_;

View File

@ -50,6 +50,7 @@ bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
waybar::Client::inst()->idle_inhibit_manager, bar_.surface); waybar::Client::inst()->idle_inhibit_manager, bar_.surface);
status_ = "activated"; status_ = "activated";
} }
click_param = status_;
} else { } else {
ALabel::handleToggle(e); ALabel::handleToggle(e);
} }