Repository navigation
Description
Port the hotkey pair press latch of libobs/obs-hotkey.c.h to the existing crate rust/obs-hotkey as a new module, pair. A hotkey pair (obs_hotkey_pair_register_frontend/_encoder/_output/_service/_source) is two hotkeys, each with a func that returns whether it acted. The frontend registers eight of them: Start/Stop Streaming, Start/Stop Recording, Pause/Unpause Recording, Start/Stop Replay Buffer, Start/Stop Virtual Camera, Enable/Disable Preview, Enable/Disable Studio Mode and Show/Hide Context Bar. libobs registers each half with a callback of its own, which keeps one latch per half, so that one key bound to both halves toggles and a held half blocks the other. Three paths reach these callbacks, always with the hotkey mutex held:
- the hotkey thread, which presses and releases bindings on each 25 ms poll;
obs_hotkey_inject_event()(the frontend while OBS has focus, and obs-websocket'sTriggerHotkeyByKeySequence);obs_hotkey_trigger_routed_callback(), which the frontend calls from its router (callback rerouting is on in the frontend) and obs-websocket calls forTriggerHotkeyByName(a press, then a release).
The unit, about 25 lines:
obs_hotkey_pair_first_func()andobs_hotkey_pair_second_func(), theobs_hotkey_funccallbacks thatregister_hotkey_pair_internal()registers for the two halves, with the pair as their data. For one half:- if the other half is latched, the event is dropped;
- else if this half is latched and the event is a release, the latch is cleared and the func is not called;
- else the func is called (with the half's data, the pair id and the half's hotkey), and if it returns true, the latch takes the event's pressed value.
These stay C: create_hotkey_pair(), register_hotkey_pair_internal() and the obs_hotkey_pair_register_* functions, the pair hash (obs->hotkeys.hotkey_pairs), obs_hotkey_pair_load/_save/_set_names/_set_descriptions/_unregister, and the call of the pair's func itself (func[i](data[i], pair_id, hotkey, pressed)), which goes through a hidden C wrapper.
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, the portal shortcut id codec, the binding codec, the key-name translations and the hotkey press state machine (#1751). It is part of a large file, so it goes in through function extraction (testing-policy.md, "Extracting a function before porting it"), then the port. Two PRs: the accessor goes into PR 1 (below). Its Rust tests join the crate's existing tests/hotkey/ binary. No new test binary.
Dependencies and existing tests
- It reads and writes two fields of
struct obs_hotkey_pair(obs-internal.h):pressed0andpressed1. It callsfunc[i]withdata[i]andpair_id. - Seams into C, all hidden (declared in
obs-internal.h, notEXPORT), as for the press state machine (libobs: Move the hotkey press state machine into obs-hotkey-press.c #1752, libobs: Reach hotkey bindings through a hidden accessor #1779):obs_hotkey_pair_fields(pair), a struct of pointers topressed0andpressed1, so Rust never mirrorsstruct obs_hotkey_pair;obs_hotkey_pair_call_func(pair, half, hotkey, pressed), which callsfunc[half](data[half], pair_id, hotkey, pressed)and returns its result.
- Entry points out of the unit, also hidden:
obs_hotkey_pair_first_func()andobs_hotkey_pair_second_func(), which keep theobs_hotkey_funcsignature because they are registered as the hotkey callbacks. - Today only the pair case of
test_hotkey_press_state(libobs: Move the hotkey press state machine into obs-hotkey-press.c #1752) touches the unit: one press and release of each half, and the second half blocked while the first is held. PR 1 adds two tests (below). - Input: the events come from the OS key state, from the frontend's router and from obs-websocket (
TriggerHotkeyByName,TriggerHotkeyByKeySequence), but only as a hotkey id and a pressed bool, which libobs looks up first. The unit indexes nothing and allocates nothing.
Plan
- Characterization, extraction and accessor PR (behaviour-neutral):
- New test
test_hotkey_pair_latch, its own commit on the unchanged C. It links the real libobs and uses only the public API: a frontend pair driven byobs_hotkey_trigger_routed_callback()with callback rerouting on, as the frontend does. No key is held and the calls are synchronous, so it needs no XTEST and builds on every OS. It pins press and release of each half, a press not acted on, a release without a press, a second press of a latched half, each half blocked while the other is latched, the second half released after the first, one key on both halves as a toggle, the latch per pair, and a func that triggers its partner from inside its press. Every call is checked for the pair id and the half's own hotkey. It covers the hybrid libobs too, so it sees the port. - The two functions move verbatim into
libobs/obs-hotkey-pair.c.h, in the same unity group (libobs.core, just beforeobs-hotkey.c.h), and losestatic. The tests that compileobs-hotkey.c.h(test_hotkey_load,test_wayland_hotkeys,test_portal_shortcuts,test_hotkey_press_steps, and the obs-build manifest entry fortest_hotkey_load) compile the new file next to it. No platform conditional moves. - New test
test_hotkey_pair_steps, with the move. It compiles the C into itself liketest_hotkey_press_steps, registers a pair, and calls the two callbacks with the latch set by hand. It pins the latch after every event, in all 32 cases (4 latch states, both latched included, × 2 halves × press or release × func true or false), that the pair registers the two callbacks with itself as their data, and that a half writes only its own latch, after its func returns. - The accessor and the call wrapper, as RED (a
pair_fieldscase intest_hotkey_pair_stepsthat does not build) then GREEN: the moved file reaches the pair only through them.
- New test
- Port PR (RED, then GREEN):
obs_hotkey::pairgets the safe core: one step per event,step(latch, half, pressed, call) -> latch, wherecallis a closure that calls the func and returns its result. It is called at most once, at the point the C calls it.src/ffi/pair.rsexports the two callbacks with the C signature, and calls back only through the accessor and the wrapper. The C file moves to its own ported group,libobs.ported-hotkey-pair, with its own.pch.h,source-sets.jsonentry and export fragment (rust-exports.map,rust-hidden.txt,rust-unexports-macos.txt), aslibobs.ported-hotkey-presshas.- The shim must read the other half's latch, and its own, before the call, and write only its own latch after the call, through the pointer. A func can change the latch from inside (a func that triggers its partner). Writing back both values from a copy taken before the call would differ from the C.
test_hotkey_pair_stepsandtest_hotkey_pair_latchboth pin this. - Tests:
- Tier 1 ports every
test_hotkey_pair_stepsandtest_hotkey_pair_latchexpectation 1:1, over the pure core. - Tier 3 checks parity against the moved C, exhaustively: all 4 latch states × 2 halves × press or release × func result, plus a func that sets either latch from inside its call. It compares whether the func was called, its arguments, and both latches after the step.
- Tier 2 runs with
OBS_LIBOBS_BACKEND=Cand in the hybrid withlibobs-c-reference, unchanged;test_hotkey_pair_latchandtest_hotkey_press_statesee the swap. - Tier 4 does not apply (no protocol change).
- Tier 1 ports every
- Docs: the
rust/README.mdrow, and thedocs/rust-port/naming.mdrow forrust/obs-hotkey(addobs-hotkey-pair.c.h).
For the reviewer to decide
- The accessor goes in PR 1, not in a PR of its own. For the press state machine the accessor was a separate PR (libobs: Reach hotkey bindings through a hidden accessor #1779), because that plan had three PRs and the field view touched how the moved C read every binding. Here the view is two
boolpointers plus one call wrapper, the testing policy allows the adaptation as "a separate, behavior-neutral commit or PR", and a separate PR would only add a round of review and CI for about 20 lines. So it is its own RED and GREEN commits inside PR 1. It could be split out if wanted. - The func call stays C. The port could instead get
func,dataandpair_idthrough the accessor and call the function pointer from Rust. A C wrapper keeps the pair's callback ABI in C, asobs_hotkey_binding_press()and_release()do for the press state machine. - Threads and the hotkey mutex. The callbacks run with
obs->hotkeys.mutex(recursive) held, on the hotkey thread, or on the thread that callsobs_hotkey_inject_event()orobs_hotkey_trigger_routed_callback()(the UI thread, an obs-websocket thread). The func runs synchronously inside and may call back into libobs, including the partner half. So the Rust core keeps no state between calls (it all lives in the pair) and takes no lock of its own. - Behaviours the characterization pins, not endorses (none is changed by this plan):
- The second half pressed while the first is latched, and released after it: its press is dropped, its release reaches its func, which so gets a release without a press. One key bound to both halves does this on every press. The frontend's funcs ignore releases.
- A second press of a latched half calls the func again, and the half stays latched whatever the func returns. libobs's own paths never send two presses without a release (the pressed count), but
TriggerHotkeyByNameand the router reach the callback directly. - A func that triggers its partner's press from inside its own press latches both halves, and the pair then drops every event until it is registered again. The frontend's funcs do not do this.
None looks like a user-facing bug today. I propose no fix PR before the port. If one is wanted, it should come before PR 2, so the port copies fixed C.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 22, 2026
Claiming: #1798
libobs/obs-hotkey-pair.c.hbehind hidden entry points, a hiddenobs_hotkey_pair_fields()/obs_hotkey_pair_call_func()accessor,test_hotkey_pair_latch(real libobs, 11 cases) andtest_hotkey_pair_steps(all 32 state × input × result combinations). No behaviour change.rust/obs-hotkey(modulepair) with exhaustive oracle parity.test: Characterize the hotkey pair press latch
libobs: Move the hotkey pair press latch into obs-hotkey-pair.c
test: Pin the hotkey pair fields the pair press latch uses
libobs: Reach hotkey pairs through a hidden accessor
libobs: Move the hotkey pair press latch into obs-hotkey-pair.c (obs-…
rdoupe commentedon Oct 22, 2026
Port is up in #1820. The only intentional difference from C is null handling: a null
data, or a null latch pointer fromobs_hotkey_pair_fields(), does nothing where C would dereference it. The three behaviours pinned as not endorsed in #1799 are kept, and each half still writes only its own latch, through the accessor pointer, after its func returns.libobs: Add Tier 1 tests for the hotkey pair press latch port
libobs: Port the hotkey pair press latch to obs-hotkey
libobs: Check the hotkey pair press latch port against the C
docs: Record the hotkey pair press latch port
libobs: Port the hotkey pair press latch to obs-hotkey (#1820)