From f45d5829577d59eb9980a31793f2feb2f0c15eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20C=C3=B4rte-Real?= Date: Thu, 26 Nov 2020 02:34:36 +0000 Subject: [PATCH] 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. --- src/modules/battery.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index eece435a..2d553705 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -134,11 +134,17 @@ const std::tuple 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"};