Repository navigation
Port omarchy-powerd daemon to C99 with native sd-bus - #231
Conversation
Replaces the 1,330-line Python 3 system/overlay/usr/libexec/omarchy-powerd daemon (plus its resident busctl monitor, systemd-inhibit, and sleep helper processes) with a single C99 binary (desktop/configuration/powerd.c, ~84 KB ELF, linked with libsystemd, pthread, and libm). Key improvements: - Replaces 4 resident processes (~20 MiB total RSS/Swap) with 1 C99 process (~1.5 MiB RSS). - Uses native sd-bus directly for logind PrepareForSleep and NameOwnerChanged signals, Inhibit() delay lock fd, CanSuspend, BlockInhibited, and systemd-suspend.service ActiveState polling. - Preserves the complete state machine (including low-battery sleep protection), evdev key/cover/combo handling, netlink power-supply uevents, smoothstep backlight fades, brightness persistence, locked USB authorization control, and /run/omarchy-powerd.sock protocol. Assisted-by: LLM
Makefile always builds omarchy-powerd with -DHAVE_SD_BUS and libsystemd, while the unit test harnesses compile without HAVE_SD_BUS on minimal CI runners that lack libsystemd-dev. Assisted-by: LLM
powerd.c includes linux/input.h and netlink headers, which macOS lacks; the repository's suite is green on both, and a test that needs what a Mac lacks skips with its reason (AGENTS.md). Assisted-by: LLM
|
@tcballard one thing to fix before this can land: the power daemon needs systemd's library headers to build, but the package recipe doesn't declare them as a build dependency, so it only builds where the container happens to have them. Its suspend/sleep path is also skipped in the tests when the headers are missing, so CI doesn't cover it. Could you add the build dependency and make the tests cover that path? The other helper PRs (#222, #227–#230) can then go in one after another. |
The loop tests ran the daemon with OMARCHY_POWERD_NO_DBUS, so the code that takes logind's delay inhibitor, follows PrepareForSleep and asks CanSuspend over sd-bus never ran in CI, and a machine without libsystemd's headers built the tests without it. The new LogindOverDbus tests start a private dbus-daemon and a small fake logind (sd-bus, compiled from the test file) and check that the daemon holds the inhibitor, releases it for a suspend from elsewhere after darkening, asks CanSuspend over the bus before its own suspend, ends that sleep on logind's signal, and takes the inhibitor again when logind restarts. CI installs libsystemd's headers and sets OMARCHY_TEST_REQUIRE_SD_BUS, so these tests can't silently skip there. Assisted-by: LLM
# Conflicts: # CHANGELOG.md # desktop/install-tree
omarchy-a's power daemon (omarchy-powerd, OrchardLinux/omarchy-a#231) is C built against libsystemd's sd-bus. Its headers and pkg-config file are in systemd-libs; name it in makedepends instead of relying on the build container happening to have it. Assisted-by: LLM
|
Merged, thank you Tom! The power daemon in C is a big win on the 1 GB boards. What we added on your branch, as Henrik asked: the D-Bus side now has its own tests. They start a private bus with a small fake logind and check that powerd holds its sleep inhibitor, lets go of it for a suspend from elsewhere only after the screen is dark, asks CanSuspend over the bus before its own suspend, ends that sleep on logind's signal, and takes the inhibitor again when logind restarts. CI installs libsystemd's headers and fails instead of skipping if they're missing. The package recipe now names systemd-libs as a build dependency (OrchardLinux/packages#41). We also merged main in and wrote the changelog line. |
At desktop idle the shell was spawning 8 processes per second because panels/power/Status.qml ran a 1-second omarchy-battery-status timer (which also forked awk) across four live instances (bar, lock screen, control center, and power panel). RotationLock.qml likewise ran four separate 2-second polling timers and four startup busctl probes. - Compute omarchy-battery-status size and rate in pure bash without awk (guarding optional sysfs reads, octal leading zeros, and integer width), keeping the charge_full -> mAh fallback for charge-reporting gauges. - Share one UPower-signal-driven BatteryStatus singleton (30 s fallback, coalesced concurrent refreshes, on-demand refresh when Control Center or Power panel opens). - Share one RotationLockState singleton watching the config directory (and its parent for directory replacement) with one busctl probe and a shared setLocked() helper used by both Control Center and Display settings. [Orchard: cut to the battery and rotation-lock readers, with both of the PR's commits folded into one; the auto-brightness and omarchy-powerd wakeup changes are left out, since those daemons are being ported to C (OrchardLinux#230, OrchardLinux#231), where the same fixes belong.] Assisted-by: LLM
Replaces the 1,330-line Python 3
omarchy-powerddaemon (plus its residentbusctl monitor,systemd-inhibit, andsleep infinityhelpers) with a single C99 binary (desktop/configuration/powerd.c, ~84 KB ELF, linked withlibsystemd,-lpthread,-lm).sd-busdirectly forPrepareForSleep,NameOwnerChanged,Inhibit()delay lock fd,CanSuspend,BlockInhibited, andsystemd-suspend.serviceActiveState./run/omarchy-powerd.sockprotocol.tests/test_powerd.pyandtests/test_low_battery.pyto compilepowerd.cand run the exhaustive state-space walk, unit tests, low-battery tests, and real C99EventLooptests against the binary.Tested: 112/112 pass (
test_powerd.py,test_low_battery.py,test_package_staging.py,test_package.py).