Skip to content

obs-hotkey: Port the Windows key map - #3078

Merged
rdoupe merged 6 commits into
masterfrom
fix/rust-port-windows-virtual-key-ta-301
Oct 30, 2026
Merged

rdoupe merged 6 commits into
masterfrom
fix/rust-port-windows-virtual-key-ta-301

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3076

What and why

Port of the Windows virtual-key table, key name route and Meta rule of libobs/obs-windows.c.h to rust/obs-hotkey, as a new module windows_keys, the Windows counterpart of the X11 (#2903, #3060) and macOS (#2917) key map ports. On Windows, libobs uses them when it fills the hotkey platform's virtual-key table, in the hotkey thread's "is this key down" poll, for each key's name in Settings > Hotkeys, and in the public obs_key_from_virtual_key / obs_key_to_virtual_key.

Commits:

  1. libobs: Move the Windows key map and key names (behaviour-neutral): eight hidden functions on plain values in libobs/obs-windows-keys.c.h, declared without EXPORT in libobs/obs-windows-keys.h, in their own unity group, libobs.windows-keys, with no Windows header. The 156 virtual keys the table uses are defined by value in the header and _Static_asserted against winuser.h in obs-windows.c.h. obs-windows.c keeps the platform context, GetAsyncKeyState, MapVirtualKey, GetKeyNameTextW (still called only when the gate holds), the translations and every dstr call; obs_key_to_virtual_key asks for the table through a getter, so the platform context is still read only for a key other than Meta. test_win_wsc_product_refs, which compiles obs-windows.c.h into itself on Windows, now compiles the moved file too (its test-graph sources only).
  2. test: Characterize the Windows key map (test_windows_keys_steps, 9 cases, every platform).
  3. obs-hotkey: Add Tier 1 tests for Windows keys (RED). The crate's build script now also makes the raw OBS_KEY_0x* codes constants, so the Rust table names its keys as the C switch does.
  4. obs-hotkey: Port the Windows key map (GREEN: core, shims, group libobs.ported-windows-keys registered in libobs/build/ported-source-sets/windows-keys.json, the three hidden-symbol lists, ci/test_ported_sources.py, and test_windows_keys_steps_rust).
  5. obs-hotkey: Check the Windows key port against C (oracle, Tier 3, port_comparison, mutation check).
  6. docs: Record the Windows key map port.

The eight functions: the virtual key table (get_virtual_key(), now a match arm for arm with the C switch); the Meta rule (either Windows key); obs_key_to_str()'s route (none, F13 to F24 and Mouse 1 to 29 by number, Pause, Meta, else the system name), its scan code (bit 24 for the 11 extended keys) and its gate before GetKeyNameTextW(); the first key with a virtual key; the virtual key of a key; the combination order (Control, Meta, Alt, Shift, then the key).

Kept and characterized, not endorsed: Meta has no virtual key of its own, and obs_key_from_virtual_key(VK_LWIN) is OBS_KEY_VK_LWIN, so Meta doesn't round-trip; a letter or digit shares its virtual key with its raw OBS_KEY_0x* code, and the letter wins.

Intentional differences (in the parity test header, rust/README.md and docs/features.md):

  • obs_key_to_virtual_key on Windows returns 0 for a key outside 0 .. OBS_KEY_LAST_VALUE - 1; C indexes the table with it, past its end. OBS's own callers pass keys in range; a script or plugin calling the exported function might not. The docs/features.md line for X11 and macOS now covers Windows.
  • A null table or getter reads as empty, a null number is not written and a null keys array gets no keys (C dereferences them; libobs always passes them).

test_windows_keys_steps_rust runs the unchanged characterization against the Rust shims: it compiles none of the C and takes the shims from libobs_rust-static. The staticlib's obs-hotkey and obs-util members also reference 11 hidden libobs functions (the hotkey seams of obs-hotkey.c and the logging halves of base-variadic.c), so test/cmocka/windows-keys-rust-stubs.c stands in for them, each aborting (the shims call none of them), and the test links obs-util's system libraries as libobs does. It builds on Linux only: the shims have no host code, and the macOS and Windows links of obs-util's members are not worked out here.

The moved code is upstream's (Lain, Igor Bochkariov, Palana), credited in the move and port commits. No upstream issue.

RED → GREEN

  • RED commit: d294b4f. soldr cargo test -p obs-data --test obs-tests-core hotkey::windows_keys fails 23 of 24 with "not yet implemented" (the VK values pass). On the RED commit, local_gate.py --lane lint passed and --test-diff origin/master failed only those 23 (5311 of 5334 passed, 6 skipped; runs were on 20fec2d7b, the same commit before the rebase onto the X11 keysym port, obs-hotkey: Port X11 keysyms and mouse answers #3060). After the rebase, --lane lint passed again and all other hotkey:: tests pass (323).
  • GREEN: Tier 1 hotkey::windows_keys 24/24; Tier 3 hotkey::windows_keys_parity 9/9; all hotkey:: tests pass. Linux x86_64 (GCC): test_windows_keys_steps passes on the C build and on the hybrid build tree, and test_windows_keys_steps_rust passes 9/9 on the hybrid tree (with VK_ESCAPE planted for Enter in the Rust table it fails while the C one passes), and the 24 hotkey and key C tests (ctest -R 'hotkey|keys|key_', the _rust variant included) pass against the hybrid libobs and against libobs-c-reference, none skipped. Exported symbols identical on the C, hybrid and C reference builds (1767 each), the eight shims local (t). The win-x64 cross-compile check (cmake/cross, clang-cl and the Windows SDK) builds the ported group with no warning. Runs were on 1ce674a and, after the rebase onto the Wayland keysym port (obs-hotkey: Port the Wayland keysym tables #3072), again on 4d739e0 (quick checks, the lint lane, all hotkey:: tests 385/385, the bench test, the export comparison: 1767 each, the eight shims local, and the 25 hotkey and key C tests on the hybrid and C reference builds).
  • Real app (UI, protocol output or logging changes): N/A, no UI, protocol output or logging change. Not run on Windows.

Local gates (runs were on 1ce674a, rebased on current master): ./lint, local_gate.py --lane lint and --lane cross ok; ./unittest Rust tiers 5397 + 857 passed, 6 skipped; the CI guard tests (build groups, ported sources, oracle stand-ins and MSVC, sorted shared lists, test graph, cmocka guards, naming) pass; --test-diff origin/master 5371/5371 passed, 6 skipped (runs were on cbc088cb4, before the rebase); soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings clean; soldr cargo test -p obs-c-oracle --locked --bench port_comparison passes. Not run locally: Tier 2 in Docker (./unittest's tier2-linux lane) and the local-gate stamp, which need Docker access this host's build account doesn't have (ci-lint local-gate run passes lint, rust-test and cross and stops at tier2-linux on it); the Tier 2 tests above ran natively instead, and the head is unstamped, so PR CI runs the full suite. Nothing here has run on a Windows machine: the Windows Rust tests and Tier 2 in PR CI are the first.

Test cost: new tests (33): longest 0.03 s at the reduced parity level, peak RSS 23 MB over 25 runs, no threads of their own.

Move check (runs were on 9cbcf4097): master's hotkey platform code and the moved one with its new callers, extracted over logging stand-ins for every Windows, dstr and translation call (with the Windows SDK's VK_* values), built with gcc and clang at -O0, -O2 and under ASan and UBSan, over every key from -OBS_KEY_LAST_VALUE to twice it (virtual key, pressed check four times, name three times), 2,900 virtual keys and 6,000 combinations per seed, 5 seeds, with Meta also asked with obs NULL: identical logs (5,608,688 lines each side). 25 of 26 planted mutants change the log; the survivor adds OBS_KEY_NONE to a combination, which names nothing, so it is equivalent. The win-x64 cross-compile check builds the move's group and obs-windows.c.h with every _Static_assert holding and no new warning; clang-cl /W4 /WX with the Windows SDK accepts the characterization and the moved file.

Mutation check of the port: 21 mutants (16 in the core, 5 in the shims), all killed; table in commit 5 (773cf74). The shim mutants are killed by Tier 3, the tier that reaches the shims.

port_comparison (windows_keys/init_and_names/64, Linux x86_64): Rust 4.91 µs, C 3.87 µs for the platform's table fill and 64 keys' lookup and name route; the fill runs once, when the hotkey platform starts.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

@rdoupe
rdoupe force-pushed the fix/rust-port-windows-virtual-key-ta-301 branch from 80328b3 to 1ce674a Compare October 30, 2026 18:19
rdoupe and others added 6 commits October 30, 2026 15:00
Behaviour-neutral extraction before the Rust port. The key map and key
name decisions of the Windows hotkey platform move from
libobs/obs-windows.c.h into libobs/obs-windows-keys.c.h, as hidden
functions on plain values declared without EXPORT in the new
libobs/obs-windows-keys.h:

- obs_windows_keys_virtual_key(): get_virtual_key() whole, the table
  obs_hotkeys_platform_init() still fills vk_codes from in its loop;
- obs_windows_keys_either_win(): obs_hotkeys_platform_is_pressed()'s
  Meta rule (either Windows key);
- obs_windows_keys_name(), obs_windows_keys_scan_code() and
  obs_windows_keys_system_name(): obs_key_to_str()'s route (none, F13
  to F24 and Mouse 1 to 29 by number, Pause, Meta, else the system
  name), the scan code with the extended bit for its 11 keys, and the
  gate before GetKeyNameTextW();
- obs_windows_keys_from_virtual_key(): obs_key_from_virtual_key()'s
  first match, with the vk_codes table passed in;
- obs_windows_keys_to_virtual_key(): obs_key_to_virtual_key(), VK_LWIN
  for Meta, else the table's entry. The table comes through a getter,
  so obs->hotkeys.platform_context is still read only for a key other
  than Meta;
- obs_windows_keys_combination(): obs_key_combination_to_str()'s order,
  Control, Meta, Alt, Shift, then the key.

obs-windows.c keeps the platform context (its allocation and free),
GetAsyncKeyState(), MapVirtualKey(), GetKeyNameTextW(), the
translations and obs_get_hotkey_translation(), obs_key_to_name() and
every dstr call, each at its point. GetKeyNameTextW() is still called
only when the gate holds.

The new file includes no Windows header. The 156 virtual keys the map
uses are defined in obs-windows-keys.h by value (OBS_WINDOWS_KEYS_VK_*),
and obs-windows.c.h checks each against winuser.h's VK_*, and UINT's
size, with _Static_assert. The table's body is master's, with only that
prefix added.

Checked in a scratch harness (not committed). It extracts the hotkey
platform code of origin/master's obs-windows.c.h (the platform struct
to obs_key_combination_to_str()) and of this one with the moved file,
and builds each over stand-ins that log every call with its arguments
and result: GetAsyncKeyState, MapVirtualKey (0, small, wide and random
scan codes), GetKeyNameTextW (failing or naming), bzalloc and bfree,
obs_get_hotkey_translation, obs_key_to_name and every dstr call, with
the VK_* values of the Windows SDK's winuser.h. Each run fills the
table, then for every key from -OBS_KEY_LAST_VALUE to twice it asks
the virtual key, the pressed check four times and the name three
times (mouse translations set, empty or missing; the context is
zero-padded so keys outside the table read 0 on both sides), the key
of every code from -300 to 599 and 2000 random ones, and 6000
combinations (every 10-bit mask, then random words, with and without
a key, after an empty or non-empty string). Meta's virtual key and
pressed check also run with obs NULL. 5 seeds, built with GCC and
Clang at -O0 and -O2, with and without ASan and UBSan (no recovery):
the logs are identical in every build, 5,608,688 lines each side.

26 deliberately broken moves were planted; the harness fails 25. Table
entries, the default, the Meta rule, the F and Mouse numbers and
ranges, the Pause, Meta and none routes, the scan code's shift,
extended keys and bit, both halves of the gate, the first match and
its range, Meta's VK, the table asked for before the Meta check, the
combination's order and bits, and in the callers GetKeyNameTextW()
called before the gate, the Windows keys asked in the other order,
the table filled off by one, the mouse number dropped and the scan
code mapped from the key. The survivor adds OBS_KEY_NONE to a
combination, which obs_key_to_str() names as nothing, so it is
equivalent.

The win-x64 cross-compile check (cmake/cross, clang-cl and the Windows
SDK) builds the new group and libobs.windows+ with every
_Static_assert holding and no new warning.

git blame on the moved lines shows upstream commits by Lain, Igor
Bochkariov and Palana; they move as they are.

The new file has its own group, libobs.windows-keys, in the Windows
sources, with a precompiled header of only obs-windows-keys.h, so a C
test can compile it on any OS; libobs-windows.pch.h includes the
header for obs-windows.c. test_win_wsc_product_refs, which compiles
obs-windows.c.h into itself, now compiles the moved file with it (its
test-graph sources; the test itself is unchanged). The exported symbol
set is unchanged: the Linux and macOS builds don't build either file,
and on Windows the functions are not exported.

Refs #3076.

Co-authored-by: Lain <[email protected]>
Co-authored-by: Igor Bochkariov <[email protected]>
Co-authored-by: Palana <[email protected]>
test_windows_keys_steps compiles libobs/obs-windows-keys.c.h (ASan and
UBSan) and calls only its hidden functions, so it needs no Windows
header and runs on every platform (9 cases):

- the virtual key table: each of the 290 keys it maps, with the value
  winuser.h gives its VK_* (or the raw code of an OBS_KEY_0x* key),
  and 0 for every other key; the five mouse buttons, Mouse 6 and 29
  without one, a letter and its raw code sharing 'A', and Meta without
  one of its own (characterized, not endorsed);
- the pressed check's Meta rule: only OBS_KEY_META;
- the name route: none, F13 to F24 and Mouse 1 to 29 with their
  numbers (written only for those two), Pause, Meta, and the system
  name for F12, F25, a letter, the OBS_KEY_VK_* keys and past Mouse 29;
- the scan code: in bits 16 and up, the high bits shifted out, and bit
  24 for exactly the 11 extended virtual keys, also without a scan code;
- the system name gate: a non-zero scan code, and never an
  OBS_KEY_VK_CANCEL to OBS_KEY_VK_OEM_CLEAR key;
- the key of a virtual key: the first match ('A' is the letter, not
  OBS_KEY_0x41; VK_LWIN is OBS_KEY_VK_LWIN, not Meta, so Meta doesn't
  round-trip: characterized, not endorsed; 0 is OBS_KEY_NONE), none for
  a code no key has, and the last entry searched;
- the virtual key of a key: VK_LWIN for Meta without asking for the
  table, else its entry, the table asked for once each;
- the combination: Control, Meta, Alt, Shift, then the key, for each of
  the 16 masks with and without a key, the other bits ignored.

Not characterized: the virtual key of a key outside the table, which
reads past its end. The port gives 0 for it; its Tier 3 tests list it.

Passes on the C libobs build. clang-cl /W4 /WX with the Windows SDK
accepts the test and the moved file.

Refs #3076.
RED for the port of libobs/obs-windows-keys.c.h to a new module,
windows_keys, of rust/obs-hotkey. The safe core is a stub (todo!()):
virtual_key(), get_virtual_key()'s table; either_win(), the pressed
check's Meta rule; name(), scan_code() and system_name(),
obs_key_to_str()'s route; from_virtual() on a slice of virtual keys and
to_virtual() with the table behind a getter; combination(), the keys a
combination names. The 156 VK_* values it uses are constants already.

The crate's build script now also makes the raw OBS_KEY_0x* codes
constants (it skipped them, with their lowercase x), so the table
can name its keys as the C switch does.

tests/hotkey/windows_keys.rs ports test_windows_keys_steps 1:1, its 9
cases under the same names, in the same order, with the same inputs
and expectations. The rest pin the edges: the VK values, keys outside
the enum (negative, past the end, i32::MIN and MAX) for the table, the
route and the gate, the modifier keys, digits, letters, number pad and
F keys, short and empty tables, and the combination's five keys at
most. One pins the fix: to_virtual() gives 0 for a key outside the
table, where C reads past its end, and still asks for the table as C
does for any key but Meta. Proptests check each function against a
model written from the C.

The tests are a module of the existing core category binary,
obs-tests-core; no new test binary.

soldr cargo test -p obs-data --test obs-tests-core hotkey::windows_keys
fails 23 of 24 with "not yet implemented" (the VK values pass).

Refs #3076.
GREEN for #3076. Ports libobs/obs-windows-keys.c.h, the key map and
key name route of the Windows hotkey platform, to the windows_keys
module of rust/obs-hotkey. The hybrid libobs drops the C file and links
the Rust shims in its place.

Safe core (src/windows_keys.rs):
- virtual_key(): get_virtual_key()'s table as a match, arm for arm,
  over the 156 VK_* values winuser.h gives (constants here, checked
  against winuser.h by obs-windows.c and against the C by Tier 3);
- either_win(): Meta is down when either Windows key is;
- name(): none, F13 to F24 and Mouse 1 to 29 with their numbers,
  Pause, Meta, else the system name;
- scan_code(): the scan code in bits 16 and up, bit 24 for the 11
  extended virtual keys;
- system_name(): not an OBS_KEY_VK_* key, and a non-zero scan code;
- from_virtual(): the first key with the virtual key, else none;
- to_virtual(): VK_LWIN for Meta, else the key's entry in the table,
  asked for only then;
- combination(): Control, Meta, Alt, Shift, then the key.
It keeps no state, takes no lock, allocates nothing and denies
clippy's arithmetic, indexing, as-conversion, unwrap, expect, panic,
todo and unreachable lints.

Intentional difference, a bug in the C on Windows:
obs_key_to_virtual_key() read vk_codes[key] for any key, past the
table for one outside it (a script or plugin can pass any value); it
now returns 0.

Shim (src/ffi/windows_keys.rs): the eight functions with the C
signatures. The table crosses as OBS_KEY_LAST_VALUE ints, passed in or
through the caller's getter; a null table or getter reads as empty, a
null number is not written and a null keys array gets no keys, where C
would dereference them.

C side: the file leaves libobs.windows-keys for its own ported group,
libobs.ported-windows-keys, registered in
libobs/build/ported-source-sets/windows-keys.json for Windows. The
functions are not EXPORT, so the shims are hidden: rust-hidden.txt,
the local: list of rust-exports.map and rust-unexports-macos.txt (MSVC
exports only what rust-exports.d lists, so no fragment).
ci/test_ported_sources.py checks the group is ported on Windows only.

test_windows_keys_steps still compiles the C file into itself,
unchanged. test_windows_keys_steps_rust builds the same source without
the C file and takes the shims from libobs_rust-static (hybrid backend,
Linux). The staticlib's obs-hotkey and obs-util members it pulls in
also reference 11 functions libobs links but does not export (the
hotkey seams of obs-hotkey.c and the logging halves of
base-variadic.c); test/cmocka/windows-keys-rust-stubs.c stands in for
them, each aborting, as the shims call none of them, and the test
links obs-util's system libraries (jansson, libuuid, GIO with GObject
and GLib) as libobs does. It is Linux only: the shims have no host
code, and the macOS and Windows links of obs-util's members are not
worked out here. With VK_ESCAPE planted for Enter in the Rust table it
fails while test_windows_keys_steps passes.

Tier 1 hotkey::windows_keys passes 24/24 (all hotkey:: tests 346/346).
test_windows_keys_steps passes on the C build and on the hybrid build
tree, and test_windows_keys_steps_rust 9/9. The exported symbols are
identical on the Linux C, hybrid and C reference builds (1767
each), the eight shims local (t). The win-x64 cross-compile check
builds the ported group with no warning, and clippy for
x86_64-pc-windows-msvc (all targets) is clean.

Refs #3076.

Co-authored-by: Lain <[email protected]>
Co-authored-by: Igor Bochkariov <[email protected]>
Co-authored-by: Palana <[email protected]>
Oracle (oracle/windows_keys.c): the original obs-windows-keys.c.h,
unmodified, with its eight functions renamed to oracle_*, and getters
for the values the C uses and its 156 virtual keys by name.

Tier 3 (tests/hotkey/windows_keys_parity.rs, 9 tests):
- the values, and every virtual key by name, against the C;
- the virtual key, the Meta rule, the name route (and the number it
  writes) and the system name gate of every key from -2 to past
  OBS_KEY_LAST_VALUE and of the extremes;
- the scan code of every virtual key from -2 to 0x1FF on scan codes
  with and without high bits;
- the key of every virtual key, and the virtual key of every key in
  the table (and how often the table is asked for), on four tables:
  the platform's, zeroed, every key distinct, and repeating codes;
- the combination of every 9-bit modifier mask with no key, a
  modifier key, an ordinary key and the last key;
- proptests over random keys, virtual keys, scan codes, modifier
  words and tables.

Negative keys go to both sides: obs_key_t is unsigned to GCC and
Clang and signed to MSVC, and every function compared gives the same
answer either way.

Intentional difference, excluded and checked on the Rust side only:
the virtual key of a key outside the table (C reads past it; Rust
gives 0, still asking for the table once). Null pointers, which C
dereferences, are checked on the Rust side too.

port_comparison gets benches/port_comparison/windows_keys.rs: the
platform's table fill and 64 keys' lookup and name route, folded into
a checksum both sides must match. Linux x86_64: Rust 4.91 us, C 3.87
us. It allocates nothing with bmalloc.

Mutation check (done once, not committed); failing tests per mutant:

| Mutant | Tier 1 | Tier 3 |
|---|---|---|
| a table entry changed | 3 | 1 |
| the table's default 1 | 5 | 2 |
| a raw code's arm dropped | 1 | 1 |
| either_win() is Alt | 2 | 2 |
| F number off by one | 2 | 2 |
| Mouse range ends at 28 | 2 | 2 |
| Pause routed to Meta | 1 | 2 |
| scan code shifted by 8 | 2 | 2 |
| Num Lock not extended | 1 | 1 |
| gate ignores the scan code | 3 | 1 |
| gate's VK range exclusive | 1 | 2 |
| from_virtual() last match wins | 3 | 2 |
| Meta is VK_RWIN | 3 | 2 |
| table asked for Meta | 2 | 1 |
| Alt before Meta | 2 | 2 |
| OBS_KEY_NONE kept in a combination | 2 | 2 |
| shim: F and Mouse swapped | 0 | 3 |
| shim: number not written | 0 | 2 |
| shim: table one entry short | 0 | 1 |
| shim: combination count plus one | 0 | 2 |
| shim: system name ignores the key | 0 | 2 |

All 21 are killed; the shim mutants by Tier 3, the tier that reaches
the shims. The proptest regression files keep the seeds the mutants
failed on.

Tier 1 and Tier 3 pass (24/24 and 9/9). At the reduced parity level
the longest new test takes 0.03 s; peak RSS 23 MB over 25 runs; no
threads of their own.

Refs #3076.
The rust/README.md crate table now lists libobs/obs-windows-keys.c.h
among the rust/obs-hotkey units, and its port table has a row for it,
after the macOS key map: the eight functions, what stays C in
obs-windows.c (the platform context, every Windows call, the
translations and every dstr call), the static asserts against
winuser.h, how the table crosses, what is kept and characterized, the
intentional differences, what Tier 3 compares and that only Tier 3
sees the swap. naming.md's rust/obs-hotkey row, the crate's
description and its lib.rs module docs add the file and the module.

docs/features.md's line on obs_key_to_virtual_key for a key OBS
doesn't have now covers Windows too (0, as for a key with no virtual
key), with this issue.

Fixes #3076.
@rdoupe
rdoupe force-pushed the fix/rust-port-windows-virtual-key-ta-301 branch from 1ce674a to 4d739e0 Compare October 30, 2026 19:05
@rdoupe
rdoupe marked this pull request as ready for review October 30, 2026 19:45
@rdoupe
rdoupe requested a review from zackees as a code owner October 30, 2026 19:45
@rdoupe
rdoupe added this pull request to the merge queue Oct 30, 2026
Merged via the queue into master with commit da47b85 Oct 30, 2026
41 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-windows-virtual-key-ta-301 branch October 30, 2026 20:17
zackees added a commit that referenced this pull request Oct 30, 2026
…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.
github-merge-queue Bot pushed a commit that referenced this pull request Oct 30, 2026
)

* libobs: Add Tier 1 and Tier 3 tests for the hotkey binding press count 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

* libobs: Port the hotkey binding press count to obs-hotkey

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

* rust: rustfmt the binding press parity seams

* fixup: stub the binding press seams, not the ported pair, in the Windows 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.
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Oct 30, 2026
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 Windows virtual-key table and key names

1 participant