Fix power profile auto-switching on USB-C only machines#5444
Open
mijuny wants to merge 1 commit intobasecamp:devfrom
Open
Fix power profile auto-switching on USB-C only machines#5444mijuny wants to merge 1 commit intobasecamp:devfrom
mijuny wants to merge 1 commit intobasecamp:devfrom
Conversation
Contributor
There was a problem hiding this comment.
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-setthat aggregates state across power_supply devices. - Simplify udev rule to trigger on any
MainsorUSBpower_supply change and always call the script in auto-detect mode. - Enable and start
power-profiles-daemonduring 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.
ee897a9 to
7e6e139
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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. AddingATTR{type}=="USB"online=0/1 matchers also breaks: a per-portonline=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-setscript:bin/omarchy-powerprofiles-setaccepts 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 existingac/batteryarguments.install/config/powerprofilesctl-rules.shsimplifies 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.sudo systemctl enable --now power-profiles-daemon(see the note below).1777098818.shre-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 inomarchy-base.packages) but never enabled it. The Arch package preset leaves it disabled, so the daemon never started on boot andpowerprofilesctl setcalls 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 --nowline 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
AC0): plug/unplug correctly switchesperformance↔balanced. Also exposes the bug differently from the issue reporter:AC0does fire events here, but the daemon beingdisabledby package preset silently breaks profile switching anyway.ACAD): same plug/unplug switching works; the three ports that are alwaysonline=0(no charger) are correctly ignored by aggregate detection.