Repository navigation
libobs: Extract the hotkey binding press count and its seam (#1836, PR 1) - #3032
Conversation
The binding press count (press_released_binding() and release_pressed_binding() in obs-hotkey.c, next to be ported to rust/obs-hotkey as binding_press) turns binding events into hotkey events: the hotkey's callback runs on the first press and the last release only. test_hotkey_binding_press_steps compiles obs-hotkey.c into itself like test_hotkey_press_steps, registers a hotkey through the public API, and calls obs_hotkey_binding_press() and obs_hotkey_binding_release() with the binding's pressed flag and its hotkey's pressed count set by hand. It pins what the real libobs cannot reach or cannot show: - the flag, the count and the call after every event: 2 flag states x 6 counts (-2..3) x press or release, each in the three routing states; - the arguments of each call, and that the flag and the count are written before it and nothing after it; - two bindings of one hotkey (the count is per hotkey, not per binding); - remove_bindings() releasing only the pressed bindings it removes, so unregistering a hotkey held through two bindings calls it once. Characterized, not endorsed: neither function checks the flag, so 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. Refs #1836
Behavior-neutral extraction before the Rust port: press_released_binding(), release_pressed_binding() and their two wrappers obs_hotkey_binding_press() and obs_hotkey_binding_release() move verbatim from libobs/obs-hotkey.c.h into libobs/obs-hotkey-binding-press.c.h. remove_bindings(), which stays in obs-hotkey.c.h, now calls the wrapper it already declared in obs-internal.h, so the static forward declaration goes away. 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. The two wrappers are declared in obs-internal.h without EXPORT, so -fvisibility=hidden keeps them local. The tests that compile obs-hotkey.c.h on their own (test_hotkey_load, test_hotkey_getters_characterization, test_hotkey_pair_steps, test_hotkey_press_steps, test_wayland_hotkeys and test_portal_shortcuts) now compile the new file next to it. Tier 2 Linux, targeted: test_hotkey_binding_press_steps 4/4 and test_wayland_hotkeys pass in the hybrid build. Refs #1836
The hotkey binding press count, libobs/obs-hotkey-binding-press.c.h, writes the binding's pressed flag and its hotkey's pressed count, and calls the hotkey. All three are private, and the Rust port should not mirror either struct, so the unit now reaches them through two hidden functions in obs-hotkey.c.h: - obs_hotkey_binding_count_fields(binding): pointers to the binding's pressed flag and its hotkey's pressed count, plus the hotkey; - obs_hotkey_dispatch(hotkey, pressed): the hotkey's own callback, or the router when callback rerouting is on (nothing when it is on and no router is set), so the callback ABI and the frontend's router stay C. The pointers alias the fields themselves, so each is still written at the same point, with the same lock held, and nothing is written after the call. Both are declared in obs-internal.h without EXPORT, so the exported symbols are unchanged. The new fields_and_dispatch case in test_hotkey_binding_press_steps pins them: the accessor points at the binding's own flag and its hotkey's count, a value written through it is the one the unit writes, and the dispatch makes the rerouting choice and nothing else. Tier 2 Linux, targeted: test_hotkey_binding_press_steps 5/5, and the other 19 hotkey, Wayland and portal tests, pass in the hybrid build. Refs #1836
|
Handed off to the coordinator.
PR 2 (the Rust port of |
|
Coordinator: this PR turned master red on macOS. PR CI never ran macOS Tier 2 for this path, and Linux passes. My best guess, not verified on a Mac: on macOS the test's libobs has a real hotkey platform context, so the hotkey thread polls key state. It sees that D and E are not physically down and releases the hand-pressed bindings on its own, before Please fix it forward, or revert while you look. Every master push stays red on macOS Tier 2 until then. |
|
Correction to my comment above: the hotkey-thread guess was wrong. #3045 finds the real cause. |
PR 1 of 2 for #1836 (Refs, not Fixes): the behavior-neutral half — characterization, extraction and the seam. The Rust port of the file is PR 2.
RED then GREEN
Three commits, each behavior-neutral on the C side:
test: Characterize the hotkey binding press count— newtest_hotkey_binding_press_steps. It compilesobs-hotkey.cinto itself liketest_hotkey_press_steps, registers a hotkey through the public API, and callsobs_hotkey_binding_press()/_release()with the binding's flag and the hotkey's count set by hand. It pins the flag, the count and the call after every event (2 flag states × 6 counts −2..3 × press or release, each in the three routing states), the arguments of each call, that both fields are written before the call and nothing after it, two bindings of one hotkey, andremove_bindings()releasing only the pressed bindings it removes. Characterized, not endorsed: neither function checks the flag, so a press of a pressed binding counts again and a release at count 0 goes negative (libobs never reaches either).libobs: Move the hotkey binding press count into its own file— the four functions move verbatim intolibobs/obs-hotkey-binding-press.c.h, in thelibobs.coreunity group just beforeobs-hotkey.c.h, withlibobs.pch.h.remove_bindings()calls the wrapper it already declared inobs-internal.h, so the static forward declaration goes. No group, PCH orsource-sets.jsonchange; no platform conditional moves.libobs: Reach the binding press count through a hidden accessor— RED was thefields_and_dispatchcase (it did not build: neither function existed), GREEN isobs_hotkey_binding_count_fields()(pointers to the binding's flag, its hotkey's count, and the hotkey) andobs_hotkey_dispatch()(the rerouting choice and the call, so the callback ABI and the frontend's router stay C). Both are declared inobs-internal.hwithoutEXPORT; the pointers alias the fields, so every write happens at the same point with the same lock held.Tiers
rust/tools/linux-validate/run.py(hybridlibobs+libobs-c-reference): 629 tests, and the 20 hotkey / Wayland / portal tests pass, includingtest_hotkey_press_state,test_hotkey_pair_latch,test_hotkey_press_steps,test_hotkey_load,test_wayland_hotkeysandtest_portal_shortcuts. The unchanged C tests are untouched../lint: clean exceptci/test_check_changes.py, which fails in this sandbox withgit: command not foundinside its own probe (environment, not this change).docs/features.md: no line — behavior is unchanged.Test cost
New tests:
test_hotkey_binding_press_steps, 5 cases, 0.05 s total, no own threads, no allocation in the unit under test. It joins thetest/cmockacmocka binary set (native-core), so no new Rust test executable.Reviewer notes
test_hotkey_press_statealready covers the poll and inject paths on the unchanged C.obs_hotkey::binding_press,libobs.ported-hotkey-binding-pressgroup with its own PCH /source-sets.jsonentry / export fragment, Tier 1 over these expectations and Tier 3 against the moved C.