Repository navigation
libobs: Port the hotkey pair press latch to obs-hotkey - #1820
Merged
Merged
Conversation
RED for the port of libobs/obs-hotkey-pair.c.h to a new module, pair, of rust/obs-hotkey. The safe core is a stub (todo!()): Half (First, Second, with other() and the C's index()), the Latches trait the latch reads and writes the pair's two latches through, PairLatches (pressed0 and pressed1 by value), and event(), one event of one half, which takes the half's func as a closure called at most once with the latches, so a func can trigger either half from inside its call, and returns the Outcome (Dropped, Cleared or Called with the func's result). tests/hotkey/pair.rs ports both C characterizations 1:1, under the same case names, in the same order, with the same steps and expectations: the 4 cases of test_hotkey_pair_steps (steps_*, all 32 combinations of latch state, half, press or release and func result included) and the 11 of test_hotkey_pair_latch (state_*). A small model repeats the C around the core: the pair's latches, a func per half that logs its call and returns a set result for a press and for a release, and the trigger, which runs a half's callback synchronously, so a func can trigger its partner. Edge cases: the order the latches are read and written in (the other half's latch, then this half's, before the func; only this half's, after it); every latch state a func can leave behind, kept except that a true result then sets this half's latch; a dropped or cleared event never calling the func; the plain latches per half; and a proptest of the invariants over random sequences. soldr cargo test -p obs-data --test obs-tests-core hotkey::pair fails 20 of 20 with "not yet implemented". Refs obs-rust#1798
Ports libobs/obs-hotkey-pair.c.h to the pair module of rust/obs-hotkey: the callbacks libobs registers for the two halves of a hotkey pair, such as Start and Stop Streaming, a source's Mute and Unmute, or a scene item's Show and Hide. While one half is latched, the other half's events are dropped; a press whose func returns true latches its half, and its release then clears the latch without calling the func; any other event calls the func, and a true result sets the latch to the event's pressed value. The pair, its hash, register_hotkey_pair_internal(), the funcs and their callback ABI stay C in obs-hotkey.c.h; the hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/pair.rs): event() reads the latches only through the Latches trait, at the C's points: the other half's latch, then this half's, before the func; this half's latch, and only it, after the func returns. It never writes back a value read before the call, so a func that triggers either half from inside its call keeps what it wrote. It keeps no state and takes no lock, and denies clippy's panic, indexing and arithmetic lints. Shim (src/ffi/pair.rs): obs_hotkey_pair_first_func and obs_hotkey_pair_second_func keep the C signature (obs_hotkey_func), as register_hotkey_pair_internal() registers them as the hotkeys' callbacks. They take the pair's latch pointers once through the hidden obs_hotkey_pair_fields() (obs-rust#1799), so struct obs_hotkey_pair is not mirrored, and read and write the latches through those pointers, never a copy. The func is called in C, through obs_hotkey_pair_call_func(). Kept, characterized, not endorsed (obs-rust#1799): a release without a press reaches the func; a second press of a latched half calls the func again and the half stays latched; both halves can end up latched. Intentional difference: a null data, or a null latch pointer from the accessor, does nothing (C dereferences it); libobs never passes one. C side: the file leaves libobs.core for its own group, libobs.ported- hotkey-pair (LIBOBS_PORTED_SOURCES), whose PCH is obs-internal.h. The two callbacks are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. The exported symbol sets are unchanged (1766). test_hotkey_load, test_wayland_hotkeys, test_portal_shortcuts, test_hotkey_press_steps and test_hotkey_pair_steps still compile the C file into themselves, unchanged; test_hotkey_pair_latch sees the swap through the public API. ci/test_ported_sources.py checks the group on every host. Refs obs-rust#1798
Oracle (oracle/hotkey_pair.c): the original obs-hotkey-pair.c.h, unmodified, with its two callbacks renamed to oracle_*, plus the layout of struct obs_hotkey_pair_fields and the sizes of bool and obs_hotkey_id. The seams it calls keep their names: under cargo test the test binary defines obs_hotkey_pair_fields() and obs_hotkey_pair_call_func() over fake pairs, for the oracle and the shims alike. Tier 3 (tests/hotkey/pair_parity.rs): the seams log every call, per thread: each accessor call; each func call with its pair, half, hotkey, pressed value and both latches as the func sees them; and each return, with the result and both latches as the func leaves them. A func follows a script: it returns a set result, and before or after that it may set either latch of either pair and trigger either half of either pair through the same side's callbacks, as a func that triggers its partner does. So a latch read after the call instead of before, a write from a copy taken before the call, a write of the other half's latch, or a write before the func returns changes the log or the latches. After every step the C and Rust sides must have the same log, one to one, and the same latches in every pair. Runs: - the layout; - every single event: 4 latch states x 2 halves x press or release x func result x what the func does while it runs (nothing, or either latch set to either value, before or after a nested event; a nested event of either half, pressed or not, with either result): 2880 runs; - every sequence of four events (half, pressed, func result) from every latch state: 16384 runs; - the scripted cases of the C characterizations: a func triggering its partner from inside its press, a func latching the other half or its own while it runs, and the latch per pair; - 2000 random runs: up to 3 pairs with random latches, up to 40 steps of events (any hotkey pointer and id) whose funcs return random results and may set latches and trigger events of any pair, nested, and latch changes from outside. Excluded, the intentional difference: a null data, or a null latch pointer from the accessor, which does nothing in Rust and is dereferenced in C (checked on the Rust side). Mutation check (done once, not committed): 18 of 18 mutants of the core and the shim fail the parity tests: the other half's latch not checked; this half's latch checked instead; the release of a latched half calling the func; that release dropped with the latch kept; the latch ignoring the func result; the latch set to true, not the pressed value; a second press of a latched half dropped; the other half's latch, or this half's, written back from a copy taken before the call; this half's latch written before the func; the other half's latch re-read after the func; a cleared release also calling the func; the half indexes swapped; and, in the shim, the second callback acting as the first half, the latch pointers swapped, the func given no hotkey or the other half's index, and the latches copied before the event and both written back after it. The 13 core mutants also fail Tier 1. Refs obs-rust#1798
The rust/README.md rows for rust/obs-hotkey (crate table and port table), the naming.md row and the crate description now include libobs/obs-hotkey-pair.c.h. The port row lists what stays C, the seams the shims use, the order the latches are read and written in, what the characterization pins and the port keeps, the intentional difference (a null data or a null accessor pointer doing nothing) and what Tier 2 and Tier 3 compare. Fixes obs-rust#1798
rdoupe
force-pushed
the
port/hotkey-pair-rust
branch
from
October 22, 2026 19:41
8d22f1e to
86ca8e3
Compare
zackees
enabled auto-merge
October 22, 2026 19:48
This was referenced Oct 22, 2026
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 #1798 (PR 2 of 2; #1799 moved the pair press latch into
libobs/obs-hotkey-pair.c.h, addedtest_hotkey_pair_latchandtest_hotkey_pair_steps, and added the hiddenobs_hotkey_pair_fields()/obs_hotkey_pair_call_func()accessor)What and why
This PR ports
libobs/obs-hotkey-pair.c.h, the hotkey pair press latch, to a newpairmodule ofrust/obs-hotkey(#444, phase 6). The latch is the two callbacks libobs registers for the halves of a hotkey pair: the frontend's Start/Stop pairs (Streaming, Recording, Replay Buffer, Virtual Camera, ...), a source's Mute/Unmute and Monitor On/Off, and a scene item's Show/Hide.The pair, its hash,
register_hotkey_pair_internal(), theobs_hotkey_pair_*API, the funcs and their callback ABI stay C inobs-hotkey.c.h. The hybrid libobs drops the C file and links the Rust shims in its place.src/pair.rs):event(latches, half, pressed, call) -> Outcome(Dropped, Cleared, or Called with the func's result).callis the half's func, called at most once.Latchestrait, at the C's points:step(latch, ...) -> latch. It takes the latches by reference instead, so the shim can pass the pair's own latches and no copy exists to write back.arithmetic_side_effects,indexing_slicing,unwrap_used,expect_used,panic,todo,unimplementedandunreachable. No hostcfg, nounsafe.src/ffi/pair.rs):obs_hotkey_pair_first_funcandobs_hotkey_pair_second_func.obs_hotkey_func, becauseregister_hotkey_pair_internal()registers them as the hotkeys' callbacks, with the pair as their data.obs->hotkeys.mutexheld: on the hotkey thread, inobs_hotkey_inject_event(), or inobs_hotkey_trigger_routed_callback()(the frontend's router and obs-websocket'sTriggerHotkeyByName). The func runs inside them, as before. So the shims keep no state and take no lock.obs_hotkey_pair_fields()(libobs: Move the hotkey pair press latch into obs-hotkey-pair.c #1799), sostruct obs_hotkey_pairis not mirrored. TheLatchesview over those pointers reads and writes the pair itself on every access. No Rust reference to a latch exists while the func runs, so a nested callback that writes through the same pointers aliases nothing.obs_hotkey_pair_call_func().obs-hotkey-pair.c.hleaveslibobs.corefor its own group,libobs.ported-hotkey-pair, listed insource-sets.json(LIBOBS_PORTED_SOURCES). Its PCH,libobs-ported-hotkey-pair.pch.h, isobs-internal.h. The only change to the file is that include and its header comment.test_hotkey_load,test_wayland_hotkeys,test_portal_shortcuts,test_hotkey_press_stepsandtest_hotkey_pair_stepsstill compile it into themselves, unchanged.ci/test_ported_sources.pychecks the group on Linux, Windows and macOS.obs-internal.hwithoutEXPORT, so the shims are hidden like libobs: Port the hotkey press state machine to obs-hotkey #1786's:rust-hidden.txt, thelocal:list ofrust-exports.map, andrust-unexports-macos.txt.nmshows them as local (t) in all three libraries. The exported symbol sets are unchanged (1766).oracle/hotkey_pair.c): the original file, unmodified, with the two callbacks renamed tooracle_*, plus the layout ofstruct obs_hotkey_pair_fieldsand the sizes ofboolandobs_hotkey_id. The two seams it calls keep their names. Undercargo testthe parity test defines them over fake pairs, for the oracle and the shims alike.src/ffi/pair.rsand therust/README.mdrow):data, or a null latch pointer from the accessor, does nothing (C dereferences it). libobs never passes one: the data is the pair it registered.rust/README.mdrows, thedocs/rust-port/naming.mdrow and the crate's Cargodescription. Nodocs/features.mdline: there is no user-visible change.test_hotkey_pair_latch(11 cases) linksOBS::libobsand goes through the public API only. In the hybrid libobs it runs the Rust shims and core throughobs_hotkey_trigger_routed_callback(), so it is the end-to-end proof on every OS.test_hotkey_press_statedrives a pair through the real hotkey thread on Linux.There is no
_rustvariant oftest_hotkey_pair_stepslinkinglibobs_rust-static, as #1786 and #1800 found for theirs: obs-hotkey pulls in obs-data, obs-util and hidden libobs symbols that such a test does not link. So Tier 3 is the direct comparison on every OS.RED → GREEN
0dada4276libobs: Add Tier 1 tests for the hotkey pair press latch port. The core istodo!().soldr cargo test -p obs-data --test obs-tests-core hotkey::pairfails 20 of 20 with "not yet implemented".tests/hotkey/pair.rs) ports both C characterizations 1:1, under the same case names, in the same order, with the same steps and expectations:test_hotkey_pair_steps(steps_*), all 32 combinations of latch state, half, press or release and func result included;test_hotkey_pair_latch(state_*).obs-tests-core. No new test binary.c583b8584libobs: Port the hotkey pair press latch to obs-hotkey.hotkey::pairpasses 20/20.35f49060flibobs: Check the hotkey pair press latch port against the C(tests/hotkey/pair_parity.rs).bool *read cannot be logged, so the reads are compared by their effect. The order of the reads is pinned on the core by Tier 1's access log, and the shim reads only through the core.hotkey::passes 234/234 (26 of themhotkey::pair).every_single_event_matches_candrandom_sequences_match_ccatch every one, andevery_sequence_of_four_matches_call but the four that need a func that changes a latch or triggers an event while it runs. The 13 core mutants also fail Tier 1.test_hotkey_pair_latchfailedpress_not_acted_onandone_key_toggle(9/11) and passed 11/11 against libobs-c-reference. After the restore, 11/11 against both.OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON, both full builds. Fullctest -j4, headless (private Xvfb with-noreset, private D-Bus, fresh HOME):OBS_LIBOBS_BACKEND=CHYBRID,OBS_BUILD_C_REFERENCE=ONHYBRID,OBS_BUILD_C_REFERENCE=ONNothing was skipped or failed to run. After the final rebase onto
bd49ef7db(#1812, CI and docs only), both trees were rebuilt, and the eleven hotkey tests, the symbol comparison,hotkey::and the lint and cross lanes passed again.The eleven hotkey tests pass against all three libraries:
test_hotkey_pair_latch11/11,test_hotkey_pair_steps4/4,test_hotkey_press_state18/18,test_hotkey_press_steps11/11,test_hotkey_load7/7,test_wayland_hotkeys8/8,test_portal_shortcuts32/32,test_portal_shortcut_sets12/12,test_hotkey_bindings_codec18/18,test_hotkey_translations16/16,test_x11_hotkey_layout4/4. The ported group is compiled only into libobs-c-reference (and the C-backend libobs).uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed.soldr cargo test -p obs-data --test obs-tests-core hotkey::passes 234/234, andsoldr cargo test -p obs-hotkeypasses (the crate keeps its tests inobs-tests-core).ci/test_build_groups.py,ci/test_ported_sources.pyandci/platform_ifdef_ratchet.pypass.test_hotkey_pair_latchdrives the hybrid libobs's pairs through the same path the frontend's router and obs-websocket use.Windows/macOS: not built there. The core and shims have no host conditional.
test_hotkey_pair_latchandtest_hotkey_pair_stepsare built on every OS, so on Windows and macOS the swap is covered bytest_hotkey_pair_latchagainst the hybrid libobs, by Tier 3 (therust-testsjob) and by the unchanged C tests (rust-tier2). PR CI covers those builds.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)