omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Keyboard backlight stays off after unlock: brightness-keyboard off saves 0 over the good value

Open mnemonicspace opened this issue 3 months ago • 2 comments

System details

Framework 13 Pro Intel X7

What's wrong?

What happens

After the session locks and I unlock it, the keyboard backlight stays off. It is not restored until I raise it by hand with XF86KbdBrightnessUp.

What should happen

The backlight returns to the level it was at before the lock. The lock service already intends this: it blanks with omarchy-brightness-keyboard off and the unlock path calls omarchy-system-wake, which runs omarchy-brightness-keyboard restore.

Cause

omarchy-brightness-keyboard off runs (bin/omarchy-brightness-keyboard:29):

brightnessctl -sd "$device" set 0

-s saves the current value before setting. Called once from a lit keyboard it correctly saves the good level. Called a second time while the backlight is already 0, it saves 0 — destroying the saved value. The later restore (brightnessctl -rd, line 32) then faithfully restores darkness.

shell/plugins/lock/Service.qml can blank more than once per lock. runBlank() (line 172) drives blankProcess (lines 409-412), and is reached both at lock time and from idleBlankTimer (lines 414-432), which calls root.runBlank() at line 430. runWake() (line 167) re-arms that timer whenever the lock screen is woken, so any wake-then-idle cycle on the lock screen produces a second blank, and from that point the saved value is 0.

This is a follow-on to #7562, which added the omarchy-brightness-keyboard restore call to omarchy-system-wake. That call is present and does run; the problem is that the value it restores has already been overwritten with 0 by a second off, so the restore succeeds and restores darkness.

Reproduce

Directly, without locking:

dev=$(basename /sys/class/leds/*kbd_backlight*)
brightnessctl -d "$dev" set 20
omarchy-brightness-keyboard off       # saves 20, sets 0   (correct)
omarchy-brightness-keyboard off       # saves 0,  sets 0   (destroys it)
omarchy-brightness-keyboard restore   # restores 0

Observed: final brightness 0. Expected: 20.

A single off/restore pair works correctly, which is why this looks intermittent — it only bites when the lock screen blanks twice.

Suggested fix

Skip the save when the device is already off, in bin/omarchy-brightness-keyboard:

if [[ $direction == "off" ]]; then
  if [[ "$(brightnessctl -d "$device" get)" -gt 0 ]]; then
    brightnessctl -sd "$device" set 0
  else
    brightnessctl -d "$device" set 0
  fi
  exit 0
fi

Workaround

Pinning brightnessctl's saved state read-only keeps a good value:

chmod 444 "$XDG_RUNTIME_DIR/brightnessctl/leds/<device>"

The blank still works, its save fails harmlessly, and restore returns a real level.

System

  • Omarchy 4.0.0-1
  • Kernel 7.1.8-arch1-3
  • CPU Intel Core Ultra X7 358H, GPU Intel Panther Lake [Arc B390]
  • Framework Laptop 13, LED device chromeos::kbd_backlight (max_brightness 100)
  • brightnessctl 0.5.1-3
  • quickshell-git 0.3.0.r20.g28771c7-1
  • Hyprland 0.56.2

Note

omarchy debug is listed by omarchy --help ("Diagnostics and support logs") but does not dispatch on 4.0.0-1: omarchy debug, omarchy debug --help and omarchy debug --no-sudo --print all return "Unknown Omarchy command". System details above were gathered by hand for that reason.

mnemonicspace avatar Aug 21 '26 01:08 mnemonicspace

Confirming on different hardware, with one additional path that the open PRs (#8134, #8382, #8119) don't cover.

System: MacBookPro16,1 (Intel i9-9980HK, AMD Navi 14 + Intel UHD 630, Apple T2), Omarchy 4.0.1-1, kernel 7.1.8-arch1-Watanare-T2-3-t2, brightnessctl 0.5.1-3. LED device :white:kbd_backlight (hid-apple, max_brightness 14660). bin/omarchy-system-wake, bin/omarchy-brightness-keyboard, shell/plugins/lock/Service.qml and shell/plugins/services/idle/Service.qml are identical to quattro @ c720f0b.

Symptom: backlight goes to 0 after every screensaver dismiss and after every suspend/unlock, even after raising it by hand in between.

What I observed: the saved state $XDG_RUNTIME_DIR/brightnessctl/leds/:white:kbd_backlight contained 0, and a 1 s poller on the LED's sysfs brightness caught the zeroing coming from omarchy-system-wake itself:

journal (omarchy-shell, idle plugin):
22:13:11  idle-cycle-start: screensaver=150 lock=300
22:13:11  process-start: screensaver ...
22:13:25  idle-cycle-cancel: screensaver-dismissed
22:13:25  process-start: wake omarchy-system-wake
22:13:25  process-exit: wake exitCode=0

sysfs poller:
22:12:17  start=4398
22:13:26  4398 -> 0

No lock and no off happened in that window: the screensaver was dismissed at 150 s, before the 300 s lock. omarchy-system-wake ran omarchy-brightness-keyboard restore anyway and restored the stale 0 over the level I had set by hand.

Two things this adds to the analysis above:

  1. Restore fires without a preceding off. shell/plugins/services/idle/Service.qml:106 runs omarchy-system-wake on every idle-cycle cancel once the cycle has idled, and bin/omarchy-system-wake:9 unconditionally runs omarchy-brightness-keyboard restore. So whatever brightnessctl last saved is re-applied on every screensaver dismiss, regardless of whether anything turned the keyboard off. With the saved value at 0 this is what makes the bug look like "always 0" rather than "sometimes stays off after unlock"; with a non-zero saved value it still silently reverts any manual change made since the last lock.

  2. How 0 gets into the saved state without a double blank. systemd-backlight had restored 0 at boot (/var/lib/systemd/backlight/...kbd_backlight = 0, saved at the previous shutdown while the lock screen was blanked). The first lock's off then saved that 0, and from there (1) keeps re-applying it. Because every wake resets the live value to 0, any later off saves 0 again, so the loop survives the user raising the level.

Interplay with the open PRs:

  • #8134 / #8382 (skip the save when already 0) stop 0 from being written, which breaks the loop in (2). They don't change (1): a stale non-zero value is still restored on every screensaver dismiss.
  • #8119 gates the restore on "this session blanked", but only inside the lock plugin. The idle plugin's wake at services/idle/Service.qml:106 → omarchy-system-wake → restore isn't touched, so path (1) remains.

Suggested fix for (1): omarchy-system-wake should not restore the keyboard unless something turned it off — either drop the restore from omarchy-system-wake and let the lock plugin own both off and restore (roughly what #8119 does), or have the idle plugin call restore only when it (or the lock) actually ran off in that cycle.

Workaround that has held here: seed the saved state after boot with a post-boot hook (brightnessctl -d "$dev" set 10%; brightnessctl -sd "$dev" set 10%), so restore never has a 0 to hand back.

phedoreanu avatar Aug 30 '26 15:08 phedoreanu

Automated duplication check: this issue looks similar to #6667, which covers the same keyboard backlight stays off after unlock. I keep that one open and close this one to keep the discussion in one place.

If you feel this is the wrong decision, please open the issue again with a note on the difference.

bjarneo avatar Sep 20 '26 20:09 bjarneo