Skip to content

Read the keyboard seat again when /dev/input changes instead of every 10 seconds - #15203

Merged
dhh merged 7 commits into
quattrofrom
keyboard-layout-device-events
Oct 13, 2026
Merged

dhh merged 7 commits into
quattrofrom
keyboard-layout-device-events

Conversation

@dhh

@dhh dhh commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

The keyboard layout widget ran hyprctl -j devices every 10s, in each bar, for as long as the seat had more than one keyboard. That is most seats with an external keyboard, a KVM or a Bluetooth keyboard: this laptop has four, counting the GL.iNet KVM and fcitx5's virtual keyboard. The poll was there because Hyprland raises no event when a keyboard arrives or leaves. Its IPC event list has activelayout and configreloaded, but no device events.

What changed

  • New Commons/InputDevices.qml singleton: one inotifywait for the whole shell watching three places:
    • /dev/input, where every keyboard the kernel sees (USB, Bluetooth via uhid, uinput) adds and removes its nodes;
    • /run/udev/data's c13: (input, major 13) records, which udev writes once it has finished with a device, i.e. when libinput hands it to Hyprland;
    • /dev itself, but only to re-arm the watch if /dev/input is removed and recreated.
  • It emits changed() once a burst of events has been quiet for 500ms, and again 3s later, in case Hyprland trailed the event.
  • A watcher that keeps exiting immediately (an exhausted inotify limit, say) is retried with backoff up to once a minute rather than given up on. inotify-tools is already in the base packages.
  • KeyboardLayout.qml reads the seat again on InputDevices.changed. The 10s timer now runs only until a first reading lands, and while a reading leaves the seat in doubt. A failed or unparseable reading now counts as in doubt, so it is retried. keyboardCount went with the old condition, since nothing else read it.
  • OMARCHY_INPUT_ROOT points the watch at a fixture root, the way OMARCHY_PROC_ROOT/OMARCHY_SYS_ROOT do for /proc and /sys.

Testing

  • New test/shell.d/input-devices-test.sh (compositor-gated) runs the singleton against a fixture root. It checks:
    • no signal while nothing changes;
    • nodes arriving 300ms apart raise nothing until the last settles, then one signal, then the follow-up;
    • the same on removal;
    • a removed and recreated /dev/input is watched again;
    • a c13: udev record signals, and other records don't.
  • Mutation checks: settle.start() in place of restart(), no re-arm on recreate, and a settle that never fires each fail their check.
  • Ran the idle-shell test from Fail tests when the shell polls while idle or the fast paths get slow again #15196 against this branch with its hyprctl -j devices allowance removed, on this four-keyboard seat: it passes, where quattro's shell spawns hyprctl -j devices every 10s.
  • keyboard-layout-test.sh and hyprland-keyboard-layout-test.sh pass.

For a human to check

  • Plug in or unplug a keyboard (or pair a Bluetooth one) with two layouts configured, and check that the bar label follows within a second.
  • fcitx5's virtual keyboard comes and goes without a /dev/input node. The widget already ignores it (isTypedKeyboard), and its layout changes still arrive as activelayout events.
  • Once this lands, Fail tests when the shell polls while idle or the fast paths get slow again #15196's allowance for hyprctl -j devices can be dropped.

🤖 Generated with Claude Code

… 10 seconds

Hyprland raises no event when a keyboard arrives or leaves, so a seat with
more than one keyboard was asked every 10s, per bar, for as long as the
shell ran. One inotify watch of /dev/input announces each device instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain.

Summary

The PR replaces repeated keyboard reads with one shared watch on input-device changes.

  • Keyboard layout updates follow input-device changes without steady polling.

Both earlier, unnumbered findings are addressed: failed keyboard reads now keep retries running, and the arrival test staggers nodes to catch a timer that does not restart. No new actionable issues were found.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Input-device change] --> B[Restart both timers]
  B --> C[Quiet for 500 ms]
  B --> D[Follow-up after 3 seconds]
  C --> E[Read keyboards]
  D --> E
  F[Watch exits quickly] --> G[Retry with backoff]
  F --> H[Read keyboards every 10 seconds]
  G --> I[Watch stays up for one second]
  I --> B
  I --> J[Stop fallback after a good reading]
Loading

Reviews (6) · Last reviewed commit: "Read the seat only after a watch that he..." · Reviewed by Greptile

Comment thread test/shell.d/input-devices-test.sh Resolved
dhh and others added 4 commits October 12, 2026 19:55
…eated /dev/input, and retry failed readings

Addresses Codex review: udev can take longer than the settle delay, a watch
on a deleted /dev/input never fires again, and a failed reading no longer had
the old poll to recover it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the test shell before its watcher

Addresses Greptile review: back-to-back nodes could not tell a restarted
settle timer from a started one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rying a failing watcher

Addresses Codex review: udev can finish with a device later than any fixed
delay, which its /run/udev/data record marks, and an inotify setup failure
gave up for good after five tries; it now backs off to once a minute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses Codex review: a device arriving while the watcher restarted went
unseen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
dhh and others added 2 commits October 12, 2026 20:30
Addresses Codex review: a device leaving between the widget's first reading
and the watch going up went unseen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… instead of timing it

Addresses Claude review: a watcher failing at once announced on every retry,
so each bar asked Hyprland about once a second; the keyboard widget's
fallback timer now covers a watch that keeps failing. The burst check
compares the first signal with the last node rather than asserting on a
200ms margin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh
dhh merged commit 8f5ca14 into quattro Oct 13, 2026
1 check passed
@emirb emirb added this to the 4.5 milestone Oct 17, 2026
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.

2 participants