Skip to content

Fix power profile auto-switching on USB-C only machines#5444

Open
mijuny wants to merge 1 commit intobasecamp:devfrom
mijuny:power-profiles-usb-c-machines
Open

Fix power profile auto-switching on USB-C only machines#5444
mijuny wants to merge 1 commit intobasecamp:devfrom
mijuny:power-profiles-usb-c-machines

Conversation

@mijuny
Copy link
Copy Markdown

@mijuny mijuny commented Apr 25, 2026

Fixes #5412.

The current udev rule matches only ATTR{type}=="Mains", which on USB-C only laptops can fail two ways: the legacy AC device may not fire udev change events at all (the issue reporter's ThinkPad P14S Gen 6), or multiple USB-C ports show up as separate ucsi-source-psy-* devices that the rule ignores. Adding ATTR{type}=="USB" online=0/1 matchers also breaks: a per-port online=0 (port present but nothing plugged into it) fires the battery-profile rule even while another port supplies AC. For example, the Framework 13 can have 4 such ports leading to race and possible false positive battery signal.

AI disclaimer: Fixes found and done with help from Claude Code (Opus 4.7).

This PR moves the AC-vs-battery decision out of the udev rule and into the omarchy-powerprofiles-set script:

  • bin/omarchy-powerprofiles-set accepts a no-arg "auto-detect" mode that reads aggregate state across all Mains and USB power-supply devices and picks the right profile. Backwards-compatible with the existing ac / battery arguments.
  • install/config/powerprofilesctl-rules.sh simplifies the udev rule: fire on any Mains or USB power_supply change, no online filter, always call the script with no arg so it picks up current aggregate state.
  • The install hook now also runs sudo systemctl enable --now power-profiles-daemon (see the note below).
  • Migration 1777098818.sh re-runs the install hook so existing systems pick up the new rule and enable the daemon.

Note: here we would be enabling power-profiles-daemon by default

Flagging this as a deliberate policy call for the PR, not just a side effect of the bug fix. Until now Omarchy installed power-profiles-daemon (it's in omarchy-base.packages) but never enabled it. The Arch package preset leaves it disabled, so the daemon never started on boot and powerprofilesctl set calls quietly failed even when the udev rule fired. With the new rule but without enabling the daemon, the bug would be corrected in code but the fix would have no effect for users.

I think enabling it by default could be the right call, otherwise Omarchy ships with a feature that doesn't work out of the box. But happy to drop the enable --now line if we would rather keep the daemon opt-in.

#5417 also addresses #5412 (alongside two other fixes). It uses the per-port USB rule pattern (ATTR{type}=="USB", ATTR{online}=="0/1"). This PR proposes moving the decision into the script with aggregate detection, which avoids the possible multi-port race described above.

Tested on

  • ASUS ExpertBook B9406CAA (Panther Lake, 2x USB-C, AC device named AC0): plug/unplug correctly switches performancebalanced. Also exposes the bug differently from the issue reporter: AC0 does fire events here, but the daemon being disabled by package preset silently breaks profile switching anyway.
  • Framework 13 (4x USB-C, AC device named ACAD): same plug/unplug switching works; the three ports that are always online=0 (no charger) are correctly ignored by aggregate detection.

Copilot AI review requested due to automatic review settings April 25, 2026 11:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes automatic power profile switching on USB‑C–only laptops by moving AC/battery detection logic out of the udev rule and into omarchy-powerprofiles-set, while also ensuring power-profiles-daemon is enabled so powerprofilesctl calls actually take effect.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Changes:

  • Add no-arg “auto-detect” mode to omarchy-powerprofiles-set that aggregates state across power_supply devices.
  • Simplify udev rule to trigger on any Mains or USB power_supply change and always call the script in auto-detect mode.
  • Enable and start power-profiles-daemon during install/config, and add a migration to apply the updated rule + daemon enablement on existing systems.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
bin/omarchy-powerprofiles-set Adds auto-detection of AC vs battery from /sys/class/power_supply so multi-port USB‑C scenarios resolve correctly.
install/config/powerprofilesctl-rules.sh Updates udev rules to trigger broadly and enables power-profiles-daemon so profile switching works out of the box.
migrations/1777098818.sh Applies the updated udev rules and daemon enablement to already-installed systems.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread install/config/powerprofilesctl-rules.sh Outdated
@mijuny mijuny force-pushed the power-profiles-usb-c-machines branch from ee897a9 to 7e6e139 Compare April 25, 2026 11:12
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.

Auto power profile switching broken on USB-C only machines on v3.6.0

2 participants