Skip to content

Show OSD when ACPI platform profile changes#5802

Open
nicx01 wants to merge 2 commits into
basecamp:devfrom
nicx01:powerprofiles-osd-watch
Open

Show OSD when ACPI platform profile changes#5802
nicx01 wants to merge 2 commits into
basecamp:devfrom
nicx01:powerprofiles-osd-watch

Conversation

@nicx01
Copy link
Copy Markdown

@nicx01 nicx01 commented May 13, 2026

Summary

  • Adds an OSD (via SwayOSD) when the ACPI platform profile changes — e.g. when the ThinkPad mode key cycles between Power Saver / Balanced / Performance. Today the profile changes silently and the user gets no feedback, unlike volume or brightness.
  • Implemented as a small user-level service: omarchy-powerprofiles-osd-watch (Python, stdlib only) + omarchy-powerprofiles-osd.service, plus a first-run hook for new installs and a migration to enable it for existing users.

Why POLLPRI instead of listening to power-profiles-daemon?

I initially listened to net.hadess.PowerProfiles PropertiesChanged. That works but the OSD consistently lagged ~2 seconds behind the actual hardware change. Diagnosing it with three parallel detectors:

+11.710s [POLLPRI ] sysfs=performance     ← kernel/firmware updated /sys
+11.712s [INOTIFY ] event=changed
+13.713s [INOTIFY ] event=changes-done-hint
+13.730s [DBUS    ] ActiveProfile=performance

power-profiles-daemon uses GLib's GFileMonitor on /sys/firmware/acpi/platform_profile, and GLib coalesces changed events with a fixed ~2s window before firing changes-done-hint. The daemon only emits the DBus signal at the end of that window. Watching the sysfs file directly with POLLPRI reacts to the kernel's notification immediately.

Files

  • bin/omarchy-powerprofiles-osd-watch — Python stdlib watcher (select.poll() + POLLPRI on the sysfs node).
  • config/systemd/user/omarchy-powerprofiles-osd.serviceType=simple, ordered after swayosd-server.service.
  • install/first-run/powerprofiles-osd.sh — enables the service on new installs.
  • migrations/1778646038.sh — installs the unit file and enables the service for existing users.

Notes

  • Works on any laptop that exposes /sys/firmware/acpi/platform_profile. If the node is absent the watcher exits cleanly and the service goes inactive — no impact on unsupported hardware.
  • Tested on a Lenovo ThinkPad Z13 G2 (AMD, amd_pstate); the visible OSD latency went from ~2 s to effectively instant on mode-key press.
  • Icons used are the standard freedesktop power-profile-*-symbolic names that current icon themes already ship.

Test plan

  • Fresh install: install/first-run/powerprofiles-osd.sh enables the service, mode key shows the OSD.
  • Existing user runs omarchy update: migration 1778646038.sh enables the service.
  • CLI powerprofilesctl set performance|balanced|power-saver also produces an OSD.
  • On a machine without /sys/firmware/acpi/platform_profile, the service exits cleanly.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 13, 2026 13:06
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

Adds an immediate on-screen display (OSD) via SwayOSD when the ACPI platform profile changes (e.g., ThinkPad performance-mode key), implemented as a user-level systemd service backed by a small Python sysfs watcher.

Changes:

  • Add omarchy-powerprofiles-osd-watch (Python) to watch /sys/firmware/acpi/platform_profile via POLLPRI and trigger an OSD.
  • Add a user systemd unit to run the watcher after swayosd-server.service.
  • Add first-run and migration hooks intended to enable the service for new and existing installs.

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.

Reviewed changes

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

File Description
bin/omarchy-powerprofiles-osd-watch New watcher that polls the ACPI platform profile sysfs node and triggers SwayOSD.
config/systemd/user/omarchy-powerprofiles-osd.service New user service unit to run the watcher alongside the graphical session and SwayOSD.
install/first-run/powerprofiles-osd.sh Intended first-run enablement hook for fresh installs.
migrations/1778646038.sh Migration to install the unit file and enable the service for existing users.

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

@@ -0,0 +1 @@
systemctl --user enable --now omarchy-powerprofiles-osd.service
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch — fixed in c79d8f3 by adding the script to the explicit enumeration in bin/omarchy-first-run right after swayosd.sh.

nicx01 added 2 commits May 13, 2026 15:20
The ThinkPad mode key (and any other hardware/userspace path that flips
the ACPI platform profile) now produces a SwayOSD with the new profile
name and a freedesktop power-profile icon, mirroring how volume and
brightness changes already surface to the user.

The watcher reads /sys/firmware/acpi/platform_profile and uses POLLPRI
to react to firmware-driven changes. This deliberately bypasses
power-profiles-daemon's PropertiesChanged signal, which is gated behind
GLib's GFileMonitor "changes-done-hint" event and therefore arrives
~2 seconds after the firmware updated the file. POLLPRI fires as soon
as the kernel sees the value change, so the OSD is effectively
instantaneous.
bin/omarchy-first-run enumerates first-run scripts explicitly, so adding
install/first-run/powerprofiles-osd.sh alone never runs on fresh
installs. Invoke it right after the SwayOSD setup.
@nicx01 nicx01 force-pushed the powerprofiles-osd-watch branch from c79d8f3 to 5fc30e2 Compare May 13, 2026 13:23
@nicx01 nicx01 requested a review from Copilot May 13, 2026 13:28
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

Copilot reviewed 3 out of 5 changed files in this pull request and generated no new comments.

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