From 8e0f3c7ddfb93491d158045677b70498cc616340 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 5 Apr 2020 16:56:51 +0200 Subject: [PATCH] feat: full-at (#649) * feat: full-at * fix(man): typo --- man/waybar-battery.5.scd | 4 ++++ src/modules/battery.cpp | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index f96f85cb..8bcd2e82 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -18,6 +18,10 @@ The *battery* module displays the current capacity and state (eg. charging) of y typeof: string ++ The adapter to monitor, as in /sys/class/power_supply/ instead of auto detect. +*full-at* ++ + typeof: integer ++ + Define the max percentage of the battery, usefull for an old battery, e.g. 96 + *interval* ++ typeof: integer ++ default: 60 ++ diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index dfd67531..e7e831c9 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -115,6 +115,16 @@ const std::tuple waybar::modules::Battery::getInfos time_remaining = -(float)(total_energy_full - total_energy) / total_power; } uint16_t capacity = total / batteries_.size(); + // Handle full-at + if (config_["full-at"].isUInt()) { + auto full_at = config_["full-at"].asUInt(); + if (full_at < 100) { + capacity = static_cast(capacity / full_at) * 100; + if (capacity > full_at) { + capacity = full_at; + } + } + } return {capacity, time_remaining, status}; } catch (const std::exception& e) { spdlog::error("Battery: {}", e.what());