Alexays / Waybar

Highly customizable Wayland bar for Sway and Wlroots based compositors. :v: :tada:
MIT License
5.81k stars 656 forks source link

modules/battery: Deprioritize `capacity` /sys value for battery calculation if other methods are available #3381

Closed OpenSauce04 closed 5 days ago

OpenSauce04 commented 5 days ago

Closes #3293

The current code for battery calculation seems to assume that the capacity value returns the non-design battery capacity. This is not the case, and it instead returns the design capacity of the battery.

Currently, the capacity value is used above all other methods if it is present in the /sys directory of the battery. This means that the design capacity of the battery will always be displayed regardless of the design-capacity configuration option.

To remedy this issue, I have restructured the code so that the capacity value is only used if the other possible options for calculation have been exhausted beforehand.

This screenshot shows two instances Waybar while the battery is plugged in at full capacity. The top instance is the current release version, and the bottom instance is the code present in this pull request: image

This pull request maintains the functionality of the design-capacity configuration option. Here is the previous screenshot taken again with design-capacity set to true: image

Please correct me if I have done anything incorrectly in this pull request, as I am not very familiar with the codebase.

OpenSauce04 commented 5 days ago

The CI failure appears to be unrelated to the code in this pull request

Alexays commented 5 days ago

LGTM