From 17291dffdf623f21fe9902d59a0cf90b4f6a594e Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 17 May 2019 10:59:54 +0200 Subject: [PATCH] fix(Battery): plugged state --- src/modules/battery.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index b01ff2b..2c1cc11 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -93,10 +93,14 @@ const std::tuple waybar::modules::Battery::getIn total += capacity; total_current += current_now; } - uint16_t capacity = total / batteries_.size(); - if (status == "Charging" && total_current != 0) { - status = "Plugged"; + if (!adapter_.empty() && status == "Discharging") { + bool online; + std::ifstream(adapter_ / "online") >> online; + if (online) { + status = "Plugged"; + } } + uint16_t capacity = total / batteries_.size(); return {capacity, total_current, status}; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; @@ -113,7 +117,7 @@ const std::string waybar::modules::Battery::getAdapterStatus(uint8_t capacity, return "Full"; } if (online) { - return current_now == 0 ? "Charging" : "Plugged"; + return "Charging"; } return "Discharging"; }