Skip to content

rust: Port libobs/obs-hotkey-name-map.c to obs-hotkey #833

Closed

Description

@zackees

Unit

libobs/obs-hotkey-name-map.c (134 lines) to a new obs-hotkey crate: the exported obs_key_to_name and obs_key_from_name (obs-hotkey.h), and the internal obs_hotkey_name_map_free (obs-internal.h, called on shutdown).

Phase and position

Phase 6, tracker #444: the hotkey name map, listed there as separately claimable after obs-data.c (#784) and obs-properties.c (#828).

Dependencies and existing tests

No unit test covers the file directly; test_portal_shortcuts and test_x11_hotkey_layout call both functions incidentally. A characterization test test/cmocka/test_hotkey_name_map.c lands first, C only: every key in obs-hotkeys.h round-trips name → key → name, unknown and OBS_KEY_LAST_VALUE+ codes, OBS_KEY_NONE, case sensitivity, before and after obs_startup.

Notes

  • The C keeps a uthash map in obs->hotkeys built once with pthread_once, falling back to a linear scan when obs is NULL. Both give the same answer (first key with that name), so the port uses its own lazily built map and leaves the obs->hotkeys.name_map field unused; obs-internal.h is not edited. obs_hotkey_name_map_free becomes a hidden no-op export.
  • The name table is generated at build time from obs-hotkeys.h (608 entries), so it cannot drift from the C list.
  • Expected intentional differences, both where C has undefined behavior: a NULL name returns OBS_KEY_NONE (C's fallback calls strcmp(NULL) when obs is NULL), and a negative key logs and returns "" like an out-of-range one (C indexes before the array).

Activity

  1. added
    enhancement
    port
    on Oct 15, 2026
  2. zackees commented on Oct 15, 2026

    @zackees
    MemberAuthor

    Claiming: libobs/obs-hotkey-name-map.c

    1. Characterization PR, no Rust: test/cmocka/test_hotkey_name_map.c.
    2. RED: obs-hotkey crate, todo!() core, Tier 1 1:1 port, Tier 3 parity for every key code and name against the C oracle.
    3. GREEN: the port; ENABLE_RUST_LIBOBS=ON drops the C file.

    First PR today.

  3. added
    claimed
    on Oct 15, 2026
  4. zackees commented on Oct 15, 2026

    @zackees
    MemberAuthor

    Correction to the issue text: the key table has 636 entries, not 608. The OBS_MOUSE_BUTTON(x) keys in obs-hotkeys.h expand to OBS_HOTKEY(x) in this file and are part of the list.

  5. zackees commented on Oct 15, 2026

    @zackees
    MemberAuthor

    Done: #834 characterized obs-hotkey-name-map.c (C only) and #835 ported it to the obs-hotkey crate (Tier 1 1:1; Tier 3 against the original in both C modes, no core and with the name map; Tier 2 247/247 OFF and ON; ENABLE_RUST_LIBOBS=ON drops the C file). obs_hotkey_name_map_free is a hidden no-op; the obs->hotkeys.name_map field stays in obs-internal.h, unused.

    Intentional differences (C has undefined behavior there): a null name returns OBS_KEY_NONE; a negative code logs and returns "".

    Nothing left on this unit.

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

    claimedenhancementport

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions