Making active a bool

This commit is contained in:
Jordan Leppert 2020-11-01 18:25:41 +00:00
parent b015836e7b
commit 9785a89013
2 changed files with 14 additions and 17 deletions

View File

@ -12,8 +12,8 @@ class IdleInhibitor : public ALabel {
IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&); IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&);
~IdleInhibitor(); ~IdleInhibitor();
auto update() -> void; auto update() -> void;
static std::list<waybar::AModule*> modules; static std::list<waybar::AModule*> modules;
static std::string status; static bool status;
private: private:
bool handleToggle(GdkEventButton* const& e); bool handleToggle(GdkEventButton* const& e);

View File

@ -2,7 +2,7 @@
#include "util/command.hpp" #include "util/command.hpp"
std::list<waybar::AModule*> waybar::modules::IdleInhibitor::modules; std::list<waybar::AModule*> 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, waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar,
const Json::Value& config) const Json::Value& config)
@ -37,7 +37,7 @@ waybar::modules::IdleInhibitor::~IdleInhibitor() {
auto waybar::modules::IdleInhibitor::update() -> void { auto waybar::modules::IdleInhibitor::update() -> void {
// Check status // Check status
if (status == "activated") { if (status) {
label_.get_style_context()->remove_class("deactivated"); label_.get_style_context()->remove_class("deactivated");
if (idle_inhibitor_ == nullptr) { if (idle_inhibitor_ == nullptr) {
idle_inhibitor_ = zwp_idle_inhibit_manager_v1_create_inhibitor( 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( label_.set_markup(
fmt::format(format_, fmt::arg("status", status), fmt::arg("icon", getIcon(0, status)))); fmt::format(format_, fmt::arg("status", status_text), fmt::arg("icon", getIcon(0, status_text))));
label_.get_style_context()->add_class(status); label_.get_style_context()->add_class(status_text);
if (tooltipEnabled()) { if (tooltipEnabled()) {
label_.set_tooltip_text(status); label_.set_tooltip_text(status_text);
} }
// Call parent update // Call parent update
ALabel::update(); ALabel::update();
@ -63,17 +64,13 @@ auto waybar::modules::IdleInhibitor::update() -> void {
bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) { bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
if (e->button == 1) { if (e->button == 1) {
if (status == "activated") { status = !status;
status = "deactivated";
} else {
status = "activated";
}
}
// Make all other idle inhibitor modules update // Make all other idle inhibitor modules update
for (auto const& module : waybar::modules::IdleInhibitor::modules) { for (auto const& module : waybar::modules::IdleInhibitor::modules) {
if (module != this) { if (module != this) {
module->update(); module->update();
}
} }
} }