From 968d9c753f5119e7be92d06262a4aa4f20e8e83c Mon Sep 17 00:00:00 2001
From: Qntn <62796186+qtaped@users.noreply.github.com>
Date: Mon, 17 Jan 2022 22:07:07 +0000
Subject: [PATCH] fix(battery): More accurate battery state (#2556)
Fixes #2563
Closes #2363
* Get battery status before adapter. (#2363)
* changelog: Move to Fixed section
Co-authored-by: patrick96
---
CHANGELOG.md | 2 ++
src/modules/battery.cpp | 10 +++++-----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ddc09a1..ada85b87 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -201,6 +201,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([`#1915`](https://github.com/polybar/polybar/issues/1915))
- `internal/network`: The module now properly supports 'altnames' for
interfaces.
+- `internal/battery`: More accurate battery state
+([`#2563`](https://github.com/polybar/polybar/issues/2563))
- Some modules stop updating when system time moves backwards. ([`#857`](https://github.com/polybar/polybar/issues/857), [`#1932`](https://github.com/polybar/polybar/issues/1932))
## [3.5.7] - 2021-09-21
diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp
index e0f47c98..1bdff9bc 100644
--- a/src/modules/battery.cpp
+++ b/src/modules/battery.cpp
@@ -35,11 +35,11 @@ namespace modules {
auto path_battery = string_util::replace(PATH_BATTERY, "%battery%", m_conf.get(name(), "battery", "BAT0"s)) + "/";
// Make state reader
- if (file_util::exists((m_fstate = path_adapter + "online"))) {
+ if (file_util::exists((m_fstate = path_battery + "status"))) {
+ m_state_reader =
+ make_unique([=] { return file_util::contents(m_fstate).compare(0, 8, "Charging") == 0; });
+ } else if (file_util::exists((m_fstate = path_adapter + "online"))) {
m_state_reader = make_unique([=] { return file_util::contents(m_fstate).compare(0, 1, "1") == 0; });
- } else if (file_util::exists((m_fstate = path_battery + "status"))) {
- m_state_reader =
- make_unique([=] { return file_util::contents(m_fstate).compare(0, 8, "Charging") == 0; });
} else {
throw module_error("No suitable way to get current charge state");
}
@@ -261,7 +261,7 @@ namespace modules {
case battery_module::state::LOW:
if (m_formatter->has_format(FORMAT_LOW)) {
return FORMAT_LOW;
- }
+ }
return FORMAT_DISCHARGING;
case battery_module::state::DISCHARGING: return FORMAT_DISCHARGING;
default: return FORMAT_CHARGING;