Repository navigation
Automatic keyboard lighting from the ambient light sensor - #14557
omarchybot wants to merge 4 commits into
Conversation
Brings back automatic keyboard lighting, split out of #14431 so it gets its own review: laptops with an ambient light sensor and a keyboard LED light the keys in the dark and dim them as the room brightens, and the brightness keys and firmware keys still choose by hand.
The lock screen's blank waited two seconds for the keyboard lock, then went ahead without it. The automatic loop's lid check, made while holding that lock, can itself take two seconds when logind stalls, so the blank could land first and the update light the keys again while the screen stayed locked. A brightness key that timed out went ahead the same way. The blank and the wake restore now wait for the lock however long it is held, and a key that cannot get it in two seconds changes nothing. The update keeps the lock short: it asks about the lid before taking it, and a session check that does not answer within a second is killed and counts as locked.
A wake can restore brightnessctl's saved lit level after the user turned the keys off. If automatic control is already paused on that choice, put its observed manual level back before considering the ambient-light threshold, so an idle wake cannot override the user's brightness keys or firmware choice. Co-Authored-By: GPT-6 in Codex <[email protected]> Co-Authored-By: Claude Opus 5.5 High via Pi <[email protected]>
First-run enablement does not run for users who have already completed setup. Enable the new service during their update too, using the existing user-unit migration pattern for graphical sessions and updates without a user manager. Include the service in the package-default contract check; both settings recipes already install it whenever the desktop source contains it. Co-Authored-By: GPT-6 in Codex <[email protected]> Co-Authored-By: Claude Opus 5.5 High via Pi <[email protected]>
|
Reviewed the separate keyboard-lighting scope with Claude Opus 5.5 High via Pi. The delivered changes preserve an already observed manual off after an idle wake and enable the service for existing installs. Those failures were exercised on an isolated ISO worker; 77 focused keyboard, systemd and package-contract checks pass. Both current settings recipes already install the unit when present, so no package change is needed. A reproducible unlock defect remains: repeated wake calls during password unlock can lose a manual level chosen just before blanking. The worker test changes 201 back to the automatic 226 rather than retaining the choice. This remains a draft pending a correction that preserves hibernate restoration, and the review reached its three-round bound. It is stacked on #14431; its branch will need updating with the landed core and retargeting before it can land separately. Greptile also flagged unchanged manual off choices, a stale blank record that can misclassify a later firmware off, and updates when the session-lock helper returns an unknown state. All three reproduce on the isolated worker using sensor, LED and lock-state fixtures: an unchanged off becomes 20, a firmware off becomes 226, and an unknown lock state also relights to 226. They need addressing within this separate feature; the draft is not being treated as ready because its existing suite passes. |
|
| rm -f "$MANUAL_LEVEL_FILE" | ||
| fi | ||
|
|
||
| if [[ -n $last_set && $current != "$last_set" ]]; then |
There was a problem hiding this comment.
tick misses brightness-key choices that leave the LED unchanged. With max=255 and lux 179, auto sets zero. Pressing Down records 0, but current == last_set skips the pause. At lux 165, auto lights the keys to 20 even though the change is below OVERRIDE_LUX_DELTA.
Detect a fresh numeric manual record even when the LED has not moved.
| if (( delta * 100 < max * DEADBAND_PERCENT )); then | ||
| last_set=$current | ||
| return 0 |
There was a problem hiding this comment.
apply_percent leaves a stale blank record when no LED change is needed. If auto already has the keys off, lock blanking writes blank. After unlock, current == last_set and the early return leave that record in place.
A later firmware brightness increase starts a pause without clearing the record. Turning the keys off with firmware then looks like lock blanking, so auto cancels the pause and lights them again. Clear a consumed blank record even when auto does not write a new level.
| session_locked() { | ||
| local status=0 | ||
| timeout -k 1 1 omarchy-hyprland-session-locked >/dev/null 2>&1 || status=$? | ||
| (( status == 0 || status == 124 || status == 137 )) |
There was a problem hiding this comment.
session_locked treats an unknown lock state as unlocked. omarchy-hyprland-session-locked returns 2 when hyprctl fails or cannot establish the state, but this check only stops updates for 0 or a timeout. A failed probe during a locked session can therefore relight keys that the lock screen blanked.
Allow updates only when the helper explicitly returns 1.
|
@ryanrhughes three things beyond the open items the description already lists (repeated wake restores, unchanged manual off, stale blank records, unknown lock states):
The base is still the merged |
Laptops with an ambient light sensor and a keyboard backlight can keep their keys lit in a dark room and dim them as the room brightens. Brightness keys and firmware keys still choose a level by hand, with automatic control resuming after a sufficient ambient-light change. The service skips machines without both devices.
Manual brightness commands and automatic updates share a lock. Lock-screen blanking and wake restoration wait for an update, while a brightness key gives up after two seconds rather than changing the LED without the lock. A stalled session-state probe counts as locked. A stale idle-wake restoration preserves an already observed manual brightness choice.
First-run enables the service, and a migration enables it for existing users, including updates without a live user manager. Both current settings recipes already install the unit whenever the desktop source contains it.
Stacked on #14431. This remains a draft: repeated wake calls during password unlock can still lose a manual level chosen just before blanking. That behavior needs resolving while preserving hibernate restoration before this feature lands. Unchanged manual off choices, stale blank records and unknown session-lock states also need handling.
Supersedes #14517 by @maralcbr, whose commits this carries unchanged.