mirror of
https://github.com/rad4day/Waybar.git
synced 2023-12-21 10:22:59 +01:00
Making active a bool
This commit is contained in:
parent
b015836e7b
commit
9785a89013
@ -13,7 +13,7 @@ class IdleInhibitor : public ALabel {
|
|||||||
~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);
|
||||||
|
@ -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,12 +64,7 @@ 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) {
|
||||||
@ -76,6 +72,7 @@ bool waybar::modules::IdleInhibitor::handleToggle(GdkEventButton* const& e) {
|
|||||||
module->update();
|
module->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ALabel::handleToggle(e);
|
ALabel::handleToggle(e);
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user