Skip to content

fix(brightness): resume keyboard ALS after an off leftover - #486

Closed
oliverlukschander wants to merge 2 commits into
omacom:quattrofrom
oliverlukschander:fix/kbd-backlight-als-stuck-off
Closed

oliverlukschander wants to merge 2 commits into
omacom:quattrofrom
oliverlukschander:fix/kbd-backlight-als-stuck-off

Conversation

@oliverlukschander

@oliverlukschander oliverlukschander commented Sep 20, 2026 •

Copy link
Copy Markdown

What's wrong

omarchy-brightness-keyboard-auto pauses whenever anything else writes the keyboard LED, and only resumes after ambient light moves a lot (20 lux, or 40%). That is the right behavior for Shift+F1/F2 to a visible level. It is the wrong behavior for lock-screen blanking (brightnessctl -s set 0), a restore of a saved 0% level, or a 1% leftover (2/255), which is invisible: the daemon stays paused on dark keys.

On an M2 Pro (apple,j416s) the ALS daemon was running, room light was ~26 lux (maps to ~90%), and kbd_backlight sat at 2/255. A fresh --once immediately applied ~88%. PWM hardware was fine; the daemon had paused on an off leftover and never resumed in a stable room.

The change

The daemon tells a deliberate off from a leftover by who wrote it, not by the level left behind:

  • omarchy-brightness-keyboard up|down|cycle (the key bindings) records the level each key press changes the LED to, in $XDG_RUNTIME_DIR. off/restore (lock-screen blank, wake) record nothing.
  • An LED at ≤2% of max counts as effectively off. It is a choice only if the last key press turned the keys off; otherwise (blank, near-zero restore, leftover) ALS resumes.
  • Keys turned off by hand stay off until the next key press, whatever the room light does. Visible levels, from the keys or any other tool, still pause until lux moves enough.
  • The daemon drops the record when it writes the LED itself or starts, and reads it as digits only.
  • Lock and lid-close still skip ALS.

Testing

  • bash test/shell.d/brightness-keyboard-auto-test.sh drives the daemon's tick one poll at a time, with every LED write going through the real omarchy-brightness-keyboard key, lock-blank and restore paths:
    • a lock blank or saved near-zero restore of lit keys is relit
    • keys stepped down to 1/255 by hand (the OSD already reads 0% there) stay off through a blank before the next poll, the restore, and a darkened room
    • the next key press ends the hold; visible levels, from the keys or another tool, still pause until lux moves
    • a key press that changed nothing, or a record older than the daemon's last write or its start, does not make a later blank look deliberate
    • a non-numeric record is never evaluated as arithmetic
  • Each mechanism was mutation-checked: removing it fails a named assertion
  • bin/omarchy commands --check passed; the syntax check over bin/omarchy-* is clean
  • ./test/all has 6 failures, identical on a clean quattro checkout and unrelated to this helper (arm-channel-staging, config, package-build-contract, runtime-smoke, settings-package-units, unowned-system-paths; no omarchy-pkgs checkout here)
  • On-metal (Mac14,10 / apple,j416s, leds_pwm): the LED reads back exactly the recorded level; stepping down from 226 stops at 1 and holds through a blank, the restore and a darkened room; the next key press ends the hold; a blank of lit keys is relit

Not addressed here

  • omarchy-system-wake restores the last blank's saved level on every unlock, even when nothing was blanked since, which can still relight keys turned off by hand. That is a lock/wake change with its own trade-offs, so it goes in a separate follow-up PR.
  • Existing installs pick this up on the next omarchy update. No migration: the helper is the packaged binary the user unit already runs.

🤖 Generated with Claude Code

Lock-screen blanking and systemd-backlight restore write 0 (or a 1% leftover)
to kbd_backlight. The auto daemon treated that as a Shift+F1/F2 override and
stayed paused while room light was stable, so the keys could remain
invisible. Treat an effectively-off LED as not a manual choice; visible
manual levels still pause.

@wesleygrimes wesleygrimes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for tracking this down @oliverlukschander. What about people who deliberately turn the keyboard backlight off? Could we preserve that manual choice while still recovering from lock-screen blanking or a saved near-zero restore? It would be good to test both cases.

Treating every near-zero LED level as a leftover also relit keys the user
had turned off on purpose. omarchy-brightness-keyboard now records the level
a key press changes the LED to, and the ALS daemon counts an off level as a
choice once the last key press turned the keys off. That off holds until the
next key press; lock blanks and near-zero restores still resume ALS.

The daemon drops the record when it writes the LED itself or starts, and
reads it as digits only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@oliverlukschander

Copy link
Copy Markdown
Author

Good call: the first version couldn't tell the two apart. Both just looked like "LED ≤ 2%" to the daemon.

ad228ce keys it on who wrote the level instead of what level is left:

  • omarchy-brightness-keyboard up|down|cycle (Shift+F1/F2 and the XF86Kbd keys) records the level a key press sets. off/restore are the lock screen's blank and wake, so they record nothing.
  • The ALS daemon counts an off level as a choice only after a key press turned the keys off. Anything else that leaves them off (a lock-screen blank, a saved near-zero restore, a 1% leftover) still resumes ALS. Visible levels still pause, whether from the keys or another tool.
  • A deliberate off holds until the next key press. I didn't give it the "resume once the room light moves enough" rule that visible levels have: turn the keys off in a dark room, switch a lamp on, and that rule would relight them. Happy to switch to one rule for every level if you'd prefer.

Both cases are tested through the real key, lock-blank and restore paths in test/shell.d/brightness-keyboard-auto-test.sh. A deliberate off stays off through a blank, the restore and a darkened room, including stepping down to 1/255, where the OSD already reads 0% and people actually stop. A blank or near-zero restore of lit keys is relit. Also checked on an M2 Pro against the real LED and sensor.

One related thing I found along the way: omarchy-system-wake runs omarchy-brightness-keyboard restore on every unlock, lock-screen input and screensaver cancel, and brightnessctl restores the last blank's saved level even when nothing was blanked since. That can still relight a deliberate off after a quick lock/unlock (and overwrite any manual level), and it's the likeliest source of the stale near-zero restores behind this PR. It's a lock/wake change with its own trade-offs, so I'm fixing it in a separate follow-up PR and will link it here.

@oliverlukschander

Copy link
Copy Markdown
Author

Closing this in favour of #533: @maralcbr already landed the same fix on quattro-upstream (relighting keys left dark by a lock blank or a 1% leftover, while respecting keys turned off by hand), plus the follow-ups that forget stale key presses. Thanks Marcelo, that covers what this PR set out to do, and thanks @wesleygrimes for the review that pushed it in the same direction.

Two small things I found along the way, in case they're useful. Happy to send either as a PR if wanted:

  • Stepping down with the keys often stops at 1/255 (already dark, OSD reads 0%). A lock blank then reads 0, which doesn't match the recorded 1, so the keys relight.
  • omarchy-system-wake runs omarchy-brightness-keyboard restore on every unlock and screensaver wake, and brightnessctl keeps its save after -r, so a wake with nothing blanked brings back an old blank's level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question Further information is requested US

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants