Repository navigation
libobs: Move the hotkey pair press latch into obs-hotkey-pair.c - #1799
Merged
Merged
Conversation
Characterization before the hotkey pair press latch (obs_hotkey_pair_first_func and obs_hotkey_pair_second_func in obs-hotkey.c) moves to its own file and is ported to obs-hotkey. Only the pair case of test_hotkey_press_state touches it today. test_hotkey_pair_latch links the real libobs and uses the public API only. It drives a frontend pair the way the frontend does: callback rerouting on, and obs_hotkey_trigger_routed_callback() runs a half's callback on the calling thread. No key is held and no hotkey thread timing is involved, so it is synchronous and builds on every OS. 11 cases pin: press and release of each half (one func call; the release of a press acted on clears the latch without a call); a press not acted on (no latch, its release is passed 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 used as a toggle; the latch per pair; and a func that triggers its partner from inside its press. Each call is checked for the pair id and the half's own hotkey. Characterized, not endorsed: - The second half pressed while the first is latched and released after it: its press is dropped, its release reaches its func. - A second press of a latched half calls the func again, and the half stays latched whatever the func returns. - A func that triggers its partner's press from inside its own press latches both halves, and the pair then drops every event. Refs obs-rust#1798
Behavior-neutral extraction before the Rust port: the two callbacks that register_hotkey_pair_internal() registers for the halves of a hotkey pair, obs_hotkey_pair_first_func() and obs_hotkey_pair_second_func(), move verbatim from libobs/obs-hotkey.c.h into libobs/obs-hotkey-pair.c.h. The only change is that they are no longer static: obs-hotkey.c.h registers them, and the tests that compile obs-hotkey.c.h build each file as its own translation unit. Both are declared in obs-internal.h without EXPORT, so -fvisibility=hidden keeps them local. create_hotkey_pair(), register_hotkey_pair_internal() and the pair hash stay where they are. The new file joins libobs.core just before obs-hotkey.c.h, with libobs.pch.h. No group, PCH or source-sets.json change, no platform conditional moves, and the exported symbols are unchanged (1766). The tests that compile obs-hotkey.c.h on their own (test_hotkey_load, test_wayland_hotkeys, test_portal_shortcuts, test_hotkey_press_steps, and the obs-build manifest entry for test_hotkey_load) now compile the new file next to it. New test test_hotkey_pair_steps compiles the C into itself like test_hotkey_press_steps, registers a pair, and calls the two callbacks with the latch set by hand. It pins what the real libobs cannot show: the latch after every event in all 32 cases (4 latch states, both latched included, x 2 halves x press or release x 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. test_hotkey_pair_latch passes unchanged. Refs obs-rust#1798
Before the pair press latch reaches its pair through an accessor, one case in test_hotkey_pair_steps pins it: obs_hotkey_pair_fields() points at the pair's own pressed0 and pressed1, a latch set through it is the one the callbacks read, and one set by a callback shows through it; and obs_hotkey_pair_call_func() calls one half's func with its data, the pair id and the hotkey, returns its result and leaves the latch alone. It does not build yet: neither function exists. Refs obs-rust#1798
The hotkey pair press latch, libobs/obs-hotkey-pair.c.h, reads and writes two fields of struct obs_hotkey_pair, which is private, and calls the pair's func with its data and id. The Rust port should not mirror that struct, so the latch now reaches the pair only through two hidden functions in obs-hotkey.c.h: - obs_hotkey_pair_fields(pair): pointers to pressed0 and pressed1, the latch of each half; - obs_hotkey_pair_call_func(pair, half, hotkey, pressed): calls func[half](data[half], pair_id, hotkey, pressed) and returns its result. Each callback fetches the fields once. The pointers alias the fields themselves, so each latch is still read and written at the same point, after the func returns, under the same lock. Both are declared in obs-internal.h without EXPORT, so the exported symbols are unchanged. test_hotkey_pair_steps passes 4/4 (pair_fields included) and test_hotkey_pair_latch 11/11. Refs obs-rust#1798
rdoupe
force-pushed
the
refactor/hotkey-pair-move
branch
from
October 22, 2026 15:49
fcb5cf8 to
de16686
Compare
zackees
enabled auto-merge
October 22, 2026 16:12
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 22, 2026
This was referenced Oct 22, 2026
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 22, 2026
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
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Oct 22, 2026
* libobs: Add Tier 1 tests for the hotkey pair press latch port 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 #1798 * libobs: Port the hotkey pair press latch to obs-hotkey 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() (#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 (#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 #1798 * libobs: Check the hotkey pair press latch port against the C 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 #1798 * docs: Record the hotkey pair press latch port 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 #1798
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.
Refs #1798 (PR 1 of the plan: the characterization, the extraction and the accessor. The port follows.)
What and why
This is a behaviour-neutral extraction before the Rust port, as the testing policy asks for part of a large file. The hotkey pair press latch moves from
libobs/obs-hotkey.c.hintolibobs/obs-hotkey-pair.c.h. The latch is the two callbacks libobs registers for the halves of a hotkey pair, such as Start and Stop Streaming. While one half is latched, the other half's events are dropped. A press whose func returns true latches its half, and its release clears the latch without calling the func. The move comes with two characterization tests, because only one case oftest_hotkey_press_statetouched the unit. There is no Rust, no behaviour change and no public header change.What moves:
obs_hotkey_pair_first_func()andobs_hotkey_pair_second_func(), verbatim. The only change is that they losestatic:register_hotkey_pair_internal()inobs-hotkey.c.hregisters them, and the tests that compileobs-hotkey.c.hbuild each.c.has its own translation unit.What stays:
create_hotkey_pair(),register_hotkey_pair_internal(), theobs_hotkey_pair_register_*functions, the pair hash and the rest of the pair API stay inobs-hotkey.c.h.The accessor, in its own RED and GREEN commits: the moved file now reaches the pair only through two new functions in
obs-hotkey.c.h:obs_hotkey_pair_fields(pair), pointers topressed0andpressed1(the latch of each half), so the port does not mirrorstruct 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, so the pair's callback ABI stays C, asobs_hotkey_binding_press()does for the press state machine.Each callback fetches the fields once. The pointers alias the fields themselves, so each latch is still read and written at the same point, after the func returns, under the same lock.
Hidden: all four functions are declared in
obs-internal.hwithoutEXPORT, so-fvisibility=hiddenkeeps them local (t) symbols. The exported symbols are unchanged.Build: the new file joins the existing
libobs.coregroup just beforeobs-hotkey.c.h, withlibobs.pch.hlike every member of that group. The group, the PCH,source-sets.jsonand the CMake source lists of libobs are unchanged. The moved code has no platform conditional.Tests that compile
obs-hotkey.c.hthemselves:test_hotkey_load,test_wayland_hotkeys,test_portal_shortcutsandtest_hotkey_press_stepsnow compileobs-hotkey-pair.c.hnext to it, as they doobs-hotkey-press.c.h(CMake, and the obs-build C test manifest fortest_hotkey_load). Their test files are unchanged.Why the accessor is in this PR: for the press state machine it was a PR of its own (#1779), because that plan had three PRs and the field view changed how the moved C read every binding. Here it is two
boolpointers and one call wrapper. The testing policy allows the adaptation as "a separate, behavior-neutral commit or PR", so it is two commits here. They can be split out into their own PR if wanted.test_hotkey_pair_latch(new, its own commit before the move) links the real libobs and uses only the public API, so it also covers the hybrid libobs and will see the port. It drives a frontend pair the way the frontend does: callback rerouting is on, andobs_hotkey_trigger_routed_callback()(which the frontend's router and obs-websocket'sTriggerHotkeyByNamecall) runs a half's callback on the calling thread. No key is held and no hotkey thread timing is involved, so every call is synchronous, and the test builds and runs on every OS, liketest_hotkey_bindings_codec. On Linux it runs under xvfb-run, becauseobs_startupneeds a display there. It shares the display with the other tests, because it holds no key. Its 11 cases, each also checking that the func got the pair id and its own half's hotkey:test_hotkey_pair_steps(new, with the move) compiles the C into itself liketest_hotkey_press_steps, registers a pair through the API, and calls the two callbacks with the latch set by hand. Its 4 cases pin what the real libobs cannot show:pair_fields, the RED case) that the accessor points at the pair's own latches and the call wrapper calls the right half's func with its data, the pair id and the hotkey, returns its result and leaves the latch alone.Characterized, not endorsed (a comment in the tests, and in the issue). None is changed here, and the issue proposes no fix before the port:
TriggerHotkeyByNameand the router reach the callback directly.RED → GREEN
020308e89test: Pin the hotkey pair fields the pair press latch usesadds one case,pair_fields, totest_hotkey_pair_steps. It fails to build there, in both build trees, becauseobs_hotkey_pair_fields(), its struct andobs_hotkey_pair_call_func()do not exist yet (test_hotkey_pair_stepsis the only target that fails). Before it,test_hotkey_pair_latchis its own commit,aab3783c6test: Characterize the hotkey pair press latch, and passes 11/11 on the unchanged C. The move is4b1e34c21libobs: Move the hotkey pair press latch into obs-hotkey-pair.c.de16686e0libobs: Reach hotkey pairs through a hidden accessor.test_hotkey_pair_latchpasses 11/11 andtest_hotkey_pair_steps4/4, against libobs with the C backend, the hybrid libobs and libobs-c-reference.obs-hotkey-pair.c.h, the accessor or the call wrapper was built into libobs (C backend) and both tests:OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON, both full builds. Fullctest -j4, headless (private Xvfb, 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. In the hybrid run, two timing tests outside the hotkey code failed once under
-j4load (test_deinterlace_2x_field_order: a field held one frame too long;test_pulse_monitor_device: the default-sink switch took longer than its 3 s wait) and passed when run again; both pass in the other two runs.test_hotkey_press_state(18/18),test_hotkey_press_steps(11/11),test_hotkey_load(7/7),test_wayland_hotkeys(8/8),test_portal_shortcuts(32/32),test_hotkey_bindings_codec(18/18),test_hotkey_translations(16/16) andtest_x11_hotkey_layout(4/4) pass, unchanged, against all three. After the final rebase ontob6fbbceeb(#1795), both trees were rebuilt, and all ten hotkey tests and the symbol comparison passed again.uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed.ci/test_build_groups.py,ci/test_ported_sources.pyandci/platform_ifdef_ratchet.pypass. clang-format 22.1.3 is clean on the changed files.Windows/macOS: not built there. The moved code has no host conditional, and the accessor and the wrapper are plain C.
test_hotkey_pair_latchandtest_hotkey_pair_stepsare built on every OS, liketest_hotkey_bindings_codecandtest_hotkey_press_steps, and are portable C (no cmocka range assertions, nofail_msg()).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)