Skip to content

libobs: Port the hotkey binding press count to obs-hotkey (#1836) - #3075

Merged
zackees merged 4 commits into
masterfrom
port/1836-binding-press
Oct 30, 2026
Merged

zackees merged 4 commits into
masterfrom
port/1836-binding-press

Conversation

@zackees

@zackees zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member

Ports libobs/obs-hotkey-binding-press.c.h to binding_press in rust/obs-hotkey (part 2 of #1836; PR 1, the characterization, extraction and seam, was #3032 and is merged).

RED

6de87e34c — the two new test modules and the port's wirings, against a todo!() core.

soldr cargo test -p obs-data --test obs-tests-core hotkey::binding_press
thread 'hotkey::binding_press_parity::every_state_matches_c' panicked at rust/obs-hotkey/src/binding_press.rs:68:5:
not yet implemented

GREEN

a83937d1e — the safe core (press, release), the hidden shims, the oracle and the C group move.

  • Tier 1: tests/hotkey/binding_press.rs ports the 5 cases of test_hotkey_binding_press_steps 1:1 (every_step in all three routing states, writes_before_the_return, two_bindings, release_without_press, wraps_at_the_edges) plus a proptest of the count invariant. 12 passed.
  • Tier 3: tests/hotkey/binding_press_parity.rs compares the shims with the original C (oracle/hotkey_binding_press.c) on fake bindings, logging every accessor call and every dispatch with the flag and count it sees: the C test's whole table, two bindings of one hotkey, sequences from a pressed state, the intentional null differences and random runs. 6 passed.
  • Tier 2: test_hotkey_press_state sees the swap through a real libobs (CI's Tier 2 lane); test_hotkey_press_steps, test_hotkey_pair_steps, test_hotkey_load, test_wayland_hotkeys and test_portal_shortcuts still compile the C file into themselves.
  • Tier 4: does not apply (no protocol change).

The shims take the flag, the count and the hotkey once through the hidden obs_hotkey_binding_count_fields() (#1836) and write through those pointers, never a copy; obs_hotkey_dispatch() is last and only when the core says so, and the binding is not touched after it. The press count uses C's int semantics (wrap at the edges of i32, where C is undefined).

Because the wrappers are Rust now, the press state machine's oracle calls oracle_seam_* stand-ins instead of the real symbols, and press_parity drives them through the ported shim so both sides log the same thing.

Test cost

New tests: longest 0.37 s (binding_press_parity::random_runs_match_c, over 25 runs of the binary), peak RSS 19.6 MB over 25 runs, no own threads.

./lint: every lane passes except test_check_changes.py, which cannot shell out to git in this checkout (clud shim), an environment artifact and not this change. test_build_groups.py, test_ported_sources.py, test_registration.py pass; soldr cargo clippy -p obs-hotkey -p obs-c-oracle --all-targets is clean.

Fixes #1836

@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Coordinator: pushed fixup: rustfmt the hotkey parity tests (11fce9f) for the Fast Gate lint failure. The Tier 2 failure (test_deinterlace_2x_field_order discard_2x_top_first_50i_into_30, line 516) is in code this PR doesn't touch; the new CI run will show whether it was a flake.

@zackees
zackees force-pushed the port/1836-binding-press branch from 11fce9f to 96de425 Compare October 30, 2026 17:06
@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Worker tick: rebased port/1836-binding-press onto origin/master (3edcda476, the X11 keysyms/mouse port).

Conflicts were all registry-style and are resolved by keeping master's text plus this unit:

  • rust/obs-hotkey/Cargo.toml, rust/README.md, docs/rust-port/naming.md: master's list plus libobs/obs-hotkey-binding-press.c.h (master's obs-nix-x11-input.c.h entry kept).
  • rust/obs-hotkey/src/lib.rs: master's module doc plus [binding_press] (and master's [nix_x11_input]).

The coordinator's fixup: rustfmt the hotkey parity tests change is identical to the rustfmt output in this rebased tip, so it is included; the rebase superseded that commit hash. ./lint is clean locally (lane lint ok). The one Tier 2 failure in the previous run (discard_2x_top_first_50i_into_30, deinterlace field order) is untouched code and looks like the known RUN_SERIAL deinterlace flake.

@zackees
zackees enabled auto-merge October 30, 2026 17:10
@zackees
zackees added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026
@zackees
zackees added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 30, 2026
@zackees
zackees force-pushed the port/1836-binding-press branch from 96de425 to 8b7766b Compare October 30, 2026 18:32
@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Worker tick: rebased port/1836-binding-press onto origin/master (c45ef94e9) after the merge queue reported it DIRTY. The conflicts were three union rows (the obs-hotkey port lists in docs/rust-port/naming.md, rust/README.md, rust/obs-hotkey/Cargo.toml and the lib.rs module list) and are resolved by keeping both master's Wayland keysym and X11 input entries and this branch's binding_press entry. ./lint ok (217.4 s). CI re-runs on 8b7766bea.

@zackees zackees left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: no defects found. press/release match obs-hotkey-binding-press.c.h (flag set, count checked before the increment on press and after the decrement on release, dispatch last), with null and i32-overflow handled where C is UB. RED (6de87e3) then GREEN (a83937d) is visible. Tier 3 parity runs against the new oracle and Tier 2 via test_hotkey_press_state. No C tests or public headers changed, and the tests are in the existing hotkey binary. The Test cost line is present, and it's an internal port, so no ledger line is needed.

@zackees
zackees enabled auto-merge October 30, 2026 18:41
@zackees
zackees added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026
@zackees
zackees added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026
@zackees
zackees added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 30, 2026
…t port

RED for the port of libobs/obs-hotkey-binding-press.c.h to a new module,
binding_press, of rust/obs-hotkey. The safe core is a stub (todo!()): press and
release take the binding's pressed flag and its hotkey's pressed count by
reference, write them and return whether the caller dispatches the hotkey
event now (the count was 0 before a press, or reaches 0 after a release).

tests/hotkey/binding_press.rs ports the 5 cases of the C characterization
test_hotkey_binding_press_steps 1:1, under the same names and with the same
steps and expectations: every_step (2 flag states x 6 counts x press or
release, run once per routing state, since routing only decides whether a call
happens at all), writes_before_the_return, two_bindings, release_without_press
and wraps_at_the_edges, plus a proptest of the count invariant over random
event sequences.

The Tier 3 parity test (tests/hotkey/binding_press_parity.rs) compares the
shims with the original C (oracle/hotkey_binding_press.c) on fake bindings,
logging every accessor call and every dispatch with the flag and count it
sees: the C test's whole table, two bindings of one hotkey, sequences from a
pressed state, the intentional null differences, and random runs.

soldr cargo test -p obs-data --test obs-tests-core hotkey::binding_press
fails with "not yet implemented".

Refs #1836
Ports libobs/obs-hotkey-binding-press.c.h to the binding_press module of
rust/obs-hotkey: the press count that turns each binding's press and release
into hotkey events, so a hotkey's callback runs on the first press and the
last release only and a hotkey held through two bindings fires once. The
hotkey thread's poll, obs_hotkey_inject_event() and remove_bindings() stay C
in obs-hotkey.c.h and call the wrappers inside libobs, so the bindings array,
its walk, the mutex and the callback stay C; the hybrid libobs drops the C
file and links the Rust shims in its place.

Safe core (src/binding_press.rs): press and release work on the flag and the
count by reference and return whether to dispatch, so they keep no state, take
no lock and never see a pointer. The press tests the count before incrementing
it and the release after decrementing it, as the C does, so a press of a
pressed binding counts again and a release at count 0 goes negative
(characterized, not endorsed: libobs presses only a released binding and
releases only a pressed one). The count is C's int and wraps at the edges of
i32, where C is undefined; libobs never reaches them.

Shim (src/ffi/binding_press.rs): obs_hotkey_binding_press and
obs_hotkey_binding_release keep the C signature and are hidden (declared in
obs-internal.h without EXPORT). They take the binding's flag, its hotkey's
count and the hotkey once through the hidden obs_hotkey_binding_count_fields()
(#1836, so neither struct is mirrored) and write the flag and the count
through those pointers, never through a copy; the dispatch is
obs_hotkey_dispatch(), last and only when the core says so, and the binding is
not touched after it, since a callback may rebind or unregister hotkeys. A
null binding or a null accessor field does nothing (C dereferences it).

C side: the file leaves libobs.core for its own group,
libobs.ported-hotkey-binding-press (LIBOBS_PORTED_SOURCES), whose PCH is
obs-internal.h. The two wrappers are not EXPORT, so the shims are hidden in
rust-hidden.txt, the local: list of rust-exports.map and
rust-unexports-macos.txt. 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; test_hotkey_press_state sees the
swap through the public hotkey API. ci/test_ported_sources.py checks the group
on every host.

Because the wrappers are Rust now, the press state machine's oracle
(oracle/hotkey_press.c) calls oracle_seam_* stand-ins instead of the real
symbols, and press_parity drives them through the ported shim so the same log
is compared on both sides.

Tier 3 compares the call log (accessor calls; dispatches with the hotkey, the
pressed value and the flag and count they see) and the flag of every binding
and the count of every hotkey after every step, over every flag and count
state, two bindings of one hotkey, every sequence of four events and random
sequences.

Fixes #1836
@zackees
zackees force-pushed the port/1836-binding-press branch from 8b7766b to 81a5593 Compare October 30, 2026 20:20
@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Coordinator: the merge-group ejection was source::audio_input::edge_downmix_model hitting nextest's 30 s timeout, a test this PR doesn't touch (the same timeout hit #3093). After that, #3078 (Windows key map) landed and conflicted. I rebased onto master, kept both entries in the obs-hotkey file lists (Cargo.toml description, lib.rs docs, naming.md, rust/README.md), checked that obs-hotkey --tests compiles, and confirmed rustfmt is clean. Pushed 81a5593.

…ows keys link

#3078's test_windows_keys_steps_rust stubbed obs_hotkey_binding_press
and _release, which were C seams. With this port they come from the
Rust staticlib (duplicate definitions), whose shims now call
obs_hotkey_binding_count_fields and obs_hotkey_dispatch (undefined).
Stub those two instead.
@zackees

zackees commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

Coordinator: Tier 2 Linux (build) and asan failed to link test_windows_keys_steps_rust after the rebase onto #3078. Its windows-keys-rust-stubs.c stubbed obs_hotkey_binding_press/_release, which this PR moves into the Rust staticlib, and it lacked the shims' new callees. Pushed fixup: cb88c49, which stubs obs_hotkey_binding_count_fields and obs_hotkey_dispatch instead. This is a link stand-in file, not a C test.

@zackees
zackees added this pull request to the merge queue Oct 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 30, 2026
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…#3103)

edge_downmix_model ran 4000 full-size cases unscaled and hit nextest's
30 s limit on master b083524 (run 41121995484) and in the merge
queue for obs-rust#3075 and obs-rust#3093. Route the block through
obs_c_oracle::parity::cases() like the other proptest modules, so PR,
queue and master runs take the reduced count (obs-rust#2593); local, nightly
and release runs keep 4000.
@zackees
zackees added this pull request to the merge queue Oct 30, 2026
Merged via the queue into master with commit 06e8b43 Oct 30, 2026
41 checks passed
@zackees
zackees deleted the port/1836-binding-press branch October 30, 2026 22:18
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In review to Done in obs-rust Multiview Oct 30, 2026
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 31, 2026
obs-rust#3112) (obs-rust#3113)

* test(ci): fail when a bench stand-in is also a workspace export (obs-rust#3112)

The port_comparison bench defines stand-ins for libobs functions the C
oracle objects call by name. Once a port ships the real #[no_mangle]
shim, the bench binary holds two definitions and neither rust-lld nor
lld-link will link it (obs-rust#3075 did that to obs_hotkey_binding_press and
_release, and the bench has been unbuildable since). No bench build runs
in PR CI, so nothing caught it.

Red: this test fails on master for those two names.

* perf(bench): drop the stand-ins obs-hotkey now exports (obs-rust#3112)

obs_hotkey_binding_press() and obs_hotkey_binding_release() are real
#[no_mangle] shims in obs-hotkey since obs-rust#3075, so the bench's stand-ins
for them are duplicate definitions and the bench binary would not link:
rust-lld reports 'duplicate symbol' on Linux/macOS and lld-link fails the
same way on Windows.

Green: the bench links again (soldr cargo bench --no-run) and the new
test passes. record.py --category format completes once more, which is
what obs-rust#3111's before/after numbers need.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

rust: Port the hotkey binding press count in obs-hotkey.c to obs-hotkey

1 participant