Repository navigation
Description
Port the hotkey binding press count of libobs/obs-hotkey.c.h to the existing crate rust/obs-hotkey as a new module, binding_press. A hotkey can have several bindings (key combinations), and each binding is pressed and released on its own: by the hotkey thread on each 25 ms poll, by obs_hotkey_inject_event() (the frontend while OBS has focus, and obs-websocket's TriggerHotkeyByKeySequence), and by remove_bindings() when a pressed binding is rebound or its hotkey unregistered. The press count turns those binding events into hotkey events: the hotkey's callback runs on the first press and the last release only, so a hotkey held through two bindings fires once.
The unit, about 25 lines:
press_released_binding(): sets the binding'spressedflag, increments the hotkey'spressedcount (anint), and calls the hotkey only if the count was 0.release_pressed_binding(): clears the flag, decrements the count, and calls the hotkey only if the count is now 0.- The call: the hotkey's
func(data, id, hotkey, pressed)when callback rerouting is off; the router (router_func(router_func_data, id, pressed)) when it is on; nothing when it is on and no router is set. - The wrappers
obs_hotkey_binding_press()and_release(), which the ported press state machine calls (obs-hotkey-press.c.h).
These stay C: remove_bindings() (which calls the release), inject_hotkey(), query_hotkeys() and the binding walk, the hotkey hash, the router and rerouting setters, and the callback call itself, which goes through a hidden C function.
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 ids and sets, the binding codec, the key-name translations, the hotkey press state machine (#1751) and the pair press latch (#1798). 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 seam 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 writes
struct obs_hotkey_binding'spressed(obs-internal.h), reads itshotkey, and reads and writesstruct obs_hotkey'spressedcount. It readsobs->hotkeys.reroute_hotkeys,router_funcandrouter_func_dataonly to choose the call. - Seams into C, both hidden (declared in
obs-internal.h, notEXPORT), as for the press state machine (libobs: Reach hotkey bindings through a hidden accessor #1779) and the pair latch (libobs: Move the hotkey pair press latch into obs-hotkey-pair.c #1799):obs_hotkey_binding_count_fields(binding), a struct of pointers to the binding's flag and its hotkey's count, plus the hotkey, so Rust never mirrorsstruct obs_hotkey_bindingorstruct obs_hotkey;obs_hotkey_dispatch(hotkey, pressed), which makes the rerouting choice and the call, so the callback ABI and the router (the frontend's) stay C.
- Entry points out of the unit, also hidden:
obs_hotkey_binding_press()andobs_hotkey_binding_release(), unchanged. - Existing tests:
test_hotkey_press_state(18 cases, real libobs, libobs: Move the hotkey press state machine into obs-hotkey-press.c #1752) reaches the unit through the poll and inject paths: two bindings pressed one after the other, a duplicated binding, rebinding and unregistering while pressed, rerouting with and without a router.test_hotkey_press_stepschecks the pressed count after each poll. PR 1 adds cases for what is missing (below). - Input: local only. The events come from the OS key state, from the frontend and from obs-websocket, but only as presses and releases of bindings libobs already holds. The unit indexes nothing and allocates nothing.
Plan
- Characterization, extraction and seam PR (behaviour-neutral):
- Six new cases in
test_hotkey_press_state, their own commit on the unchanged C: two bindings of one hotkey pressed and released in the same poll; one injected event that presses both bindings of a hotkey; unregistering a hotkey held through two bindings; unregistering a pressed hotkey with rerouting on; rerouting switched on or off while a hotkey is pressed; the router removed while a hotkey is pressed. - The four functions move verbatim into
libobs/obs-hotkey-binding-press.c.h, in the same unity group (libobs.core, just beforeobs-hotkey.c.h).remove_bindings()now callsobs_hotkey_binding_release()(the static release is no longer in its file). The tests that compileobs-hotkey.c.h(test_hotkey_load,test_wayland_hotkeys,test_portal_shortcuts,test_hotkey_press_steps,test_hotkey_pair_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_binding_press_steps, with the move. It compiles the C into itself liketest_hotkey_pair_steps, binds a hotkey through the API, and calls the press and the release with the flag and the count set by hand. It pins the flag, the count and the call after every event in all 24 cases (flag × count −2..3 × press or release), each in the three routing states, the arguments of each call, that the flag and the count are written before the call and nothing after it, two bindings of one hotkey, andremove_bindings()releasing only the pressed bindings it removes. - The accessor and the dispatch, as RED (a
count_fields_and_dispatchcase intest_hotkey_binding_press_stepsthat does not build) then GREEN: the moved file reaches the binding and the hotkey only through them.
- Six new cases in
- Port PR (RED, then GREEN):
obs_hotkey::binding_pressgets the safe core:fn press(flag: &mut bool, count: &mut i32) -> boolandfn release(...) -> bool("call now").src/ffi/binding_press.rsexportsobs_hotkey_binding_press()and_release(), takes the pointers once through the accessor, writes the flag and the count through them, and then, if the core says so, callsobs_hotkey_dispatch()last. The C file moves to its own ported group,libobs.ported-hotkey-binding-press, with its own.pch.h,source-sets.jsonentry and export fragment (rust-exports.map,rust-hidden.txt,rust-unexports-macos.txt), aslibobs.ported-hotkey-pairhas.- The count must use C's
intarithmetic (wrapping_add/wrapping_suboni32to stay defined at the edges, which libobs never reaches), and the shim must not read or write the binding or the hotkey after the dispatch. A callback can change both from inside its call;test_hotkey_binding_press_stepspins this. - Tests:
- Tier 1 ports every
test_hotkey_binding_press_stepsexpectation 1:1, over the pure core. - Tier 3 checks parity against the moved C, exhaustively: flag × count (−2..3) × press or release × the three routing states, plus sequences over two and three bindings of one hotkey and a callback that changes the flag and the count from inside. It compares the dispatch log (hotkey, pressed, and the flag and the count the call sees) and the flag and the count after every step.
- Tier 2 runs with
OBS_LIBOBS_BACKEND=Cand in the hybrid withlibobs-c-reference, unchanged;test_hotkey_press_statesees 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-binding-press.c.h).
For the reviewer to decide
- The seam goes in PR 1, not in a PR of its own, as for the pair latch (libobs: Move the hotkey pair press latch into obs-hotkey-pair.c #1799): one accessor and one dispatch function, in their own RED and GREEN commits. They can be split out if wanted.
- A new accessor, not a wider
obs_hotkey_binding_fields(). The press state machine's accessor (libobs: Reach hotkey bindings through a hidden accessor #1779) givesconst bool *pressedand no hotkey, and the ported press state machine mirrors that struct and gets it by value, so widening it would change the ABI the Rust side already uses. The newobs_hotkey_binding_count_fields()gives a writable flag pointer, the count and the hotkey. Both point at the samepressedflag. - The rerouting choice and the call stay C, in
obs_hotkey_dispatch(). The port could read the rerouting flag and the router through an accessor and call the function pointers from Rust; a C function keeps the callback ABI and the router (the frontend's) in C, asobs_hotkey_pair_call_func()does for the pair. - Threads and the hotkey mutex. Every caller holds
obs->hotkeys.mutex(recursive): the hotkey thread, the thread callingobs_hotkey_inject_event(), and any thread rebinding or unregistering. The callback runs synchronously inside and may call back into libobs. So the Rust core keeps no state (it all lives in the binding and the hotkey) and takes no lock. - Behaviours the characterization pins, not endorses (none is changed by this plan):
- With rerouting on, a release while no router is set is lost: the router got the press and never gets its release (the count still drops, so the next press reaches the router again). The frontend reaches this only at exit: it removes its router just before it unregisters its hotkeys, so a hotkey held then gets no release, which no longer matters there.
- Neither function checks the flag: a press of a pressed binding counts again, and a release at count 0 makes it negative. libobs presses only a released binding and releases only a pressed one, so this is unreachable today.
None looks like a user-facing bug today. I propose no fix PR before the port.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 22, 2026
Claiming: #1836
libobs/obs-hotkey-binding-press.c.h, a hiddenobs_hotkey_binding_count_fields()accessor andobs_hotkey_dispatch()(reroute choice and call stay in C), 6 new cases intest_hotkey_press_stateandtest_hotkey_binding_press_steps. No behaviour change.rust/obs-hotkey(modulebinding_press) with exhaustive oracle parity.zackees commentedon Oct 25, 2026
/ready
Triage: a scoped port (the binding press count into
rust/obs-hotkeyasbinding_press), claimed by @rdoupe with the characterization/seam PR #1837 open. The usual port acceptance: RED → GREEN, Tier 2 against the hybrid libobs, and a Tier 3 differential test of the press/release/rebind sequences against the C. P3, size:M.zackees commentedon Oct 30, 2026
Claiming: Port the hotkey binding press count (obs-hotkey) — PR 1 of the two-PR plan in the issue.
Plan:
test_hotkey_press_state, move the four functions verbatim intolibobs/obs-hotkey-binding-press.c.hin thelibobs.coreunity group, newtest_hotkey_binding_press_steps(24 flag × count events in the three routing states, plus the accessor and dispatch as RED then GREEN), and the seam declarations inobs-internal.h.obs_hotkey::binding_presswith Tier 1 and Tier 3 tests, thelibobs.ported-hotkey-binding-pressgroup and the export fragment.First PR: this tick.
zackees commentedon Oct 30, 2026
Progress: PR 1 (characterization + extraction + seam) is #3032, now queued to merge.
test_hotkey_binding_press_steps(5 cases) pins the flag, the count and the call after every event in all three routing states, the arguments of each call, that both fields are written before the call, two bindings of one hotkey, andremove_bindings()releasing only the pressed bindings it removes.libobs/obs-hotkey-binding-press.c.h(libobs.core, withlibobs.pch.h; no group/PCH/source-sets.jsonchange).obs_hotkey_binding_count_fields()andobs_hotkey_dispatch()inobs-hotkey.c.h, declared withoutEXPORT.CI Gate ✅); Tier 2 Linux 629 tests, the 20 hotkey/Wayland/portal tests pass.PR 2 (the port to
obs_hotkey::binding_presswith Tier 1 + Tier 3 and thelibobs.ported-hotkey-binding-pressgroup) follows once #3032 lands, since it needs the moved file on master.zackees commentedon Oct 30, 2026
Progress: PR 2 (the port itself) is #3075, on
port/1836-binding-press.obs_hotkey::binding_press(press,releaseover the flag and the count), the hidden shimsobs_hotkey_binding_press/_releasethroughobs_hotkey_binding_count_fields()andobs_hotkey_dispatch(), and the C file moved tolibobs.ported-hotkey-binding-press.test_hotkey_binding_press_steps1:1 (12 tests pass). Tier 3 compares the shims withoracle/hotkey_binding_press.con fake bindings (6 tests pass): the whole table, two bindings of one hotkey, sequences from a pressed state, the null differences and random runs.oracle_seam_*stand-ins, andpress_paritydrives them through the ported shim, so both sides still log the same calls.test_hotkey_binding_press_steps,test_hotkey_press_steps,test_hotkey_pair_stepsandtest_hotkey_press_stateis running.libobs: Add Tier 1 and Tier 3 tests for the hotkey binding press coun…
libobs: Port the hotkey binding press count to obs-hotkey
libobs: Add Tier 1 and Tier 3 tests for the hotkey binding press coun…
libobs: Port the hotkey binding press count to obs-hotkey
libobs: Add Tier 1 and Tier 3 tests for the hotkey binding press coun…
libobs: Port the hotkey binding press count to obs-hotkey
libobs: Extract the hotkey binding press count and its seam (obs-rust…
libobs: Port the hotkey binding press count to obs-hotkey (#1836) (#3075