Skip to content

fix(hyprland/language): split activelayout on the last comma outside parens - #5247

Open
vanshdev0101 wants to merge 1 commit into
Alexays:masterfrom
vanshdev0101:fix/hyprland-language-bracket-keyboard-name
Open

fix(hyprland/language): split activelayout on the last comma outside parens#5247
vanshdev0101 wants to merge 1 commit into
Alexays:masterfrom
vanshdev0101:fix/hyprland-language-bracket-keyboard-name

Conversation

@vanshdev0101

Copy link
Copy Markdown

Closes #4586.

The bug

The activelayout payload is <keyboard>,<layout>, and both halves can contain commas — the keyboard in its vendor string, the layout inside its variant parentheses. Language::onEvent handled the latter by truncating the payload at the last ( and taking the last comma of what remained.

That assumes every bracket belongs to the layout. Keyboard names carry them too:

activelayout>>ite-tech.-inc.-ite-device(8910)-keyboard,Russian

truncates to ite-tech.-inc.-ite-device, which has no comma, so onEvent returned early and the layout never updated. The module goes blank on every switch for anyone whose keyboard has a bracket in its name.

Note this is independent of keyboard-name: the parse bails before that check runs, so setting it doesn't help.

The fix

Scan back for the last comma outside parentheses. That keeps commas inside a variant like English (US, intl., with dead keys) protected, while ignoring brackets anywhere in the keyboard name. The helper (rfindOutsideParens) went into util/string.hpp so it could be unit-tested without pulling in ALabel/IPC.

The issue suggests porting niri/language's logic. That doesn't transfer — niri's IPC returns a structured layout list (keyboardLayoutNames()) and never parses a payload, so there's no equivalent code to lift.

Testing

Reproduced on real hardware — a Bluetooth device that Hyprland registers as a keyboard with a bracketed name, on Hyprland 0.56.2. Given a second layout on that device only, switching layouts before the fix:

[debug] hyprland IPC received activelayout>>vis-s226-(avrcp),Russian
[debug] hyprland language didn't find matching layout
[debug] hyprland language formatted layout name LANG=[]

and after:

[debug] hyprland IPC received activelayout>>vis-s226-(avrcp),Russian
[debug] hyprland language onevent with Russian
[debug] hyprland language formatted layout name LANG=[Russian]

Added test/utils/string.cpp covering rfindOutsideParens and the payload split, including the reported payload and the variant-with-commas case the old ( heuristic existed to protect. I checked the tests fail against the previous algorithm rather than only passing against the new one — 3 of 11 assertions fail when the helper is reverted, including the #4586 case. meson test is green (waybar, hyprland, utils), full ninja build clean, clang-format clean.

util/string.hpp gained <algorithm>, <string_view> and <vector> includes: it was relying on transitive ones, and the new test is the first place that includes it standalone.

What I did not test: a physical keyboard whose name contains a bracket — the reproduction above uses a Bluetooth AVRCP device Hyprland exposes as a keyboard, which produces the same payload shape. I also only exercised this on Hyprland 0.56.2.

…parens

The activelayout payload is "<keyboard>,<layout>", and both halves can
contain commas: the keyboard in its vendor string, the layout inside its
variant parentheses. onEvent handled the latter by truncating the payload
at the last '(' and taking the last comma of what remained.

That assumes every bracket belongs to the layout, but keyboard names carry
them too. For "ite-tech.-inc.-ite-device(8910)-keyboard,Russian" the
truncation left "ite-tech.-inc.-ite-device", which has no comma at all, so
the event was discarded and the layout never updated.

Scan back for the last comma outside parentheses instead. This keeps the
commas inside a variant such as "English (US, intl., with dead keys)"
protected while ignoring brackets in the keyboard name.

Closes Alexays#4586
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.

hyprlang/language does not work correctly when the keyboard name has an open bracket but the layout does not

1 participant