Repository navigation
Description
Unit
Port the hotkey binding codec of libobs/obs-hotkey.c.h to the existing crate rust/obs-hotkey as a new module, bindings. The codec turns one item of a hotkey's saved bindings array into an obs_key_combination_t and back. It is the on-disk hotkey format of every profile and scene collection: the "shift", "control", "alt" and "command" bools and the "key" name.
load_modifierand the parse inload_binding: read the four modifier bools and the key name from oneobs_data_titem, and decide whether to accept it;- the rule in
create_binding(ours) that rejectsOBS_KEY_MOUSE1andOBS_KEY_MOUSE2, which the frontend reserves for UI interaction. It covers JSON andobs_hotkey_load_bindings()bindings alike; save_modifierand the per-binding body ofsave_bindings_helper: write the same keys, in the order shift, control, alt, command, key.
About 50 lines. These stay C: load_bindings (the hotkey_bindings_changed signal), obs_hotkey_load, obs_hotkey_load_bindings, obs_hotkey_pair_load, enum_load_bindings, obs_hotkeys_load_*, save_hotkey, obs_hotkey_save, obs_hotkey_pair_save and save_context_hotkeys. They touch obs->hotkeys.bindings, the uthash tables and struct obs_hotkey.
Phase and position
Phase 6 (#444), libobs core through opaque seams. It joins rust/obs-hotkey, which already holds the key name map, the Wayland key state and the portal shortcut id codec. It is part of a large file, so it enters through function extraction (testing-policy.md, "Extracting a function before porting it"). Its Rust tests join the crate's existing tests/hotkey/ binary, next to the name map, key state and portal id tests; no new test binary.
Dependencies and existing tests
- No
struct obs_*internals, no accessors and no obs-util prerequisite. The codec calls the exportedobs_data_get_bool,obs_data_get_string,obs_data_set_boolandobs_data_set_string(already in Rust inobs-data), andobs_key_from_nameandobs_key_to_name(already in Rust inobs-hotkey::name_map).obs_key_combination_tis a public, stable layout inobs-hotkey.h. - The safe core stays free of obs_data: for example
combo_from_fields(shift, control, alt, command, key_name) -> Option<Combo>,combo_bindable(&Combo) -> boolandcombo_to_fields(&Combo). Onlysrc/ffi/calls theobs_data_*C ABI, socargo testneeds no obs-data and the crate picks up no Cargo dependency on it. test_hotkey_load(7 cases: the mouse-button rule for JSON, API and pairs, allowed bindings kept, rejected bindings still replacing old ones, no callbacks) compilesobs-hotkey.c.hinto itself withobs=hotkey_test_obs, so a Rust swap is invisible to it. There is no real-libobs test ofobs_hotkey_saveand no round-trip test, so PR 1 adds one.- Format compatibility: any difference in a key name, a modifier key or the key order loses or rewrites users' bindings. The characterization compares the saved JSON byte for byte, and a save, load and save again must give the same bytes.
- The input is semi-trusted: scene collections and profiles can come from others. The codec only reads four bools and a string, and the key name lookup is already ported and fuzzed through the name map.
Plan
- Characterization and extraction PR (behaviour-neutral, one PR as in libobs: Move the output packet interleaver into obs-output-interleave.c #1595 and libobs: Move the caption text wrap into obs-output-caption-text.c #1618):
- New test
test_hotkey_bindings_codec, linkingOBS::libobswithobs_startup()and using only the public API:obs_hotkey_loadandobs_hotkey_saveon a frontend hotkey,obs_hotkey_load_bindings,obs_hotkey_pair_loadandobs_hotkey_pair_save, and a source's hotkey data (obs_source_create,obs_hotkeys_save_source). It pins each modifier alone, all 16 modifier sets and the saved key order; a modifier that is not a JSONtrue; every key name, with save, load and save as a byte-for-byte fixpoint; unknown, empty, missing and non-string keys;{}and modifier-only bindings; MOUSE1 and MOUSE2 rejected with and without modifiers, and MOUSE3 kept; duplicates and order; items that are not objects; an empty array; and whenhotkey_bindings_changedis sent. - The codec moves verbatim into
libobs/obs-hotkey-bindings.c.h, in the same unity group (libobs.core, just beforeobs-hotkey.c.h, alphabetical), behind three hidden entry points declared inobs-internal.hwithoutEXPORT:obs_hotkey_combination_from_data(),obs_hotkey_combination_bindable()andobs_hotkey_combination_to_data().test_hotkey_load,test_wayland_hotkeysandtest_portal_shortcutscompile the new file next toobs-hotkey.c.h.
- New test
- Port PR (RED, then GREEN):
obs_hotkey::bindings: the safe core over fields, andsrc/ffi/bindings.rswith the three entry points. The C file moves to its own ported group,libobs.ported-hotkey-bindings, with its own.pch.hand export fragment, aslibobs.ported-nix-hotkey-statehas.- Tests: Tier 1 ports every
test_hotkey_bindings_codecexpectation 1:1. Tier 3 parity of the C file (an oracle over a small fake obs_data) against the Rust core, with a proptest over modifier bits, key names (valid, invalid, empty, non-UTF-8) and combinations. Tier 2 OFF and ON unchanged, wheretest_hotkey_bindings_codecsees the swap. Tier 4 does not apply (no protocol change). - Docs: the
rust/README.mdrows, thedocs/rust-port/naming.mdrow forrust/obs-hotkey(addobs-hotkey-bindings.c.h) and the crate's Cargodescription.
No intended behaviour changes, and no format change. Two behaviours that the test marks "characterized, not endorsed" are kept by the port and fixed later, each in its own PR with its own test change:
load_bindingmeans to drop an item with no modifiers and no known key, but its check,!modifiers, tests the address ofcombo.modifiers, which is never NULL. So it drops nothing:{}and an unknown, empty or missing key load as a binding ofOBS_KEY_NONEand are saved back as{"key":"OBS_KEY_NONE"}. Such a binding never fires.- An empty or missing array clears the hotkey's bindings but sends no
hotkey_bindings_changed, becauseload_bindingssignals only when the array has items.obs_hotkey_load_bindingsalso signals when it removed bindings.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 21, 2026
Claiming: #1621
test_hotkey_bindings_codec(18 cases, real libobs, save → load → save compared byte for byte), and the codec moved verbatim intolibobs/obs-hotkey-bindings.c.h. Opening it now.rust/obs-hotkey'sbindingsmodule, as its own PR after 1 merges.libobs: Move the hotkey binding codec into obs-hotkey-bindings.c (obs…
libobs: Add Tier 1 tests for the hotkey binding codec port
libobs: Port the hotkey binding codec to obs-hotkey
libobs: Port the hotkey binding codec to obs-hotkey (obs-rust#1628)