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;