Skip to content

Fix keyboard backlight restore after screensaver dismiss - #10366

Open
marcindyguda wants to merge 7 commits into
omacom:quattrofrom
marcindyguda:fix/keyboard-backlight-stale-restore
Open

marcindyguda wants to merge 7 commits into
omacom:quattrofrom
marcindyguda:fix/keyboard-backlight-stale-restore

Conversation

@marcindyguda

@marcindyguda marcindyguda commented Sep 5, 2026 •

Copy link
Copy Markdown

Problem

After the screensaver shows and is dismissed (before the lock deadline), the keyboard backlight stays dark instead of keeping its previous brightness.

Root cause

  • Lock blanking (shell/plugins/lock/Service.qml blankProcess) runs omarchy-brightness-keyboard off = brightnessctl -s set 0 (save + off).
  • Wake (bin/omarchy-system-wake) runs omarchy-brightness-keyboard restore = brightnessctl -r.
  • But screensaver dismiss (shell/plugins/services/idle/Service.qml cancelIdleCycle) also runs omarchy-system-wake without any preceding off, so restore applied a stale save (often 0 from an earlier cycle) and clobbered the still-lit keyboard. A repeated off while already at zero had the same clobbering effect on the save file.

Reproduced live on a MacBook (kbd_backlight, max 255): stray restore with no preceding off reset a lit keyboard to the stale saved value.

Fix

bin/omarchy-brightness-keyboard now pairs off/restore with a marker file (${XDG_RUNTIME_DIR:-/tmp}/omarchy-keyboard-backlight-off):

  • off only saves (-s) when the keyboard is actually lit; a repeated off at zero is a plain set 0 that leaves the save intact.
  • restore is a no-op without the marker (screensaver dismiss), one-shot (clears the marker), and leaves an already-lit keyboard alone.

No caller changes needed; omarchy-system-wake keeps calling restore.

Verification

  • New test/shell.d/keyboard-backlight-test.sh passes; idle-test.sh passes (bin-style-test.sh failure is pre-existing on clean checkout, unrelated omarchy-remove-ai-openclaw).
  • Live check: 25 -> off -> 0 (marker) -> restore -> 25 (marker cleared); stray restore on a lit keyboard is a no-op.

Fixes #12942

Fixes #14011

Fixes #10767

Fixes #12274

omarchybot and others added 3 commits October 2, 2026 07:00
The backlight keys stay bound on the lock screen, so a user can change the level after a blank. Restore only treated a nonzero level as their choice, so stepping down to 0 while locked was undone by the next wake. Clearing the marker on up, down and cycle makes any level chosen by hand final.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Codex Medium <[email protected]>
A failed set leaves the keyboard blanked, so the saved level is still the one to restore.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Codex Medium <[email protected]>
Removing the marker before brightnessctl -r meant a failed restore left the keyboard dark with nothing for the next wake to retry. brightnessctl -r exits 0 when its write is refused, so the level is read back instead: the marker goes once the keyboard is lit, whether the restore lit it or it already was.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Codex Medium <[email protected]>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 2, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed and verified at 3ff0554. The cause is as described: omarchy-system-wake runs omarchy-brightness-keyboard restore when a screensaver is dismissed, although nothing blanked the keyboard. That applies whatever brightnessctl -s last saved, and a second off at 0 saves 0 over the real level.

How it was checked. The test in this PR only greps for strings, so I wrote a separate reproduction. It ran on a disposable Omarchy worker against a real LED device (uleds, omabot::kbd_backlight, max 255), driving off, restore, omarchy-system-wake and the up/down keys through 17 checks. On quattro (821ae58), 8 fail: a screensaver dismiss darkens a lit keyboard, restores an old level over a newer one, or re-lights a keyboard the user turned off; a repeated blank restores 0; a level set on the lock screen is thrown away. On this branch, and on it merged into quattro, all 17 pass. keyboard-backlight-test.sh, idle-test.sh, bin-style-test.sh and brightness-keys-test.sh pass on the worker. ./test/cli has one failure, vscode generated theme references current theme file, which fails the same way on quattro 821ae58 without this change.

Pushed to the branch, from the review rounds:

  • 4acc229 and a1623b8: a backlight key pressed on the lock screen now cancels the pending restore once its write succeeds. Before this, stepping the keyboard down to 0 while locked was undone at unlock, because restore treated only a nonzero level as the user's choice.
  • 3ff0554: restore keeps the marker until the keyboard is actually lit again, so a failed restore can be retried by the next wake. brightnessctl -r exits 0 even when its write is refused (checked on the worker), so the script reads the level back instead of trusting the exit status.

Second opinion: Codex Medium reviewed four rounds. It found both of the follow-up defects above, agreed the approach is the right one, and its last round on 3ff0554 found nothing further. Its agreement is not guaranteed to be independent of this review.

Competing fixes: #12960 (only save when lit) and #12502 (only restore at 0, plus a wake on resume in the lock service) cover parts of the same bug. Run through the first eight of the same checks, #12960 fails four and #12502 fails two, including re-lighting a keyboard the user turned off after a lock cycle. Neither can tell a deliberate 0 from a blank, and the marker here can. #12502's resume runWake() addresses a separate path. With this change, the repeated blank it causes no longer loses the saved level.

Not fixed here, for the maintainer:

This now closes #12942, #14011, #10767 and #12274; it does not fix #6667, where Dell's firmware timeout zeroes the light before the lock. Waiting on the maintainer: the review is done, and the one failing CLI test is quattro's, not this branch's.

@greptile-apps

greptile-apps Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The latest changes appear safe to merge; the earlier shared /tmp fallback concern remains non-blocking.

Findings

  1. P2 Security Fallback marker is shared ▶

Summary

Updates keyboard brightness changes so they do not hold the lock while showing the OSD.

  • Keyboard wake keeps brightness changes made while the lock is showing.

Reviews (3) · Last reviewed commit: "Release the keyboard lock before the OSD..." · Reviewed by Greptile

Comment thread bin/omarchy-brightness-keyboard Resolved
Comment thread bin/omarchy-brightness-keyboard Resolved
Comment thread bin/omarchy-brightness-keyboard Outdated
# later restore without a preceding off (e.g. screensaver dismiss, which wakes
# via omarchy-system-wake without ever blanking the keyboard) is a no-op
# instead of restoring a stale brightnessctl save.
state_marker="${XDG_RUNTIME_DIR:-/tmp}/omarchy-keyboard-backlight-off"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 security Fallback marker is shared

If XDG_RUNTIME_DIR is unset, the marker uses the same predictable /tmp path for every user. Another user can create that file, causing an unpaired wake to attempt a stale brightness restore. Use user-private state so one user's marker cannot affect another user's keyboard.

How this was verified: The fallback path is shared across users, and restore checks only for the file's existence before calling brightnessctl -r.

Comment thread test/shell.d/keyboard-backlight-test.sh Resolved
@Sha01in

Sha01in commented Oct 6, 2026

Copy link
Copy Markdown

Tested this on a 2017 Google Pixelbook (Eve), Omarchy 4.0.4, by running this PR's omarchy-brightness-keyboard against the stock one (the installed script matches quattro):

Steps Stock This PR
blank (off), wake, raise the level twice, wake reverted to the old level keeps the new level
cycle to off, wake turned back on stays off
set 60, blank, wake 60 60
set 60, blank twice, wake stays off 60

So this also covers #12274 (a manual change, including turning it off, gets reverted on the next wake) and the repeated-blank case in #12942 / #14011.

AI disclosure: tested with help from Claude Code (Opus 5.5); I ran it on the hardware.

omarchybot and others added 2 commits November 1, 2026 03:04
…ware levels

omacom#15908 landed the repeated-blank and unpaired-restore fixes on quattro with a level record and a lock, so this branch now builds on that instead of its own marker. What it still adds: a level changed with the keys while blanked replaces the record, unless the key changed nothing (down at 0), and restore leaves a backlight that something else lit since the blank, as a firmware key does, at its level.

The grep-only keyboard-backlight-test.sh is replaced by behavioural cases in quattro's brightness-keyboard-test.sh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A key that changes the level now deletes the saved record, so it is a third writer beside off and restore. Outside the lock, a key landing between off saving the level and setting 0 deleted the record before the blank, and the next wake left the keyboard dark; and a key landing inside a restore was overwritten by it.

The keys test now also steps up and back down to 0 while blanked, which only the key path's record deletion keeps off.

Co-Authored-By: Codex Medium <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

This branch stopped merging after #15908 landed on quattro (0c29fa5). That change rewrote off and restore in bin/omarchy-brightness-keyboard around a saved-level record and a lock. I merged quattro into the branch and pushed the result, so it merges cleanly again at bb98cf4.

What quattro already fixes. A repeated blank no longer saves 0 over the level, and a restore with no blank before it (a screensaver dismissed before the lock) leaves the keyboard alone. That covers #12942 and the screensaver case in #10767, so the marker file this branch used to add is gone. The branch now builds on #15908's record instead.

What this still fixes. On quattro, a level chosen on the lock screen is thrown away at unlock: the restore writes back the level from before the blank. With this branch:

  • A brightness key that changes the level while the keyboard is blanked replaces the saved level, including a step back down to 0. A key that changes nothing, such as down at 0, keeps it, so the unlock still relights the keyboard.
  • restore leaves alone a keyboard that something else has lit since the blank, such as a firmware-handled key (Fn+Space on a ThinkPad).
  • The brightness keys take the same lock as off and restore. Without it, a key pressed between the blank saving the level and setting 0 deleted the record, and the next wake left the keyboard dark.
  • The grep-only test/shell.d/keyboard-backlight-test.sh is replaced by four behavioural assertions in quattro's test/shell.d/brightness-keyboard-test.sh.

How it was checked. On a disposable Omarchy worker with a real LED device (uleds, max 255), I ran nine off/restore/key sequences. quattro (d367a56) fails three: a level raised with the keys while blanked, a step back down to 0 while blanked, and a level set from outside the script while blanked. Each is replaced by the pre-blank level at unlock. This branch passes all nine. brightness-keyboard-test.sh passes 11 of 11 on the branch, and its new cases fail on quattro and with the fix reverted. Removing any one of the three new conditions fails the case written for it. ./test/cli, keybindings-menu-test.sh and bin-style-test.sh pass on the worker.

Earlier bot findings. Of Greptile's four comments on 3ff0554: down at 0 cancelling the restore is fixed (unchanged levels keep the record). A failed read losing the level was already fixed on quattro. The grep-only tests are replaced. The shared /tmp fallback when XDG_RUNTIME_DIR is unset still stands, but it comes from quattro's code and this branch does not touch it.

Second opinion. Codex Medium and muse-wonder (via pi, thinking high) reviewed the merge. Both found the race on the unlocked key path, which bb98cf4 fixes, and Codex asked for the up-then-down case that is now in the test. Their second round, on bb98cf4, found nothing further. Their agreement is not guaranteed to be independent of this review.

@marcindyguda, the description still describes the marker file and the old test. Updating it to the change above would help whoever merges it, but the code needs nothing more from you.

Waiting on the maintainer: the Tests and translation workflows for this push need approval to run on a fork. Once CI is green, the maintainer decides.

Comment thread bin/omarchy-brightness-keyboard Resolved
A manual change held the lock through omarchy-osd, which can wait on a stalled shell, so held keys, blank and wake queued behind it. A key the device rejected still showed the level it never set. Both come from omacom#10364.

Co-Authored-By: Chris AtLee <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

I pushed one more commit to this branch, 34f80ef. It carries over two pieces from #10364 by @catlee, who is credited as co-author:

  • A brightness key that the device rejects now exits with an error before the OSD. Before, it showed a level that was never applied. The saved level stays, so the next unlock still restores it.
  • The lock is released before omarchy-osd runs. That answers Greptile's note on bin/omarchy-brightness-keyboard:35. A slow or stalled shell no longer holds up held keys, blank or wake. Every read and write of the brightness and the saved level still happens under the lock.

What was checked. Everything ran on a fresh Omarchy worker at 34f80ef, against quattro d367a56:

  • test/shell.d/brightness-keyboard-test.sh passes 13 of 13.
  • The two new cases fail with the script put back as it was at bb98cf4. One fails because the rejected key showed an OSD. The other fails because the OSD ran with the lock still held.
  • The real-LED check against a uleds kbd_backlight device passes 9 of 9. quattro fails 3 of those 9.
  • ./test/cli, bin-style-test.sh and keybindings-menu-test.sh are green.

Claude Opus 5.5 did the review. Codex Medium and muse-wonder (via pi, thinking high) reviewed the commit as second opinions and found nothing to change. They agree with the reading above, but their independence from it is not guaranteed.

What's left.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

3 participants