Skip to content

Keep the keyboard backlight level across lock and suspend - #12502

Open
mohan314e wants to merge 3 commits into
omacom:quattrofrom
mohan314e:keep-keyboard-backlight-level
Open

mohan314e wants to merge 3 commits into
omacom:quattrofrom
mohan314e:keep-keyboard-backlight-level

Conversation

@mohan314e

@mohan314e mohan314e commented Sep 19, 2026 •

Copy link
Copy Markdown

What's wrong

The keyboard backlight goes off and never comes back. Turning it on by hand doesn't help — the next wake turns it off again.

How it's meant to work

Locking blanks the backlight:

  1. Remember the current level (brightnessctl -s)
  2. Set it to 0

Waking puts it back:

  1. Restore the remembered level (brightnessctl -r)

That is correct, as long as step 1 only ever runs while the light is actually on.

Why it breaks

Step 1 remembers whatever it finds — including 0. So a blank that runs while the light is already off remembers 0.

After that, "restore the remembered level" means "set it to 0". Every time. Nothing ever writes a good value back, so it never heals on its own.

So the whole bug reduces to one question: can a blank ever run while the light is already off?

Yes — and only one path does it

A blank is normally preceded by a wake, and a wake restores the light. So the light is on when the blank runs. Fine.

Four places schedule a blank:

what it is wake before it?
:146 you lock the screen yes — you were just using the laptop
:181 you touch the lock screen yes — runWake() ran first
:551 a password attempt ends yes — submitting called runWake()
:490 resume from suspend no

:490 is the suspend gap. The blank countdown freezes during suspend. On resume it fires late, notices the gap, and re-arms — but it never wakes anything:

  1. Before suspend: blank runs. Remembers 40, sets 0.
  2. Suspend, then resume. The light is still 0.
  3. :490 fires and re-arms. No wake, so nothing restores the light.
  4. Five seconds later the blank runs again. It finds 0. It remembers 0.

Poisoned, permanently.

Resume can't be rescued anywhere else either. runWake()'s callers are :169, :218, :244, :298 and :323, and the last needs real typing or mouse movement on the lock screen. Opening a lid is neither.

Fix 1 — Service.qml:490: wake, don't just re-arm. runWake() arms the timer itself while locked, so the five-second run-up before blanking still happens. The light is simply real again before the next blank records it.

A second, separate problem

Restore writes the remembered level no matter what. But the backlight hotkeys still work while locked. So if you set the level yourself on the lock screen, the next wake throws your choice away (#10767).

The level at restore time tells you which happened:

level when restore runs what it means what to do
still 0 nothing has touched it since the blank the remembered level is still yours — apply it
anything else it was set after the blank that is newer than what we remembered — leave it alone

The same rule also covers locking while the light was already off: remembers 0, sees 0, applies 0 — no change, no special case needed.

Fix 2 — restore only writes while the level is still 0.

This is also why off is left as-is. Guarding off against saving 0 would mean a backlight you deliberately turned off is never remembered, and the next wake would switch it back on.

Fix 3 — omarchy-system-wake restores the keyboard before the display. The display call goes through Hyprland IPC, which lid transitions can stall; the keyboard write goes straight to sysfs and is instant. Doing it first means it is already done if the display call hangs — and runWake() drops a new wake request while the previous one is still running.

OMARCHY_LEDS_PATH follows the existing OMARCHY_BACKLIGHT_PATH and OMARCHY_DRM_PATH seams, so the new test can run on hardware with no keyboard backlight.

Reported in #9339, #10105 and #7650.

Validation: the new test/shell.d/brightness-keyboard-test.sh covers blank/restore, a level changed while blanked, and a deliberate zero. It fails against the unpatched script and passes on this branch. qmllint reports no new warnings on Service.qml. ./test/all passes apart from ten files that fail identically on a clean checkout in this environment for unrelated reasons. The three changes were also applied to a running 4.0.4-1 system and exercised through real blank and restore cycles; a full suspend and resume cycle was not manually tested.

🤖 Generated with Claude Code

Fixes #10767


Update: changes after merging quattro (1d06a4b)

After this PR was opened, quattro merged #15908. That PR replaced brightnessctl -s/-r in omarchy-brightness-keyboard with a record taken at the first blank and used by the next wake. The merge conflict was resolved in 1d06a4b, and some of the description above no longer matches the diff:

For validation of the current diff, see #12502 (comment).

A blank saves the current level before writing zero, and a wake restores
whatever was saved. Resume is the one path that reaches a blank with no wake in
front of it, so the level still holds the zero the pre-suspend blank wrote and
that blank saves zero over the real level. Every later restore then puts the
backlight back to off, permanently. Wake on the suspend gap instead of only
re-arming, so the level is real again before the next blank records it.

Restore applies the saved level only while the backlight is still at the zero
the blank wrote. Any other level was set after the blank -- the backlight
hotkeys stay bound while locked -- so it is newer than the saved value and has
to survive the wake. A level deliberately left at zero still saves and restores
as zero, so turning the backlight off by hand is not undone on the next wake.

Restore the backlight before the display in omarchy-system-wake. The brightness
write reaches sysfs immediately while the display call goes through Hyprland
IPC, which lid transitions can stall, and runWake() drops a wake request while
the previous one is still running.

Reported in omacom#9339, omacom#10105 and omacom#7650.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@llstrk

llstrk commented Sep 25, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: the three changes do what the description says for a non-zero level. One side effect is worth addressing: a keyboard deliberately turned off with the hotkeys can now come back on after a lock-then-sleep. Two smaller gaps that this PR does not introduce are noted below.

Verified in source and in sandboxed runs of the changed scripts:

Change Result
Lock timer's suspend-gap branch calls runWake() The call-graph analysis in the description holds. This branch was the only re-arm with no wake before it, and runWake() still re-arms while locked, so the 5 s run-up is kept. The repo's own hibernate hook (default/systemd/system-sleep/keyboard-backlight) sets the keyboard to 0 without saving; with an earlier level saved, head restores it where the merge-base recorded 0.
restore only writes at level 0 A level changed with the hotkeys while locked, and a non-zero level changed before a screensaver dismissal (#10767), survive the wake. An empty or failed get falls back to the old unconditional restore, and with no saved file brightnessctl -r writes nothing.
Keyboard restored before the display in omarchy-system-wake The keyboard level is back before the Hyprland IPC calls in omarchy-brightness-display on run. Without a keyboard backlight, the display wake still runs.
New test 7/7 pass on head. With only the OMARCHY_LEDS_PATH seam applied to the merge-base, it fails at "restore leaves a level changed while blanked". On the untouched merge-base it stops earlier at device discovery, because the seam is missing.

A hotkey zero is relit after a lock-then-sleep

up, down and cycle set the level without updating the saved value, so restore cannot tell a hotkey zero from a blank. With the new suspend-gap wake, this now also affects sleeps that lock before the first blank (menu or systemctl suspend/hibernate, lid close):

Earlier lock blank saved 40. User sets keyboard to 0 with the hotkeys, then a sleep path locks and suspends
before the 5 s blank. After resume, no input on the lock screen.

                          merge-base                 head
suspend-gap timer fires   re-arm only                runWake() -> restore sees 0, writes 40
blank 5 s later           saves 0, sets 0            saves 40, sets 0
unlock (restore)          keyboard 0, saved 0        keyboard 40, saved 40

The same gap already exists on the merge-base when the screensaver is dismissed after a hotkey zero, and when the lock screen gets input before the first blank. The test "restore keeps a deliberate zero off" starts with off capturing the zero, so it does not cover a hotkey zero with an older saved level.

Impact: a keyboard backlight turned off by hand comes back on after this kind of sleep, and again after unlock. This contradicts the description's statement that a deliberate zero is kept.

Suggested change: make the hotkey paths record the new level, for example brightnessctl -sd "$device" get after the set in up, down and cycle. A hotkey zero is then restored as zero on every path, and the level-0 guard still keeps changes made while locked. A test case with saved level 40, current level 0 and restore would cover it. Otherwise, narrow the deliberate-zero wording in the description.

Residual gap, not introduced by this PR (dropped wake during an IPC stall): runWake() drops a request while an earlier wake process is still running, but still re-arms the blank timer. If a wake spends more than 5 s in its display or clamshell step, the blank fires, and a later request is dropped, a second blank's off saves 0 over the good level. Once that sequence occurs, the result follows from the scripts and brightnessctl 0.5.1 on both the merge-base and head (checked with the real scripts and a stub that holds the display step; the QML decisions were modelled from source). How often the timing occurs was not measured. The reorder closes a related single-blank case on the merge-base. Since the description already cites IPC stalls, a timeout on the display and clamshell steps (as omarchy-system-sleep-lock does) or re-running a dropped wake when wakeProcess exits would close it.

Residual gap, not introduced by this PR (first sleep of a login): brightnessctl 0.5.1 keeps the saved level in $XDG_RUNTIME_DIR/brightnessctl, so it is empty after a reboot or new login. If the first locked sleep brings the keyboard back at 0 before any blank has saved a level, restore has nothing to apply and the next blank saves 0. The hotkey change above would reduce this.

Description note: the suspend-gap branch only runs when the blank timer is still armed at suspend (the timer is one-shot). A lock that blanked more than 5 s before sleep has no pending timer. That case is already handled by the first input after resume, which restores the saved level on both branches. The fix therefore targets lock-then-sleep and input shortly before sleep, rather than every resume.


Review information

Test scope: Source review of head 6c6ab91 against merge-base 60663fa, including brightnessctl 0.5.1 source and the lock, idle, sleep, lid and hibernate paths. The changed shell scripts and the new test ran in a sandbox with stubbed brightnessctl and display commands. Lock-service QML timing decisions were modelled from source, not executed. No real hardware, suspend/resume cycle or running lock screen was tested.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments with targeted cross-checks, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 1, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 6c6ab91 and reproduced on an Omarchy worker VM against quattro (8b4eae6). Both bugs are real, and both are fixed by this head.

How it was tested. A uleds LED named *::kbd_backlight stood in for the keyboard backlight, driven by the real lock screen and real brightnessctl. Stopping quickshell for 10 seconds stood in for suspend: the blank countdown fires late with a wall-clock gap, as it does after resume.

Scenario quattro this head
Lock, blank, input, then sleep with a blank pending; the light is 0 at resume, as the hibernate hook leaves it the post-resume blank saves 0; dark after input and after unlock saved level stays 40; light back after input and after unlock
Hotkey up while blanked (#10767) the wake overwrites 10 with the saved 40 10 kept through wake and unlock

Each fix was also reverted on its own. With Service.qml:490 back to armBlankTimer(), the first scenario goes dark again. With restore back to unconditional, the second scenario loses the hotkey level, and the new brightness-keyboard-test.sh fails at "restore leaves a level changed while blanked".

One limit, and it is not new. A level turned to 0 with the hotkeys while an older level is saved still comes back on after a lock, on quattro and on this head alike. On the worker, the lock surface appearing under the pointer runs a wake within a second of locking, and that wake restores the saved level before any blank can record the 0. So the case raised in the earlier community review is not a regression from this pull request. Covering it would mean the hotkey paths saving the level, which would not cover keys the firmware handles (see #10767), so that belongs in its own change.

Suite. ./test/cli passes. The brightness, lock, sleep-lock, idle and session-lock tests all pass. The full test/shell.d run has 4 failures at this head, and none come from this diff: two (ascii-test, branding-about-animation-test) also fail on quattro, omarchy-kernel-migration-test fails the same way on this branch's merge-base, and runtime-smoke-test passes when run alone. There is no CI on this pull request.

Second opinion. Codex at medium effort reviewed the diff and found no defect. It agreed the change is proportionate and the restore guard behaves as intended; that agreement is not guaranteed to be independent. It noted that the suspend path only applies when a blank is still pending at suspend (lock-then-sleep, or input shortly before sleep), which is narrower than the description's walkthrough suggests.

This pull request now closes #10767. It is labelled verified but not ready, only because the full suite is not green, for the reasons above. Waiting on the maintainer.

@jandrusk

Copy link
Copy Markdown

Both bugs look real and the restore/wake fixes match what #14011 / #12942 describe. Clean merge, has tests. Overlaps #13729 / #12553 (ThinkPad/hibernate restore) — those can stay as hardware-specific follow-ups.

…s record

omacom#15908 replaced brightnessctl's save with a record taken at the first blank, which already keeps the level across a second blank after a resume. That is what the lock service's wake-instead-of-rearm change was for, and with the record in place a wake there no longer changes the keyboard, so that change is dropped along with the leds path override nothing reads any more.

What quattro does not cover is omacom#10767: restore still puts the record back over a level the hotkeys set while blanked. restore now consumes the record without writing when the backlight is already lit, and the test for it moves into quattro's brightness-keyboard-test.sh.

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 had stopped merging cleanly: since the last review, quattro merged #15908, which replaced brightnessctl -s/-r in omarchy-brightness-keyboard with a record taken at the first blank and consumed by the next wake. I merged quattro into this branch and resolved it (1d06a4b), keeping what quattro still lacks. @mohan314e, thank you for this; here is what changed.

What this pull request now does. The fix for #10767 is kept, rebuilt on #15908's record: when restore finds the backlight already lit, the hotkeys set it while blanked, so it drops the record without writing over that level. Restoring the keyboard before the display in omarchy-system-wake is unchanged. The test moved into quattro's brightness-keyboard-test.sh.

What was dropped, and why. The Service.qml change (wake instead of re-arming when the blank countdown fires late after a resume) no longer does anything for the keyboard: #15908 already stops a second blank from saving 0 over the first, and the late wake finds no record to restore. The OMARCHY_LEDS_PATH override was only for the old test, and quattro's test substitutes the path itself. The description above still describes both, so it is now out of date; @mohan314e, it would help the maintainer if you trimmed it to match.

How it was tested, on an Omarchy worker VM against quattro at 7eedd17, with a uleds LED named *::kbd_backlight, the real lock screen and real brightnessctl:

Scenario quattro this head
Hotkey up to 10 while blanked (#10767), then input and unlock back to the saved 40 10 kept
Light turned off while asleep with a blank pending, as the hibernate hook does dark after resume, input and unlock the same

The new test fails on quattro's script, which is this head with the guard reverted, and passes here. ./test/cli passes, and so do the brightness, lock, sleep and idle shell tests. The full test/shell run has 4 failures (ascii, branding-about-animation, first-run, runtime-smoke), all of which fail the same way on quattro.

Not covered, on quattro or here. The second row: default/systemd/system-sleep/keyboard-backlight sets the light to 0 before hibernate without recording it, so if the lock blanks again after resume it records that 0, and nothing brings the light back. The dropped Service.qml change does not help with that on quattro either: the result on the worker was the same with it. And a level set with the hotkeys while blanked is still lost if a second blank comes before a wake, because the record from the first blank wins. Both behave the same way on quattro, so neither comes from this change.

Second opinion. Codex at medium effort and muse-wonder (via pi, thinking high) reviewed the resolution. Neither found a defect in it, and both agreed with dropping the Service.qml change and the path override; that agreement is not guaranteed to be independent. Both raised the second-blank gap above.

This is labelled verified and is waiting on the maintainer.

@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5 · Add the required regression test before merging.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect keyboard brightness during lock and wake workflows.

Add the required regression test before merging.

Findings

  1. P2 Brightness fix lacks a test ▶
  2. P2 Keyboard light turns back on ▶

Summary

The PR keeps a newer nonzero keyboard brightness choice during wake.

  • Wake keeps a new keyboard brightness choice made while locked.
  • System wake restores the keyboard before waking the display.

Reviews (2) · Last reviewed commit: "Merge quattro: drop the keyboard backlig..." · Reviewed by Greptile

Comment on lines +53 to +55
if [[ $current =~ ^[0-9]+$ ]] && (( current > 0 )); then
rm -f "$saved"
elif [[ ! $level =~ ^[0-9]+$ ]] || brightnessctl -d "$device" set "$level" >/dev/null; then

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 Keyboard light turns back on

restore still overwrites a brightness choice of zero made while locked. After off saves 3, a user can raise the light and then use down or cycle to turn it off again. The new current > 0 check misses that change, so the next wake restores 3.

To preserve this choice too, have successful hotkey changes update the saved level under the same lock, and add a test for turning the light off while locked.

@raffsmagic

Copy link
Copy Markdown
Contributor

Tested 1d06a4b6 on real hardware, a Dell XPS 9320 with a keyboard backlight (dev channel):

  • test/shell.d/brightness-keyboard-test.sh passes.
  • Ran omarchy-brightness-keyboard from quattro and from this PR: level 1, off, set 2 by hand, restore. quattro went back to 1, this PR kept 2.

Not tested: the backlight key while actually locked (by eye it was inconclusive, and the lock logs don't show it), and suspend/resume.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Nov 23, 2026
Comment on lines +51 to +54
current="$(brightnessctl -d "$device" get)"
# Lit after a blank means the hotkeys set it while locked, which is newer than the record.
if [[ $current =~ ^[0-9]+$ ]] && (( current > 0 )); then
rm -f "$saved"

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 Brightness fix lacks a test

The new restore branch has no regression test. AGENTS.md requires a bug fix with logic to include a test that fails before the fix and passes afterward. This requirement must be met before merging.

Add a test that saves a level with off, changes the brightness to another nonzero level, and checks that restore keeps the newer choice and removes the saved record.

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!

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed head 8461f007d95384f2491835e3a6abd8daa491c76c against current quattro, including the lock/idle wake paths, locked hotkey bindings, both Greptile findings, and the current competing fixes. This pass was a source comparison; no tests or suspend/resume cycles ran, and no code was pushed.

The older #10366 now contains the same nonzero restore guard, plus serialization of hotkey changes and removal of the saved record when a hotkey actually changes the level. That covers two cases this guard leaves open: returning to 0 with the hotkeys while blanked, and making a hotkey change followed by another blank before the wake. For those cases, this head retains the older saved level and restores it. #10366 also handles a keyboard lit outside the command, which older #10364 still overwrites. These are the concrete reasons to pursue #10366 for this fix; that branch still needs verification at its current head.

Greptile is right that this head has no regression test after the merge carrying #19904's test removal. The separate keyboard-before-display change is a tradeoff: it restores the keyboard before any display IPC wait, but also puts display wake behind the keyboard's blocking lock. That remains a maintainer decision.

Codex High, Opus 5.5 High, and muse-wonder via pi (thinking high) checked this comparison. Both second reviewers recommended #10366; their agreement is not guaranteed to be independent. They also identified #10364's no-op down at 0 clearing the saved level, which #10366 avoids. This pull request stays open with bug, waiting on the maintainer's choice between the competing fixes; it has not been re-verified at this head.

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

Development

Successfully merging this pull request may close these issues.

Keyboard brightness changes do not update saved state, so screensaver wake restores an old level

5 participants