From 80ef63791d8257da7acac0a9fd8cf2d24083fc0f Mon Sep 17 00:00:00 2001 From: Jonas Date: Sun, 3 Mar 2019 22:02:34 +0100 Subject: [PATCH] [bugfix] idle_inhibitor handles click events correctly - Declare event handler in ALabel virtual so the idle_inhibitor can overriding them - Handle the right click event in idle_inhibitor and call ALabel handler if needed --- include/ALabel.hpp | 5 ++--- include/modules/idle_inhibitor.hpp | 2 +- src/modules/idle_inhibitor.cpp | 15 ++++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index f389da5f..f066f56e 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -28,9 +28,8 @@ protected: bool alt_ = false; std::string default_format_; -private: - bool handleToggle(GdkEventButton *const &ev); - bool handleScroll(GdkEventScroll *); + virtual bool handleToggle(GdkEventButton *const &ev); + virtual bool handleScroll(GdkEventScroll *); }; } // namespace waybar diff --git a/include/modules/idle_inhibitor.hpp b/include/modules/idle_inhibitor.hpp index ce6e58d4..76f54d37 100644 --- a/include/modules/idle_inhibitor.hpp +++ b/include/modules/idle_inhibitor.hpp @@ -13,7 +13,7 @@ class IdleInhibitor: public ALabel { ~IdleInhibitor(); auto update() -> void; private: - bool onClick(GdkEventButton* const& ev); + bool handleToggle(GdkEventButton* const& e); const Bar& bar_; std::string status_; diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index b00d1932..f9a8cde7 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -1,5 +1,5 @@ #include "modules/idle_inhibitor.hpp" - +#include "util/command.hpp" waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, const Json::Value& config) : ALabel(config, "{status}"), bar_(bar), status_("deactivated"), idle_inhibitor_(nullptr) @@ -10,7 +10,7 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& } event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.signal_button_press_event().connect( - sigc::mem_fun(*this, &IdleInhibitor::onClick)); + sigc::mem_fun(*this, &IdleInhibitor::handleToggle)); dp.emit(); } @@ -32,9 +32,8 @@ auto waybar::modules::IdleInhibitor::update() -> void } } -bool waybar::modules::IdleInhibitor::onClick(GdkEventButton* const& e) -{ - if(e->button == 1) { +bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { + if (e->button == 1) { if (idle_inhibitor_) { zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); idle_inhibitor_ = nullptr; @@ -44,7 +43,13 @@ bool waybar::modules::IdleInhibitor::onClick(GdkEventButton* const& e) bar_.client.idle_inhibit_manager, bar_.surface); status_ = "activated"; } + if (config_["on-click"].isString() && e->button == 1) { + waybar::util::command::forkExec(config_["on-click"].asString()); + } + } else { + ALabel::handleToggle(e); } + dp.emit(); return true; }