Skip to content

bug: libobs: X11 hotkey on "[" shows and fires as "8" with a second keyboard layout (upstream #12941) #349

Closed

Description

@rdoupe

Upstream OBS bug, reported by Blayung in obsproject/obs-studio#12941 (Arch Linux, X11, OBS 32.0.2; the Flatpak build behaves the same). Binding a hotkey to [ in Settings -> Hotkeys shows 8 instead, and ] shows 9. In OBS both keys trigger the hotkey; outside OBS only the number does. The reporter shared their layout: a custom Latin group and a Cyrillic group, both built on xkb latin. Penwy triaged it (asked for the layout and the Flatpak check). The code has not changed in this fork.

Location

  • libobs/obs-nix-x11.c obs_nix_x11_key_from_virtual_key(): Qt hands over the pressed key as a keysym, and this function turns it into an obs_key_t through the keycode that has that keysym. It walks the core keyboard map keycode by keycode, each with all its groups and levels, and takes the first keycode that has the keysym anywhere.
  • With a second layout group, the core map row of the 8 key (keycode 17) is 8 asterisk 8 asterisk ... bracketleft trademark: xkb latin puts [ on AltGr+8, and the reporter's Cyrillic group includes it. The [ key (keycode 34) has bracketleft unshifted in group 1, but keycode 17 comes first, so [ becomes OBS_KEY_8. fill_keycodes() registered keycode 17 as the 8 key, so the hotkey is shown as "8" and the hotkey thread only fires it while keycode 17 is down.
  • Xlib's XKeysymToKeycode() searches the same map one column (group and level) at a time and returns keycode 34.

Class

Wrong behaviour: hotkeys on [, ] and other symbols that a second layout group also puts on a number key are bound to the wrong key. Typing the symbol in Settings is the only way to bind them.

How it is reached

  • Any X11 setup with two layout groups where the second one has the symbol on another key at a higher level, for example English + German (setxkbmap -layout us,de: AltGr+8 is [, AltGr+9 is ], AltGr+7 is {), or the reporter's Latin + Cyrillic layout.
  • Settings -> Hotkeys, press [: the field shows "8". Outside OBS, pressing [ does nothing and pressing 8 triggers the action.

Reproduced headlessly. The reporter's layout, compiled with xkbcomp and loaded into a private Xvfb started with -noreset, gives exactly that core map row. (Without -noreset, Xvfb reloads its default keymap when the last client disconnects, which is why setxkbmap seemed to have no effect there.) Against it, libobs maps [ to OBS_KEY_8, ] to OBS_KEY_9 and { to OBS_KEY_7, the same as with us,de.

Upstream work

None found: no upstream PR touches this function, and libobs/obs-nix-x11.c has not changed upstream since 2024.

Proposed fix and failing test

Fix: search the keyboard map one column (group and level) at a time across all keycodes, 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.

RED test (cmocka, test_x11_hotkey_layout). It loads the reporter's core map rows for the 8, 9, [ and ] keys, starts libobs on X11 and restores the rows afterwards. Four cases:

  • [ and ] map to OBS_KEY_BRACKETLEFT and OBS_KEY_BRACKETRIGHT;
  • guard: symbols that only exist on a shifted or AltGr level still map to their key;
  • a [ hotkey is shown as [ in Settings;
  • with OBS not focused, the [ key fires a [ hotkey and the 8 key does not (XTEST key presses).

Three cases fail today and the guard passes.

Activity

  1. rdoupe commented on Oct 12, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_x11_hotkey_layout (3 of 4 failing): the reporter's layout rows loaded into a private X server; [ and ] must map to their own keys, the Settings label must read [, and an XTest press of the [ key must fire the hotkey while OBS is unfocused.
    2. GREEN: map keysyms to keycodes one group/level column at a time, like XKeysymToKeycode().
      PR today.
  2. rdoupe commented on Oct 12, 2026

    @rdoupe
    CollaboratorAuthor

    @Blayung you reported this in obsproject/obs-studio#12941, so a heads-up: it's fixed here in obs-rust by #350, merged today with a regression test.

    Cause: on X11, OBS turned a key symbol into a physical key by taking the first key that has that symbol anywhere in the keymap, in any layout group or shift level. With your layout, the 8 key carries [ on AltGr in the Cyrillic group and comes before the real [ key, so [ became 8 (and ] became 9): Settings showed "8", and outside OBS only the number key fired. Thanks for sharing your layout; with it loaded the bug reproduces exactly. Now OBS searches one group and level at a time, the way Xlib's XKeysymToKeycode does, so [ maps to the key that types it unshifted; symbols that only exist on a shifted or AltGr level still map to their key. The test loads your layout's rows for those keys into a private X server: before, [ mapped to 8 and pressing the [ key did nothing while OBS was unfocused; now the label reads [ and the key fires the hotkey.

    Not covered: if the second layout is the active one when you bind the key, typing [ with AltGr+8 now binds the [ key, not the 8 key.

    Workaround on stock OBS: remove the second layout while you need the hotkey, or bind a key that no other key carries on its AltGr level.

    obs-rust is an AI-assisted fork of OBS; on Arch it's obs-studio-rust-git in the AUR.

    If you try it, a short reply here on whether your [ and ] hotkeys work would really help.

  3. Blayung commented on Oct 17, 2026

    @Blayung

    @rdoupe Yep, it works with this fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions