From 4872091442e869769c5db05d96358d3b660e03ad Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sat, 31 Oct 2020 16:31:27 +0000 Subject: [PATCH 1/9] Draft fix for syncing idle inhibitor across outputs. The idle_inhibitor surface has been moved to Client, all instances of idle inhibitor module now use one surface between them. Any time an idle inhibitor is clicked, currently it force updates ALL modules on all outputs, this needs work. --- include/bar.hpp | 1 + include/client.hpp | 1 + include/modules/idle_inhibitor.hpp | 1 - src/bar.cpp | 12 ++++++++++++ src/modules/idle_inhibitor.cpp | 30 +++++++++++++++++++++--------- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index fdc5a739..d1077842 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -31,6 +31,7 @@ class Bar { auto toggle() -> void; void handleSignal(int); + void updateAll(); struct waybar_output *output; Json::Value config; diff --git a/include/client.hpp b/include/client.hpp index 39b6ae3b..b7631ccf 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -22,6 +22,7 @@ class Client { struct zwlr_layer_shell_v1 * layer_shell = nullptr; struct zxdg_output_manager_v1 * xdg_output_manager = nullptr; struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr; + struct zwp_idle_inhibitor_v1* idle_inhibitor; std::vector> bars; private: diff --git a/include/modules/idle_inhibitor.hpp b/include/modules/idle_inhibitor.hpp index 5ce324da..f1c690df 100644 --- a/include/modules/idle_inhibitor.hpp +++ b/include/modules/idle_inhibitor.hpp @@ -18,7 +18,6 @@ class IdleInhibitor : public ALabel { const Bar& bar_; std::string status_; - struct zwp_idle_inhibitor_v1* idle_inhibitor_; int pid_; }; diff --git a/src/bar.cpp b/src/bar.cpp index 8af6b971..747f0bf8 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -461,3 +461,15 @@ auto waybar::Bar::setupWidgets() -> void { right_.pack_end(*module, false, false); } } + +void waybar::Bar::updateAll() { + for (auto const& module : modules_left_) { + module->update(); + } + for (auto const& module : modules_center_) { + module->update(); + } + for (auto const& module : modules_right_) { + module->update(); + } +} diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index d94e9579..c6a4c78b 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -6,7 +6,6 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& : ALabel(config, "idle_inhibitor", id, "{status}"), bar_(bar), status_("deactivated"), - idle_inhibitor_(nullptr), pid_(-1) { event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.signal_button_press_event().connect( @@ -15,9 +14,9 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& } waybar::modules::IdleInhibitor::~IdleInhibitor() { - if (idle_inhibitor_ != nullptr) { - zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); - idle_inhibitor_ = nullptr; + if (waybar::Client::inst()->idle_inhibitor != nullptr) { + zwp_idle_inhibitor_v1_destroy(waybar::Client::inst()->idle_inhibitor); + waybar::Client::inst()->idle_inhibitor = nullptr; } if (pid_ != -1) { kill(-pid_, 9); @@ -26,6 +25,13 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { } auto waybar::modules::IdleInhibitor::update() -> void { + // Check status + if (waybar::Client::inst()->idle_inhibitor != nullptr) { + status_ = "activated"; + } else { + status_ = "deactivated"; + } + label_.set_markup( fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_)))); label_.get_style_context()->add_class(status_); @@ -39,17 +45,23 @@ auto waybar::modules::IdleInhibitor::update() -> void { bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { if (e->button == 1) { label_.get_style_context()->remove_class(status_); - if (idle_inhibitor_ != nullptr) { - zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); - idle_inhibitor_ = nullptr; + if (waybar::Client::inst()->idle_inhibitor != nullptr) { + zwp_idle_inhibitor_v1_destroy(waybar::Client::inst()->idle_inhibitor); + waybar::Client::inst()->idle_inhibitor = nullptr; status_ = "deactivated"; } else { - idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( - waybar::Client::inst()->idle_inhibit_manager, bar_.surface); + waybar::Client::inst()->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor( + waybar::Client::inst()->idle_inhibit_manager, bar_.surface); status_ = "activated"; } click_param = status_; } + + // Make all modules update + for (auto const& bar : waybar::Client::inst()->bars) { + bar->updateAll(); + } + ALabel::handleToggle(e); return true; } From aa4fc3dd29544586482525e20f55c8c5becb82f0 Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sat, 31 Oct 2020 17:30:25 +0000 Subject: [PATCH 2/9] Idle inhibitor toggle no longer update all modules - a list of idle inhibitors is maintained on the Client. --- include/bar.hpp | 1 - include/client.hpp | 3 +++ src/bar.cpp | 12 ------------ src/modules/idle_inhibitor.cpp | 9 ++++++--- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/include/bar.hpp b/include/bar.hpp index d1077842..fdc5a739 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -31,7 +31,6 @@ class Bar { auto toggle() -> void; void handleSignal(int); - void updateAll(); struct waybar_output *output; Json::Value config; diff --git a/include/client.hpp b/include/client.hpp index b7631ccf..b6762f63 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -21,8 +21,11 @@ class Client { struct wl_registry * registry = nullptr; struct zwlr_layer_shell_v1 * layer_shell = nullptr; struct zxdg_output_manager_v1 * xdg_output_manager = nullptr; + struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr; struct zwp_idle_inhibitor_v1* idle_inhibitor; + std::vector idle_inhibitor_modules; + std::vector> bars; private: diff --git a/src/bar.cpp b/src/bar.cpp index 747f0bf8..8af6b971 100644 --- a/src/bar.cpp +++ b/src/bar.cpp @@ -461,15 +461,3 @@ auto waybar::Bar::setupWidgets() -> void { right_.pack_end(*module, false, false); } } - -void waybar::Bar::updateAll() { - for (auto const& module : modules_left_) { - module->update(); - } - for (auto const& module : modules_center_) { - module->update(); - } - for (auto const& module : modules_right_) { - module->update(); - } -} diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index c6a4c78b..7a0dd505 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -10,6 +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::handleToggle)); + waybar::Client::inst()->idle_inhibitor_modules.push_back(this); dp.emit(); } @@ -57,9 +58,11 @@ bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { click_param = status_; } - // Make all modules update - for (auto const& bar : waybar::Client::inst()->bars) { - bar->updateAll(); + // Make all other idle inhibitor modules update + for (auto const& module : waybar::Client::inst()->idle_inhibitor_modules) { + if (module != this) { + module->update(); + } } ALabel::handleToggle(e); From 4889e655ebe5a58b18c294ef3b96d8dd6a46240c Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sun, 1 Nov 2020 13:33:28 +0000 Subject: [PATCH 3/9] Since idle_inhibitor's have a surface, we should have one for each inhibitor module. Therefore, the status is stored on the Client, and all modules create or destroy their inhibitors depending on Client's idle_inhibitor_status. Also, when modules are destroyed they remove themselves from Client's idle_inhibitor_modules. --- include/client.hpp | 4 +-- include/modules/idle_inhibitor.hpp | 2 +- src/modules/idle_inhibitor.cpp | 49 ++++++++++++++++++------------ 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/include/client.hpp b/include/client.hpp index b6762f63..592af8f3 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -23,8 +23,8 @@ class Client { struct zxdg_output_manager_v1 * xdg_output_manager = nullptr; struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr; - struct zwp_idle_inhibitor_v1* idle_inhibitor; - std::vector idle_inhibitor_modules; + std::list idle_inhibitor_modules; + std::string idle_inhibitor_status = "deactivated"; std::vector> bars; diff --git a/include/modules/idle_inhibitor.hpp b/include/modules/idle_inhibitor.hpp index f1c690df..abfc9960 100644 --- a/include/modules/idle_inhibitor.hpp +++ b/include/modules/idle_inhibitor.hpp @@ -12,12 +12,12 @@ class IdleInhibitor : public ALabel { IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&); ~IdleInhibitor(); auto update() -> void; + struct zwp_idle_inhibitor_v1* idle_inhibitor_ = nullptr; private: bool handleToggle(GdkEventButton* const& e); const Bar& bar_; - std::string status_; int pid_; }; diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index 7a0dd505..fe7ee16f 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -5,20 +5,26 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& const Json::Value& config) : ALabel(config, "idle_inhibitor", id, "{status}"), bar_(bar), - status_("deactivated"), pid_(-1) { event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.signal_button_press_event().connect( sigc::mem_fun(*this, &IdleInhibitor::handleToggle)); + + // Add this to the Client's idle_inhibitor_modules waybar::Client::inst()->idle_inhibitor_modules.push_back(this); + dp.emit(); } waybar::modules::IdleInhibitor::~IdleInhibitor() { - if (waybar::Client::inst()->idle_inhibitor != nullptr) { - zwp_idle_inhibitor_v1_destroy(waybar::Client::inst()->idle_inhibitor); - waybar::Client::inst()->idle_inhibitor = nullptr; + if (idle_inhibitor_ != nullptr) { + zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); + idle_inhibitor_ = nullptr; } + + // Remove this from the Client's idle_inhibitor_modules + waybar::Client::inst()->idle_inhibitor_modules.remove(this); + if (pid_ != -1) { kill(-pid_, 9); pid_ = -1; @@ -27,17 +33,24 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { auto waybar::modules::IdleInhibitor::update() -> void { // Check status - if (waybar::Client::inst()->idle_inhibitor != nullptr) { - status_ = "activated"; + std::string status = waybar::Client::inst()->idle_inhibitor_status; + if (status == "activated") { + if (idle_inhibitor_ == nullptr) { + idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( + waybar::Client::inst()->idle_inhibit_manager, bar_.surface); + } } else { - status_ = "deactivated"; + if (idle_inhibitor_ != nullptr) { + zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); + idle_inhibitor_ = nullptr; + } } label_.set_markup( - fmt::format(format_, fmt::arg("status", status_), fmt::arg("icon", getIcon(0, status_)))); - label_.get_style_context()->add_class(status_); + fmt::format(format_, fmt::arg("status", status), fmt::arg("icon", getIcon(0, status)))); + label_.get_style_context()->add_class(status); if (tooltipEnabled()) { - label_.set_tooltip_text(status_); + label_.set_tooltip_text(status); } // Call parent update ALabel::update(); @@ -45,17 +58,15 @@ auto waybar::modules::IdleInhibitor::update() -> void { bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { if (e->button == 1) { - label_.get_style_context()->remove_class(status_); - if (waybar::Client::inst()->idle_inhibitor != nullptr) { - zwp_idle_inhibitor_v1_destroy(waybar::Client::inst()->idle_inhibitor); - waybar::Client::inst()->idle_inhibitor = nullptr; - status_ = "deactivated"; + std::string status = waybar::Client::inst()->idle_inhibitor_status; + label_.get_style_context()->remove_class(status); + if (status == "activated") { + status = "deactivated"; } else { - waybar::Client::inst()->idle_inhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor( - waybar::Client::inst()->idle_inhibit_manager, bar_.surface); - status_ = "activated"; + status = "activated"; } - click_param = status_; + waybar::Client::inst()->idle_inhibitor_status = status; + click_param = status; } // Make all other idle inhibitor modules update From bb33427f6532dfbf09d7bbc6755ca3e2f3946115 Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sun, 1 Nov 2020 13:38:58 +0000 Subject: [PATCH 4/9] Making idle_inhibitor_ private and initialised in constructor, as it was before. --- include/modules/idle_inhibitor.hpp | 2 +- src/modules/idle_inhibitor.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/modules/idle_inhibitor.hpp b/include/modules/idle_inhibitor.hpp index abfc9960..a857011c 100644 --- a/include/modules/idle_inhibitor.hpp +++ b/include/modules/idle_inhibitor.hpp @@ -12,12 +12,12 @@ class IdleInhibitor : public ALabel { IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&); ~IdleInhibitor(); auto update() -> void; - struct zwp_idle_inhibitor_v1* idle_inhibitor_ = nullptr; private: bool handleToggle(GdkEventButton* const& e); const Bar& bar_; + struct zwp_idle_inhibitor_v1* idle_inhibitor_; int pid_; }; diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index fe7ee16f..990af2ca 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -5,6 +5,7 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& const Json::Value& config) : ALabel(config, "idle_inhibitor", id, "{status}"), bar_(bar), + idle_inhibitor_(nullptr), pid_(-1) { event_box_.add_events(Gdk::BUTTON_PRESS_MASK); event_box_.signal_button_press_event().connect( From c6743988d3f7afee8a4952b24817eaa59a08fe49 Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sun, 1 Nov 2020 16:03:39 +0000 Subject: [PATCH 5/9] Removing 'click_param' as it is no longer used. --- include/ALabel.hpp | 1 - src/modules/idle_inhibitor.cpp | 1 - 2 files changed, 2 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index 6848d677..5b9ac541 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -19,7 +19,6 @@ class ALabel : public AModule { protected: Gtk::Label label_; std::string format_; - std::string click_param; const std::chrono::seconds interval_; bool alt_ = false; std::string default_format_; diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index 990af2ca..5eb94eb5 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -67,7 +67,6 @@ bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { status = "activated"; } waybar::Client::inst()->idle_inhibitor_status = status; - click_param = status; } // Make all other idle inhibitor modules update From 071cb86b45d5a348430feac0516794836cf77721 Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sun, 1 Nov 2020 17:09:48 +0000 Subject: [PATCH 6/9] Moving idle inhibitor shared stuff out of Client and into idle_inhibitor module as static members. --- include/client.hpp | 2 -- include/modules/idle_inhibitor.hpp | 2 ++ src/modules/idle_inhibitor.cpp | 15 +++++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/client.hpp b/include/client.hpp index 592af8f3..902f6866 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -23,8 +23,6 @@ class Client { struct zxdg_output_manager_v1 * xdg_output_manager = nullptr; struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr; - std::list idle_inhibitor_modules; - std::string idle_inhibitor_status = "deactivated"; std::vector> bars; diff --git a/include/modules/idle_inhibitor.hpp b/include/modules/idle_inhibitor.hpp index a857011c..f5926318 100644 --- a/include/modules/idle_inhibitor.hpp +++ b/include/modules/idle_inhibitor.hpp @@ -12,6 +12,8 @@ class IdleInhibitor : public ALabel { IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&); ~IdleInhibitor(); auto update() -> void; + static std::list idle_inhibitor_modules; + static std::string idle_inhibitor_status; private: bool handleToggle(GdkEventButton* const& e); diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index 5eb94eb5..ce5f9914 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -1,6 +1,9 @@ #include "modules/idle_inhibitor.hpp" #include "util/command.hpp" +std::list waybar::modules::IdleInhibitor::idle_inhibitor_modules; +std::string waybar::modules::IdleInhibitor::idle_inhibitor_status = "deactivated"; + waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, const Json::Value& config) : ALabel(config, "idle_inhibitor", id, "{status}"), @@ -12,7 +15,7 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& sigc::mem_fun(*this, &IdleInhibitor::handleToggle)); // Add this to the Client's idle_inhibitor_modules - waybar::Client::inst()->idle_inhibitor_modules.push_back(this); + waybar::modules::IdleInhibitor::idle_inhibitor_modules.push_back(this); dp.emit(); } @@ -24,7 +27,7 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { } // Remove this from the Client's idle_inhibitor_modules - waybar::Client::inst()->idle_inhibitor_modules.remove(this); + waybar::modules::IdleInhibitor::idle_inhibitor_modules.remove(this); if (pid_ != -1) { kill(-pid_, 9); @@ -34,7 +37,7 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { auto waybar::modules::IdleInhibitor::update() -> void { // Check status - std::string status = waybar::Client::inst()->idle_inhibitor_status; + std::string status = waybar::modules::IdleInhibitor::idle_inhibitor_status; if (status == "activated") { if (idle_inhibitor_ == nullptr) { idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( @@ -59,18 +62,18 @@ auto waybar::modules::IdleInhibitor::update() -> void { bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { if (e->button == 1) { - std::string status = waybar::Client::inst()->idle_inhibitor_status; + std::string status = waybar::modules::IdleInhibitor::idle_inhibitor_status; label_.get_style_context()->remove_class(status); if (status == "activated") { status = "deactivated"; } else { status = "activated"; } - waybar::Client::inst()->idle_inhibitor_status = status; + waybar::modules::IdleInhibitor::idle_inhibitor_status = status; } // Make all other idle inhibitor modules update - for (auto const& module : waybar::Client::inst()->idle_inhibitor_modules) { + for (auto const& module : waybar::modules::IdleInhibitor::idle_inhibitor_modules) { if (module != this) { module->update(); } From a9dae931c73e44f6c18fa0fc8a3220fbea5f265b Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sun, 1 Nov 2020 17:14:05 +0000 Subject: [PATCH 7/9] Renaming idle_inhibitor_modules and idle_inhibitor_status to shorter, more convenient names. --- include/client.hpp | 2 -- include/modules/idle_inhibitor.hpp | 4 ++-- src/modules/idle_inhibitor.cpp | 20 ++++++++++---------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/include/client.hpp b/include/client.hpp index 902f6866..39b6ae3b 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -21,9 +21,7 @@ class Client { struct wl_registry * registry = nullptr; struct zwlr_layer_shell_v1 * layer_shell = nullptr; struct zxdg_output_manager_v1 * xdg_output_manager = nullptr; - struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr; - std::vector> bars; private: diff --git a/include/modules/idle_inhibitor.hpp b/include/modules/idle_inhibitor.hpp index f5926318..2cbc6f12 100644 --- a/include/modules/idle_inhibitor.hpp +++ b/include/modules/idle_inhibitor.hpp @@ -12,8 +12,8 @@ class IdleInhibitor : public ALabel { IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&); ~IdleInhibitor(); auto update() -> void; - static std::list idle_inhibitor_modules; - static std::string idle_inhibitor_status; + static std::list modules; + static std::string status; private: bool handleToggle(GdkEventButton* const& e); diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index ce5f9914..96db8799 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -1,8 +1,8 @@ #include "modules/idle_inhibitor.hpp" #include "util/command.hpp" -std::list waybar::modules::IdleInhibitor::idle_inhibitor_modules; -std::string waybar::modules::IdleInhibitor::idle_inhibitor_status = "deactivated"; +std::list waybar::modules::IdleInhibitor::modules; +std::string waybar::modules::IdleInhibitor::status = "deactivated"; waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, const Json::Value& config) @@ -14,8 +14,8 @@ waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& event_box_.signal_button_press_event().connect( sigc::mem_fun(*this, &IdleInhibitor::handleToggle)); - // Add this to the Client's idle_inhibitor_modules - waybar::modules::IdleInhibitor::idle_inhibitor_modules.push_back(this); + // Add this to the modules list + waybar::modules::IdleInhibitor::modules.push_back(this); dp.emit(); } @@ -26,8 +26,8 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { idle_inhibitor_ = nullptr; } - // Remove this from the Client's idle_inhibitor_modules - waybar::modules::IdleInhibitor::idle_inhibitor_modules.remove(this); + // Remove this from the modules list + waybar::modules::IdleInhibitor::modules.remove(this); if (pid_ != -1) { kill(-pid_, 9); @@ -37,7 +37,7 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { auto waybar::modules::IdleInhibitor::update() -> void { // Check status - std::string status = waybar::modules::IdleInhibitor::idle_inhibitor_status; + std::string status = waybar::modules::IdleInhibitor::status; if (status == "activated") { if (idle_inhibitor_ == nullptr) { idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( @@ -62,18 +62,18 @@ auto waybar::modules::IdleInhibitor::update() -> void { bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { if (e->button == 1) { - std::string status = waybar::modules::IdleInhibitor::idle_inhibitor_status; + std::string status = waybar::modules::IdleInhibitor::status; label_.get_style_context()->remove_class(status); if (status == "activated") { status = "deactivated"; } else { status = "activated"; } - waybar::modules::IdleInhibitor::idle_inhibitor_status = status; + waybar::modules::IdleInhibitor::status = status; } // Make all other idle inhibitor modules update - for (auto const& module : waybar::modules::IdleInhibitor::idle_inhibitor_modules) { + for (auto const& module : waybar::modules::IdleInhibitor::modules) { if (module != this) { module->update(); } From b015836e7b55def65d83cba9b3367ce2c1636417 Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sun, 1 Nov 2020 18:17:51 +0000 Subject: [PATCH 8/9] Ensure style class is removed from all IdleInhibitor instances by moving it to update(). --- src/modules/idle_inhibitor.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index 96db8799..24d94f51 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -37,13 +37,14 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { auto waybar::modules::IdleInhibitor::update() -> void { // Check status - std::string status = waybar::modules::IdleInhibitor::status; if (status == "activated") { + label_.get_style_context()->remove_class("deactivated"); if (idle_inhibitor_ == nullptr) { idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( waybar::Client::inst()->idle_inhibit_manager, bar_.surface); } } else { + label_.get_style_context()->remove_class("activated"); if (idle_inhibitor_ != nullptr) { zwp_idle_inhibitor_v1_destroy(idle_inhibitor_); idle_inhibitor_ = nullptr; @@ -62,14 +63,11 @@ auto waybar::modules::IdleInhibitor::update() -> void { bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { if (e->button == 1) { - std::string status = waybar::modules::IdleInhibitor::status; - label_.get_style_context()->remove_class(status); if (status == "activated") { status = "deactivated"; } else { status = "activated"; } - waybar::modules::IdleInhibitor::status = status; } // Make all other idle inhibitor modules update From 9785a8901382278c1832320a2c67cfec75dcf45f Mon Sep 17 00:00:00 2001 From: Jordan Leppert Date: Sun, 1 Nov 2020 18:25:41 +0000 Subject: [PATCH 9/9] Making active a bool --- include/modules/idle_inhibitor.hpp | 4 ++-- src/modules/idle_inhibitor.cpp | 27 ++++++++++++--------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/modules/idle_inhibitor.hpp b/include/modules/idle_inhibitor.hpp index 2cbc6f12..4b6c097f 100644 --- a/include/modules/idle_inhibitor.hpp +++ b/include/modules/idle_inhibitor.hpp @@ -12,8 +12,8 @@ class IdleInhibitor : public ALabel { IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&); ~IdleInhibitor(); auto update() -> void; - static std::list modules; - static std::string status; + static std::list modules; + static bool status; private: bool handleToggle(GdkEventButton* const& e); diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index 24d94f51..ba5d6943 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -2,7 +2,7 @@ #include "util/command.hpp" std::list waybar::modules::IdleInhibitor::modules; -std::string waybar::modules::IdleInhibitor::status = "deactivated"; +bool waybar::modules::IdleInhibitor::status = false; waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, const Json::Value& config) @@ -37,7 +37,7 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() { auto waybar::modules::IdleInhibitor::update() -> void { // Check status - if (status == "activated") { + if (status) { label_.get_style_context()->remove_class("deactivated"); if (idle_inhibitor_ == nullptr) { idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( @@ -51,11 +51,12 @@ auto waybar::modules::IdleInhibitor::update() -> void { } } + std::string status_text = status ? "activated" : "deactivated"; label_.set_markup( - fmt::format(format_, fmt::arg("status", status), fmt::arg("icon", getIcon(0, status)))); - label_.get_style_context()->add_class(status); + fmt::format(format_, fmt::arg("status", status_text), fmt::arg("icon", getIcon(0, status_text)))); + label_.get_style_context()->add_class(status_text); if (tooltipEnabled()) { - label_.set_tooltip_text(status); + label_.set_tooltip_text(status_text); } // Call parent update ALabel::update(); @@ -63,17 +64,13 @@ auto waybar::modules::IdleInhibitor::update() -> void { bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { if (e->button == 1) { - if (status == "activated") { - status = "deactivated"; - } else { - status = "activated"; - } - } + status = !status; - // Make all other idle inhibitor modules update - for (auto const& module : waybar::modules::IdleInhibitor::modules) { - if (module != this) { - module->update(); + // Make all other idle inhibitor modules update + for (auto const& module : waybar::modules::IdleInhibitor::modules) { + if (module != this) { + module->update(); + } } }