From ca62481dc9bc5567b9febb290c38def5e34ba91c Mon Sep 17 00:00:00 2001 From: arne Date: Sun, 26 Oct 2025 06:43:28 +0100 Subject: [PATCH] fix: default weighted average to true --- include/modules/battery.hpp | 1 + man/waybar-battery.5.scd | 4 ++-- src/modules/battery.cpp | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index c593e59b..264edc6e 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -46,6 +46,7 @@ class Battery : public ALabel { std::string old_status_; std::string last_event_; bool warnFirstTime_{true}; + bool weightedAverage_{true}; const Bar& bar_; util::SleeperThread thread_; diff --git a/man/waybar-battery.5.scd b/man/waybar-battery.5.scd index 5da7d91d..6d98fd4e 100644 --- a/man/waybar-battery.5.scd +++ b/man/waybar-battery.5.scd @@ -93,7 +93,7 @@ The *battery* module displays the current capacity and state (eg. charging) of y *weighted-average*: ++ typeof: bool ++ - default: false ++ + default: true ++ Option to combine multiple batteries with different capacities. *on-scroll-down*: ++ @@ -180,7 +180,7 @@ The *battery* module allows one to define custom formats based on up to two fact Every entry in the *events* object consists of a ** (typeof: *string*) and a ** (typeof: *string*). ++ ** can be in one of the following formats: -- *on--* +- *on--* - *on--* Where: diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index 138432d0..dcfce6f0 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -27,6 +27,8 @@ waybar::modules::Battery::Battery(const std::string& id, const Bar& bar, const J if (global_watch < 0) { throw std::runtime_error("Could not watch for battery plug/unplug"); } + + if (config_["weighted-average"].isBool()) weightedAverage_ = config_["weighted-average"].asBool(); #endif spdlog::debug("battery: worker interval is {}", interval_.count()); worker(); @@ -585,8 +587,7 @@ waybar::modules::Battery::getInfos() { } // Handle weighted-average - if ((config_["weighted-average"].isBool() ? config_["weighted-average"].asBool() : false) && - total_energy_exists && total_energy_full_exists) { + if (weightedAverage_ && total_energy_exists && total_energy_full_exists) { if (total_energy_full > 0.0f) calculated_capacity = ((float)total_energy * 100.0f / (float)total_energy_full); }