Always mark battery as full at 100%

Since we're now clamping at 100% and rounding, mark as full at that
point. Some batteries will stay in charging state for a long time while
stuck at the same charge level. Just mark them as full to not be
confusing.
This commit is contained in:
Pedro Côrte-Real 2020-11-26 02:34:36 +00:00
parent eb3f4216d4
commit f45d582957

View File

@ -134,11 +134,17 @@ const std::tuple<uint8_t, float, std::string> waybar::modules::Battery::getInfos
}
if (capacity > 100.f) {
// This can happen when the battery is calibrating and goes above 100%
// Handle it gracefully by clamping at 100% and presenting it as full
// Handle it gracefully by clamping at 100%
capacity = 100.f;
}
uint8_t cap = round(capacity);
if (cap == 100) {
// If we've reached 100% just mark as full as some batteries can stay
// stuck reporting they're still charging but not yet done
status = "Full";
}
return {round(capacity), time_remaining, status};
return {cap, time_remaining, status};
} catch (const std::exception& e) {
spdlog::error("Battery: {}", e.what());
return {0, 0, "Unknown"};