diff --git a/libobs/build/libobs.core+.h.c b/libobs/build/libobs.core+.h.c index c775d2bdf4..709623cbda 100644 --- a/libobs/build/libobs.core+.h.c +++ b/libobs/build/libobs.core+.h.c @@ -24,7 +24,7 @@ #include "libobs/obs-hotkey-enum-fields.c.h" #include "libobs/obs-hotkey-identity-fields.c.h" #include "libobs/obs-hotkey-identity-setter-fields.c.h" -#include "libobs/obs-hotkey-inject-entry.c.h" +#include "libobs/obs-hotkey-inject-entry-fields.c.h" #include "libobs/obs-hotkey-object-fields.c.h" #include "libobs/obs-hotkey-owned-translations-fields.c.h" #include "libobs/obs-hotkey-pair-meta-setter-calls.c.h" diff --git a/libobs/build/libobs.ported-hotkey-inject-entry+.h.c b/libobs/build/libobs.ported-hotkey-inject-entry+.h.c new file mode 100644 index 0000000000..b083a9da95 --- /dev/null +++ b/libobs/build/libobs.ported-hotkey-inject-entry+.h.c @@ -0,0 +1,4 @@ +/* C reference for the Rust hotkey event injection wrapper. */ +#include "libobs/build/libobs.pch.h" + +#include "libobs/obs-hotkey-inject-entry.c.h" diff --git a/libobs/build/ported-source-sets/hotkey-inject-entry.json b/libobs/build/ported-source-sets/hotkey-inject-entry.json new file mode 100644 index 0000000000..b09a7a5672 --- /dev/null +++ b/libobs/build/ported-source-sets/hotkey-inject-entry.json @@ -0,0 +1,5 @@ +{ + "LIBOBS_PORTED_SOURCES": [ + "build/libobs.ported-hotkey-inject-entry+.h.c" + ] +} diff --git a/libobs/cmake/rust-exports.d/obs-hotkey-inject_entry.txt b/libobs/cmake/rust-exports.d/obs-hotkey-inject_entry.txt new file mode 100644 index 0000000000..83fccfecde --- /dev/null +++ b/libobs/cmake/rust-exports.d/obs-hotkey-inject_entry.txt @@ -0,0 +1 @@ +obs_hotkey_inject_event diff --git a/libobs/cmake/rust-hidden.d/obs-hotkey-inject_entry.txt b/libobs/cmake/rust-hidden.d/obs-hotkey-inject_entry.txt new file mode 100644 index 0000000000..ef068aef4f --- /dev/null +++ b/libobs/cmake/rust-hidden.d/obs-hotkey-inject_entry.txt @@ -0,0 +1 @@ +obs_hotkey_inject_entry_request diff --git a/libobs/obs-hotkey-inject-entry-fields.c.h b/libobs/obs-hotkey-inject-entry-fields.c.h new file mode 100644 index 0000000000..7e1514b8ad --- /dev/null +++ b/libobs/obs-hotkey-inject-entry-fields.c.h @@ -0,0 +1,9 @@ +#include "libobs/build/libobs.pch.h" + +bool obs_hotkey_inject_entry_strict(const void *core); + +bool obs_hotkey_inject_entry_strict(const void *core) +{ + const struct obs_core *context = core; + return context->hotkeys.strict_modifiers; +} diff --git a/rust/README.md b/rust/README.md index b559a4a67b..136b806c58 100644 --- a/rust/README.md +++ b/rust/README.md @@ -121,6 +121,7 @@ and compares their exported symbols. `OBS_LIBOBS_BACKEND=C` is temporary rollbac | `libobs/obs-hotkey-background-enum.c.h` | `obs-hotkey::background_enum` | Public background shortcut enumeration under the hotkey mutex: a NULL callback returns before locking, an unavailable core returns without calls, the live list (count and entries) is read again before every callback, arguments are the exact combination, borrowed trigger and bound flag with the caller's data, a false return stops early, and every acquired lock is released once. The unchanged isolated C characterization stays; an actual-library lifecycle test reaches the exported symbol. Real-header shortcut layout, borrowed list-pointer check and differential parity over the original C. No intentional differences. | | `libobs/obs-hotkey-background-error.c.h` | `obs-hotkey::background_error` | Mutex-protected owned error copies, preserving NULL on failed locking or missing errors and bmalloc/bfree ownership for empty or arbitrary byte strings. Unchanged portal characterization and real-header differential parity. No intentional differences. | | `libobs/obs-hotkey-background-press.c.h` | `obs-hotkey::background_press` | Inverted disable bit stored under the existing hotkey seam lock; exact synchronous `hotkey_background_press_changed(bool enabled)` signal after unlock, once per transition. Preserves missing-core no-op, repeated-value silence, fixed 128-byte calldata and listener re-entry. Unchanged C characterization, safe-core mirrors and original-C differential state/payload/lock parity. No intentional differences. | +| `libobs/obs-hotkey-inject-entry.c.h` | `obs-hotkey::inject_entry` | Captures one injection event after the existing hotkey seam locks, forwards every binding in the existing C array walk, including false events, then unlocks. Preserves all modifier bits and one captured strict flag through callbacks and live registry mutation. Unchanged C recorder, safe mirrors, real-header layout and original-C differential parity. No intentional differences. | | `libobs/obs-hotkey-background-query.c.h` | `obs-hotkey::background_query` | Swapped in hybrid libobs (#3969). The public combination query preserves the native short circuit, identifier lookup and release. Actual-library native fallback characterization, real-header combination layout, callback-based differential parity and isolated allocation accounting. No exclusions or intentional differences. | | `libobs/obs-hotkey-background-trigger.c.h` | `obs-hotkey::background_trigger` | Owned background trigger retrieval under the existing hotkey mutex. Preserves exact combo/wake_data, callback-before-unlock, rejected-output cleanup and exact allocation transfer, including allocated empty and successful NULL results. Unchanged C characterization, safe-core assertions, real-header layouts and differential ownership/dispatch parity. No intentional differences. | | `libobs/obs-hotkey-binding-getters.c.h` | `obs-hotkey::binding_getters` | Three public binding getters: exact stored combination, independent binding ID and pointer identity. No intentional differences. Null stored hotkeys are preserved; null binding inputs remain outside the C contract. Full real-header binding/combination layouts and differential parity, with actual-library C characterization. | diff --git a/rust/obs-build/tests/native/registration/headless_characterizations_expected.json b/rust/obs-build/tests/native/registration/headless_characterizations_expected.json index a862544e85..b97d90747b 100644 --- a/rust/obs-build/tests/native/registration/headless_characterizations_expected.json +++ b/rust/obs-build/tests/native/registration/headless_characterizations_expected.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -37,7 +37,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -60,7 +61,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/portal_output_expected.json b/rust/obs-build/tests/native/registration/portal_output_expected.json index 0803efcbf5..a2ddce0161 100644 --- a/rust/obs-build/tests/native/registration/portal_output_expected.json +++ b/rust/obs-build/tests/native/registration/portal_output_expected.json @@ -88,7 +88,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -134,7 +134,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "unity_groups": { "background-control": [ @@ -144,7 +145,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_enum.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_enum.json index b03cbfe312..62a6189d7b 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_enum.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_enum.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -30,7 +30,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -51,7 +52,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_press.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_press.json index 9df128fce9..28ae7e56a3 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_press.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_press.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -30,7 +30,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -51,7 +52,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_trigger.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_trigger.json index 350fd17da3..b94f69e9f0 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_trigger.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_background_trigger.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -30,7 +30,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -51,7 +52,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_binding_press_steps.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_binding_press_steps.json index 8796e105c8..64945384bb 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_binding_press_steps.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_binding_press_steps.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -36,7 +36,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -49,7 +50,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_getters_characterization.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_getters_characterization.json index a8b1f5041b..9ebacd3dde 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_getters_characterization.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_getters_characterization.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-pair-meta.c.h", @@ -31,7 +31,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -47,7 +48,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_inject_entry.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_inject_entry.json new file mode 100644 index 0000000000..a2eba24825 --- /dev/null +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_inject_entry.json @@ -0,0 +1,34 @@ +{ + "schema": 1, + "targets": { + "test_hotkey_inject_entry": { + "sources": [ + "test/cmocka/test_hotkey_inject_entry.c", + "test/cmocka/hotkey-inject-entry-link-support.c" + ], + "definitions": [ + "obs=inject_test_obs", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" + ], + "libraries": [ + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + }, + "libobs_rust-static" + ] + } + }, + "tests": { + "test_hotkey_inject_entry": { + "target": "test_hotkey_inject_entry", + "command": [ + "${target}" + ] + } + } +} diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_load.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_load.json index f268da5ff0..7ed7a23dcb 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_load.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_load.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -30,7 +30,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -46,7 +47,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_pair_steps.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_pair_steps.json index 9bb1618958..53fa36af04 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_pair_steps.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_pair_steps.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -36,7 +36,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -49,7 +50,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_press_steps.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_press_steps.json index ca5ccd2fbd..5b79dcc714 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_press_steps.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_press_steps.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -36,7 +36,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -49,7 +50,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_unregister_entry.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_unregister_entry.json index c274011a45..5cd09feee6 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_unregister_entry.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_unregister_entry.json @@ -10,7 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -32,7 +32,8 @@ "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", "pthread_mutex_lock=unregister_entry_mutex_lock", "pthread_mutex_unlock=unregister_entry_mutex_unlock", - "obs_hotkey_unregister_one=unregister_entry_remove_one" + "obs_hotkey_unregister_one=unregister_entry_remove_one", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -48,7 +49,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_portal_shortcuts.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_portal_shortcuts.json index 66e72a92ce..c299a07548 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_portal_shortcuts.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_portal_shortcuts.json @@ -15,7 +15,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -61,7 +61,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "unity_groups": { "background-control": [ @@ -71,7 +72,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_wayland_hotkeys.json b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_wayland_hotkeys.json index 7b4af5da77..7e9094788c 100644 --- a/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_wayland_hotkeys.json +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_wayland_hotkeys.json @@ -11,7 +11,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -37,7 +37,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -60,7 +61,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/rust/obs-c-oracle/oracle/hotkey_inject_entry.c b/rust/obs-c-oracle/oracle/hotkey_inject_entry.c new file mode 100644 index 0000000000..7accb1190c --- /dev/null +++ b/rust/obs-c-oracle/oracle/hotkey_inject_entry.c @@ -0,0 +1,128 @@ +/* Original injection wrapper, real field adapter, and a bounded thread-local + * recorder. Registry mutation changes the live header, never the saved array. */ +#include "libobs/build/libobs.pch.h" +#include +#include + +static _Thread_local struct obs_core inject_core; +static _Thread_local struct obs_hotkey_binding inject_bindings[16]; +static _Thread_local bool inject_present, inject_held, inject_strict, inject_mutate; +static _Thread_local size_t inject_state[7]; +static _Thread_local uint32_t inject_visits[16][5]; + +static void inject_record(unsigned step) +{ + inject_state[4] = inject_state[4] * 4 + step; +} + +void *oracle_hotkey_inject_entry_lock(void); +void *oracle_hotkey_inject_entry_lock(void) +{ + assert(!inject_held); + inject_state[0]++; + inject_record(1); + if (!inject_present) + return NULL; + inject_held = true; + inject_core.hotkeys.strict_modifiers = inject_strict; + return &inject_core; +} + +static bool inject_lock_bool(void) +{ + return oracle_hotkey_inject_entry_lock() != NULL; +} + +void oracle_hotkey_inject_entry_unlock(void); +void oracle_hotkey_inject_entry_unlock(void) +{ + assert(inject_held); + inject_state[2]++; + inject_record(3); + inject_held = false; +} + +void oracle_hotkey_inject_entry_binding(obs_hotkey_binding_t *binding, obs_key_combination_t key, bool pressed, + bool strict); +void oracle_hotkey_inject_entry_binding(obs_hotkey_binding_t *binding, obs_key_combination_t key, bool pressed, + bool strict) +{ + assert(inject_held); + const size_t index = inject_state[3]++; + assert(index < 16 && binding == &inject_bindings[index]); + inject_visits[index][0] = (uint32_t)index; + inject_visits[index][1] = key.modifiers; + inject_visits[index][2] = (uint32_t)key.key; + inject_visits[index][3] = pressed; + inject_visits[index][4] = strict; + inject_record(2); + inject_core.hotkeys.strict_modifiers = !inject_core.hotkeys.strict_modifiers; + if (inject_mutate) + inject_core.hotkeys.bindings.num = 0; +} + +void oracle_hotkey_inject_entry_walk(obs_hotkey_binding_internal_enum_func func, void *data); +void oracle_hotkey_inject_entry_walk(obs_hotkey_binding_internal_enum_func func, void *data) +{ + assert(inject_held && func && data); + inject_state[1]++; + inject_record(0); + inject_core.hotkeys.strict_modifiers = !inject_strict; + const size_t count = inject_core.hotkeys.bindings.num; + obs_hotkey_binding_t *array = inject_core.hotkeys.bindings.array; + for (size_t i = 0; i < count; i++) + assert(func(data, i, &array[i])); +} + +void oracle_obs_hotkey_inject_event(obs_key_combination_t hotkey, bool pressed); +#define obs (&inject_core) +#define obs_hotkey_seam_lock inject_lock_bool +#define obs_hotkey_seam_unlock oracle_hotkey_inject_entry_unlock +#define obs_hotkey_seam_enum_bindings oracle_hotkey_inject_entry_walk +#define obs_hotkey_binding_inject oracle_hotkey_inject_entry_binding +#define obs_hotkey_inject_event oracle_obs_hotkey_inject_event +#include "libobs/obs-hotkey-inject-entry.c.h" +#undef obs_hotkey_inject_event +#undef obs_hotkey_binding_inject +#undef obs_hotkey_seam_enum_bindings +#undef obs_hotkey_seam_unlock +#undef obs_hotkey_seam_lock +#undef obs + +#define obs_hotkey_inject_entry_strict oracle_hotkey_inject_entry_strict +#include "hotkey-inject-entry-fields.inc" +#undef obs_hotkey_inject_entry_strict + +void oracle_hotkey_inject_entry_reset(bool present, bool strict, size_t count, bool mutate); +void oracle_hotkey_inject_entry_reset(bool present, bool strict, size_t count, bool mutate) +{ + assert(!inject_held && count <= 16); + memset(&inject_core, 0, sizeof(inject_core)); + memset(inject_state, 0, sizeof(inject_state)); + memset(inject_visits, 0, sizeof(inject_visits)); + inject_present = present; + inject_strict = strict; + inject_mutate = mutate; + inject_core.hotkeys.strict_modifiers = !strict; + inject_core.hotkeys.bindings.array = inject_bindings; + inject_core.hotkeys.bindings.num = count; +} + +void oracle_hotkey_inject_entry_snapshot(size_t *state, uint32_t *visits); +void oracle_hotkey_inject_entry_snapshot(size_t *state, uint32_t *visits) +{ + assert(!inject_held); + inject_state[5] = inject_core.hotkeys.strict_modifiers; + inject_state[6] = inject_core.hotkeys.bindings.num; + memcpy(state, inject_state, sizeof(inject_state)); + memcpy(visits, inject_visits, sizeof(inject_visits)); +} + +void oracle_hotkey_inject_entry_layout(size_t *out); +void oracle_hotkey_inject_entry_layout(size_t *out) +{ + out[0] = sizeof(obs_key_combination_t); + out[1] = _Alignof(obs_key_combination_t); + out[2] = offsetof(obs_key_combination_t, modifiers); + out[3] = offsetof(obs_key_combination_t, key); +} diff --git a/rust/obs-c-oracle/oracle/hotkey_inject_entry_fields.c b/rust/obs-c-oracle/oracle/hotkey_inject_entry_fields.c new file mode 100644 index 0000000000..580dc2a3af --- /dev/null +++ b/rust/obs-c-oracle/oracle/hotkey_inject_entry_fields.c @@ -0,0 +1,3 @@ +/* Real owner-relative adapter for standalone Rust workspace consumers. */ +#include "libobs/build/libobs.pch.h" +#include "hotkey-inject-entry-fields.inc" diff --git a/rust/obs-hotkey/src/ffi/inject_entry.rs b/rust/obs-hotkey/src/ffi/inject_entry.rs new file mode 100644 index 0000000000..3e224c8ec4 --- /dev/null +++ b/rust/obs-hotkey/src/ffi/inject_entry.rs @@ -0,0 +1,140 @@ +//! Opaque registry access; the existing pointer-returning lock adapter owns the +//! seam lock. The field adapter has no global or runtime-symbol dependencies. +use core::ffi::c_void; + +use super::binding_press::obs_hotkey_binding; +use super::nix_hotkey_state::obs_key_combination; +use crate::inject_entry::{self, Event, Registry}; +use crate::press::KeyCombination; + +pub type Lock = unsafe extern "C" fn() -> *mut c_void; +pub type Strict = unsafe extern "C" fn(*const c_void) -> bool; +pub type Visitor = unsafe extern "C" fn(*mut c_void, usize, *mut obs_hotkey_binding) -> bool; +pub type Walk = unsafe extern "C" fn(Visitor, *mut c_void); +pub type Inject = unsafe extern "C" fn(*mut obs_hotkey_binding, obs_key_combination, bool, bool); +pub type Unlock = unsafe extern "C" fn(); + +unsafe extern "C" { + fn obs_hotkey_background_press_lock() -> *mut c_void; + fn obs_hotkey_inject_entry_strict(core: *const c_void) -> bool; + fn obs_hotkey_seam_enum_bindings(visitor: Visitor, data: *mut c_void); + fn obs_hotkey_seam_unlock(); + fn obs_hotkey_binding_inject( + binding: *mut obs_hotkey_binding, + hotkey: obs_key_combination, + pressed: bool, + strict: bool, + ); +} + +struct Live { + core: *mut c_void, + lock: Lock, + strict: Strict, + walk: Walk, + inject: Inject, + unlock: Unlock, +} + +impl Registry for Live { + fn lock(&mut self) -> bool { + // SAFETY: the adapter returns a live core only after the seam locks it. + self.core = unsafe { (self.lock)() }; + !self.core.is_null() + } + fn strict_modifiers(&self) -> bool { + if self.core.is_null() { + return false; + } + // SAFETY: successful lock keeps this core live until unlock. + unsafe { (self.strict)(self.core) } + } + fn bindings(&mut self, event: Event) { + let mut dispatch = (event, self.inject); + // SAFETY: the C walk uses this stack context synchronously and retains + // the existing C array snapshot. No borrow crosses the binding callback. + unsafe { (self.walk)(visit, (&raw mut dispatch).cast()) }; + } + fn unlock(&mut self) { + // SAFETY: the core releases exactly one successful acquisition. + unsafe { (self.unlock)() }; + } +} + +unsafe extern "C" fn visit( + data: *mut c_void, + _index: usize, + binding: *mut obs_hotkey_binding, +) -> bool { + // SAFETY: Live::bindings keeps this copyable context live during the walk. + let (event, inject) = unsafe { *data.cast::<(Event, Inject)>() }; + inject_entry::forward(event, binding, |binding, event| { + // SAFETY: the C walk supplies a live binding under the hotkey lock. + unsafe { + inject( + binding, + obs_key_combination { + modifiers: event.hotkey.modifiers, + key: event.hotkey.key, + }, + event.pressed, + event.strict_modifiers, + ); + } + }) +} + +/// Original public ABI, including false injected events. +#[unsafe(no_mangle)] +pub extern "C" fn obs_hotkey_inject_event(hotkey: obs_key_combination, pressed: bool) { + obs_hotkey_inject_entry_request(hotkey, pressed); +} + +/// Static entry for existing hotkey fixtures with their own core namespace. +#[unsafe(no_mangle)] +pub extern "C" fn obs_hotkey_inject_entry_request(hotkey: obs_key_combination, pressed: bool) { + // SAFETY: these existing seams and the field adapter share libobs's core; + // all callbacks return synchronously while the recursive lock is held. + unsafe { + with_seams( + hotkey, + pressed, + obs_hotkey_background_press_lock, + obs_hotkey_inject_entry_strict, + obs_hotkey_seam_enum_bindings, + obs_hotkey_binding_inject, + obs_hotkey_seam_unlock, + ); + } +} + +/// Same ABI conversion and dispatch for the real-header recorder/oracle worlds. +/// +/// # Safety +/// The adapters must obey the same synchronous registry and lifetime contracts +/// as the production seams. A successful lock must return a live core pointer. +pub unsafe fn with_seams( + hotkey: obs_key_combination, + pressed: bool, + lock: Lock, + strict: Strict, + walk: Walk, + inject: Inject, + unlock: Unlock, +) { + inject_entry::inject( + &mut Live { + core: core::ptr::null_mut(), + lock, + strict, + walk, + inject, + unlock, + }, + KeyCombination { + modifiers: hotkey.modifiers, + key: hotkey.key, + }, + pressed, + ); +} diff --git a/rust/obs-hotkey/src/ffi/mod.rs b/rust/obs-hotkey/src/ffi/mod.rs index 7b1267f279..f831028895 100644 --- a/rust/obs-hotkey/src/ffi/mod.rs +++ b/rust/obs-hotkey/src/ffi/mod.rs @@ -15,6 +15,7 @@ pub mod enumeration; pub mod hotkey_name_map; pub mod identity_getters; pub mod identity_setters; +pub mod inject_entry; #[cfg(not(target_os = "macos"))] pub mod key_combination; pub mod nix_hotkey_state; diff --git a/rust/obs-hotkey/src/inject_entry.rs b/rust/obs-hotkey/src/inject_entry.rs new file mode 100644 index 0000000000..0e2fb4be79 --- /dev/null +++ b/rust/obs-hotkey/src/inject_entry.rs @@ -0,0 +1,37 @@ +//! One injected event, captured under the registry lock and shared by its walk. +use crate::press::KeyCombination; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct Event { + pub hotkey: KeyCombination, + pub pressed: bool, + pub strict_modifiers: bool, +} + +/// The existing C-owned binding walk retains its snapshot/mutation semantics. +pub trait Registry { + fn lock(&mut self) -> bool; + fn strict_modifiers(&self) -> bool; + fn bindings(&mut self, event: Event); + fn unlock(&mut self); +} + +/// Dispatch even false events; the existing binding engine decides their effect. +pub fn inject(registry: &mut impl Registry, hotkey: KeyCombination, pressed: bool) { + if !registry.lock() { + return; + } + let event = Event { + hotkey, + pressed, + strict_modifiers: registry.strict_modifiers(), + }; + registry.bindings(event); + registry.unlock(); +} + +/// The binding adapter always continues the current enumeration. +pub fn forward(event: Event, binding: B, inject: impl FnOnce(B, Event)) -> bool { + inject(binding, event); + true +} diff --git a/rust/obs-hotkey/src/lib.rs b/rust/obs-hotkey/src/lib.rs index fb9794de80..c5379648e8 100644 --- a/rust/obs-hotkey/src/lib.rs +++ b/rust/obs-hotkey/src/lib.rs @@ -49,6 +49,7 @@ pub mod cocoa_keys; pub mod enumeration; pub mod identity_getters; pub mod identity_setters; +pub mod inject_entry; pub mod key_combination; mod key_route; pub mod name_map; diff --git a/rust/obs-hotkey/tests/hotkey/inject_entry.rs b/rust/obs-hotkey/tests/hotkey/inject_entry.rs new file mode 100644 index 0000000000..d0a65c7d5a --- /dev/null +++ b/rust/obs-hotkey/tests/hotkey/inject_entry.rs @@ -0,0 +1,146 @@ +use obs_hotkey::inject_entry::{Event, Registry, forward, inject}; +use obs_hotkey::name_map::{KEY_NONE, OBS_KEY_A, OBS_KEY_MOUSE3}; +use obs_hotkey::nix_hotkey_state::INTERACT_CONTROL_KEY; +use obs_hotkey::press::KeyCombination; +use std::cell::Cell; + +#[derive(Default)] +pub struct Recorder { + pub present: bool, + pub strict_at_lock: bool, + pub count: usize, + pub locked: bool, + pub strict: Cell, + pub order: Vec, + pub visits: Vec<(usize, Event)>, + pub locks: usize, + pub enumerations: usize, + pub unlocks: usize, +} + +impl Registry for Recorder { + fn lock(&mut self) -> bool { + assert!(!self.locked); + self.locks += 1; + self.order.push(b'L'); + self.locked = self.present; + if self.locked { + self.strict.set(self.strict_at_lock); + } + self.locked + } + fn strict_modifiers(&self) -> bool { + assert!(self.locked); + self.strict.get() + } + fn bindings(&mut self, event: Event) { + assert!(self.locked); + self.enumerations += 1; + self.order.push(b'E'); + self.strict.set(!self.strict_at_lock); + for index in 0..self.count { + assert!(forward(event, index, |binding, event| { + assert!(self.locked); + assert_eq!(binding, self.visits.len()); + assert_eq!(event.strict_modifiers, self.strict_at_lock); + self.visits.push((binding, event)); + self.order.push(b'B'); + self.strict.set(!self.strict.get()); + })); + } + } + fn unlock(&mut self) { + assert!(self.locked); + assert_eq!(self.visits.len(), self.count); + self.unlocks += 1; + self.order.push(b'U'); + self.locked = false; + } +} + +#[test] +fn mirrors_test_hotkey_inject_entry_no_core() { + let mut r = Recorder::default(); + inject( + &mut r, + KeyCombination { + modifiers: u32::MAX, + key: OBS_KEY_MOUSE3, + }, + false, + ); + assert_eq!( + (r.locks, r.enumerations, r.unlocks, r.visits.len()), + (1, 0, 0, 0) + ); + assert_eq!(r.order, b"L"); + assert!(!r.locked); +} + +#[test] +fn mirrors_test_hotkey_inject_entry_empty_registry() { + let mut r = Recorder { + present: true, + strict_at_lock: true, + ..Recorder::default() + }; + inject( + &mut r, + KeyCombination { + modifiers: 0, + key: KEY_NONE, + }, + true, + ); + assert_eq!((r.locks, r.enumerations, r.unlocks), (1, 1, 1)); + assert_eq!(r.order, b"LEU"); + assert!(!r.locked); +} + +#[test] +fn mirrors_test_hotkey_inject_entry_forwarding() { + let mut r = Recorder { + present: true, + count: 3, + ..Recorder::default() + }; + for hotkey in [ + KeyCombination { + modifiers: 0, + key: KEY_NONE, + }, + KeyCombination { + modifiers: u32::MAX, + key: OBS_KEY_MOUSE3, + }, + KeyCombination { + modifiers: INTERACT_CONTROL_KEY, + key: OBS_KEY_A, + }, + ] { + for flags in 0..4 { + let pressed = flags & 1 != 0; + r.strict_at_lock = flags & 2 != 0; + r.strict.set(!r.strict_at_lock); + r.order.clear(); + r.visits.clear(); + inject(&mut r, hotkey, pressed); + assert_eq!( + r.visits, + (0..3) + .map(|i| ( + i, + Event { + hotkey, + pressed, + strict_modifiers: r.strict_at_lock + } + )) + .collect::>() + ); + assert_eq!(r.order, b"LEBBBU"); + assert!(!r.locked); + } + } + assert_eq!((r.locks, r.enumerations, r.unlocks), (12, 12, 12)); +} diff --git a/rust/obs-hotkey/tests/hotkey/inject_entry_parity.rs b/rust/obs-hotkey/tests/hotkey/inject_entry_parity.rs new file mode 100644 index 0000000000..74224e3201 --- /dev/null +++ b/rust/obs-hotkey/tests/hotkey/inject_entry_parity.rs @@ -0,0 +1,188 @@ +//! Tier 3: extracted original C, the production ABI conversion/dispatch, and +//! safe-core recorder. No intentional differences or excluded defined inputs. +use core::ffi::c_void; +use obs_hotkey::ffi::binding_press::obs_hotkey_binding; +use obs_hotkey::ffi::inject_entry::{self as ffi, Visitor}; +use obs_hotkey::ffi::nix_hotkey_state::obs_key_combination; +use obs_hotkey::inject_entry::inject; +use obs_hotkey::name_map::{KEY_NONE, OBS_KEY_A, OBS_KEY_MOUSE3}; +use obs_hotkey::press::KeyCombination; +use proptest::prelude::*; + +unsafe extern "C" { + fn oracle_hotkey_inject_entry_reset(present: bool, strict: bool, count: usize, mutate: bool); + fn oracle_obs_hotkey_inject_event(key: obs_key_combination, pressed: bool); + fn oracle_hotkey_inject_entry_lock() -> *mut c_void; + fn oracle_hotkey_inject_entry_strict(core: *const c_void) -> bool; + fn oracle_hotkey_inject_entry_walk(visitor: Visitor, data: *mut c_void); + fn oracle_hotkey_inject_entry_binding( + binding: *mut obs_hotkey_binding, + key: obs_key_combination, + pressed: bool, + strict: bool, + ); + fn oracle_hotkey_inject_entry_unlock(); + fn oracle_hotkey_inject_entry_snapshot(state: *mut usize, visits: *mut u32); + fn oracle_hotkey_inject_entry_layout(out: *mut usize); +} + +fn compare( + present: bool, + strict: bool, + count: usize, + mutate: bool, + key: KeyCombination, + pressed: bool, +) { + let run = |original| { + let mut state = [0; 7]; + let mut visits = [[0; 5]; 16]; + // SAFETY: bounded thread-local C world, no allocations or shared global + // state. The adapters and callbacks finish before snapshot copies the + // exact seven size_t and sixteen five-u32 records to these arrays. + unsafe { + oracle_hotkey_inject_entry_reset(present, strict, count, mutate); + let combo = obs_key_combination { + modifiers: key.modifiers, + key: key.key, + }; + if original { + oracle_obs_hotkey_inject_event(combo, pressed); + } else { + ffi::with_seams( + combo, + pressed, + oracle_hotkey_inject_entry_lock, + oracle_hotkey_inject_entry_strict, + oracle_hotkey_inject_entry_walk, + oracle_hotkey_inject_entry_binding, + oracle_hotkey_inject_entry_unlock, + ); + } + oracle_hotkey_inject_entry_snapshot(state.as_mut_ptr(), visits.as_mut_ptr().cast()); + } + (state, visits) + }; + let expected = run(true); + assert_eq!(run(false), expected); + + let mut recorder = super::inject_entry::Recorder { + present, + strict_at_lock: strict, + count, + ..Default::default() + }; + recorder.strict.set(!strict); + inject(&mut recorder, key, pressed); + let mut visits = [[0; 5]; 16]; + for (index, event) in &recorder.visits { + visits[*index] = [ + *index as u32, + event.hotkey.modifiers, + event.hotkey.key as u32, + u32::from(event.pressed), + u32::from(event.strict_modifiers), + ]; + } + let trace = recorder.order.iter().fold(0usize, |n, b| { + n * 4 + + match b { + b'L' => 1, + b'E' => 0, + b'B' => 2, + b'U' => 3, + _ => unreachable!(), + } + }); + assert_eq!( + expected, + ( + [ + recorder.locks, + recorder.enumerations, + recorder.unlocks, + recorder.visits.len(), + trace, + usize::from(recorder.strict.get()), + if present && count > 0 && mutate { + 0 + } else { + count + } + ], + visits + ) + ); + assert!(!recorder.locked); +} + +#[test] +fn real_header_combination_layout() { + let mut layout = [0; 4]; + // SAFETY: writes exactly four size_t values measured from the real header. + unsafe { oracle_hotkey_inject_entry_layout(layout.as_mut_ptr()) }; + assert_eq!( + layout, + [ + size_of::(), + align_of::(), + core::mem::offset_of!(obs_key_combination, modifiers), + core::mem::offset_of!(obs_key_combination, key) + ] + ); +} + +#[test] +fn differential() { + for present in [false, true] { + for strict in [false, true] { + for pressed in [false, true] { + for count in [0, 1, 3, 16] { + for key in [KEY_NONE, OBS_KEY_A, OBS_KEY_MOUSE3] { + for modifiers in [0, 1, 4, u32::MAX] { + for mutate in [false, true] { + compare( + present, + strict, + count, + mutate, + KeyCombination { modifiers, key }, + pressed, + ); + } + } + } + } + } + } + } + let strategy = ( + any::(), + any::(), + 0usize..=16, + any::(), + prop::sample::select(vec![KEY_NONE, OBS_KEY_A, OBS_KEY_MOUSE3]), + any::(), + any::(), + ); + proptest::test_runner::TestRunner::new(proptest::test_runner::Config { + cases: obs_c_oracle::parity::cases(128), + failure_persistence: None, + ..Default::default() + }) + .run( + &strategy, + |(present, strict, count, mutate, key, modifiers, pressed)| { + compare( + present, + strict, + count, + mutate, + KeyCombination { modifiers, key }, + pressed, + ); + Ok(()) + }, + ) + .unwrap(); +} diff --git a/rust/obs-hotkey/tests/hotkey/main.rs b/rust/obs-hotkey/tests/hotkey/main.rs index b6ae5d9ace..4ad546da1e 100644 --- a/rust/obs-hotkey/tests/hotkey/main.rs +++ b/rust/obs-hotkey/tests/hotkey/main.rs @@ -29,6 +29,8 @@ mod identity_getters; mod identity_getters_parity; mod identity_setters; mod identity_setters_parity; +mod inject_entry; +mod inject_entry_parity; mod key_combination; mod key_combination_parity; mod nix_hotkey_state; diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index e9d9cb4d73..8b0dce6b89 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -5639,7 +5639,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -5658,7 +5658,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -5679,7 +5680,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -5773,7 +5774,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -5792,7 +5793,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -5813,7 +5815,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -5892,7 +5894,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -5911,7 +5913,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -5932,7 +5935,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -6072,7 +6075,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -6097,7 +6100,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -6110,7 +6114,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -6239,7 +6243,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-pair-meta.c.h", @@ -6259,7 +6263,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -6275,7 +6280,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -6360,15 +6365,11 @@ "test_hotkey_inject_entry": { "sources": [ "test/cmocka/test_hotkey_inject_entry.c", - "libobs/obs-hotkey-inject-entry.c.h" + "test/cmocka/hotkey-inject-entry-link-support.c" ], "definitions": [ "obs=inject_test_obs", - "obs_hotkey_inject_event=inject_test_event", - "obs_hotkey_binding_inject=inject_test_binding", - "obs_hotkey_seam_lock=inject_test_lock", - "obs_hotkey_seam_unlock=inject_test_unlock", - "obs_hotkey_seam_enum_bindings=inject_test_enum_bindings" + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -6378,7 +6379,8 @@ { "name": "OBS::w32-pthreads", "requires": "OS_WINDOWS" - } + }, + "libobs_rust-static" ] }, "test_hotkey_load": { @@ -6391,7 +6393,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -6410,7 +6412,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -6426,7 +6429,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -6546,7 +6549,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -6571,7 +6574,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -6584,7 +6588,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -6648,7 +6652,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -6673,7 +6677,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -6686,7 +6691,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -6764,7 +6769,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -6786,7 +6791,8 @@ "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", "pthread_mutex_lock=unregister_entry_mutex_lock", "pthread_mutex_unlock=unregister_entry_mutex_unlock", - "obs_hotkey_unregister_one=unregister_entry_remove_one" + "obs_hotkey_unregister_one=unregister_entry_remove_one", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "libraries": [ "OBS::libobs", @@ -6802,7 +6808,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -11533,7 +11539,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -11579,7 +11585,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "unity_groups": { "background-control": [ @@ -11589,7 +11596,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", @@ -20162,7 +20169,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry.c.h", - "libobs/obs-hotkey-inject-entry.c.h", + "libobs/obs-hotkey-inject-entry-fields.c.h", "libobs/obs-hotkey-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", "libobs/obs-hotkey-enum.c.h", @@ -20188,7 +20195,8 @@ "obs_hotkeys_configure_background=obs_hotkey_background_control_configure_request", "obs_hotkeys_set_background_probe=obs_hotkey_background_control_probe_request", "obs_hotkey_combination_get_background_trigger=obs_hotkey_background_trigger_request", - "obs_hotkey_enable_background_press=obs_hotkey_background_press_request" + "obs_hotkey_enable_background_press=obs_hotkey_background_press_request", + "obs_hotkey_inject_event=obs_hotkey_inject_entry_request" ], "includes": [ "libobs" @@ -20211,7 +20219,7 @@ "libobs/obs-hotkey-identity-setters.c.h" ], "hotkey_inject_entry": [ - "libobs/obs-hotkey-inject-entry.c.h" + "libobs/obs-hotkey-inject-entry-fields.c.h" ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", diff --git a/test/cmocka/hotkey-inject-entry-link-support.c b/test/cmocka/hotkey-inject-entry-link-support.c new file mode 100644 index 0000000000..fd8412ffd8 --- /dev/null +++ b/test/cmocka/hotkey-inject-entry-link-support.c @@ -0,0 +1,5 @@ +/* The unchanged recorder owns inject_test_obs and the existing registry seams. + * Both adapters are real production sources, including the pointer-returning + * seam lock. No placeholder core or replacement adapter is introduced. */ +#include "libobs/obs-hotkey-background-press-fields.c.h" +#include "libobs/obs-hotkey-inject-entry-fields.c.h" diff --git a/test/cmocka/tests.d/hotkey_inject_entry_link_support.cmake b/test/cmocka/tests.d/hotkey_inject_entry_link_support.cmake new file mode 100644 index 0000000000..1f8140f77a --- /dev/null +++ b/test/cmocka/tests.d/hotkey_inject_entry_link_support.cmake @@ -0,0 +1,21 @@ +# Link the real field/lock adapters for the unchanged injection recorder. +function(_hotkey_inject_entry_link_support) + if(TARGET libobs_rust-static) + if(NOT TARGET test_hotkey_inject_entry) + return() + endif() + get_target_property(_links test_hotkey_inject_entry LINK_LIBRARIES) + get_target_property(_sources test_hotkey_inject_entry SOURCES) + get_target_property(_graph_sources test_hotkey_inject_entry OBS_NATIVE_TEST_GRAPH_SOURCES) + set(_adapter "${CMAKE_CURRENT_SOURCE_DIR}/hotkey-inject-entry-link-support.c") + set(_graph_adapter "test/cmocka/hotkey-inject-entry-link-support.c") + if( + "libobs_rust-static" IN_LIST _links + AND NOT _adapter IN_LIST _sources + AND NOT _graph_adapter IN_LIST _graph_sources + ) + target_sources(test_hotkey_inject_entry PRIVATE "${_adapter}") + endif() + endif() +endfunction() +cmake_language(DEFER CALL _hotkey_inject_entry_link_support)