From 4d3879f26f115f2ca2ca60732e7cddadc324c831 Mon Sep 17 00:00:00 2001 From: Alexis Date: Fri, 10 Aug 2018 17:05:12 +0200 Subject: [PATCH] refactor: avoid useless has_class check --- src/modules/battery.cpp | 2 +- src/modules/custom.cpp | 7 ++++--- src/modules/pulseaudio.cpp | 5 ++--- src/modules/workspaces.cpp | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 12396d4..efab635 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -37,7 +37,7 @@ auto waybar::modules::Battery::update() -> void charging = true; } } - if (charging == true) { + if (charging) { _label.get_style_context()->add_class("charging"); } else { _label.get_style_context()->remove_class("charging"); diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index 693e220..8f5ab56 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -4,7 +4,6 @@ waybar::modules::Custom::Custom(std::string name, Json::Value config) : _name(name), _config(config) { - _label.get_style_context()->add_class("custom-" + name); if (!_config["exec"]) { std::cerr << name + " has no exec path." << std::endl; return; @@ -36,9 +35,11 @@ auto waybar::modules::Custom::update() -> void } // Hide label if output is empty - if (output.empty()) + if (output.empty()) { + _label.get_style_context()->remove_class("custom-" + _name); _label.hide(); - else { + } else { + _label.get_style_context()->add_class("custom-" + _name); auto format = _config["format"] ? _config["format"].asString() : "{}"; _label.set_text(fmt::format(format, output)); _label.show(); diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 1b196cc..7e4b99b 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -103,9 +103,8 @@ auto waybar::modules::Pulseaudio::update() -> void if (_muted) { format = _config["format-muted"] ? _config["format-muted"].asString() : format; - if (!_label.get_style_context()->has_class("muted")) - _label.get_style_context()->add_class("muted"); - } else if (_label.get_style_context()->has_class("muted")) + _label.get_style_context()->add_class("muted"); + } else _label.get_style_context()->remove_class("muted"); _label.set_label(fmt::format(format, _volume)); _label.set_tooltip_text(_desc); diff --git a/src/modules/workspaces.cpp b/src/modules/workspaces.cpp index 33e7660..80c29be 100644 --- a/src/modules/workspaces.cpp +++ b/src/modules/workspaces.cpp @@ -42,9 +42,9 @@ auto waybar::modules::Workspaces::update() -> void } else { auto styleContext = it->second.get_style_context(); bool isCurrent = node["focused"].asBool(); - if (styleContext->has_class("current") && !isCurrent) { + if (!isCurrent) { styleContext->remove_class("current"); - } else if (!styleContext->has_class("current") && isCurrent) { + } else if (isCurrent) { styleContext->add_class("current"); } if (hided) {