fix: battery runtime estimation with negative sysfs values #3942
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some drivers (example: qualcomm-battmgr, present on Snapdragon X1 laptops) expose the current_now and power_now values in sysfs as negative int when the device is discharging, positive when charging.
This breaks the battery runtime estimation in Waybar, as it expects a uint32 for power_now.
Change the battery module to use the absolute values of current_now and power_now.
I discussed about it with the maintainer of qualcomm-battmgr, and the conclusion has been that it's better to fix the userland tools to respect the ABI documentation for current_now (which specifies negative values when discharging), and allows for negative values for power_now: https://lore.kernel.org/linux-arm-msm/20250213-patch-qcomm-bat-uint-power-v1-1-16e7e2a77a02@mailbox.org/