diff --git a/libobs/build/libobs.core+.h.c b/libobs/build/libobs.core+.h.c index de9eb6df88..0e61febb16 100644 --- a/libobs/build/libobs.core+.h.c +++ b/libobs/build/libobs.core+.h.c @@ -31,6 +31,7 @@ #include "libobs/obs-hotkey-register-fields.c.h" #include "libobs/obs-hotkey-routed-callback-fields.c.h" #include "libobs/obs-hotkey-routing-controls-fields.c.h" +#include "libobs/obs-hotkey-unregister-entry.c.h" #include "libobs/obs-hotkey-unregister-fields.c.h" #include "libobs/obs-hotkey.c.h" #include "libobs/obs-module-disable-query.c.h" diff --git a/libobs/obs-hotkey-unregister-entry.c.h b/libobs/obs-hotkey-unregister-entry.c.h new file mode 100644 index 0000000000..7b99d79178 --- /dev/null +++ b/libobs/obs-hotkey-unregister-entry.c.h @@ -0,0 +1,33 @@ +#include "libobs/build/libobs.pch.h" + +extern void obs_hotkey_unregister_one(obs_hotkey_id id); +void obs_hotkey_unregister_pair_call(obs_hotkey_pair_id id); + +/* Reuse the registry lock and existing removers; keep the public bodies verbatim. */ +#define lock obs_hotkey_seam_lock +#define unlock obs_hotkey_seam_unlock +#define unregister_hotkey obs_hotkey_unregister_one +#define unregister_hotkey_pair obs_hotkey_unregister_pair_call + +void obs_hotkey_unregister(obs_hotkey_id id) +{ + if (!lock()) + return; + + unregister_hotkey(id); + unlock(); +} + +void obs_hotkey_pair_unregister(obs_hotkey_pair_id id) +{ + if (!lock()) + return; + + unregister_hotkey_pair(id); + unlock(); +} + +#undef lock +#undef unlock +#undef unregister_hotkey +#undef unregister_hotkey_pair diff --git a/libobs/obs-hotkey.c.h b/libobs/obs-hotkey.c.h index 22e6f4be0e..1ad9226ed3 100644 --- a/libobs/obs-hotkey.c.h +++ b/libobs/obs-hotkey.c.h @@ -354,22 +354,11 @@ static inline void unregister_hotkey_pair(obs_hotkey_pair_id id) bfree(pair); } -void obs_hotkey_unregister(obs_hotkey_id id) +/* Private call seam: retain pair teardown in this translation unit. */ +void obs_hotkey_unregister_pair_call(obs_hotkey_pair_id id); +void obs_hotkey_unregister_pair_call(obs_hotkey_pair_id id) { - if (!lock()) - return; - - unregister_hotkey(id); - unlock(); -} - -void obs_hotkey_pair_unregister(obs_hotkey_pair_id id) -{ - if (!lock()) - return; - unregister_hotkey_pair(id); - unlock(); } static void context_release_hotkeys(struct obs_context_data *context) diff --git a/rust/obs-build/tests/native/registration/canonical_hotkey_background_press_swap_is_registered.rs b/rust/obs-build/tests/native/registration/canonical_hotkey_background_press_swap_is_registered.rs index 88021dc1da..62e88ed2f3 100644 --- a/rust/obs-build/tests/native/registration/canonical_hotkey_background_press_swap_is_registered.rs +++ b/rust/obs-build/tests/native/registration/canonical_hotkey_background_press_swap_is_registered.rs @@ -48,6 +48,7 @@ fn canonical_hotkey_background_press_swap_is_registered() { "test_hotkey_load", "test_hotkey_pair_steps", "test_hotkey_press_steps", + "test_hotkey_unregister_entry", "test_portal_shortcuts", "test_wayland_hotkeys", ] diff --git a/rust/obs-build/tests/native/registration/canonical_hotkey_background_trigger_swap_is_registered.rs b/rust/obs-build/tests/native/registration/canonical_hotkey_background_trigger_swap_is_registered.rs index 0d439f296d..c8b39fccb9 100644 --- a/rust/obs-build/tests/native/registration/canonical_hotkey_background_trigger_swap_is_registered.rs +++ b/rust/obs-build/tests/native/registration/canonical_hotkey_background_trigger_swap_is_registered.rs @@ -44,6 +44,7 @@ fn canonical_hotkey_background_trigger_swap_is_registered() { "test_hotkey_load", "test_hotkey_pair_steps", "test_hotkey_press_steps", + "test_hotkey_unregister_entry", "test_portal_shortcuts", "test_wayland_hotkeys", ] 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 ed85f4a874..a862544e85 100644 --- a/rust/obs-build/tests/native/registration/headless_characterizations_expected.json +++ b/rust/obs-build/tests/native/registration/headless_characterizations_expected.json @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -68,6 +69,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "test/cmocka/test_wayland_hotkeys.c" ], 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 bc05a6d54c..0803efcbf5 100644 --- a/rust/obs-build/tests/native/registration/portal_output_expected.json +++ b/rust/obs-build/tests/native/registration/portal_output_expected.json @@ -87,6 +87,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -152,6 +153,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "test/cmocka/test_portal_shortcuts.c" ], 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 62d8316492..b03cbfe312 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -59,6 +60,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.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 3a7a5683e9..9df128fce9 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -59,6 +60,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.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 2872c03c8f..350fd17da3 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -59,6 +60,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.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 f97de18256..8796e105c8 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -57,6 +58,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "test/cmocka/test_hotkey_binding_press_steps.c" ], 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 20d538acab..a8b1f5041b 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -55,6 +56,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.c.h" ], 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 ebedb9815b..f268da5ff0 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -54,6 +55,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.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 bedf53e426..9bb1618958 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -57,6 +58,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.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 e03ffe7700..ca5ccd2fbd 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -57,6 +58,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.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 new file mode 100644 index 0000000000..c274011a45 --- /dev/null +++ b/rust/obs-build/tests/native/registration/rust-static/cases/hotkey-control/test_hotkey_unregister_entry.json @@ -0,0 +1,111 @@ +{ + "schema": 1, + "targets": { + "test_hotkey_unregister_entry": { + "sources": [ + "libobs/obs-hotkey-binding-press.c.h", + "test/cmocka/test_hotkey_unregister_entry.c", + "libobs/obs-hotkey-background-query.c.h", + "libobs/obs-hotkey-register.c.h", + "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-identity-setters.c.h", + "libobs/obs-hotkey-background-enum.c.h", + "libobs/obs-hotkey-enum.c.h", + "libobs/obs-hotkey-save-load.c.h", + "libobs/obs-hotkey-bindings.c.h", + "libobs/obs-hotkey-translations.c.h", + "libobs/obs-hotkey-press.c.h", + "libobs/obs-hotkey-pair.c.h", + "test/cmocka/hotkey-enum-link-support.c", + "test/cmocka/hotkey-background-trigger-link-support.c", + "test/cmocka/hotkey-background-press-link-support.c" + ], + "definitions": [ + "obs=hotkey_test_obs", + "obs_hotkeys_retry_background=obs_hotkey_background_control_retry_request", + "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", + "pthread_mutex_lock=unregister_entry_mutex_lock", + "pthread_mutex_unlock=unregister_entry_mutex_unlock", + "obs_hotkey_unregister_one=unregister_entry_remove_one" + ], + "libraries": [ + "OBS::libobs", + "OBS::caption", + "OBS::native-test-cmocka", + "libobs_rust-static" + ], + "unity_groups": { + "background-control": [ + "libobs/obs-hotkey-background-control-fields.c.h" + ], + "hotkey_identity_setters": [ + "libobs/obs-hotkey-identity-setters.c.h" + ], + "hotkey_inject_entry": [ + "libobs/obs-hotkey-inject-entry.c.h" + ], + "hotkey_registration": [ + "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey.c.h" + ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], + "source_0": [ + "libobs/obs-hotkey-binding-press.c.h" + ], + "source_1": [ + "test/cmocka/test_hotkey_unregister_entry.c" + ], + "source_2": [ + "libobs/obs-hotkey-background-query.c.h" + ], + "source_5": [ + "libobs/obs-hotkey-background-enum.c.h" + ], + "source_6": [ + "libobs/obs-hotkey-enum.c.h" + ], + "source_7": [ + "libobs/obs-hotkey-save-load.c.h" + ], + "source_8": [ + "libobs/obs-hotkey-bindings.c.h" + ], + "source_9": [ + "libobs/obs-hotkey-translations.c.h" + ], + "source_10": [ + "libobs/obs-hotkey-press.c.h" + ], + "source_11": [ + "libobs/obs-hotkey-pair.c.h" + ], + "hotkey_enumeration_fields": [ + "test/cmocka/hotkey-enum-link-support.c" + ], + "hotkey_background_trigger": [ + "test/cmocka/hotkey-background-trigger-link-support.c" + ], + "hotkey_background_press": [ + "test/cmocka/hotkey-background-press-link-support.c" + ] + }, + "pch": "libobs/build/libobs.pch.h" + } + }, + "tests": { + "test_hotkey_unregister_entry": { + "target": "test_hotkey_unregister_entry", + "command": [ + "${target}" + ] + } + } +} 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 9cfbd4b6fc..66e72a92ce 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 @@ -14,6 +14,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -79,6 +80,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "test/cmocka/test_portal_shortcuts.c" ], 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 8a8643be20..7b4af5da77 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 @@ -10,6 +10,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -68,6 +69,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "test/cmocka/test_wayland_hotkeys.c" ], diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index 0cf6356dcd..d444a5dee0 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -5638,6 +5638,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -5687,6 +5688,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.c.h" ], @@ -5768,6 +5772,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -5817,6 +5822,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.c.h" ], @@ -5883,6 +5891,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -5932,6 +5941,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.c.h" ], @@ -6059,6 +6071,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -6106,6 +6119,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "test/cmocka/test_hotkey_binding_press_steps.c" ], @@ -6222,6 +6238,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -6267,6 +6284,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.c.h" ], @@ -6370,6 +6390,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -6414,6 +6435,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.c.h" ], @@ -6521,6 +6545,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -6568,6 +6593,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.c.h" ], @@ -6619,6 +6647,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -6666,6 +6695,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "libobs/obs-hotkey-binding-press.c.h" ], @@ -6723,6 +6755,104 @@ ] } }, + "test_hotkey_unregister_entry": { + "sources": [ + "libobs/obs-hotkey-binding-press.c.h", + "test/cmocka/test_hotkey_unregister_entry.c", + "libobs/obs-hotkey-background-query.c.h", + "libobs/obs-hotkey-register.c.h", + "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-identity-setters.c.h", + "libobs/obs-hotkey-background-enum.c.h", + "libobs/obs-hotkey-enum.c.h", + "libobs/obs-hotkey-save-load.c.h", + "libobs/obs-hotkey-bindings.c.h", + "libobs/obs-hotkey-translations.c.h", + "libobs/obs-hotkey-press.c.h", + "libobs/obs-hotkey-pair.c.h", + "test/cmocka/hotkey-enum-link-support.c", + "test/cmocka/hotkey-background-trigger-link-support.c", + "test/cmocka/hotkey-background-press-link-support.c" + ], + "definitions": [ + "obs=hotkey_test_obs", + "obs_hotkeys_retry_background=obs_hotkey_background_control_retry_request", + "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", + "pthread_mutex_lock=unregister_entry_mutex_lock", + "pthread_mutex_unlock=unregister_entry_mutex_unlock", + "obs_hotkey_unregister_one=unregister_entry_remove_one" + ], + "libraries": [ + "OBS::libobs", + "OBS::caption", + "OBS::native-test-cmocka", + "libobs_rust-static" + ], + "unity_groups": { + "background-control": [ + "libobs/obs-hotkey-background-control-fields.c.h" + ], + "hotkey_identity_setters": [ + "libobs/obs-hotkey-identity-setters.c.h" + ], + "hotkey_inject_entry": [ + "libobs/obs-hotkey-inject-entry.c.h" + ], + "hotkey_registration": [ + "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey.c.h" + ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], + "source_0": [ + "libobs/obs-hotkey-binding-press.c.h" + ], + "source_1": [ + "test/cmocka/test_hotkey_unregister_entry.c" + ], + "source_2": [ + "libobs/obs-hotkey-background-query.c.h" + ], + "source_5": [ + "libobs/obs-hotkey-background-enum.c.h" + ], + "source_6": [ + "libobs/obs-hotkey-enum.c.h" + ], + "source_7": [ + "libobs/obs-hotkey-save-load.c.h" + ], + "source_8": [ + "libobs/obs-hotkey-bindings.c.h" + ], + "source_9": [ + "libobs/obs-hotkey-translations.c.h" + ], + "source_10": [ + "libobs/obs-hotkey-press.c.h" + ], + "source_11": [ + "libobs/obs-hotkey-pair.c.h" + ], + "hotkey_enumeration_fields": [ + "test/cmocka/hotkey-enum-link-support.c" + ], + "hotkey_background_trigger": [ + "test/cmocka/hotkey-background-trigger-link-support.c" + ], + "hotkey_background_press": [ + "test/cmocka/hotkey-background-press-link-support.c" + ] + }, + "pch": "libobs/build/libobs.pch.h" + }, "test_hotkey_volume_keys": { "sources": [ "test/cmocka/test_hotkey_volume_keys.c" @@ -11358,6 +11488,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -11423,6 +11554,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "test/cmocka/test_portal_shortcuts.c" ], @@ -19983,6 +20117,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "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-identity-setters.c.h", "libobs/obs-hotkey-background-enum.c.h", @@ -20041,6 +20176,9 @@ "hotkey_unregister": [ "libobs/obs-hotkey-unregister.c.h" ], + "hotkey_unregister_entry": [ + "libobs/obs-hotkey-unregister-entry.c.h" + ], "source_0": [ "test/cmocka/test_wayland_hotkeys.c" ], @@ -23411,6 +23549,12 @@ ] ] }, + "test_hotkey_unregister_entry": { + "target": "test_hotkey_unregister_entry", + "command": [ + "${target}" + ] + }, "test_hotkey_volume_keys": { "target": "test_hotkey_volume_keys", "command": [ diff --git a/test/cmocka/test_hotkey_unregister_entry.c b/test/cmocka/test_hotkey_unregister_entry.c new file mode 100644 index 0000000000..c416f8823a --- /dev/null +++ b/test/cmocka/test_hotkey_unregister_entry.c @@ -0,0 +1,177 @@ +/* C-source characterization of the public removal wrappers and the real pair + * helper. Only mutex calls and the already-ported single-key remover record; + * there is no desktop, input thread, synthetic wait or duplicated pair logic. + * The Rust swap must relink this unchanged test to its replacement wrappers. */ +#include +#include +#include +#include +#include +#include +#include "obs-internal.h" + +/* Supply the real C owner-release helper, as the other isolated C fixtures do. + * Its single-key removal entry has a separate name so the recorder below owns + * dispatch observation; no placeholder cleanup or Rust archive fallback. */ +#undef obs_hotkey_unregister_one +#define obs_hotkey_unregister_one unregister_entry_c_remove_one +#include "libobs/obs-hotkey-unregister.c.h" +#undef obs_hotkey_unregister_one +#define obs_hotkey_unregister_one unregister_entry_remove_one + +struct obs_core *hotkey_test_obs; +static struct obs_core core; +static bool locked, removing_pair; +static long pair_allocations; +static char order[16]; +static size_t order_count, removed_count; +static obs_hotkey_id removed[4]; +static obs_hotkey_pair_t *expected_pair; + +static void record(char step) +{ + assert_true(order_count < sizeof(order)); + order[order_count++] = step; +} + +int pthread_mutex_lock(pthread_mutex_t *mutex) +{ + assert_ptr_equal(mutex, &core.hotkeys.mutex); + assert_false(locked); + locked = true; + record('L'); + return 0; +} + +int pthread_mutex_unlock(pthread_mutex_t *mutex) +{ + assert_ptr_equal(mutex, &core.hotkeys.mutex); + assert_true(locked); + if (removing_pair) { + assert_null(core.hotkeys.hotkey_pairs); + assert_int_equal(bnum_allocs(), pair_allocations); + } + locked = false; + record('U'); + return 0; +} + +void obs_hotkey_unregister_one(obs_hotkey_id id) +{ + assert_true(locked); + assert_true(removed_count < sizeof(removed) / sizeof(removed[0])); + if (removing_pair) { + assert_true(removed_count < 2); + /* The pair stays registered during both member removals. */ + assert_ptr_equal(core.hotkeys.hotkey_pairs, expected_pair); + assert_int_equal(id, expected_pair->id[removed_count]); + } + removed[removed_count++] = id; + record('R'); +} + +bool obs_hotkeys_platform_is_pressed(obs_hotkeys_platform_t *context, obs_key_t key) +{ + (void)context; + (void)key; + return false; +} + +static int setup(void **state) +{ + (void)state; + memset(&core, 0, sizeof(core)); + memset(order, 0, sizeof(order)); + memset(removed, 0, sizeof(removed)); + hotkey_test_obs = &core; + locked = removing_pair = false; + order_count = removed_count = 0; + expected_pair = NULL; + return 0; +} + +static int teardown(void **state) +{ + (void)state; + assert_false(locked); + assert_null(core.hotkeys.hotkey_pairs); + hotkey_test_obs = NULL; + return 0; +} + +static void no_core(void **state) +{ + (void)state; + hotkey_test_obs = NULL; + obs_hotkey_unregister(OBS_INVALID_HOTKEY_ID); + obs_hotkey_pair_unregister(OBS_INVALID_HOTKEY_PAIR_ID); + assert_int_equal(order_count, 0); + assert_int_equal(removed_count, 0); +} + +static void single_forwarding(void **state) +{ + (void)state; + const obs_hotkey_id ids[] = {0, (size_t)UINT32_MAX + (size_t)1, OBS_INVALID_HOTKEY_ID, 0}; + for (size_t i = 0; i < sizeof(ids) / sizeof(ids[0]); i++) { + obs_hotkey_unregister(ids[i]); + assert_int_equal(removed[i], ids[i]); + } + assert_int_equal(removed_count, 4); + assert_int_equal(order_count, 12); + assert_memory_equal(order, "LRULRULRULRU", 12); +} + +static void missing_pair(void **state) +{ + (void)state; + core.hotkeys.next_pair_id = 4; + const obs_hotkey_pair_id ids[] = {0, 3, 4, OBS_INVALID_HOTKEY_PAIR_ID}; + for (size_t i = 0; i < sizeof(ids) / sizeof(ids[0]); i++) + obs_hotkey_pair_unregister(ids[i]); + assert_int_equal(removed_count, 0); + assert_int_equal(order_count, 8); + assert_memory_equal(order, "LULULULU", 8); +} + +static void pair_member_order(void **state) +{ + (void)state; + pair_allocations = bnum_allocs(); + obs_hotkey_pair_t *pair = bzalloc(sizeof(*pair)); + const obs_hotkey_pair_id id = (size_t)UINT32_MAX + (size_t)1; + pair->pair_id = id; + pair->id[0] = OBS_INVALID_HOTKEY_ID; + pair->id[1] = (size_t)UINT32_MAX + (size_t)1; + core.hotkeys.next_pair_id = id + 1; + /* The production registry's size_t hash rule, independent of host width. */ + HASH_ADD_KEYPTR_BYHASHVALUE(hh, core.hotkeys.hotkey_pairs, &pair->pair_id, sizeof(size_t), + (unsigned int)(pair->pair_id % UINT_MAX), pair); + expected_pair = pair; + removing_pair = true; + obs_hotkey_pair_unregister(pair->pair_id); + assert_int_equal(removed_count, 2); + assert_int_equal(order_count, 4); + assert_memory_equal(order, "LRRU", 4); + assert_int_equal(bnum_allocs(), pair_allocations); + expected_pair = NULL; + removing_pair = false; + /* A repeated removal finds no pair and still balances the lock. */ + obs_hotkey_pair_unregister(id); + assert_int_equal(removed_count, 2); + assert_int_equal(order_count, 6); + assert_memory_equal(order, "LRRULU", 6); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown(no_core, setup, teardown), + cmocka_unit_test_setup_teardown(single_forwarding, setup, teardown), + cmocka_unit_test_setup_teardown(missing_pair, setup, teardown), + cmocka_unit_test_setup_teardown(pair_member_order, setup, teardown), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} + +#undef obs_hotkey_unregister_one diff --git a/test/cmocka/tests.d/hotkey_background_press_link_support.cmake b/test/cmocka/tests.d/hotkey_background_press_link_support.cmake index e620b0ab26..cf058cd678 100644 --- a/test/cmocka/tests.d/hotkey_background_press_link_support.cmake +++ b/test/cmocka/tests.d/hotkey_background_press_link_support.cmake @@ -11,6 +11,7 @@ function(_hotkey_background_press_link_support) test_hotkey_load test_hotkey_pair_steps test_hotkey_press_steps + test_hotkey_unregister_entry test_portal_shortcuts test_wayland_hotkeys ) diff --git a/test/cmocka/tests.d/hotkey_background_trigger_link_support.cmake b/test/cmocka/tests.d/hotkey_background_trigger_link_support.cmake index 32ae27246e..f804d28279 100644 --- a/test/cmocka/tests.d/hotkey_background_trigger_link_support.cmake +++ b/test/cmocka/tests.d/hotkey_background_trigger_link_support.cmake @@ -11,6 +11,7 @@ function(_hotkey_background_trigger_link_support) test_hotkey_load test_hotkey_pair_steps test_hotkey_press_steps + test_hotkey_unregister_entry test_portal_shortcuts test_wayland_hotkeys ) diff --git a/test/cmocka/tests.d/test_hotkey_unregister_entry.cmake b/test/cmocka/tests.d/test_hotkey_unregister_entry.cmake new file mode 100644 index 0000000000..d85a840326 --- /dev/null +++ b/test/cmocka/tests.d/test_hotkey_unregister_entry.cmake @@ -0,0 +1 @@ +# Registered in the canonical native test graph (test/cmocka/build/test-graph.json).