Merge pull request #4591 from rrrnld/fix/multiple-batteries
Improve multiple battery support
This commit is contained in:
commit
11c4e55376
|
|
@ -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_;
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y
|
||||||
typeof: string ++
|
typeof: string ++
|
||||||
Command to execute when scrolling up on the module.
|
Command to execute when scrolling up on the module.
|
||||||
|
|
||||||
|
*weighted-average*: ++
|
||||||
|
typeof: bool ++
|
||||||
|
default: true ++
|
||||||
|
Option to combine multiple batteries with different capacities.
|
||||||
|
|
||||||
*on-scroll-down*: ++
|
*on-scroll-down*: ++
|
||||||
typeof: string ++
|
typeof: string ++
|
||||||
Command to execute when scrolling down on the module.
|
Command to execute when scrolling down on the module.
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue