Skip to content

Turn the keyboard backlight on in the dark using the ambient light sensor - #13148

Open
terracatta wants to merge 14 commits into
omacom:quattrofrom
terracatta:keyboard-backlight-ambient-light
Open

terracatta wants to merge 14 commits into
omacom:quattrofrom
terracatta:keyboard-backlight-ambient-light

Conversation

@terracatta

@terracatta terracatta commented Sep 24, 2026 •

Copy link
Copy Markdown

What changed

  • Adds a omarchy.keyboard-backlight shell service that follows the ambient light sensor through iio-sensor-proxy (monitor-sensor --light, which only reports changes). It turns the keyboard backlight on below 10 lux and off above 50 lux, after the reading holds for 5 s. In between, a lit backlight dims with the light, from full at 10 lux down to the lowest lit step just before 50 lux. Each dimming step settles the same way, and changes under a twentieth of the full level are skipped on keyboards with many levels. "dimming": false keeps it at full.
  • Keeps manual control intact. Any level the service didn't set is treated as the user's choice: the keys or omarchy brightness keyboard.
    • A non-zero level is reused the next time it gets dark, until the shell restarts. One picked while lit also stops the dimming until the next dark/bright switch.
    • The keys take the same lock as the automatic writes, so a key press made while one is in flight steps from the level it sets rather than being overwritten. They give up waiting after 2 s rather than lag.
    • Off in the dark is held across restarts until the room has been bright for 10 minutes, 8 hours pass, or the backlight is turned back on.
    • omarchy brightness keyboard up/down/cycle nudge the service, so a choice made in steady light is seen (and saved) right away. The last level seen is kept in $XDG_RUNTIME_DIR, so a level changed while the shell was down, including by firmware-handled keys, is still taken as the user's after a restart. It's cleared on reboot, when the firmware or systemd-backlight sets the level instead.
  • Stays out of the way of session blanking. omarchy-brightness-keyboard off and restore pause and resume the service over IPC, so nothing is lit behind a blanked lock screen. On wake, it decides again from the room's light instead of adopting the restored level. The service's writes take the same lock as off/restore and skip while a blank is saved, so a write already in flight can't land behind the blank. The service stays loaded across plugin reloads, and a shell started mid-blank starts paused.
  • Leaves the keyboard alone while the lid is closed. The sensor sits in the lid, so docked in clamshell mode it reads dark. The lid is read with omarchy-hw-laptop-closed (ACPI, or logind for Apple Silicon's SMC lid), and the open and close bindings for both lid switches nudge the service. On open, monitor-sensor is restarted for a fresh reading rather than acting on the one taken under the lid.
  • Adds omarchy-hw-ambient-light, which matches the same IIO attributes as iio-sensor-proxy's udev rules, and omarchy-hw-keyboard-backlight. install/hardware/ambient-light.sh and a migration install iio-sensor-proxy where both exist, and it's in omarchy-other.packages for the ISO's offline mirror.
  • Adds omarchy toggle keyboard backlight auto (flag keyboard-backlight-auto-off, named for the off state like the other toggles). It's also in the Toggle menu as an on/off pair, guarded by both hardware checks, and its notifications go through omarchy-i18n. Disabling it stops monitor-sensor, which releases the sensor.
  • Thresholds, settle time, and hold times can be tuned under keyboardBacklight in shell.json, with defaults in code. A user's shell.json replaces the defaults entirely, so existing configs work unchanged.
  • Documents it in the Toggles manual page.

Discussion: #13147 Turn the keyboard backlight on in the dark on laptops with an ambient light sensor

Design notes

  • The logic is a pure model (KeyboardBacklightModel.js), and Service.qml only does I/O, following the battery and night light services. The service has no timers running in steady light. A single-shot timer handles the settle time and hold expiry.

  • monitor-sensor runs under setpriv --pdeathsig TERM, like the clipboard watchers. An orphan left behind by a killed shell would keep the sensor claimed and never report again. It runs with LC_ALL=C, since readings are printed with %lf, and its running state is set only from code, so a restart after an early exit can't detach it from the toggle.

  • A write that fails or is dropped (paused, lid closed) resyncs the model to the actual level and decides again, rather than being taken as a manual off. A failed write is retried after the settle time, up to three times, since in steady light nothing else would decide again.

  • Time spent blanked or with the lid closed doesn't count toward the ten bright minutes that clear a manual off; the bright period starts over at the next bright reading.

  • IPC registers through ShellIpc, like the other first-party services.

  • Brightness is read with blockAllReads. With blockLoading, reload() returns the previous load, so the service would take its own writes as manual changes. Readings taken while a write is in flight are ignored.

  • The lock service is an authentication service and isn't reachable from other services, so blanking is signalled from omarchy-brightness-keyboard off/restore, which bracket both lock blanking and idle wake. pause is sent before the blank, and before restore writes too, since a wake can come without a blank before it. resume is sent after the restore, so neither races a write. pause also takes one last look at the level, so a key press made in a steady dark room just before locking or waking isn't lost. After an off, the second pause is a no-op.

  • Firmware idle timeouts that darken the keys without changing brightness (Dell's stop_timeout) are invisible to the service, so they aren't mistaken for a manual off. I verified this on the XPS 14.

Overlap

Testing

  • test/shell.d/keyboard-backlight-auto-test.sh: 62 model cases covering parsing (including comma decimals), settle and spike filtering, the dead band, holding and clearing a manual off, the remembered level, restart persistence (including a level changed while the shell was down), the hold clearing when the bright period ends, a blank or closed lid not counting as bright time, dimming (settling, the lowest lit step, skipping invisible changes on keyboards with many levels, a picked level stopping it, and dimming: false), and resuming after a session wake into a dark or bright room.
  • test/shell.d/keyboard-backlight-auto-service-test.sh: runs the real Service.qml under headless Quickshell with a stub monitor-sensor, a stub brightnessctl whose writes land late, and a synthetic LED directory (OMARCHY_LEDS_PATH). Its 22 checks cover restart after an early exit, the C locale, its own on and off writes not being taken as manual changes, nothing being written while blanked, deciding again from the light after wake, a key press just before locking being kept, a restore without a blank not being taken as the user's, nothing being lit under a closed lid, deciding from the light once the lid opens, a fresh reading once the lid opens instead of the one taken under it, a failed write not being taken as a manual off and being retried a bounded number of times, a key press seen at once through refresh, an off made while the shell was down being held, a shell restarted mid-blank writing nothing, and the toggle still stopping monitor-sensor. Each check was confirmed against a copy of the service with its bug put back. The tests are named keyboard-backlight-auto-* to stay clear of the keyboard-backlight-test.sh that Fix keyboard backlight restore after screensaver dismiss #10366, Restore ThinkPad keyboard backlight after sleep and boot #12553, and Add optional idle timeout for keyboard backlight #12558 add.
  • test/shell.d/brightness-keyboard-test.sh (the existing suite for omarchy-brightness-keyboard) gains a section that drives the real omarchy-brightness-keyboard off/restore against the real service (adapted from the community review's reproducer). Its 8 checks cover a key press kept through a lock, a key press kept through a wake without a blank, a repeated off during a blank not being taken as the user's, a key press through up/down saved at once, a write still in flight when the lock blanks not being left lit, and a key press during an automatic write stepping from the level that write sets.
  • Rebased onto quattro at d9cc361. ./test/cli, i18n-test.sh, plugins-test.sh (the service is now required to be keepLoaded), shell-ipc-test.sh, menu-test.sh, menu-guards-test.sh, manifest-entrypoints-test.sh, lid-close-test.sh, and monitor-modeless-test.sh pass, as does the rest of ./test/shell apart from shell-idle-spawn-test.sh. That one fails the same way on quattro without this change when it's run on a live desktop: Hyprland window events start the workspace-layout and keyboard widget probes.
  • Live tested in the running shell on a Dell XPS 14 (2026, Intel ISH):
    • It turned on ~5 s after covering the sensor.
    • A key press to off was held through a bright spell and a second dark period.
    • The toggle stopped and restarted monitor-sensor.
    • No orphaned processes after test runs.
    • The review fixes are running in the live shell: monitor-sensor runs with LC_ALL=C, and the pause/resume IPC functions are registered.
  • After the rebase, the full quattro shell from this branch was run on the same XPS 14 against the real sensor, LED and lid, with brightnessctl stubbed to log. The service loaded as a first-party plugin, read 108 lux from the real sensor, wrote off after the 5 s settle through the new locked write path, and answered refresh, lid, pause and resume.

Power

In steady light the service does nothing, and power is only spent in the sensor stack. iio-sensor-proxy 3.9 falls back to polling HID sensor hub light sensors about once a second, which costs ~5 sensor hub interrupts/s on the XPS while any client listens. A fix is in progress upstream. With it, this measured 0 interrupts in steady light and 113 → 11 per 20 s overall.

Development

Claude Code (Claude Opus 5.5) wrote the code under my supervision, and I ran the live hardware tests with it.

🤖 Generated with Claude Code

@llstrk

llstrk commented Sep 24, 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 pure model in KeyboardBacklightModel.js behaves as its tests describe (all 27 assertions pass), parseLux reads the iio-sensor-proxy 3.9 output formats in the C locale, and under headless Quickshell 0.3.1 with a stub monitor-sensor the service activates, turns the backlight on after a settled dark reading and off after a settled bright one. The normal toggle path stops monitor-sensor. The install script, migration, menu entry and bin/ metadata follow repository conventions.

The integrated service, however, does not yet match the described behavior in several common situations. The main issue is a stale brightness read that makes the service treat its own writes as manual changes.

Brightness is read one step late, so the service's own writes look like a manual off

readBrightness() calls brightnessFile.reload() and then brightnessFile.text(), with blockLoading: true (Service.qml). Quickshell's FileView documents that after the first load, reload() returns the old data until the asynchronous load completes; blockLoading only blocks the very first read. Each step therefore compares expected against the brightness from before its own previous brightnessctl write.

Synthetic timeline from a headless run of Service.qml with only its LED path redirected (stub sensor, synthetic LED directory, shortened settle time):

room     service action        brightness read by step   model records
dark     set 3                 -                         expected 3
dark     (next reading)        stale 0                   phantom manual off, cleared a reading later
bright   set 0                 -                         expected 0
bright   (next readings)       stale 3, then 0           "user chose 3", then phantom manual off (persisted)
dark     settle -> "on"        0                         held, no write
result:  backlight stays off in the dark; manual-off file written

The same timeline with only blockAllReads: true added to brightnessFile records no phantom state and turns the backlight back on.

Impact: after any automatic off of a lit backlight, a manual off is recorded and saved. If the room gets dark again within brightClearMinutes (10 minutes by default), the backlight stays off. Because the hold is persisted, a shell restart (for example after omarchy update) within manualOffMaxHours of the last automatic off also starts with the backlight held off in the dark.

Suggested change: read synchronously (blockAllReads: true on brightnessFile, or reload() followed by waitForJob()), and ignore or resynchronize observations while setProcess is still running so a reading that lands before brightnessctl finishes cannot be taken as a user change.

Lock blanking and wake undo automatic decisions and pin the result as the user's choice

Locking blanks the keyboard with omarchy-brightness-keyboard off (brightnessctl -s, then 0), and wake or a dismissed screensaver runs omarchy-system-wake, which restores the saved value (brightnessctl -r). The service keeps running while locked and treats any level it did not write as the user's choice.

blank-then-dark:   bright, backlight 0 -> lock blanks (saves 0) -> room goes dark -> service sets on while locked
                   -> wake restores 0 -> recorded as manual off -> held off in the dark (persisted)
blank-then-bright: dark, backlight on -> lock blanks (saves on level) -> room turns bright
                   -> wake restores on level -> recorded as user level -> stays on in daylight

Both sequences reproduced in the headless runs with stale and with synchronous reads, so this is independent of the previous finding.

Impact: the keyboard can light up while the session is locked with the screen off, then come back held off in the dark after wake (for up to manualOffMaxHours), or stay on in daylight after an overnight lock.

Suggested change: skip writes while the lock service reports blanked displays and re-evaluate from the current lux on wake instead of adopting the restored value, or have omarchy-brightness-keyboard off/restore pause and resume the service over IPC when it is active.

Comma-decimal locales disable the feature silently

monitor-sensor calls setlocale(LC_ALL, "") and prints readings with %lf, and Service.qml runs it with the inherited environment. Under a locale such as de_DE, the output is value: 2,000000, unit: lux, which the [0-9.]+ pattern in parseLux rejects (reproduced with a GLib program using the same calls under a sandbox-built de_DE.UTF-8).

Impact: on sessions with a comma decimal separator (de_DE, fr_FR, es_ES, pt_BR, ru_RU and others), no reading is ever parsed. The sensor stays claimed and the backlight never changes, with no error shown.

Suggested change: start monitor-sensor with LC_ALL=C (for example environment: ({ LC_ALL: "C" }) on monitorProcess), as other Omarchy scripts do when parsing tool output, and add a comma-decimal line to the parser test.

The toggle no longer stops monitor-sensor after an early restart

monitorProcess declares running: root.active && root.state !== null, but restartTimer assigns monitorProcess.running = true. The assignment replaces the binding. If monitor-sensor exits before its first reading (for example when ClaimLight fails), the timer restarts it and the binding is gone. In a headless run with a stub that exited early, turning the toggle off left the restarted process running until the shell quit; the control run without the early exit stopped it at the toggle.

Impact: after such a failure, omarchy toggle keyboard backlight auto no longer releases the sensor, contrary to the PR description and the manual.

Suggested change: manage running only imperatively (as Clipboard.qml does), or restart through a property that is part of the binding.

Sensor detection is narrower than iio-sensor-proxy's

omarchy-hw-ambient-light accepts only in_illuminance_raw, in_illuminance_input and in_illuminance0_input. iio-sensor-proxy 3.9's udev rules also match in_illuminance_clear_raw, in_intensity_clear_raw and buffered in_intensity_both sensors.

Impact: machines with only those sensor types get no iio-sensor-proxy, no menu entry and no service, even though the proxy supports them. HID sensor hub sensors (Intel ISH, AMD SFH), such as the tested XPS, are covered.

Suggested change: mirror the proxy's matching attributes, or check the proxy's HasAmbientLight once it is installed.

Smaller notes

  • Documentation: the manual's shell.json example omits "version": 1, so copying it into a new file produces a config the shell ignores; saying "add this block to your existing shell.json" avoids that. The remembered level is kept only within one shell session (it is not persisted), so "remembered for the next time the room gets dark" does not hold across a restart.
  • Menu guard: the Toggle menu entry is guarded on the sensor only, so it also appears on machines with a sensor but no *kbd_backlight* LED, where it does nothing.
  • Timer range: checkTimer.interval is a 32-bit int, so manualOffMaxHours of about 597 or more wraps it (at 720 hours the interval read back negative, the hold-expiry timer never fired and Qt logged a negative-interval warning repeatedly). Clamping the interval to 2147483647 avoids it.

Optional test improvement: the unit test only covers the model, and its "ignores the level it set itself" case feeds the target value straight back, which the running service never does. The headless Quickshell setup described above (offscreen platform, stub monitor-sensor, synthetic LED directory) reproduced the stale-read, lock/wake and toggle issues and passed the stale-read case once blockAllReads was added, so a service-level test along those lines would cover them.


Review information

Test scope: source review of the PR, related Omarchy components (lock, idle, omarchy-brightness-keyboard, omarchy-system-wake) and upstream iio-sensor-proxy 3.9, Quickshell, brightnessctl and GLib source. Isolated runs executed the PR's unit assertions (under Quickshell's JavaScript engine, not Node) and the real Service.qml under headless Quickshell 0.3.1 with a stub monitor-sensor, a synthetic LED directory and shortened timings. No real ambient light sensor, keyboard backlight, lock screen or desktop session was used, so hardware-specific behavior (for example lid-closed readings or the author's power measurements) was not tested.

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

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

@terracatta

Copy link
Copy Markdown
Author

Thanks, this was accurate and useful. Everything is addressed in 5e0a1b9:

  • Stale reads: brightnessFile now uses blockAllReads, and observations are skipped while a write is in flight. I reproduced the reload() behavior headlessly first: with blockLoading it returned 0 after the file was written with 2. This also explains a flicker in my own live test that I had misattributed to key presses.
  • Lock blanking and wake: the lock service is an authentication service, so it isn't reachable from here. I went with your second option: omarchy-brightness-keyboard off and restore pause and resume the service over IPC. Each call is made after its write finishes, so it doesn't race the restored level. On resume the restored level becomes the baseline, and the service decides again from the current light. A held manual off is put back if a wake restores a lit level. Both of your sequences are now model tests.
  • Locale: monitor-sensor runs with LC_ALL=C, and parseLux also accepts a comma decimal separator.
  • Toggle after an early restart: running is no longer bound. It's set only through syncMonitor(), and the restart timer goes through the same path.
  • Detection: omarchy-hw-ambient-light now matches all six IIO attributes from iio-sensor-proxy's udev rules. There's a new omarchy-hw-keyboard-backlight, which the menu entry, install script, and migration also require.
  • Smaller notes: the timer interval is clamped to 2147483647. The manual now says to add the block to an existing shell.json, and that the remembered level lasts until the shell restarts.

I also added keyboard-backlight-service-test.sh, along the lines you described. It runs the real Service.qml under offscreen Quickshell with a stub monitor-sensor, a stub brightnessctl whose writes land late, and a synthetic LED directory. It covers the stale read, blanking and wake, the locale, and the toggle after an early exit. It fails on the original version of the PR, and also on a copy with only blockLoading put back.

@llstrk

llstrk commented Sep 27, 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.

Follow-up on the earlier review, checked at 5e0a1b97 after the author's reply.

Verified: all nine earlier points are resolved at 5e0a1b97. The new pause/resume design adds one regression: a key press the service has not yet seen is discarded at wake. Separately, one packaging gap has been present since the first revision.

Earlier point Result at 5e0a1b97
Stale brightness read Resolved. Under blockAllReads, reload() then text() waits for a fresh read (Quickshell 0.3.1 source). The new service test fails with blockLoading put back, and also with the in-flight write skip removed
Lock blanking and wake Resolved when blank and wake come in pairs: off pauses before blanking and restore resumes after restoring. A run of the unmodified script against Service.qml showed no writes while blanked and a fresh decision on wake, in both earlier sequences
Comma-decimal locales Resolved: LC_ALL=C on monitor-sensor, and parseLux accepts a comma
Toggle after an early restart Resolved: running is set only through syncMonitor(), and the service test's toggle check covers it
Sensor detection Resolved: all six IIO light attributes from iio-sensor-proxy 3.9's udev rules
Manual wording, menu guard, timer range Resolved
Service-level test Resolved: model test 35/35 and service test 8/8 (5 of 5 runs) on the head; the service test fails on a7e4dc60

None of the earlier points needed to be withdrawn.

A key press made since the last sensor change is lost at wake

The service checks for a level it did not set itself only in step(), which runs when monitor-sensor reports a changed value or a check timer fires. In a steady dark room neither happens, so a key press is not observed right away. pause() does not read the level either, and on wake resume() takes the restored level as its new baseline. The key press never becomes a held manual off or a remembered level, and the dark room then turns the old level back on.

Reproduced with the unmodified omarchy-brightness-keyboard off/restore and the real Service.qml (stub monitor-sensor with one dark reading and no later changes, synthetic LED, settle time shortened to 0.3 s):

case                              before lock   after wake
5e0a1b97, user turns it off       0             2   (service sets 2 about 0.4 s after restore)
5e0a1b97, user picks level 1      1             2
a7e4dc60, same two cases          0 / 1         0 / 1
5e0a1b97 + change below           0 / 1         0 / 1

Impact: in a dark room, when the sensor reports no change between the key press and the lock, turning the keys off brings them back on after wake (after the settle time, 5 s by default), and a chosen level is replaced by the old one. With one sensor change in between, the manual off was kept. This contradicts the manual's "stays off until the room has been bright for ten minutes..." and "a brightness you pick is reused". From source (not run), in bright light the result matches the documented "decides again", so the regression concerns dark rooms.

Suggested change: observe and persist the current brightness in pause(), before setting paused, when no write is in flight. At that point off has not blanked yet, so the level read is the user's:

function pause() {
  if (root.active && root.state && !root.paused && !setProcess.running && root.pendingLevel < 0) {
    var before = root.state.manualOffSince
    root.state = KeyboardBacklightModel.observeBrightness(root.state, readBrightness(), Date.now())
    if (root.state.manualOffSince !== before) manualOffFile.setText(root.state.manualOffSince > 0 ? String(root.state.manualOffSince) : "")
  }
  root.paused = true
  checkTimer.stop()
}

With this change both cases above keep the user's choice, and the PR's service test still passes (2 of 2 runs).

iio-sensor-proxy is missing from the ISO package list

install/hardware/ambient-light.sh installs iio-sensor-proxy with omarchy-pkg-add, but the package is in neither install/omarchy-base.packages nor install/omarchy-other.packages. Almost every other package installed by install/hardware/ scripts (for example asusctl, qmk-hid, thermald, dell-xps-touchpad-haptics) is listed in omarchy-other.packages, which docs/file-layout.md describes as a source for the ISO's offline mirror. This has been the case since the first revision.

Impact: on a machine with both a light sensor and a keyboard LED, an offline ISO install can fail to find the package, unless it reaches the mirror some other way (the ISO builder was not checked). omarchy-pkg-add then exits 1. omarchy-apply-hardware runs with set -euo pipefail, so the failed run_logged step stops the hardware scripts that follow it in install/hardware/all.sh. From source, omarchy-apply-system (also set -euo pipefail) would then skip its login and post-install steps too.

Suggested change: add iio-sensor-proxy to install/omarchy-other.packages. Open PR #7493 adds the same entry.

Related open PRs: #10366 and #12553 (and #12558, which builds on #12553) add their own test/shell.d/keyboard-backlight-test.sh, the path of this PR's model test, and change bin/omarchy-brightness-keyboard. #12553 rewrites the same off/restore branch and changes what restore puts back, which is the level resume() now takes as its baseline.

Optional test improvement: two service-test checks do not catch what they target. "its own write is not taken as a manual off" also passes on a7e4dc60 and with blockLoading put back, because the next lit reading clears the phantom off before the check (the bright phase does catch it). "decides again from the light after wake" still passes when Service.resume() skips the model's resume(). A case with steady dark, a key press to off, ipc pause, blank, restore, ipc resume and no further sensor lines would cover the regression above.


Review information

Test scope: source review of the changes since a7e4dc60, related Omarchy components (lock, idle, omarchy-system-wake, omarchy-shell) and Quickshell 0.3.1, iio-sensor-proxy 3.9 and brightnessctl source. Isolated runs executed the PR's model and service tests on both heads and on copies with one part of the fix reverted, plus the unmodified omarchy-brightness-keyboard against the real Service.qml under headless Quickshell 0.3.1, with a stub monitor-sensor, a stub brightnessctl and a synthetic LED. No real sensor, keyboard backlight, lock screen, suspend or ISO install was used.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

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

@omarchybot omarchybot added the enhancement New feature or request label Sep 27, 2026
@terracatta

Copy link
Copy Markdown
Author

Thanks again. Both findings are addressed in 1ed7e08:

  • Key press lost at wake: pause() now takes one last look at the level before the blank, through the same observe() path step() uses, which skips in-flight writes and persists a manual off. I went with your suggested change.
  • ISO package list: iio-sensor-proxy is now in install/omarchy-other.packages.
  • Test name collision: the tests are now keyboard-backlight-auto-test.sh and keyboard-backlight-auto-service-test.sh (fixture fixtures/keyboard-backlight-auto/), clear of the keyboard-backlight-test.sh that Fix keyboard backlight restore after screensaver dismiss #10366, Restore ThinkPad keyboard backlight after sleep and boot #12553, and Add optional idle timeout for keyboard backlight #12558 add. On Restore ThinkPad keyboard backlight after sleep and boot #12553's change to what restore puts back: resume() treats whatever restore produces as the session's baseline and decides again from the light, so it should hold under either behavior.
  • Service test: the phantom-off check now looks after a single reading. There are two new cases: a key press to off in steady dark followed by pause, blank, restore, and resume with no further sensor lines, and a restore without a blank. I broke the service three ways to confirm each check targets its bug. blockLoading fails "its own write is not taken as a manual off". Dropping the look in pause() fails the key press case. Skipping the model's resume() fails the restore case.

Model tests pass 35/35 and the service test passes 10/10.

@llstrk

llstrk commented Oct 1, 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.

Outcome: a key press can still be lost on a wake with no lock blank before it, a path the earlier suggestion missed.

Earlier findings (previous review): key press lost after a lock blank, resolved; ISO package list, resolved.

Key press still lost when restore has no off

omarchy-system-wake also runs restore when the screensaver is dismissed before the lock, or on unlock before the first blank (5 s). The service was never paused, so pause() never looks, and resume() adopts the level left by restore. Impact: in a steady dark room, keys turned off by hand relight about 5 s later, with no hold. Also at 5e0a1b97.

Suggested change: call omarchy-shell -q omarchy.keyboard-backlight pause before brightnessctl -rd in the restore branch.

Reproducer (fails at 1ed7e08)

Reproducer: a key press is lost on a wake that has no blank before it

Reviewed head: 1ed7e08e27896c11b0d99abc37255fe5d615f327.

A test in the style of test/shell.d/keyboard-backlight-auto-service-test.sh. It runs the real
Service.qml (through the PR's fixtures/keyboard-backlight-auto/shell.qml) under offscreen
Quickshell, and calls the real bin/omarchy-brightness-keyboard off / restore. Only the LED
path in a copy of that script is redirected (sed, as system-sleep-ownership-migration-test.sh
does for its hook), and omarchy-shell is a stub that forwards to this Quickshell instance with
quickshell ipc --pid. brightnessctl is a stub that also implements -s/-r.

The first case is the lock sequence fixed in 1ed7e08 (it passes). The second case is the
same key press followed by restore without a preceding off, which is what
omarchy-system-wake does when the idle screensaver is dismissed (or other activity ends the
idle cycle) before the lock, and when an unlock comes before the lock screen's first blank.

Save as test/shell.d/keyboard-backlight-auto-wake-test.sh in a checkout of the PR head and run
bash test/shell.d/keyboard-backlight-auto-wake-test.sh (needs quickshell; run here with
Quickshell 0.3.1).

#!/bin/bash

# Drives the real Service.qml through the real omarchy-brightness-keyboard
# off/restore. Only the LED path in a copy of the script is redirected, and
# omarchy-shell is a stub that forwards to this Quickshell instance.

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

require_command quickshell

TMPDIR=$(mktemp -d)
QS_PID=""
cleanup() {
  [[ -n $QS_PID ]] && kill "$QS_PID" 2>/dev/null
  pkill -f "tail -n \+1 -f $TMPDIR/sensor" 2>/dev/null || true
  rm -rf "$TMPDIR"
}
trap cleanup EXIT

led="$TMPDIR/leds/test::kbd_backlight"
mkdir -p "$led" "$TMPDIR/bin" "$TMPDIR/home/.local/state/omarchy/toggles" "$TMPDIR/config"
echo 0 > "$led/brightness"
echo 2 > "$led/max_brightness"
: > "$TMPDIR/sensor"
cp "$SHELL_TEST_DIR/fixtures/keyboard-backlight-auto/shell.qml" "$TMPDIR/config/shell.qml"

cat > "$TMPDIR/bin/omarchy-hw-ambient-light" <<'EOF'
#!/bin/bash
exit 0
EOF

cat > "$TMPDIR/bin/monitor-sensor" <<EOF
#!/bin/bash
exec tail -n +1 -f "$TMPDIR/sensor"
EOF

# set/get/max, plus -s and -r the way brightnessctl saves and restores. Writes
# land a little after the call, as in the service test.
cat > "$TMPDIR/bin/brightnessctl" <<EOF
#!/bin/bash
save="" restore=""
while [[ \${1:-} == -* ]]; do
  [[ \$1 == *s* ]] && save=1
  [[ \$1 == *r* ]] && restore=1
  [[ \$1 == *d ]] && shift
  shift
done
case \${1:-} in
  get) cat "$led/brightness"; exit 0 ;;
  max) cat "$led/max_brightness"; exit 0 ;;
esac
[[ -n \$save ]] && cp "$led/brightness" "$TMPDIR/saved"
if [[ -n \$restore ]]; then
  [[ -f $TMPDIR/saved ]] || exit 0
  level=\$(< "$TMPDIR/saved")
elif [[ \${1:-} == set ]]; then
  level=\$2
else
  exit 0
fi
sleep 0.2
echo "\$level" > "$led/brightness"
EOF

sed "s|/sys/class/leds|$TMPDIR/leds|" "$ROOT/bin/omarchy-brightness-keyboard" > "$TMPDIR/bin/omarchy-brightness-keyboard"
chmod +x "$TMPDIR/bin/"*

OMARCHY_PATH="$ROOT" \
OMARCHY_LEDS_PATH="$TMPDIR/leds" \
HOME="$TMPDIR/home" \
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$TMPDIR}" \
QT_QPA_PLATFORM=offscreen \
PATH="$TMPDIR/bin:$ROOT/bin:$PATH" \
  quickshell -p "$TMPDIR/config" --no-color > "$TMPDIR/quickshell.log" 2>&1 &
QS_PID=$!

cat > "$TMPDIR/bin/omarchy-shell" <<EOF
#!/bin/bash
[[ \$1 == -q ]] && shift
XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-$TMPDIR}" quickshell ipc --pid "$QS_PID" call "\$@" >/dev/null 2>&1 || true
EOF
chmod +x "$TMPDIR/bin/omarchy-shell"

keyboard() {
  PATH="$TMPDIR/bin:$ROOT/bin:$PATH" omarchy-brightness-keyboard "$@"
}

sense() {
  echo "    Light changed: $1.000000 (lux)" >> "$TMPDIR/sensor"
}

brightness_is() {
  [[ $(< "$led/brightness") == "$1" ]]
}

manual_off_saved() {
  [[ -s $TMPDIR/home/.local/state/omarchy/keyboard-backlight-manual-off ]]
}

wait_for() {
  local description="$1"
  shift
  for _ in {1..100}; do
    "$@" && return 0
    sleep 0.1
  done
  sed -n '1,80p' "$TMPDIR/quickshell.log" >&2
  fail "$description"
}

monitor_running() {
  pgrep -f "tail -n \+1 -f $TMPDIR/sensor" >/dev/null
}

wait_for "monitor-sensor starts" monitor_running

# Steady dark: on.
echo "=== Has ambient light sensor (value: 1.000000, unit: lux)" >> "$TMPDIR/sensor"
sleep 0.4
sense 0
wait_for "turns on in the dark" brightness_is 2

# The keys turn it off, no new reading, then lock blank and wake.
echo 0 > "$led/brightness"
sleep 0.4
keyboard off
sleep 0.5
keyboard restore
sleep 1
brightness_is 0 || fail "a key press before a lock is kept at wake" "brightness: $(< "$led/brightness")"
manual_off_saved || fail "a key press before a lock is held as a manual off"
pass "a key press before a lock is kept at wake"

# The keys turn it back on, seen at the next reading.
echo 2 > "$led/brightness"
sense 1
wait_for "turning it back on with the keys clears the hold" bash -c "! [[ -s $TMPDIR/home/.local/state/omarchy/keyboard-backlight-manual-off ]]"

# The keys turn it off, no new reading, then a wake with no blank before it:
# omarchy-system-wake when the idle screensaver is dismissed before the lock,
# or an unlock before the lock screen blanks.
echo 0 > "$led/brightness"
sleep 0.4
keyboard restore
sleep 1
brightness_is 0 || fail "a key press is kept through a wake without a blank" "brightness: $(< "$led/brightness")"
manual_off_saved || fail "a key press before a wake without a blank is held as a manual off"
pass "a key press is kept through a wake without a blank"

Actual output at 1ed7e08e (exit 1, identical in 3 of 3 runs):

ok - a key press before a lock is kept at wake
brightness: 2
not ok - a key press is kept through a wake without a blank

With this change to bin/omarchy-brightness-keyboard (the same last look before restore writes;
pause() ignores it when off already paused the service):

 elif [[ $direction == "restore" ]]; then
+  omarchy-shell -q omarchy.keyboard-backlight pause
   brightnessctl -rd "$device" >/dev/null
   omarchy-shell -q omarchy.keyboard-backlight resume

Actual output (exit 0, identical in 3 of 3 runs); the PR's own model and service tests still pass
(35/35 and 10/10, 2 of 2 runs):

ok - a key press before a lock is kept at wake
ok - a key press is kept through a wake without a blank
Details

Verified at 1ed7e08e (headless Quickshell, real off/restore script, stub sensor and brightnessctl):

  • Key press to off, then off and restore with no new sensor reading: the keys stay at 0 and the manual off is saved (at 5e0a1b97 they were relit to 2). A chosen level 1 is kept.
  • A repeated off without restore does not record the blank as a manual off.
  • Each new or changed service check fails with its bug put back (blockLoading, the pause() look removed, the model's resume() skipped). Model test 35/35 and service test 10/10 in 5 of 5 runs.
  • The omarchy-iso builder reads install/omarchy-other.packages and downloads the packages with dependencies into the offline mirror.

The suggested pause is ignored after off, so the lock path is unchanged; with it the reproducer passes 3 of 3 and the PR tests still pass.

Related open PRs:

Optional test improvement: no test covers the !root.paused guard in pause(). With it removed the service test still passes 10/10, while a second off during a blank holds the keys off. A second ipc pause after the blank would catch it.


Review information

Test scope: source and headless Quickshell sandbox tests with stubs at 1ed7e08e; idle and lock services read, not run; no hardware.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

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

@greptile-apps

greptile-apps Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect automatic keyboard brightness and its coordination with lock, wake, and lid workflows.

Fix dimming after waking before merging; the lid-settling issue is smaller.

Findings

  1. P1 Dimming stops after waking ▶
  2. P2 Opening skips the settling wait ▶

Summary

Adds ambient-light control for the keyboard backlight, hardware checks, installation support, and a toggle. The latest changes add gradual dimming and make brightness keys wait for automatic writes.

  • The keyboard backlight follows room light on supported laptops.
  • Manual brightness choices stay in control of the automatic backlight.
  • The service leaves the keyboard alone while the laptop lid is closed.
  • Supported laptops get a toggle and the sensor support for automatic backlighting.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  Sensor[Light reading] --> Model[Evaluate thresholds and dimming]
  Keys[Brightness keys] --> Lock[Shared write lock]
  Model --> Lock
  Lock --> LED[Keyboard brightness]
  Wake[Wake or unlock] --> Resume[Clear applied state]
  Resume --> Model
  Model --> Gate{Applied is on?}
  Gate -->|No, light between thresholds| Stopped[Dimming stays stopped]
  Gate -->|Yes| Settle[Wait for target to settle]
Loading

Reviews (6) · Last reviewed commit: "Dim the keyboard backlight with the ligh..." · Reviewed by Greptile

@terracatta

Copy link
Copy Markdown
Author

Thanks, confirmed and fixed in ccb62ef. restore now sends pause before brightnessctl -r, as you suggested, so a wake without a blank still takes the last look at a key press. After an off it's a no-op.

Your reproducer is now test/shell.d/keyboard-backlight-auto-wake-test.sh, with credit in the commit. It drives the real off/restore script against the real service. I added a third case for your optional point: off, off, restore must not hold the keys off. With the restore pause removed, the wake-without-blank case fails. With the !root.paused guard removed, the repeated-off case fails.

e0a59d2 also covers a closed lid. The sensor sits in the lid, so when docked in clamshell mode it reads dark, and the service would have lit the keys under it. The service now reads the lid state at each decision and makes no change while it's closed. The lid-open binding sends a refresh so it decides from the light right away. Two new service-test cases cover it, and each fails with its part removed. monitor-recovery-test.sh's assertion on the lid-open binding is updated to match.

On #12553: agreed. Whichever lands second has to keep resume on every restore exit path, including its early exit, or the service stays paused after the first wake.

The model (35), service (12), and wake (3) tests pass.

@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

Migration filename collision: migrations/1790188786.sh is also added by #13082 (ASUS GU605MY backlight). Whichever PR lands second will overwrite the other's migration or fail to apply. Could you rename this one to a fresh timestamp?

git mv migrations/1790188786.sh "migrations/$(date +%s).sh"

Also, #14557 (omarchybot, stacked on #14431) is going after the same feature: ALS-driven keyboard backlight. A maintainer will need to choose one design.

omarchybot added a commit to aissa-93/omarchy that referenced this pull request Oct 8, 2026
…3148

omacom#13148 also adds migrations/1790188786.sh, so whichever of the two merged second would conflict on the file, and a resolution that kept one would drop the other migration. Give this one a fresh timestamp, after the newest migration on quattro, and move the rebuild marker and the test's marker with it.

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

Copy link
Copy Markdown
Collaborator

Reviewed at e0a59d2. This is a feature, so there is no bug to reproduce; the question is whether it does what the description says. None of that could be checked on real hardware: the test worker has no ambient light sensor or keyboard LED, so every behavioural result below comes from the stubbed sensor, LED and brightnessctl in the PR's own harness plus one probe of mine, and from reading. It says nothing about the XPS 14 itself.

What ran, on a disposable Omarchy worker with the shell linked to this branch: the model test 35/35, the service test 12/12, the wake test 3/3, and monitor-recovery, manifest-entrypoints, menu and menu-guards all pass. ./test/cli fails only vscode generated theme references current theme file, as you noted. I also merged current quattro into a local copy (not pushed) and ran the same tests plus plugin-manifest-scan, plugin-validate, shell-idle-spawn and i18n. All pass except one i18n case (da/menu.json mirrors the English catalog), which fails on quattro alone too.

It no longer merges. quattro is 647 commits past the base, and four files conflict: default/hypr/bindings/utilities.lua, default/omarchy/omarchy-menu.jsonc, manual/13-toggles-idle-screensaver.md and test/shell.d/monitor-recovery-test.sh. The rebase takes more than fixing the conflicting lines:

  • The Toggle menu now uses on/off pairs (trigger.toggle.screensaver-on/-off with opposite when guards), and toggle notifications go through omarchy-i18n (see bin/omarchy-toggle-screensaver). The new entry and its two notification strings need the same shape.
  • quattro added Apple Silicon lid bindings (switch:on/off:Apple SMC power/lid events), so the refresh nudge belongs on that open binding too.
  • lidClosed() in Service.qml reads only /proc/acpi/button/lid/*/state, and a missing file counts as open. bin/omarchy-hw-laptop-closed already answers this, and on quattro it also asks logind on machines with no ACPI lid (Apple Silicon's SMC). Using it would bring that support along. As written, the closed-lid guard does nothing on such a machine. I did not check whether any of those machines exposes an IIO light sensor today.

Found, and reproduced on the worker: turning the keys off in a steadily dark room is not held across a shell restart, and omarchy update restarts the shell. The level is only read in step() and pause(), and in steady light nothing calls either, so the hold is never written. After the restart, start() reads 0 with no saved hold, and the first dark reading turns the keys back on. My probe: dark, the service sets 2, the LED is set to 0 by hand, the shell is killed and restarted with the room still dark, and the service writes 2 again with the hold file empty. "Held across restarts" in the description is true only once a sensor change, a timed check or a lock has seen the off. The fix is a design choice (read the LED on a slow interval, persist what was last written, or narrow the claim), so I have not pushed anything.

Found by reading. Narrower, and not checked on hardware. These match Greptile's comments that are still open; I checked each against the source.

  • pause() does not cancel a write that is already running or a queued pendingLevel, and setProcess.onExited starts the queued level without checking paused, active or the lid. This needs a brightnessctl call to overlap the blank, so the window is milliseconds.
  • setProcess.onExited ignores the exit status. If writing an "on" level fails, the LED stays at 0, and the next read records that as a manual off and saves an eight-hour hold.
  • The manifest has no keepLoaded, and quattro's plugin reload destroys services without it. A reload or a shell re-exec while the lock has the keys blanked starts a fresh service with paused false, and a dark reading then lights the keys behind the lock.
  • brightSince is not persisted, so a restart during the ten-minute bright spell restarts that clock.

Checked and fine: on machines without both devices, nothing runs except one probe at shell start. off and restore exit before the IPC call when there is no LED, the install script and the migration require both devices, and each of the IPC calls added to off/restore took about 80 ms on the worker.

Second opinion: Codex Medium and muse-spark-1.3-contributor (via pi, thinking high) both reviewed this head. Both found the restart loss and the four narrower items above to be real. My brief had already raised them, and the reviewers can read this session, so treat that agreement as confirmation, not independent findings. Codex pointed to the existing omarchy-hw-laptop-closed helper, which I then checked. One claim was dismissed: that the hard-coded notification strings would show up empty under other languages. They are literal strings and would show in English; the problem is that they don't follow quattro's convention.

Related: #14557 (a draft from this account) builds the same feature as a systemd user service. #10331 drives the keyboard backlight from the T1 sensor on the models it targets. #12553 and #10366 change the same off/restore branch. Choosing between the designs is up to the maintainer. The migration name clash with #13082 no longer applies, since that PR now uses 1791499643.sh.

Waiting on: @terracatta to rebase onto quattro and decide how to handle the restart case, then the maintainer to choose between this and #14557.

terracatta and others added 8 commits November 8, 2026 08:34
…nsor

Laptops with an ambient light sensor now get an automatic
keyboard backlight. A shell service watches `monitor-sensor --light`
(iio-sensor-proxy only reports changes) and switches the backlight when
the room crosses from dark to bright or back, after the reading has held
for five seconds.

Levels set with the keys, `omarchy brightness keyboard`, or idle
blanking are respected. A manual level is reused the next time it gets
dark. A manual off in the dark is held across restarts until the room
has been bright for ten minutes, eight hours pass, or the backlight is
turned back on.

- omarchy-hw-ambient-light detects the sensor. The hardware setup and a
  migration install iio-sensor-proxy where one is present.
- omarchy toggle keyboard backlight auto disables it, which also
  releases the sensor. It is also in the Toggle menu on supported
  hardware.
- Thresholds can be tuned under `keyboardBacklight` in shell.json.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Read brightness with blockAllReads. reload() with blockLoading returned
  the previous load, so the service took its own writes as manual changes
  and could hold the backlight off in the dark. Skip observations while a
  write is in flight.
- Pause across session blanking. `omarchy-brightness-keyboard off` and
  `restore` now pause and resume the service over IPC. Nothing is lit
  behind a blanked lock screen, and the restored level becomes a
  baseline rather than the user's choice. A held manual off is put back
  if a wake restores a lit level.
- Run monitor-sensor with LC_ALL=C and accept comma decimals, so
  comma-decimal locales don't silently disable it.
- Manage monitor-sensor's running state imperatively, so a restart after
  an early exit can't detach it from the toggle.
- Match every IIO light sensor attribute iio-sensor-proxy supports. Add
  omarchy-hw-keyboard-backlight and require it for the menu entry and
  the install.
- Clamp the check timer to the 32-bit interval range.
- Manual: add the block to an existing shell.json, and note that the
  remembered level lasts until the shell restarts.
- Add a headless service test with stub monitor-sensor and brightnessctl
  covering stale reads, blanking, locale, and the toggle after a restart.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…on the ISO

- Take one last look at the level in pause(). A key press only shows up at
  the next sensor change or check, so in a steady dark room an off made
  just before locking was taken as the session's at wake and undone.
- Add iio-sensor-proxy to omarchy-other.packages so the ISO's offline
  mirror carries it for the hardware install.
- Rename the tests to keyboard-backlight-auto-*, clear of the
  keyboard-backlight-test.sh other open PRs add.
- Tighten the service test: check for a phantom off after a single
  reading, and cover a key press just before locking and a restore
  without a blank.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
omarchy-system-wake runs restore without an off before it when the idle
screensaver is dismissed before the lock, or on unlock before the first
blank. The service was never paused, so nothing looked at the level before
restore overwrote it, and a key press to off in a steady dark room was
undone. restore now pauses first. After an off, that pause is a no-op.

Adds keyboard-backlight-auto-wake-test.sh, adapted from the community
review's reproducer. It drives the real off/restore script against the
real service, and also checks that a repeated off during a blank isn't
taken as the user's.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The light sensor sits in the lid, so with the lid shut (docked, in
clamshell mode) it reads dark and the service would light the keys under
it. The service now reads the lid state at each decision and makes no
change while it's closed. The lid-open binding nudges it to decide from
the light right away.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…gration to a fresh timestamp

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d changes

- The backlight keys nudge the service, so an off made in steady light is
  saved at once, and the last level seen is kept in the runtime dir, so one
  made while the shell was down (firmware-handled keys too) is still the
  user's after a restart.
- A manual off is cleared as soon as the room has been bright long enough,
  not at the next dark, so a restart in between can't bring it back.
- Writes take the lock `omarchy-brightness-keyboard off`/`restore` use and
  skip while a blank is saved, so none lands behind the lock. A queued write
  is dropped once paused or the lid closes, and a failed or dropped write
  resyncs instead of being taken as a manual off.
- The service is kept loaded across plugin reloads, and a shell started
  while blanked starts paused.
- The lid is read with omarchy-hw-laptop-closed (so Apple Silicon's SMC lid
  counts too), both lid bindings nudge it, and opening the lid restarts
  monitor-sensor for a fresh reading rather than acting on the one taken
  under the lid.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@terracatta
terracatta force-pushed the keyboard-backlight-ambient-light branch from e0a59d2 to 2c43404 Compare November 8, 2026 13:59
@terracatta

Copy link
Copy Markdown
Author

Rebased onto quattro (d9cc361) and addressed the open reviews. It merges clean again.

Rebase (thanks for the list, omarchybot):

  • The Toggle menu entry is now an on/off pair (trigger.toggle.keyboard-backlight-auto-on/-off) with English catalog entries, and the toggle's notifications go through omarchy-i18n (keyboardBacklight.autoEnabled/autoDisabled).
  • pause/resume are fitted into quattro's new off/restore, inside its lock.
  • The lid nudge is on the Apple SMC lid bindings too, and the lid is read with omarchy-hw-laptop-closed.
  • IPC goes through ShellIpc.
  • The migration is renamed to a fresh timestamp (1794145104.sh), per jandrusk.

Restart case: I took two of the options. omarchy brightness keyboard up/down/cycle nudge refresh, so an off is saved at once. The last level seen is also kept in $XDG_RUNTIME_DIR, so a change made while the shell was down (firmware keys included) is taken as the user's after a restart. It's cleared on reboot, when the level isn't the user's.

The four narrower items:

  • Writes now share the off/restore lock and skip while a blank is saved.
  • Queued writes are dropped when paused or with the lid closed.
  • A failed or dropped write resyncs instead of becoming a manual off.
  • keepLoaded is set, and a shell started mid-blank starts paused.
  • The bright period now clears the hold when it ends, so a restart afterward doesn't bring it back. brightSince itself still restarts with the shell.

The replies on each Greptile thread have the details.

Tests: model 44, service 20, wake 7. I checked each new service and wake case by putting its bug back, and it failed each time. ./test/cli passes, and so does the rest of ./test/shell, except shell-idle-spawn-test.sh. That one fails the same way on quattro when run on a live desktop. I also ran the full quattro shell from this branch on the XPS 14 against the real sensor, LED and lid (with brightnessctl stubbed). It loaded as a first-party plugin, read the room, and acted through the new write path.

terracatta and others added 3 commits November 8, 2026 09:40
…ing it

Restarting the bright period on every pause meant a wake with no blank
before it (the mouse moved after idle) set it back to zero, so waking every
few minutes kept a manual off from ever clearing in a bright room. Leave out
only the time readings weren't evaluated, and keep the period running when
off is decided again after a wake.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment on lines +180 to +181
if (!cfg.dimming || lux === null || lux === undefined || state.applied !== "on" || state.held || state.dimHeld ||
state.manualOffSince > 0 || state.pending !== "" || !(state.expected > 0)) {

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.

P1 Dimming stops after waking

resume() clears applied, but this new guard requires it to be "on". Wake with the keyboard lit at 30 lux, then let the room brighten to 45 lux: neither reading can restore applied, so the keyboard never dims. It stays fixed until the room crosses a threshold again. Keep enough state after waking to resume dimming between the thresholds.

Comment on lines +196 to +199
} else if (now - next.dimSince >= cfg.settleMs) {
next.dimTarget = -1
next.expected = target
return { state: next, set: target }

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 Opening skips the settling wait

A pending dim counts time with the lid closed toward its five-second wait. interrupt() and uninterrupt() leave dimTarget and dimSince unchanged. If the lid closes while a dim is pending, the first fresh reading after opening can apply it immediately when it maps to the same target. A brief shadow while opening can therefore change the brightness without settling. Clear the pending dim when readings stop, or restart its wait after opening.

@ilyasakin

Copy link
Copy Markdown

Measurement from a MacBook Pro 14" M3 Pro (J514S, Apple Silicon), for this sensor path. I took the SMC total system power, display off and idle, 120 one-second samples per state, back to back:

Keyboard backlight Median Mean
128/255 3.32 W 3.47 W
0 2.60 W 2.73 W

So 50% keyboard backlight costs about 0.7 W here, and today it stays lit in a bright room and with the display off.

On this machine the ambient light sensor is exposed as IIO aop-sensors-als (in_illuminance_*, about 260 lux under office light), so the input this PR needs is there on Apple Silicon as well.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants