fix(Label): reverse only battery states
This commit is contained in:
parent
fcb23d3104
commit
92967c7c06
|
@ -31,7 +31,7 @@ class ALabel : public IModule {
|
||||||
|
|
||||||
virtual bool handleToggle(GdkEventButton *const &ev);
|
virtual bool handleToggle(GdkEventButton *const &ev);
|
||||||
virtual bool handleScroll(GdkEventScroll *);
|
virtual bool handleScroll(GdkEventScroll *);
|
||||||
virtual std::string getState(uint8_t value);
|
virtual std::string getState(uint8_t value, bool reverse = false);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<int> pid_;
|
std::vector<int> pid_;
|
||||||
|
|
|
@ -129,7 +129,7 @@ std::string waybar::ALabel::getIcon(uint16_t percentage, const std::string& alt,
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string waybar::ALabel::getState(uint8_t value) {
|
std::string waybar::ALabel::getState(uint8_t value, bool reverse) {
|
||||||
if (!config_["states"].isObject()) {
|
if (!config_["states"].isObject()) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,9 @@ std::string waybar::ALabel::getState(uint8_t value) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Sort states
|
// Sort states
|
||||||
std::sort(states.begin(), states.end(), [](auto& a, auto& b) { return a.second < b.second; });
|
std::sort(states.begin(), states.end(), [&reverse](auto& a, auto& b) {
|
||||||
|
return reverse ? a.second < b.second : a.second > b.second;
|
||||||
|
});
|
||||||
std::string valid_state;
|
std::string valid_state;
|
||||||
for (auto const& state : states) {
|
for (auto const& state : states) {
|
||||||
if (value <= state.second && valid_state.empty()) {
|
if (value <= state.second && valid_state.empty()) {
|
||||||
|
|
|
@ -119,7 +119,7 @@ auto waybar::modules::Battery::update() -> void {
|
||||||
}
|
}
|
||||||
std::transform(status.begin(), status.end(), status.begin(), ::tolower);
|
std::transform(status.begin(), status.end(), status.begin(), ::tolower);
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
auto state = getState(capacity);
|
auto state = getState(capacity, true);
|
||||||
label_.get_style_context()->remove_class(old_status_);
|
label_.get_style_context()->remove_class(old_status_);
|
||||||
label_.get_style_context()->add_class(status);
|
label_.get_style_context()->add_class(status);
|
||||||
old_status_ = status;
|
old_status_ = status;
|
||||||
|
|
Loading…
Reference in New Issue