Repository navigation
Restore the keyboard backlight level after hibernation - #11669
alanwcurry-dev wants to merge 7 commits into
Conversation
The hibernate hook clears the LED before S4, because an active backlight can block the ASUS transition. Clearing it is one-way — the level cannot be read back once it reads 0 — and nothing wrote it back, so the keyboard came out of every hibernate dark and stayed dark until a brightness key was pressed. The idle-restore plugin cannot cover for it: it refuses to remember a 0. The hook now records the level before the clear and writes it back in the post phase, and only while the LED still reads 0, so a level put back by the idle-restore plugin or a lock's own restore is never fought. It also writes the LED through sysfs now that the hook is root-owned, which is what lets the tests assert the LED instead of a call to brightnessctl. omarchy-hibernation-setup returns early once hibernation is configured, so an existing install would keep the old hook; the migration replaces exactly the file this release supersedes and leaves any other hook, or a customized one, alone.
The record held a bare level, and each phase picks the first kbd_backlight device on its own. When that device changes across the hibernate, such as an external keyboard unplugged meanwhile, post would light a keyboard that was deliberately dark with another keyboard's level. Record the device beside the level and restore only when it matches. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Codex Medium <[email protected]>
sha256sum follows a symlink, so a link resolving to the superseded hook matched and mv replaced the link with a standalone file, detaching the administrator's target. 1788662350 preserves safe symlinks at the same path; this migration now does too. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: Codex Medium <[email protected]>
|
Reviewed and verified on a disposable Omarchy worker. I pushed two small fixes to your branch. Reproduction. The hook is run pre then post Migration. Run for real as root on the worker. It replaced an installed copy of the previous hook with the new one, root-owned and 0755, and a second run left it alone. The upgrade path that crosses Pushed to your branch:
Tests on the worker at The full shell suite is not green, and none of it comes from this change. On your branch as it stands, One inaccuracy, not changed. The description and the comments in the hook and its test refer to an "idle-restore plugin" with a Second opinion. Codex Medium reviewed it in two rounds. The first round found the two defects fixed above. The second, at The change is proportionate: a save and restore in the hook, plus a narrowly matched migration, which is needed because This now waits on the maintainer. |
[Low impact] The change affects keyboard backlight behavior around hibernation. The shell-style requirement in FindingsSummarySaves the keyboard backlight level before hibernation and restores it afterward.
Reviews (2) · Last reviewed commit: "Hash a readable keyboard backlight hook ..." · Reviewed by Greptile |
| printf '%s %s\n' "$device" "$(read_level "$device")" >"$level_record" | ||
| printf '0\n' >"$led" 2>/dev/null |
There was a problem hiding this comment.
|
Thanks — good to know someone is tracking the crowding, because three of the five are the same file. Same file, so only one of them survives: #11669 (this one), #13729 and #14066 all rewrite Different layers, not competing:
Which hook I would keep: #14066. It is the only one that also fixes the hooks being installed non-executable (#7618, which is why systemd-sleep was silently skipping them), it scopes the hook and its LED glob to ASUS, saves a level per LED name, and its migration recognises every version Omarchy shipped by hash while skipping symlinks and anything an administrator wrote. Its failed-save behaviour is a stated decision (the LED still goes off, and it is logged) rather than an oversight — that is the one open greptile note on mine, and theirs answers it. One thing I would carry across before it lands: the restore should only write while the LED still reads 0. During So: happy to close #11669 in favour of #14066, or of #13729 if you prefer the shared-command route. Either way I will port the "a lit LED wins" guard and my hardware logs (a real hibernate round trip, One correction to my own description, now fixed: it leaned on an "idle-restore plugin" as if it were part of Omarchy. That is a third-party plugin on my machine; upstream, the paths that relight the keyboard are |
quattro removed migration tests (omacom#16302) and its AGENTS.md now says a migration gets no suite test, so the conflicting keyboard section of system-sleep-ownership-migration-test.sh goes with that file, and keyboard-backlight-hook-migration-test.sh and its fixture are dropped. The hook test stays: it tests the hook, not the migration. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The post phase picked the first *kbd_backlight* device again and restored only when that matched the record, so a keyboard that sorts first appearing during the resume left the cleared keyboard dark. Write the level back to the recorded device itself, while it still exists. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Post exited before reading the record when no *kbd_backlight* device was listed, so the record survived in /run and a later resume could apply that level to a keyboard the cycle never cleared. Post now goes by the record alone; only pre needs a device. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: muse-wonder High <[email protected]>
The installed hook is world-readable, so a rerun for a second user can see it was already replaced without prompting for sudo, as 1788662350 does. Co-Authored-By: Claude Opus 5.5 <[email protected]> Co-Authored-By: muse-wonder High <[email protected]>
|
This branch had stopped merging into The merge ( Pushed to your branch:
Each commit has a test case except the sudo one, which was checked by hand on the worker. Verified on the worker at
Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed it in two rounds. Codex found nothing. muse-wonder found the stale record and the sudo-on-rerun issue fixed above, and the second round was clean from both. Both models, and I, agree with keeping the clear even if saving the level fails, contrary to Greptile's other comment. The clear is what keeps the S4 power-off from hanging, so a dark keyboard is the better failure. Their agreement here is not guaranteed to be independent of my own reasoning. Small things left, @alanwcurry-dev:
Waiting on the maintainer for the choices you listed: the record path, and whether the refresh belongs in this migration or in |
| installed_sha256=$(as_root sha256sum "$hook_destination" | cut -d' ' -f1) | ||
| fi | ||
|
|
||
| if [[ $installed_sha256 != "$previous_hook_sha256" ]]; then |
There was a problem hiding this comment.
Comparison breaks required shell style
This comparison quotes $previous_hook_sha256 inside [[ ]], but the repository guide requires variables to stay unquoted in these tests. Use [[ $installed_sha256 != $previous_hook_sha256 ]]. The comparison works as written, but this repository requirement must be satisfied before merging.
| if [[ $installed_sha256 != "$previous_hook_sha256" ]]; then | |
| if [[ $installed_sha256 != $previous_hook_sha256 ]]; then |
File Used: AGENTS.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
An ASUS laptop comes out of a hibernate with a dark keyboard, and it stays dark until a brightness key is pressed.
/usr/lib/systemd/system-sleep/keyboard-backlightexists so an active LED cannot hang the S4 transition, and it clears the backlight in the pre phase. Clearing is one-way — there is nothing to read back oncebrightnessis 0 — and the hook has no post phase, so the level is simply gone. Nothing else covers for it either: the paths that turn the keyboard back on areomarchy-system-wakeandomarchy-brightness-keyboard restore(brightnessctl -r), used by idle and lock, and they only replay a levelbrightnessctlsaved itself. The hook writes the LED directly and saves nothing, so once it has cleared the LED there is nothing left for them to restore.Evidence from the machine
ASUS ExpertBook PM3406CKA, Omarchy 4.0.3-1, kernel 7.2.3-arch1-3. LED set to 3, RTC alarm armed,
systemctl hibernate:The same cycle with the save/restore in place — a real hibernation, the machine off for ~140s in between, woken by the RTC alarm:
The machine this was found on also runs a third-party idle-restore plugin (not part of Omarchy), which then adopts the restored level as its own hold —
idle timeout reached; saved brightness 3, its state record holding{"brightness": 3, …}— so activity restores the user's level instead of leaving a dark keyboard.What the change does
omarchy-system-wake's restore (idle or lock) or by the user is never fought./run/omarchy-keyboard-backlight-level: it survives the hibernate inside the image and disappears on reboot.migrations/1788662350.sh) it does not needbrightnessctl, and dropping it means a missingbrightnessctlcan no longer silently skip the clear. It also lets the tests assert the LED instead of a stubbed command — the keyboard section ofsystem-sleep-ownership-migration-test.shnow does that.hibernateis touched. Suspend keeps the LED powered, so its level is never lost.Reaching existing installs
omarchy-hibernation-setupreturns early once hibernation is configured, so it never refreshes this hook on an existing machine — a fix indefault/alone would only reach fresh installs. The migration replaces the file exactly as this release supersedes it (byte-for-byte match against the previous version) and leaves everything else alone, including a customized hook and a machine where the hook was never installed. A second run is a no-op.I am happy to move that refresh into
omarchy-hibernation-setupinstead if you would rather the setup command own it; the migration exists because that early return is precisely what misses existing installs.Tests
./test/shell(239 files) in this checkout: the four files touched here pass. Five others fail, none of them related to this change —bar-icon-geometry-test.sh(a Quickshell geometry assertion),config-test.sh,snapper-test.shandunowned-system-paths-test.sh(they want anomarchy-pkgscheckout) fail identically at upstream HEAD in a clean worktree, andlocate-test.shfailed only because running the whole suite in my checkout left an ignoredbin/__pycache__/that the test reads as UTF-8 — it passes as soon as that artifact is removed.test/shell.d/keyboard-backlight-hook-test.sh(sandboxed LED via path rewrite)test/shell.d/keyboard-backlight-hook-migration-test.shsystem-sleep-ownership-migration-test.sh, updated to assert the LEDunowned-system-paths-test.shfails in this checkout with and without the change (it wants anomarchy-pkgscheckout), so that one is not from this PR.Judgement calls I can change
/run/omarchy-keyboard-backlight-level);omarchy-hibernation-setup;brightnessctlin the clear path and stub it as before.