From 7e8eee0571146c41d6d85f3b20cadb707dd40167 Mon Sep 17 00:00:00 2001 From: unresolvedsymbol <48220091+unresolvedsymbol@users.noreply.github.com> Date: Wed, 15 May 2019 22:14:51 -0500 Subject: [PATCH 1/2] fix state behavior --- include/ALabel.hpp | 2 +- src/ALabel.cpp | 4 ++-- src/modules/battery.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index e1c8e0f6..078e577c 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -31,7 +31,7 @@ class ALabel : public IModule { virtual bool handleToggle(GdkEventButton *const &ev); virtual bool handleScroll(GdkEventScroll *); - virtual std::string getState(uint8_t value, bool reverse = false); + virtual std::string getState(uint8_t value, bool lesser = false, bool reverse = false); private: std::vector pid_; diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 70e502a7..6ebbc827 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -129,7 +129,7 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt, return ""; } -std::string waybar::ALabel::getState(uint8_t value, bool reverse) { +std::string waybar::ALabel::getState(uint8_t value, bool lesser, bool reverse) { if (!config_["states"].isObject()) { return ""; } @@ -148,7 +148,7 @@ std::string waybar::ALabel::getState(uint8_t value, bool reverse) { }); std::string valid_state; for (auto const& state : states) { - if (value <= state.second && valid_state.empty()) { + if ((lesser ? value <= state.second : value >= state.second) && valid_state.empty()) { label_.get_style_context()->add_class(state.first); valid_state = state.first; } else { diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index b51ed496..1aaa6489 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -130,7 +130,7 @@ auto waybar::modules::Battery::update() -> void { } std::transform(status.begin(), status.end(), status.begin(), ::tolower); auto format = format_; - auto state = getState(capacity, true); + auto state = getState(capacity, true, true); if (!old_status_.empty()) { label_.get_style_context()->remove_class(old_status_); } From 963d4f68e4197731cac5fa52a11fa9770a177b6f Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 16 May 2019 09:39:06 +0200 Subject: [PATCH 2/2] refactor: remove useless param --- include/ALabel.hpp | 2 +- src/ALabel.cpp | 6 +++--- src/modules/battery.cpp | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/ALabel.hpp b/include/ALabel.hpp index 078e577c..cf2cc286 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -31,7 +31,7 @@ class ALabel : public IModule { virtual bool handleToggle(GdkEventButton *const &ev); virtual bool handleScroll(GdkEventScroll *); - virtual std::string getState(uint8_t value, bool lesser = false, bool reverse = false); + virtual std::string getState(uint8_t value, bool lesser = false); private: std::vector pid_; diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 6ebbc827..e1fa212d 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -129,7 +129,7 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt, return ""; } -std::string waybar::ALabel::getState(uint8_t value, bool lesser, bool reverse) { +std::string waybar::ALabel::getState(uint8_t value, bool lesser) { if (!config_["states"].isObject()) { return ""; } @@ -143,8 +143,8 @@ std::string waybar::ALabel::getState(uint8_t value, bool lesser, bool reverse) { } } // Sort states - std::sort(states.begin(), states.end(), [&reverse](auto& a, auto& b) { - return reverse ? a.second < b.second : a.second > b.second; + std::sort(states.begin(), states.end(), [&lesser](auto& a, auto& b) { + return lesser ? a.second < b.second : a.second > b.second; }); std::string valid_state; for (auto const& state : states) { diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 1aaa6489..b51ed496 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -130,7 +130,7 @@ auto waybar::modules::Battery::update() -> void { } std::transform(status.begin(), status.end(), status.begin(), ::tolower); auto format = format_; - auto state = getState(capacity, true, true); + auto state = getState(capacity, true); if (!old_status_.empty()) { label_.get_style_context()->remove_class(old_status_); }