fix(hyprland/language): split activelayout on the last comma outside parens - #5247
Open
vanshdev0101 wants to merge 1 commit into
Open
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4586.
The bug
The
activelayoutpayload is<keyboard>,<layout>, and both halves can contain commas — the keyboard in its vendor string, the layout inside its variant parentheses.Language::onEventhandled 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:
truncates to
ite-tech.-inc.-ite-device, which has no comma, soonEventreturned 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 intoutil/string.hppso it could be unit-tested without pulling inALabel/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:
and after:
Added
test/utils/string.cppcoveringrfindOutsideParensand 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 testis green (waybar,hyprland,utils), fullninjabuild clean,clang-formatclean.util/string.hppgained<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.