Repository navigation
libobs: Port the hotkey binding codec to obs-hotkey - #1628
Merged
Merged
Conversation
RED for the port of libobs/obs-hotkey-bindings.c.h to the bindings module of rust/obs-hotkey. The safe core is a stub (todo!()): combo_from_fields(), the parse of load_binding() over the four modifier bools obs_data read (in MODIFIERS order: shift, control, alt, command) and the key name; combo_bindable(), the MOUSE1/MOUSE2 rule of create_binding(); and combo_to_fields(), the fields the per-binding body of save_bindings_helper() writes, in the order it writes them. The core never sees an obs_data: the reads and writes stay at the C boundary. tests/hotkey/bindings.rs ports test_hotkey_bindings_codec 1:1: its 18 cases under the same names, in the same order, with the same JSON and the same expected bytes. The C test drives the public hotkey API of a real libobs; the C around the codec (load_bindings, load_binding, create_binding, obs_hotkey_load_bindings, save_bindings_helper and a source's enum_load_bindings) stays C, so the test repeats it in a small model, and repeats what obs_data does with the JSON (only a JSON true is a true bool, a missing or non-string "key" reads as "", array items that are not objects are dropped). The "characterized, not endorsed" cases are kept as such. Edge cases: the modifier table; every modifier set; every key name; no binding is ever dropped, for empty, unknown, non-UTF-8 and long key names; only MOUSE1 and MOUSE2 are not bindable, for any modifiers and any key code, in range or not; the field order and count for every low modifier mask and for masks with other bits; any key code, and nothing after the key; and save then load for every key and modifier set. The tests are a module of the existing core category binary, obs-tests-core; no new test binary. soldr cargo test -p obs-data --test obs-tests-core hotkey::bindings:: fails 24 of 26 with "not yet implemented"; the modifier table and empty_save (which never reaches the codec) pass. Refs obs-rust#1621
Ports libobs/obs-hotkey-bindings.c.h, the hotkey binding codec, to the
bindings module of rust/obs-hotkey. The codec turns one item of a
hotkey's saved bindings array (the "shift", "control", "alt" and
"command" bools and the "key" name) into an obs_key_combination_t and
back: the on-disk hotkey format of every profile and scene collection.
load_binding(), create_binding() and save_bindings_helper() in
obs-hotkey.c.h (still C) call it and keep the bindings array and the
hotkey_bindings_changed signal; libobs-with-rust drops the C file and
links the Rust shims in its place.
Safe core (src/bindings.rs), free of obs_data: combo_from_fields() reads
the INTERACT_*_KEY bit of each modifier that obs_data read as true
(load_modifier) and the key from its name; combo_bindable() rejects
OBS_KEY_MOUSE1 and OBS_KEY_MOUSE2 and nothing else; combo_to_fields()
yields one true per set modifier bit (save_modifier), in the order
shift, control, alt, command, then the key. Kept, characterized, not
endorsed: no item is dropped, because the C's check tests the address
of the modifiers, so {} and an unknown, empty or missing key load as
OBS_KEY_NONE. The input comes from scene collections and profiles, so
the module denies clippy's indexing_slicing, arithmetic_side_effects,
unwrap_used, expect_used, panic, todo, unimplemented and unreachable.
Shim (src/ffi/bindings.rs): obs_hotkey_combination_from_data, _bindable
and _to_data, with the C signatures. They make the C's obs_data calls in
the C's order (obs_data_get_bool per modifier and obs_data_get_string
for the key; obs_data_set_bool(name, true) per set modifier and
obs_data_set_string of obs_key_to_name for the key), so only a JSON true
sets a modifier, and the saved JSON, key order included, is the C's
byte for byte. A null combo_out returns false (C writes through it).
OBS_KEY_MOUSE2 joins the key codes build.rs names.
C side: the file leaves libobs.core for its own group,
libobs.ported-hotkey-bindings (LIBOBS_PORTED_SOURCES), whose PCH is
obs-internal.h. The three symbols are in rust-hidden.txt,
rust-exports.map and rust-unexports-macos.txt; they are hidden in both
libobs builds and there is no rust-exports.d fragment. The exported
symbol sets are unchanged. test_hotkey_load, test_wayland_hotkeys and
test_portal_shortcuts still compile the C file into themselves,
unchanged.
Oracle (oracle/hotkey_bindings.c): the original file with its three
functions renamed, plus the key codes and INTERACT_* bits it uses. It
reads and writes obs_data through the Rust obs-data port, as the shims
do.
Tier 3 (tests/hotkey/bindings_parity.rs): the values; the parse of the
characterization items, a null obs_data, and obs_data objects built by
random calls (user, default and autoselect bools and strings, ints,
doubles, objects, arrays, erases) on the modifier names, near misses
and others, with key names, near misses and arbitrary bytes; the rule
for every key code and the codes around the ends with any modifiers;
and the save of any modifiers and key code into two obs_data objects
that start the same, compared as JSON byte for byte, then parsed back.
Intentional differences: the null combo_out only.
Docs: rust/README.md rows, the naming.md row and the crate description.
Fixes obs-rust#1621
zackees
force-pushed
the
rust/port-hotkey-bindings
branch
from
October 21, 2026 18:13
13ea3fc to
a3bd2fd
Compare
zackees
enabled auto-merge
October 21, 2026 18:13
Member
|
Coordinator: I rebased this onto master to clear a |
5 tasks done
This was referenced Oct 21, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1621 (PR 2 of 2; PR 1, #1622, moved the codec into
libobs/obs-hotkey-bindings.c.hand addedtest_hotkey_bindings_codec)What and why
This PR ports
libobs/obs-hotkey-bindings.c.h, the hotkey binding codec, to a newbindingsmodule ofrust/obs-hotkey(#444). The codec turns one item of a hotkey's saved bindings array into anobs_key_combination_tand back. The item holds the"shift","control","alt"and"command"bools and the"key"name. It is the on-disk hotkey format of every profile and scene collection, so the port has to be byte-identical: a different key name, modifier key or key order would lose or rewrite users' bindings.load_binding(),create_binding()andsave_bindings_helper()inobs-hotkey.c.hstay C. They call the codec and keep the bindings array and thehotkey_bindings_changedsignal.libobs-with-rustdrops the C file and links the Rust shims in its place.src/bindings.rs), which never sees an obs_data:combo_from_fields()is the parse ofload_binding(). It takes the four bools obs_data read (inMODIFIERSorder: shift, control, alt, command) and the key name. It sets theINTERACT_*_KEYbit of each true modifier (load_modifier) and looks the key up by name (the ported name map).combo_bindable()is the rule ofcreate_binding(), for JSON and API bindings alike. It rejectsOBS_KEY_MOUSE1andOBS_KEY_MOUSE2and nothing else.combo_to_fields()is the per-binding body ofsave_bindings_helper(). It yields onetrueper set modifier bit (save_modifier), in the order shift, control, alt, command, and then the key.test_hotkey_bindings_codecmarks it "characterized, not endorsed": no item is dropped. The C check tests the address of the modifiers, which is never NULL. So{}and an unknown, empty or missing key load asOBS_KEY_NONEand are saved back as{"key":"OBS_KEY_NONE"}. The other kept behaviour, that an empty array sends nohotkey_bindings_changed, is inload_bindings(), which stays C, so the port does not touch it.indexing_slicing,arithmetic_side_effects,unwrap_used,expect_used,panic,todo,unimplementedandunreachable. I checked that the lints fire: a probe that indexes, adds and unwraps inside the module fails clippy with all four. No hostcfg, nounsafe.src/ffi/bindings.rs):obs_hotkey_combination_from_data,obs_hotkey_combination_bindableandobs_hotkey_combination_to_data, with the C signatures.obs_data_get_boolfor each modifier andobs_data_get_stringfor the key;obs_data_set_bool(name, true)for each set modifier andobs_data_set_stringofobs_key_to_namefor the key. So the "only a JSONtruesets a modifier" rule is the C's, and the saved JSON, key order included, is the C's byte for byte.obs_key_combination_tis the existing#[repr(C)]obs_key_combination(its layout test is innix_hotkey_state_parity).OBS_KEY_MOUSE2joins the key codes the crate'sbuild.rsnames fromobs-hotkeys.h.obs-hotkey-bindings.c.hleaveslibobs.corefor its own group,libobs.ported-hotkey-bindings, listed insource-sets.json(LIBOBS_PORTED_SOURCES). Its PCH,libobs-ported-hotkey-bindings.pch.h, isobs-internal.h. The only change to the file is that include and its header comment.test_hotkey_load,test_wayland_hotkeysandtest_portal_shortcutsstill compile it into themselves, unchanged.rust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt. They are notEXPORT, so there is norust-exports.dfragment.nmshowstfor all three in bothlibobs.sobuilds. The exported symbol sets are unchanged.oracle/hotkey_bindings.c): the original file, unmodified, with its three functions renamed, plus the key codes andINTERACT_*bits it uses. It reads and writes obs_data through the Rust obs-data port and names keys through the Rust name map, as the shims do; each of those has its own parity test.combo_outreturns false and writes nothing, where the C writes through it. libobs never passes one.rust/README.mdrows, thedocs/rust-port/naming.mdrow and the crate's Cargodescription.test_hotkey_bindings_codec(18 cases) linksOBS::libobsand goes through the public hotkey API only (obs_hotkey_load/obs_hotkey_save,obs_hotkey_load_bindings, the pair load and save, and a source's hotkey data). That makes it the end-to-end proof: in mode ON it runs the Rust codec through real libobs and compares the saved JSON byte for byte.RED → GREEN
c82d737dclibobs: Add Tier 1 tests for the hotkey binding codec port. The core istodo!().soldr cargo test -p obs-data --test obs-tests-core hotkey::bindings::fails 24 of 26 with "not yet implemented". The modifier table test passes, and so doesempty_save, which never reaches the codec.tests/hotkey/bindings.rs) portstest_hotkey_bindings_codec1:1: the 18 cases under the same names, in the same order, with the same JSON and the same expected bytes. The "characterized, not endorsed" cases are kept as such.load_bindings,load_binding,create_binding,obs_hotkey_load_bindings,save_bindings_helperand a source'senum_load_bindings, with the signal count.truereads as a true bool, a missing or non-string"key"reads as"", and array items that are not objects are dropped."key"field;0x1FFand for masks with other bits;obs-tests-core. No new test binary:ci/test_binary_cap.pypasses.13ea3fc5elibobs: Port the hotkey binding codec to obs-hotkey.hotkey::bindingspasses 35/35 (26 Tier 1, 9 Tier 3). The wholeobs-tests-corebinary passes 432/432.tests/hotkey/bindings_parity.rs), comparing against the C oracle:INTERACT_*bits;"Shift","ctrl","KEY","") and other names. The strings are key names, near misses,"","OBS_KEY_NONE"and arbitrary bytes, non-UTF-8 included;combo_outonly, which has its own test.combo_to_fields()skip the alt modifier, then restored it.each_modifier_alone,modifier_order_and_false,all_modifier_sets,modifiers_only,api_other_modifier_bits_dropped,pair_round_trip). 3 are edge cases (to_fields_order_and_count,to_fields_any_key_code,to_fields_then_from_fields), and 2 are Tier 3 parity tests (to_data_matches_c,to_data_matches_c_for_every_key_and_modifier_set).libobs-with-rustrebuilt:test_hotkey_bindings_codecfailed the same 6 cases in mode ON (12/18 passed) and passed 18/18 in mode OFF.ENABLE_RUST_LIBOBS=OFFandON). Each tree runs the full cmocka suite againstlibobs(OFF) and againstlibobs-with-rust(ON):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)No test was skipped or not run.
test_hotkey_bindings_codecpasses 18/18 in all four runs.test_hotkey_load(7),test_wayland_hotkeys(8) andtest_portal_shortcuts(28) pass in all four too.lddshows each run loading the intendedlibobs.so.libobs.ported-hotkey-bindings+.h.cis linked intolibobsand not intolibobs-with-rust(Ninja's inputs for each target). The export lists are also identical across the two lanes.The suites ran with an extracted cmocka 2.0.2 (the build host has no system cmocka package): CMake found it through
CMocka_DIR, and ctest ran withLD_LIBRARY_PATHpointing at itslib.Environment: headless (private Xvfb, private D-Bus, fresh HOME).
ASan:
hotkey::bindingsandhotkey::bindings_parity(Tier 1 and 3, every proptest) pass 35/35 under AddressSanitizer, with no reports. The Rust side was built with-Zsanitizer=address, and the C oracle with-fsanitize=address(the oracle functions carry ASan checks in the test binary).ci/local_gate.py:--lane lint: passed.--lane cross: passed.--lane cross-release: passed.--lane rust-test: passed (obs-tests-core432/432, the obs-util harness 744/744, includingexport_list, plus the windows-gnu--no-runbuild).ci/test_build_groups.py,ci/test_naming.py,ci/test_ported_sources.py,ci/test_rust_scope.py,ci/test_binary_cap.py,ci/test_cmocka_includes.py: OK.Real app (UI, protocol output or logging changes): not applicable (no behaviour change).
Checklist
master(or the description starts with a Stacked: note)test_hotkey_bindings_codec, landed in libobs: Move the hotkey binding codec into obs-hotkey-bindings.c #1622)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicablecombo_outonly