fix state behavior

This commit is contained in:
unresolvedsymbol 2019-05-15 22:14:51 -05:00
parent 37f87be9dd
commit 7e8eee0571
3 changed files with 4 additions and 4 deletions

View File

@ -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<int> pid_;

View File

@ -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 {

View File

@ -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_);
}