Skip to content

rust: Port the Wayland keysym tables, keymap rows and focused keys #3069

Closed

Description

@rdoupe

Unit

Port the keysym tables, the keymap row rule and the focused-key rule of libobs/obs-nix-wayland.c.h to rust/obs-hotkey, as a new module nix_wayland_keys, next to nix_hotkey_state (#1516) and nix_x11_keys (#2901). On Wayland (Linux and FreeBSD), libobs uses them in obs_key_from_virtual_key / obs_key_to_virtual_key, to build its keycode and keysym maps whenever the compositor sends a keymap or the layout changes, to name the GlobalShortcuts portal's preferred triggers, and to tell the hotkey thread which keys are held while OBS has keyboard focus. These decisions move:

  • obs_nix_wayland_key_from_virtual_key(): the obs key for each XKB keysym, OBS_KEY_NONE otherwise.
  • obs_nix_wayland_key_to_virtual_key(): the XKB keysym for each obs key, 0 otherwise.
  • load_keymap_data()'s rule for one keycode: a keycode at or above MAX_KEYCODES is skipped; each of the MAX_SHIFT_LEVELS levels with a keysym stores its first keysym for that level, and the obs key's keycode is stored only if none is yet (the first keycode wins).
  • set_focused_key()'s rule: the evdev scancode plus 8, the bound, the level-0 keysym, and the obs key it is pressed or released as.

These stay in C: every xkbcommon and Wayland call (including xkb_keymap_key_get_syms_by_level, whose result C passes in), the keymap mmap and compile, the rebuild's memsets, the modifier mask, the seats and registry, every obs_nix_hotkey_state_* call, wayland_key_name, obs_nix_wayland_key_to_str and the vtable.

Phase and position

Phase 6, Linux host code; the Wayland counterpart of the X11 key map port (#2901). Tracking: #4.

Dependencies and existing tests

  • No dependency to land first; nothing else is open on obs-nix-wayland.c.h or its unity group.
  • Real libobs: test_wayland_hotkeys, test_wayland_keymap, test_wayland_multiseat, test_wayland_volume_keys, test_hotkey_volume_keys.
  • No characterization of these functions on their own: test_nix_wayland_keys_steps lands first in the same PR, builds the moved C file on its own (no compositor) and pins both tables, the row rule and the focused-key rule.

Notes

One PR, separate commits: the behaviour-neutral move into libobs/obs-nix-wayland-keys.c.h (hidden functions on plain values and passed arrays, no Wayland header), characterization, RED, GREEN (group libobs.ported-nix-wayland-keys in the Linux ported sources), Tier 3 (exhaustive over every obs key and every keysym either table names, generated keymaps, every scancode 0 to 300 with press and release sequences across a layout change), docs.

Bug fixed in the port (intentional difference, listed in the parity test): a key held while the keyboard layout changes stays held for hotkeys until OBS loses focus. Its press and its release are both looked up through the current layout's level-0 keysym, so after a switch (for example QWERTY to AZERTY) the release of Q goes to the obs key A, and the hotkey bound to Q reads as held until a focus leave clears every key. The port records the obs key each keycode was pressed as, and its release releases that key. Not reported by a user; only keys whose level-0 keysym differs between the two layouts are hit.

Activity

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

    @rdoupe
    CollaboratorAuthor

    Claiming: #3069

    Plan, one PR with separate commits:

    1. libobs: Move the two keysym tables, load_keymap_data()'s level loop and set_focused_key()'s keycode rule into libobs/obs-nix-wayland-keys.c.h, hidden functions on plain values and passed arrays, behaviour-neutral (checked with a harness that builds master's and the moved functions side by side on the same inputs, with planted mutants).
    2. Characterization: test_nix_wayland_keys_steps, compiling the moved file on its own, no compositor.
    3. RED: Tier 1 for obs_hotkey::nix_wayland_keys against todo!().
    4. GREEN: the safe core and shims in libobs.ported-nix-wayland-keys, with the layout-change release fix as the one intentional difference.
    5. Tier 3 against the C oracle, with the mutation check.
    6. Docs: rust/README.md, naming.md, the crate description and module docs, a port_comparison bench.

    Draft PR expected today, once the RED commit exists.

  3. added
    ready
    on Oct 30, 2026
  4. moved this from In progress to Done in obs-rust Multiviewon Oct 30, 2026
  5. rdoupe commented on Oct 30, 2026

    @rdoupe
    CollaboratorAuthor

    Fixed by #3072 (merged through the merge queue).

    What landed: the Wayland keysym tables (both directions), the keymap row rule and the focused-key rule now live in the nix_wayland_keys module of rust/obs-hotkey, with Tier 1 tests, Tier 3 differential tests against the C oracle and the characterization test test_nix_wayland_keys_steps. The one intentional difference is the bug fixed in the port: a key held while the keyboard layout changed is now released as the key it was pressed as, so a push-to-talk on Q no longer stays on after a switch to AZERTY.

    What is left: nothing in this unit. Every xkbcommon and Wayland call, the keymap mmap and compile, the seats and registry, the obs_nix_hotkey_state_* calls, wayland_key_name, obs_nix_wayland_key_to_str and the vtable stay in C by design.

    Follow-up: the next piece of the Wayland hotkey area is the GlobalShortcuts portal client's outcome, descriptions and trigger rule (#3081), which is still open.

    Tracking issue #4 has no checkbox for this unit, so there was nothing to tick.

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