Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/modules/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down
7 changes: 6 additions & 1 deletion man/waybar-battery.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y
typeof: string ++
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*: ++
typeof: string ++
Command to execute when scrolling down on the module.
Expand Down Expand Up @@ -175,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*). ++
*<event-name>* can be in one of the following formats:

- *on-<status>-<state>*
- *on-<status>-<state>*
- *on-<status>-<capacity>*

Where:
Expand Down
5 changes: 3 additions & 2 deletions src/modules/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down