fix: default weighted average to true

This commit is contained in:
arne 2025-10-26 06:43:28 +01:00
parent b701d7f70b
commit ca62481dc9
3 changed files with 6 additions and 4 deletions

View File

@ -46,6 +46,7 @@ class Battery : public ALabel {
std::string old_status_; std::string old_status_;
std::string last_event_; std::string last_event_;
bool warnFirstTime_{true}; bool warnFirstTime_{true};
bool weightedAverage_{true};
const Bar& bar_; const Bar& bar_;
util::SleeperThread thread_; util::SleeperThread thread_;

View File

@ -93,7 +93,7 @@ The *battery* module displays the current capacity and state (eg. charging) of y
*weighted-average*: ++ *weighted-average*: ++
typeof: bool ++ typeof: bool ++
default: false ++ default: true ++
Option to combine multiple batteries with different capacities. Option to combine multiple batteries with different capacities.
*on-scroll-down*: ++ *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 *<event-name>* (typeof: *string*) and a *<command>* (typeof: *string*). ++ Every entry in the *events* object consists of a *<event-name>* (typeof: *string*) and a *<command>* (typeof: *string*). ++
*<event-name>* can be in one of the following formats: *<event-name>* can be in one of the following formats:
- *on-<status>-<state>* - *on-<status>-<state>*
- *on-<status>-<capacity>* - *on-<status>-<capacity>*
Where: Where:

View File

@ -27,6 +27,8 @@ waybar::modules::Battery::Battery(const std::string& id, const Bar& bar, const J
if (global_watch < 0) { if (global_watch < 0) {
throw std::runtime_error("Could not watch for battery plug/unplug"); throw std::runtime_error("Could not watch for battery plug/unplug");
} }
if (config_["weighted-average"].isBool()) weightedAverage_ = config_["weighted-average"].asBool();
#endif #endif
spdlog::debug("battery: worker interval is {}", interval_.count()); spdlog::debug("battery: worker interval is {}", interval_.count());
worker(); worker();
@ -585,8 +587,7 @@ waybar::modules::Battery::getInfos() {
} }
// Handle weighted-average // Handle weighted-average
if ((config_["weighted-average"].isBool() ? config_["weighted-average"].asBool() : false) && if (weightedAverage_ && total_energy_exists && total_energy_full_exists) {
total_energy_exists && total_energy_full_exists) {
if (total_energy_full > 0.0f) if (total_energy_full > 0.0f)
calculated_capacity = ((float)total_energy * 100.0f / (float)total_energy_full); calculated_capacity = ((float)total_energy * 100.0f / (float)total_energy_full);
} }