omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Layout widget switches only one of several real keyboards, so a laptop with an external keyboard half-switches

Open fabeider opened this issue 2 months ago • 3 comments

What happens

Clicking the omarchy.keyboard-layout bar widget changes the label but not the layout under the keys I am typing on. This is the symptom of #8964 and #10135, but with a cause that survives the fix both of them propose: this machine has two real keyboards, and the widget switches one of them.

Why the filter fixes do not reach it

#8964 and #10135 both address UNTYPED_KEYBOARDS letting a non-keyboard through, and both resolve once the offending device is filtered out — #8964 notes that afterwards "the widget sees 1 keyboard". That is the part this report does not duplicate.

cycleLayout() switches exactly one device, whatever selectKeyboard() settled on:

// shell/plugins/bar/widgets/KeyboardLayout.qml
root.bar.run("hyprctl switchxkblayout " + Util.shellQuote(root.keyboardName) + " next")

On a laptop with an external keyboard attached, two devices legitimately survive any filter — here at-translated-set-2-keyboard (built-in) and apple-inc.-magic-keyboard-with-numeric-keypad (external). Both are real keyboards and both belong in the list, so no UNTYPED_KEYBOARDS change can separate them.

When both rest on the same layout, layoutIndex() ties, reduce keeps keyboards[0], and that is whichever device Hyprland listed first — the built-in. That resting state is the normal one and is exactly the state a click starts from. So the click advances the built-in; the label follows it (now the furthest advanced, so selectKeyboard() keeps choosing it) and reports the new layout, while the external keyboard under my hands never moved.

No blocklist can decide which of two real keyboards a person is typing on.

Not #9552 either

#9552 reports the same wording — "bar label switches, typing doesn't" — from fcitx5 grabbing keys and committing against its own virtual keyboard. That is not this: on this machine switching the typed-on keyboard directly does change typing,

$ hyprctl switchxkblayout apple-inc.-magic-keyboard-with-numeric-keypad next

and hl-virtual-keyboard-fcitx5 tracks the real keyboard's index rather than staying on us. The compositor-to-app path works fine here; only the widget's choice of device is wrong.

Steps to reproduce

  1. A laptop with its built-in keyboard, plus any external keyboard attached.
  2. Two layouts, e.g. kb_layout = "us,br".
  3. Put both keyboards on the same layout index (a hyprctl reload does it).
  4. Click the keyboard-layout bar widget.
  5. Type on the external keyboard.

Expected: typed characters follow the layout shown on the bar. Actual: the label changes; the external keyboard still produces the old layout.

Evidence

BEFORE (both real keyboards rest on the same layout):
  at-translated-set-2-keyboard                   idx=0  English (US)
  apple-inc.-magic-keyboard-with-numeric-keypad  idx=0  English (US)

CLICK -> cycleLayout() switches only selectKeyboard()'s pick, keyboards[0]:
  $ hyprctl switchxkblayout at-translated-set-2-keyboard next

AFTER (the bar reads PT; the keyboard being typed on never moved):
  at-translated-set-2-keyboard                   idx=1  Portuguese (Brazil)
  apple-inc.-magic-keyboard-with-numeric-keypad  idx=0  English (US)

Suggested fix

Stop choosing. Move every typed keyboard, naming the target layout by index rather than next so they cannot drift apart:

const target = layoutCount > 1 ? String((activeIndex + 1) % layoutCount) : "next"
for (const name of keyboardNames) {
  bar.run("hyprctl switchxkblayout " + Util.shellQuote(name) + " " + target)
}

The comment in cycleLayout() rules out switching the seat together because it "would also carry the buttons along". That does not apply when only the filtered keyboards are named — the buttons and virtual devices stay where they started, so the reading still holds. It also makes selectKeyboard() matter only for the label, never for correctness, which contains the blast radius of #8964 and #10135: a device that slips through the filter would then be switched along with the real keyboards instead of instead of them.

Addressing by index rather than next additionally repairs drift instead of preserving it, which matters because grp:shifts_toggle creates drift routinely — it advances only the keyboard the shifts were tapped on.

I have been running this locally as a cloned plugin; it fixes both the click and the drift. Happy to open a PR.

Also, more filter names for #8964 / #10135

Not this issue, but data for those: on this Dell laptop the devices surviving isTypedKeyboard() alongside the two real keyboards are intel-hid-events, intel-hid-5-button-array, dell-wmi-hotkeys, dell-privacy-driver, and a webcam's keyboard node (emeet-smartcam-s600:-emeet-smar). The suffix regex suggested in #8964 catches dell-wmi-hotkeys but not the intel-hid-*, -privacy-driver or webcam nodes.

System

  • Omarchy 4.0.3-1
  • Hyprland v0.56.2
  • Kernel 7.2.3-arch1-3
  • Dell laptop, 11th Gen Intel i5-1135G7, Intel Iris Xe Graphics
  • fcitx5 running

fabeider avatar Sep 08 '26 21:09 fabeider

Confirmed on a third configuration, and the lockstep fix works — verified on Asahi (Mac14,2) where the "second keyboard" is not a second physical device at all.

This seat's two surviving keyboards

With UNTYPED_KEYBOARDS corrected (I excluded apple-smc-power/lid-events, see #8964), exactly two devices still survive the filter, and the resting state is the one this report describes — both at index 0, tie broken by list order:

apple-mtp-keyboard        idx=0  Spanish (Latin American)   <- picked, and switched
keyd-virtual-keyboard     idx=0  Spanish (Latin American)

keyd grabs apple-mtp-keyboard and re-emits through a uinput device, so the keystrokes arrive from keyd-virtual-keyboard while the click advances apple-mtp-keyboard. selectKeyboard() picks the built-in because it is first, so the click always hits the device whose layout is not the one that decides the character.

The fix I verified

cycleLayout() now lands every typed keyboard on the same index, instead of advancing only the one the label names:

const next = (root.layoutPosition + 1) % root.layoutCount
root.typedKeyboardNames.forEach(function (name) {
  root.bar.run("hyprctl switchxkblayout " + Util.shellQuote(name) + " " + next)
})

Result — one click, both devices, the lid switch correctly left alone:

ignored apple-smc-power/lid-events   English (US)
typed   apple-mtp-keyboard           English (US)
typed   keyd-virtual-keyboard        English (US)

This also re-syncs a seat that has already drifted, which the next form cannot do, and it wraps by index so it stays correct past the end of the list. Falls back to next on the single named keyboard when there is no layout list to index into, preserving current behaviour on a one-layout install.

Two things worth weighing against the "advance one device" approach in the original:

  • It makes all keyboards move together, so a user who deliberately keeps two keyboards on different layouts can no longer do so from the bar. SUPER+space / grp: still can.
  • It is N hyprctl invocations per click (N = typed keyboards), rather than one.

Environment

Omarchy 4.0.3rc4-1, Hyprland 0.56.2, kb_layout = "latam,us", keyd 2.6.0 with a [ids] * config. Reproduced and fixed by cloning the widget and patching both files.

remusa avatar Sep 28 '26 21:09 remusa

This is already fixed on quattro, and the fix has not shipped in a release yet.

#10670 (commit 6ee7479879fa496e21c6e54b8e643a8d77d9ab16, merged on September 7) replaced the single hyprctl switchxkblayout <keyboard> next in cycleLayout() with the fix suggested here: every keyboard that holds the same kb_layout list is switched to one absolute index, (layoutIndex + 1) % layoutCount (shell/plugins/bar/widgets/KeyboardLayout.qml, cycleLayout() and the syncNames it builds from hyprctl -j devices). The switched set is taken from every listed keyboard, not just the ones that survive UNTYPED_KEYBOARDS, so selectKeyboard() now decides only the label. With at-translated-set-2-keyboard and the Magic Keyboard both at index 0, one click sends both to index 1. The same applies to the apple-mtp-keyboard / keyd-virtual-keyboard pair in the comment above, as long as both report the same layout list. A seat that has drifted apart converges on the first click.

v4.0.3, which this was reported on, and v4.0.4, the latest release, both still have the old next call, so this will keep happening until the next release that includes that commit.

How this was checked: I read the widget and KeyboardLayoutModel.js at the current quattro head (f2a39c4) and confirmed with git tag --contains and merge-base that neither release tag contains the commit. Nothing was run on a worker: the case needs two physical keyboards, and the mechanism can be proven from the source. Codex Medium reviewed the same code separately and agreed: both devices in each scenario get the same switch. It added one caveat. A device whose layout string differs in any way, even just the order, is left out of the switched set. That applies only to a keyboard given its own kb_layout, which neither setup here has. Its independence from this review is not guaranteed.

Waiting on the maintainer, who can close this once a release carries the fix.

omarchybot avatar Oct 10 '26 22:10 omarchybot

Distinct from #8964/#10135 (filter junk devices): here two real keyboards both survive, and cycleLayout() only advances one. Fix is broadcast/hyprctl switchxkblayout across all real keyboards (or keep them synced), not a tighter filter.

Nearby AVRCP false-keyboard work: #15145 / #15150.

jandrusk avatar Oct 13 '26 16:10 jandrusk