Skip to content

Add a keyboard backlight timeout - #30

Open
flamingspaz wants to merge 2 commits into
mainfrom
feat/kbd-backlight-timeout
Open

flamingspaz wants to merge 2 commits into
mainfrom
feat/kbd-backlight-timeout

Conversation

@flamingspaz

@flamingspaz flamingspaz commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Closes #24.

What it does

The Input page gets a Keyboard backlight: Turn off after [N seconds] setting (5–3600 s, default 30). It's only shown when the daemon finds a keyboard backlight, with a note that brightness is still set from the desktop or with Fn+Space.

The EC has no backlight timeout, so frameworkd fakes one:

  • While a timeout is set, it opens every keyboard and pointing device in /dev/input. It skips power buttons, lid switches and sensors, and uses only when input happened, never which key.
  • After the timeout with no input, it remembers the current brightness and fades the backlight out over about 1 s. The next input fades it back in over about 0.1 s. Input during the fade-out reverses it straight away.
  • The desktop and Fn+Space stay in charge of brightness. If the backlight is already off at the timeout, nothing happens. If it's turned up while idle, that brightness is kept.
  • If the daemon stops or restarts while the backlight is off, it restores the remembered brightness first. That brightness isn't written to disk, so after a crash the backlight stays off until it's changed from the desktop or with Fn+Space.

Brightness goes through the kernel's LED device (/sys/class/leds/*::kbd_backlight), which the desktop uses too, rather than framework_lib. framework_lib rounds percent to duty and back down (50% reads back as 49%), so restoring through it would leave the backlight slightly dimmer each time.

Power use

The daemon is always running, so this is built to cost close to nothing:

  • While you're typing: it doesn't read input as it arrives. Events queue in the kernel, and the daemon reads them only when the timeout would run out, using their timestamps to work out when the last one happened. That's about one wakeup per timeout period, and also when newly plugged-in devices are picked up.
  • While the backlight is off: devices are registered with the async runtime only then, so it can wake as soon as there's input.
  • With the timeout set to 0: no devices are open and nothing runs on a timer.
  • Per idle cycle: nothing is written to disk.

Other changes

  • New D-Bus method SetKeyboardBacklightTimeout(i seconds), under the existing input polkit action. GetInput also returns kbdBacklightSupported and kbdBacklightTimeout.
  • New dependencies: evdev 0.13 and libc (for non-blocking opens; libc was already in the lockfile). Also enables tokio's sync, time and net features.
  • Fixes the Overview page always reporting no keyboard backlight outside fixture mode. supportsKeyboardBacklight now comes from the daemon.
  • Docs: a new section in docs/architecture.md and updated README notes.
  • Translations are in a separate commit: the new strings in German, Spanish, French and Dutch (machine translated, like the rest). This is the first plural string, so each catalog also gets the Plural-Forms header that msgfmt requires.

daemon/Cargo.toml will have a one-line conflict with #29, since both add tokio's time feature.

Testing

  • Built with ./build.sh -DBUILD_TESTING=ON -DBUILD_GUI=ON in the project's Docker image. No warnings. cargo clippy and cargo fmt --check are clean.
  • ctest: 3/3 pass. These don't cover the timeout itself.
  • msgfmt --check passes for all four catalogs.
  • Tested on a Framework laptop: the timeout turns the backlight off and brings it back.

🤖 Generated with Claude Code

@flamingspaz
flamingspaz force-pushed the feat/kbd-backlight-timeout branch from 9b418d2 to 62afe30 Compare November 6, 2026 23:41
flamingspaz and others added 2 commits November 6, 2026 23:44
The EC has no backlight timeout, so frameworkd fakes one. While a timeout
is set it opens every keyboard and pointing device, using only when input
happened, never what it was. Once idle for the timeout it remembers the
current brightness and fades the backlight out over a second; the next
input fades it back in over a tenth of a second. Input during the
fade-out reverses it straight away.

To stay cheap while the keyboard is in use, it doesn't read input as it
arrives. Events queue in the kernel, and the daemon only drains them when
the timeout would run out, using their timestamps to work out how long
it's really been idle. Devices are only registered with the reactor while
the backlight is off, so typing causes no wakeups, and nothing is written
to disk per idle cycle.

Brightness stays with the desktop and Fn+Space: the timeout reads whatever
they last set, does nothing if the backlight is already off, and keeps a
brighter level set while idle. It goes through the kernel's LED device
rather than framework_lib, whose percent/duty rounding would make each
restore slightly dimmer. On shutdown the task is stopped before the
brightness is put back, so a fade in progress can't undo it.

The Input page gets a "Turn off after" checkbox and seconds box, shown when
the daemon finds a keyboard backlight. That also fixes the Overview page
always reporting no keyboard backlight outside fixture mode.

Closes #24

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Regenerate the catalogs and add German, Spanish, French and Dutch
translations (machine translated, like the rest). This is the first plural
string, so each catalog also gets its Plural-Forms header, without which
msgfmt rejects it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@flamingspaz
flamingspaz force-pushed the feat/kbd-backlight-timeout branch from 62afe30 to 19ef83d Compare November 6, 2026 23:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add backlight timeout

1 participant