make status and state fully configurable formats
parent
b6cad05489
commit
0522577fe5
|
@ -29,6 +29,7 @@ class Battery : public ALabel {
|
||||||
util::SleeperThread threadTimer_;
|
util::SleeperThread threadTimer_;
|
||||||
std::vector<fs::path> batteries_;
|
std::vector<fs::path> batteries_;
|
||||||
int fd_;
|
int fd_;
|
||||||
|
std::string old_state_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,8 +74,6 @@ std::tuple<uint16_t, std::string> waybar::modules::Battery::getInfos()
|
||||||
std::ifstream(bat / "status") >> _status;
|
std::ifstream(bat / "status") >> _status;
|
||||||
if (_status != "Unknown") {
|
if (_status != "Unknown") {
|
||||||
status = _status;
|
status = _status;
|
||||||
} else if (config_["full-is-unknown"].isString() && config_["full-is-unknown"] == "true") {
|
|
||||||
status = "Full"; //Some notebooks (e.g. Thinkpad T430s) report a full battery as "Unknown".
|
|
||||||
}
|
}
|
||||||
total += capacity;
|
total += capacity;
|
||||||
}
|
}
|
||||||
|
@ -118,26 +116,17 @@ auto waybar::modules::Battery::update() -> void
|
||||||
{
|
{
|
||||||
auto [capacity, status] = getInfos();
|
auto [capacity, status] = getInfos();
|
||||||
label_.set_tooltip_text(status);
|
label_.set_tooltip_text(status);
|
||||||
bool charging = status == "Charging";
|
std::transform(status.begin(), status.end(), status.begin(), ::tolower);
|
||||||
auto format = format_;
|
auto format = format_;
|
||||||
if (charging) {
|
|
||||||
label_.get_style_context()->add_class("charging");
|
|
||||||
if (config_["format-charging"].isString()) {
|
|
||||||
format = config_["format-charging"].asString();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
label_.get_style_context()->remove_class("charging");
|
|
||||||
if (status == "Full") {
|
|
||||||
label_.get_style_context()->add_class("full");
|
|
||||||
if (config_["format-full"].isString()) {
|
|
||||||
format = config_["format-full"].asString();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
label_.get_style_context()->remove_class("full");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
auto state = getState(capacity, charging);
|
auto state = getState(capacity, charging);
|
||||||
if (!state.empty() && config_["format-" + state].isString()) {
|
label_.get_style_context()->remove_class(old_status_);
|
||||||
|
label_.get_style_context()->add_class(status);
|
||||||
|
old_status_ = status;
|
||||||
|
if (!state.empty() && config_["format-" + status + "-" + state].isString()) {
|
||||||
|
format = config_["format-" + status + "-" + state].asString();
|
||||||
|
}else if (config_["format-" + status].isString()) {
|
||||||
|
format = config_["format-" + status].asString();
|
||||||
|
}else if (!state.empty() && config_["format-" + state].isString()) {
|
||||||
format = config_["format-" + state].asString();
|
format = config_["format-" + state].asString();
|
||||||
}
|
}
|
||||||
if (format.empty()) {
|
if (format.empty()) {
|
||||||
|
|
Loading…
Reference in New Issue