Skip to content

rust: Port the X11 key map, keysym and keycode lookups #2901

Closed

Description

@rdoupe

Unit

Port the X11 key map lookups of libobs/obs-nix-x11.c.h to rust/obs-hotkey, as a new module nix_x11_keys, next to nix_hotkey_state (#1516) and the portal shortcut modules (#1800). On X11 (Linux and FreeBSD), libobs uses them to build the keycode lists at hotkey init, to answer the hotkey thread's "is this key down" poll, and in obs_key_from_virtual_key / obs_key_to_virtual_key. These decisions move:

  • key_from_base_keysym(): the first key whose base keysym is the symbol; else Shift_R, Control_R and Alt_R give Shift, Control and Alt; else none.
  • The per-row rule of fill_keycodes(): the first non-zero symbol of a keycode's row that is Super_L, Super_R or maps to a key, stopping at the first zero.
  • key_pressed()'s decision: Meta checks the two super keycodes, any other key each of its keycodes.
  • key_from_keycode(): the first key whose keycode list holds the code.
  • obs_nix_x11_key_from_virtual_key(): the 0 and empty-map gate, then the column-major search (each group and level across all keycodes, so the unshifted first-group key wins), then key_from_keycode().
  • obs_nix_x11_key_to_virtual_key(): Meta gives XK_Super_L, any other key its base keysym.

These stay in C: the keysym table (get_keysym), fill_base_keysyms, add_key (its list push and log), every xcb_*/X* call, the keymap copy, the mouse path, obs_nix_x11_key_to_str and the log info.

Phase and position

Phase 6, Linux host code; the last X11 hotkey logic in C after the Wayland key state (#1516). Tracking: #4.

Dependencies and existing tests

  • No dependency to land first.
  • Real libobs: test_x11_hotkey_layout (the AltGr column order), test_x11_volume_keys, test_x11_keymap.
  • No characterization of the moved functions on their own: test_nix_x11_keys_steps lands first in the same PR, builds the moved C file on its own and runs on every OS.

Notes

One PR, separate commits: the behaviour-neutral move into libobs/obs-nix-x11-keys.c.h (hidden functions on plain values, no xcb or Xlib header), characterization, RED, GREEN (group libobs.ported-nix-x11-keys in the Linux ported sources), Tier 3 (proptests over random key maps, 1 to 7 symbols per keycode, keycodes 8 to 255, and every int key), docs.

Intentional difference: obs_key_to_virtual_key on X11 returns 0 for a key outside 0 .. OBS_KEY_LAST_VALUE - 1, which has no keysym; C indexes the table with it.

Activity

  1. added
    enhancement
    port
    on Oct 29, 2026
  2. rdoupe commented on Oct 29, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #2901

    Plan, one PR with separate commits:

    1. libobs: Move the six lookups into libobs/obs-nix-x11-keys.c.h, hidden functions on plain values, behaviour-neutral (checked by building master's and the moved functions side by side on the same inputs).
    2. Characterization: test_nix_x11_keys_steps, building the moved file on its own, on every OS.
    3. RED: Tier 1 obs_hotkey::nix_x11_keys against todo!() stubs.
    4. GREEN: the safe core and src/ffi/nix_x11_keys.rs, group libobs.ported-nix-x11-keys, with the obs_key_to_virtual_key range check.
    5. Tier 3 parity against the C with a mutation check.
    6. Docs.

    I expect the draft PR today, within a few hours.

  3. added
    ready
    on Oct 29, 2026
  4. rdoupe commented on Oct 29, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by #2903 (merged through the merge queue as aad5a22). The six X11 key map lookups now live in rust/obs-hotkey as nix_x11_keys; libobs calls them through hidden functions in libobs/obs-nix-x11-keys.c.h. Tier 1 (21 cases), the unchanged C tests, and Tier 3 parity against the C (6 cases, 18 mutants all killed) pass. The one intentional difference is listed in docs/features.md: obs_key_to_virtual_key on X11 returns 0 for a key OBS does not have.

    Left, by design: the keysym table (get_keysym), the base keysym fill, add_key, every xcb/Xlib call, the keymap copy, the mouse path and the key names stay in C. There is no follow-up issue for them. The macOS counterpart of this key map work is #2914.

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

Metadata

Metadata

Assignees

Labels

enhancementportready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions