Merge pull request #76 from mithodin/charging-full
Add class for full battery and give option to interpret unknown as full
This commit is contained in:
commit
cf921a5e14
|
@ -23,12 +23,13 @@ class Battery : public ALabel {
|
||||||
|
|
||||||
void worker();
|
void worker();
|
||||||
std::tuple<uint16_t, std::string> getInfos();
|
std::tuple<uint16_t, std::string> getInfos();
|
||||||
std::string getState(uint16_t, bool);
|
std::string getState(uint16_t);
|
||||||
|
|
||||||
util::SleeperThread thread_;
|
util::SleeperThread thread_;
|
||||||
util::SleeperThread threadTimer_;
|
util::SleeperThread threadTimer_;
|
||||||
std::vector<fs::path> batteries_;
|
std::vector<fs::path> batteries_;
|
||||||
int fd_;
|
int fd_;
|
||||||
|
std::string old_status_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ std::tuple<uint16_t, std::string> waybar::modules::Battery::getInfos()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
uint16_t total = 0;
|
uint16_t total = 0;
|
||||||
std::string status;
|
std::string status = "Unknown";
|
||||||
for (auto const& bat : batteries_) {
|
for (auto const& bat : batteries_) {
|
||||||
uint16_t capacity;
|
uint16_t capacity;
|
||||||
std::string _status;
|
std::string _status;
|
||||||
|
@ -85,7 +85,7 @@ std::tuple<uint16_t, std::string> waybar::modules::Battery::getInfos()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string waybar::modules::Battery::getState(uint16_t capacity, bool charging)
|
std::string waybar::modules::Battery::getState(uint16_t capacity)
|
||||||
{
|
{
|
||||||
// Get current state
|
// Get current state
|
||||||
std::vector<std::pair<std::string, uint16_t>> states;
|
std::vector<std::pair<std::string, uint16_t>> states;
|
||||||
|
@ -102,7 +102,7 @@ std::string waybar::modules::Battery::getState(uint16_t capacity, bool charging)
|
||||||
});
|
});
|
||||||
std::string validState = "";
|
std::string validState = "";
|
||||||
for (auto state : states) {
|
for (auto state : states) {
|
||||||
if (capacity <= state.second && !charging && validState.empty()) {
|
if (capacity <= state.second && validState.empty()) {
|
||||||
label_.get_style_context()->add_class(state.first);
|
label_.get_style_context()->add_class(state.first);
|
||||||
validState = state.first;
|
validState = state.first;
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,21 +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) {
|
auto state = getState(capacity);
|
||||||
label_.get_style_context()->add_class("charging");
|
label_.get_style_context()->remove_class(old_status_);
|
||||||
if (config_["format-charging"].isString()) {
|
label_.get_style_context()->add_class(status);
|
||||||
format = config_["format-charging"].asString();
|
old_status_ = status;
|
||||||
}
|
if (!state.empty() && config_["format-" + status + "-" + state].isString()) {
|
||||||
} else {
|
format = config_["format-" + status + "-" + state].asString();
|
||||||
label_.get_style_context()->remove_class("charging");
|
} else if (config_["format-" + status].isString()) {
|
||||||
if (status == "Full" && config_["format-full"].isString()) {
|
format = config_["format-" + status].asString();
|
||||||
format = config_["format-full"].asString();
|
} else if (!state.empty() && config_["format-" + state].isString()) {
|
||||||
}
|
|
||||||
}
|
|
||||||
auto state = getState(capacity, charging);
|
|
||||||
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