Repository navigation
libobs: Map X11 keysyms to the key that types them unshifted - #350
Merged
Merged
Conversation
…yout
A hotkey bound to "[" must show as "[" and fire from the [ key, also
when another layout group has "[" on a different key. The reporter's
layout has a Latin and a Cyrillic group; the Cyrillic group includes
xkb "latin", whose 8 key is [ 8, asterisk, bracketleft, trademark ]. The
X server's core keyboard map then lists bracketleft on the 8 key
(group 2, level 3) as well as unshifted on the [ key.
The test loads that layout's core map rows for the 8, 9, [ and ] keys
(the rows the X server reports after xkbcomp loads the reporter's
layout) through a connection that stays open, starts libobs on X11, and
restores the rows afterwards. Cases:
- "[" and "]" map to OBS_KEY_BRACKETLEFT and OBS_KEY_BRACKETRIGHT;
- symbols that only exist on a shifted or AltGr level ("*", the
square root and trademark signs, "{") still map to the key that has
them (guard);
- the label Settings -> Hotkeys shows for a "[" hotkey is "[";
- with OBS not focused, the [ key fires a "[" hotkey and the 8 key does
not (key presses through XTEST, picked up by the hotkey thread).
On master, under xvfb, "[" maps to OBS_KEY_8, the hotkey is shown as
"8", and only the 8 key fires it; the guard passes. Without a display,
or without XTEST, every case skips.
Reported upstream in obsproject/obs-studio#12941 by Blayung.
Refs obs-rust#349.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
On X11, a hotkey bound to "[" was stored and shown as "8", and outside
OBS only the 8 key triggered it, when a second layout group has "[" on
the 8 key (for example English + German, or the reporter's Latin +
Cyrillic layout built on xkb "latin": AltGr+8 types "[").
Qt reports the pressed key as a keysym, and
obs_nix_x11_key_from_virtual_key() turns it into an obs_key_t through
the keycode that has it. It searched the core keyboard map keycode by
keycode, each with all its groups and levels, and took the first
keycode that had the keysym anywhere. Keycode 17 (the 8 key, with "["
at group 2, level 3) comes before keycode 34 (the [ key, with "["
unshifted in group 1), so "[" became OBS_KEY_8, "]" became OBS_KEY_9
and "{" OBS_KEY_7.
Search the map one column (group and level) at a time instead, as
XKeysymToKeycode() does, so the key that types the symbol unshifted in
the first group wins. A symbol that only exists on a shifted or AltGr
level (German "[" on AltGr+8 with no second group, "*" on Shift+8) still
maps to the key that has it.
With the fix, under xvfb (both ENABLE_RUST_LIBOBS lanes), "[" and "]"
map to OBS_KEY_BRACKETLEFT and OBS_KEY_BRACKETRIGHT, a "[" hotkey is
shown as "[" and fires from the [ key and not from the 8 key; the
shifted-level guard is unchanged. The same holds with the reporter's
layout and with "us,de" loaded through xkbcomp/setxkbmap; with "de"
alone "[" still maps to the 8 key.
Reported upstream in obsproject/obs-studio#12941 by Blayung.
Fixes obs-rust#349.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=6cb73637c43f3e989c99b1c5f6e24b0ecd5e951e secs=154 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791795989,"gate":"rust/all/fmt","host":"linux-x86_64","key":"1310046d0c92d070b5d756166d3f1a04b4c0c211f70e4cd3a2d301698fa5e7ea","lane":"lint","parents":["aa921c52ad466045348a52eaa8d9154c3c2a492c"],"secs":55,"stamp":"9e45679b0e1ed747efc7a66a11bbe2ad","tree":"6cb73637c43f3e989c99b1c5f6e24b0ecd5e951e","v":1,"via":"run"}
Ci-Attestation: {"at":1791795989,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"1310046d0c92d070b5d756166d3f1a04b4c0c211f70e4cd3a2d301698fa5e7ea","lane":"lint","parents":["aa921c52ad466045348a52eaa8d9154c3c2a492c"],"secs":55,"stamp":"aedf1724d7e8793401560b86d8c834cf","tree":"6cb73637c43f3e989c99b1c5f6e24b0ecd5e951e","v":1,"via":"run"}
Ci-Attestation: {"at":1791795989,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"cd66b81a7c115530af5730e677d9f8ff52529bc1c564ef17e8aa9b149dae221b","lane":"rust-test","parents":["aa921c52ad466045348a52eaa8d9154c3c2a492c"],"secs":48,"stamp":"f0ceed04556016160c91cdaf54e45ab3","tree":"6cb73637c43f3e989c99b1c5f6e24b0ecd5e951e","v":1,"via":"run"}
Ci-Attestation: {"at":1791795989,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"ae56690ed7930560897972e09e3bdc38f5e1b029b7aaf3ba5e2e1c9c2ada52ff","lane":"tier2-linux","parents":["aa921c52ad466045348a52eaa8d9154c3c2a492c"],"secs":51,"stamp":"3496d682803706727651686a0b0a9d3e","tree":"6cb73637c43f3e989c99b1c5f6e24b0ecd5e951e","v":1,"via":"run"}
zackees
force-pushed
the
fix/12941-x11-keysym-keycode
branch
from
October 12, 2026 09:06
90fed73 to
f4c3962
Compare
Member
|
Verified RED→GREEN locally (Tier 2 image + libxtst-dev, run under xvfb-run):
Note: the default Tier 2 image lacks libXtst, so CI builds skip this test. Rebased on master, local gate passed, and pushed as f4c3962. |
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.
Description
On X11, hotkeys bound to
[,]and similar symbols now use the key that types them. Before, a second keyboard layout group that also has the symbol on a number key turned the hotkey into that number.obs_nix_x11_key_from_virtual_key()turns it into anobs_key_tthrough the keycode that has it. It searched the core keyboard map keycode by keycode, each with all its groups and levels, and took the first keycode that had the keysym anywhere. With English + German, or the reporter's Latin + Cyrillic layout built on xkblatin, the 8 key (keycode 17) has[at group 2, level 3 (AltGr+8). It comes before the[key (keycode 34), so[becameOBS_KEY_8,]becameOBS_KEY_9and{OBS_KEY_7.[, and outside OBS only the 8 key triggered the hotkey.XKeysymToKeycode()does, so the key that types the symbol unshifted in the first group wins. A symbol that only exists on a shifted or AltGr level (German[on AltGr+8 with no second group,*on Shift+8) still maps to the key that has it.test/cmocka: Add failing test for X11 hotkeys on "[" with a second layout:test_x11_hotkey_layoutloads the reporter's core keyboard map rows for the 8, 9,[and]keys into the X server, starts libobs on X11 and restores the rows afterwards. A second connection stays open throughout, so the server keeps the map. The cases are:[and]map toOBS_KEY_BRACKETLEFTandOBS_KEY_BRACKETRIGHT;*, the square root and trademark signs,{) still map to the key that has them;[hotkey (obs_key_to_str()) is[;[key fires a[hotkey and the 8 key does not (key presses through XTEST, picked up by the real hotkey thread).Today
[maps toOBS_KEY_8, the hotkey is shown as "8", and only the 8 key fires it ([key 0 times, 8 key once). 3 of 4 fail.libobs: Map X11 keysyms to the key that types them unshifted: switches the search to one column at a time.[and]map to their own keys, the hotkey is shown as[and fires from the[key only, and the guard is unchanged. 4 of 4 pass.Motivation and Context
Fixes #349 (upstream obsproject/obs-studio#12941, reported by Blayung, who also shared the layout that made the cause clear and checked that the Flatpak build behaves the same). Penwy triaged it upstream.
There is no upstream PR for this;
libobs/obs-nix-x11.chas not changed upstream since 2024.Why this one: anyone on X11 with two layout groups, a common setup for people who type in two languages, cannot bind
[or]without them landing on a number key. The bound number then also triggers the action while typing in other programs.How Has This Been Tested?
Automated, in both libobs lanes (
ENABLE_RUST_LIBOBSOFF and ON), on current master:test_x11_hotkey_layout: 3 of 4 cases fail at the RED commit and 4 of 4 pass at GREEN, under a private Xvfb, with the installed system OpenGL module masked (the test does not load GL).ctest -Vshows every case run, none skipped. Repeated 50 times at GREEN: same result every time. The test restores the keyboard map rows exactly.[,]and{toOBS_KEY_8,OBS_KEY_9andOBS_KEY_7with labels "8", "9" and "7"; the fix gives[,]and[. The same holds forsetxkbmap -layout us,de. Withdealone,[maps to the 8 key before and after, as it should.ci/test_registration.pyare clean. The test is registered on Linux only, when X11 and XTest are found.Not tested:
obs_key_from_virtual_key()with the keysym Qt passes for the key event, asOBSHotkeyEditdoes, andobs_key_to_str()for the label.[while the second group is active now binds the[key rather than the 8 key, the same asXKeysymToKeycode(). Telling these apart would need the keycode from Qt, not the keysym; that is a larger change to the frontend contract and is not part of this PR.Types of changes
Checklist:
🤖 Generated with Claude Code