Skip to content

fix(battery): clamp health in the bar tooltip to 100% - #4192

Merged
ItsLemmy merged 2 commits into
noctalia-dev:mainfrom
maciej-rosiek:fix/battery-tooltip-health-clamp
Sep 1, 2026
Merged

ItsLemmy merged 2 commits into
noctalia-dev:mainfrom
maciej-rosiek:fix/battery-tooltip-health-clamp

Conversation

@maciej-rosiek

@maciej-rosiek maciej-rosiek commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Move the battery health calculation onto UPowerDeviceInfo as hasHealth() and healthPercent(), clamped to [0, 100].
  • Point the bar tooltip and the control center Power tab at that one definition.
  • Add battery_health_test, covering a worn battery, a battery reporting above its design capacity, and the missing-data guards.

Motivation

BatteryWidget::syncState() printed the raw EnergyFull / EnergyFullDesign ratio, while PowerTab::syncBatteryHealth() clamped the same ratio. The two views therefore disagreed about the same battery.

A battery whose learned full-charge capacity exceeds its design capacity reports health above 100%. EnergyFullDesign is written once by the vendor; EnergyFull is re-learned by the fuel gauge and can be higher on a healthy pack.

On a Framework 13:

energy-full:         74.8218 Wh
energy-full-design:  72.5696 Wh

At the same moment, the bar tooltip read Health 103% and the Power tab read Health 100%.

docs/user/control-center/index.mdx describes the figure as "current full-charge capacity as a percentage of the original design capacity", so the clamped value is the documented one. Sharing one definition keeps the two views from drifting apart again.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Refactoring
  • Build / packaging

Related Issue

None.

Testing

  • just format with clang-format 22.1.8 — no diff.
  • just build — clean, no new warnings.
  • just test — 99 passed, 1 failed. The failure is noctalia:process (completion-only async command stdout was wrong). It fails identically on unmodified main on my NixOS host, so it is pre-existing and unrelated to this change.
  • clang-tidy 22.1.8 with -warnings-as-errors=* on the four changed files — clean. I ran it on those files rather than through just lint, which hardcodes -j $(nproc).
  • Reproduced the mismatch on the packaged build under Sway against upower -i /org/freedesktop/UPower/devices/battery_BAT1.

Manual Coverage

  • Tested on Niri
  • Tested on Hyprland
  • Tested on Sway
  • Tested on another compositor:
  • Tested with different bar positions and density settings
  • Tested at different interface scaling values
  • Tested with multiple monitors

Screenshots / Videos

image

Checklist

  • This PR is ready for review, or it is marked as Draft.
  • I read and followed the relevant guidance in CONTRIBUTING.md.
  • I ran just format with clang-format v22+ installed, or this PR has no code changes.
  • I ran the relevant build or test commands, or explained why they were not run.
  • I self-reviewed the changes.
  • I checked for new warnings or errors.
  • I updated user-facing documentation in docs/user/ when this PR changes documented behavior or configuration, or this PR does not require documentation changes.
  • I added or updated assets/translations/en.json, or this PR adds no new user-facing strings.
  • I did not edit non-English translation files unless this PR is explicitly for translation tooling, an import/export sync, or a maintainer-requested locale change.
  • I used the existing canonical names for config keys, IPC names, paths, and identifiers.

Additional Notes

Reuses the existing power.battery.tooltip.health string, so there is no translation impact.

I used Claude Code to write this change, and reviewed it myself. The commit carries an Assisted-by: trailer.

@maciej-rosiek
maciej-rosiek force-pushed the fix/battery-tooltip-health-clamp branch from 662c581 to 0086c47 Compare September 1, 2026 11:25
The bar tooltip printed the raw EnergyFull / EnergyFullDesign ratio, so a
battery whose learned full-charge capacity is above its design capacity
showed values like 103%. The control center Power tab clamped the same
ratio, so the two views disagreed about the same battery.

Move the calculation onto UPowerDeviceInfo as hasHealth() and
healthPercent() so both views share one definition, and cover it with
battery_health_test.

Assisted-by: Opus 5 (1M context), claude-code v2.1.250
@maciej-rosiek
maciej-rosiek force-pushed the fix/battery-tooltip-health-clamp branch from 0086c47 to 52e2518 Compare September 1, 2026 11:30
@ItsLemmy
ItsLemmy merged commit 35483a7 into noctalia-dev:main Sep 1, 2026
@ItsLemmy

ItsLemmy commented Sep 1, 2026

Copy link
Copy Markdown
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants