Merge pull request #4591 from rrrnld/fix/multiple-batteries

Improve multiple battery support
This commit is contained in:
Alexis Rouillard
2025-12-18 19:02:31 +01:00
committed by GitHub
3 changed files with 10 additions and 3 deletions

View File

@ -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);
}