diff --git a/ci/test_hotkey_register_extraction.py b/ci/test_hotkey_register_extraction.py index 261d62dfba..65e44b1a19 100644 --- a/ci/test_hotkey_register_extraction.py +++ b/ci/test_hotkey_register_extraction.py @@ -51,6 +51,7 @@ def test_isolated_cores_compile_registration_in_the_same_translation_unit(self): EXTRACTED, "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", ORIGINAL, ], groups, diff --git a/libobs/build/libobs.core+.h.c b/libobs/build/libobs.core+.h.c index 3fe240b102..50ce3c68ac 100644 --- a/libobs/build/libobs.core+.h.c +++ b/libobs/build/libobs.core+.h.c @@ -27,6 +27,7 @@ #include "libobs/obs-hotkey-background-state-fields.c.h" #include "libobs/obs-hotkey-background-trigger-fields.c.h" #include "libobs/obs-hotkey-combination-background-id-fields.c.h" +#include "libobs/obs-hotkey-dispatch.c.h" #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" diff --git a/libobs/obs-hotkey-dispatch.c.h b/libobs/obs-hotkey-dispatch.c.h new file mode 100644 index 0000000000..c65fc741c1 --- /dev/null +++ b/libobs/obs-hotkey-dispatch.c.h @@ -0,0 +1,12 @@ +#include "libobs/build/libobs.pch.h" + +/* The call of a hotkey event: the hotkey's own callback, or the router when + * callback rerouting is on (nothing when it is on and no router is set). The + * callback ABI and the router (the frontend's) stay here. */ +void obs_hotkey_dispatch(obs_hotkey_t *hotkey, bool pressed) +{ + if (!obs->hotkeys.reroute_hotkeys) + hotkey->func(hotkey->data, hotkey->id, hotkey, pressed); + else if (obs->hotkeys.router_func) + obs->hotkeys.router_func(obs->hotkeys.router_func_data, hotkey->id, pressed); +} diff --git a/libobs/obs-hotkey.c.h b/libobs/obs-hotkey.c.h index fb29fb18a1..859174b356 100644 --- a/libobs/obs-hotkey.c.h +++ b/libobs/obs-hotkey.c.h @@ -451,17 +451,6 @@ struct obs_hotkey_binding_count_fields obs_hotkey_binding_count_fields(obs_hotke }; } -/* The call of a hotkey event: the hotkey's own callback, or the router when - * callback rerouting is on (nothing when it is on and no router is set). The - * callback ABI and the router (the frontend's) stay here. */ -void obs_hotkey_dispatch(obs_hotkey_t *hotkey, bool pressed) -{ - if (!obs->hotkeys.reroute_hotkeys) - hotkey->func(hotkey->data, hotkey->id, hotkey, pressed); - else if (obs->hotkeys.router_func) - obs->hotkeys.router_func(obs->hotkeys.router_func_data, hotkey->id, pressed); -} - void obs_hotkeys_background_clear_shortcuts(struct obs_hotkeys_background *background) { for (size_t i = 0; i < background->shortcuts.num; i++) 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 4cf30fce03..84fed6340f 100644 --- a/rust/obs-build/tests/native/registration/headless_characterizations_expected.json +++ b/rust/obs-build/tests/native/registration/headless_characterizations_expected.json @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -82,6 +83,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 c9db086872..7a8fb50f82 100644 --- a/rust/obs-build/tests/native/registration/portal_output_expected.json +++ b/rust/obs-build/tests/native/registration/portal_output_expected.json @@ -89,6 +89,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -166,6 +167,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 1258605ea6..b525f9d295 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -67,6 +68,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 bf42cef353..eff3d2e8f9 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -67,6 +68,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 c8fb9cdc46..f0d2013fe1 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -67,6 +68,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 d7f7d50bf9..123caf8d44 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -65,6 +66,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 62201084db..8e01f8a73a 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -63,6 +64,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 ad9eeb9381..2cc8086fe6 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -62,6 +63,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 0cf4acc7a0..c3a1bb694d 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -65,6 +66,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 0b51729269..b25fa2f8b1 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -65,6 +66,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 6794b9eea6..484d778f16 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 @@ -11,6 +11,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -64,6 +65,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister_entry": [ 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 321eaf8e83..36dab2b00d 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 @@ -16,6 +16,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -87,6 +88,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ 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 7060e11539..75392de188 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 @@ -12,6 +12,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -76,6 +77,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ diff --git a/test/cmocka/build/test-graph.json b/test/cmocka/build/test-graph.json index a7eb798f21..7e4b8ec307 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -6105,6 +6105,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6160,6 +6161,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6265,6 +6267,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6320,6 +6323,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6460,6 +6464,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6515,6 +6520,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6666,6 +6672,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6725,6 +6732,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6845,6 +6853,24 @@ "OBS::native-test-cmocka" ] }, + "test_hotkey_dispatch": { + "libraries": [ + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ], + "sources": [ + "test/cmocka/test_hotkey_dispatch.c" + ], + "header_libraries": [ + "SIMDe::SIMDe" + ] + }, "test_hotkey_edit_backtab": { "sources": [ "test/cmocka/test_hotkey_edit_backtab.cpp", @@ -6879,6 +6905,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6935,6 +6962,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -7108,6 +7136,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -7163,6 +7192,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -7294,6 +7324,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -7353,6 +7384,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -7424,6 +7456,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -7483,6 +7516,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -7568,6 +7602,7 @@ "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -7626,6 +7661,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister_entry": [ @@ -12565,6 +12601,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -12642,6 +12679,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -21555,6 +21593,7 @@ "libobs/obs-hotkey-unregister.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -21625,6 +21664,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey-combination-background-id.c.h", + "libobs/obs-hotkey-dispatch.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -25081,6 +25121,12 @@ ] ] }, + "test_hotkey_dispatch": { + "command": [ + "${target}" + ], + "target": "test_hotkey_dispatch" + }, "test_hotkey_edit_backtab": { "target": "test_hotkey_edit_backtab", "suite": "qt", diff --git a/test/cmocka/test_hotkey_dispatch.c b/test/cmocka/test_hotkey_dispatch.c new file mode 100644 index 0000000000..f7c1db983d --- /dev/null +++ b/test/cmocka/test_hotkey_dispatch.c @@ -0,0 +1,178 @@ +/* C-source characterization; the external seam is reserved for the Rust swap. + * Dispatch forwards events without binding lookup, locking or state changes. + * A live core and (on a delivered path) a live hotkey/callback are preconditions: + * NULL core/direct callback are unchecked C UB, characterized, not endorsed. */ +#include +#include +#include +#include +#include +#include "libobs/build/libobs.pch.h" + +static struct obs_core core; +static struct obs_core *current_core; +static obs_hotkey_t dispatch_hotkey; +static obs_hotkey_binding_t binding; +static int callback_data, router_data; +static unsigned callback_calls, router_calls; +static bool events[8]; + +static void record_callback(void *data, obs_hotkey_id id, obs_hotkey_t *key, bool pressed) +{ + assert_ptr_equal(data, &callback_data); + assert_int_equal(id, dispatch_hotkey.id); + assert_ptr_equal(key, &dispatch_hotkey); + assert_true(callback_calls < sizeof(events) / sizeof(events[0])); + events[callback_calls++] = pressed; +} + +static void record_router(void *data, obs_hotkey_id id, bool pressed) +{ + assert_ptr_equal(data, &router_data); + assert_int_equal(id, dispatch_hotkey.id); + assert_true(router_calls < sizeof(events) / sizeof(events[0])); + events[router_calls++] = pressed; +} + +#ifndef HOTKEY_DISPATCH_EXTERNAL +#ifndef HOTKEY_DISPATCH_SOURCE +#define HOTKEY_DISPATCH_SOURCE "libobs/obs-hotkey-dispatch.c.h" +#endif +#define obs current_core +#include HOTKEY_DISPATCH_SOURCE +#undef obs +#endif + +static int setup(void **unused) +{ + (void)unused; + memset(&core, 0, sizeof(core)); + memset(&dispatch_hotkey, 0, sizeof(dispatch_hotkey)); + memset(&binding, 0, sizeof(binding)); + memset(events, 0, sizeof(events)); + current_core = &core; + dispatch_hotkey.id = 42; + dispatch_hotkey.func = record_callback; + dispatch_hotkey.data = &callback_data; + binding.hotkey = &dispatch_hotkey; + binding.hotkey_id = dispatch_hotkey.id; + callback_calls = router_calls = 0; + return 0; +} + +static void active_binding_delivers_without_mutation(void **unused) +{ + (void)unused; + binding.pressed = binding.modifiers_match = true; + dispatch_hotkey.pressed = 2; + core.hotkeys.bindings.array = &binding; + core.hotkeys.bindings.num = core.hotkeys.bindings.capacity = 1; + /* Even an installed router is ignored unless rerouting is enabled. */ + core.hotkeys.router_func = record_router; + core.hotkeys.router_func_data = &router_data; + obs_hotkey_dispatch(binding.hotkey, true); + assert_int_equal(callback_calls, 1); + assert_int_equal(router_calls, 0); + assert_true(events[0]); + assert_true(binding.pressed); + assert_true(binding.modifiers_match); + assert_int_equal(dispatch_hotkey.pressed, 2); + assert_int_equal(core.hotkeys.bindings.num, 1); + assert_ptr_equal(core.hotkeys.bindings.array, &binding); +} + +static void absent_binding_still_delivers(void **unused) +{ + (void)unused; + /* No registry or matching binding: dispatch performs no lookup. */ + dispatch_hotkey.id = OBS_INVALID_HOTKEY_ID; + assert_null(core.hotkeys.hotkeys); + assert_null(core.hotkeys.bindings.array); + obs_hotkey_dispatch(&dispatch_hotkey, true); + assert_int_equal(callback_calls, 1); + assert_true(events[0]); + assert_int_equal(dispatch_hotkey.pressed, 0); + assert_false(binding.pressed); + assert_null(core.hotkeys.bindings.array); + /* An unrelated binding must not suppress delivery either. */ + binding.hotkey_id = 7; + binding.hotkey = NULL; + core.hotkeys.bindings.array = &binding; + core.hotkeys.bindings.num = core.hotkeys.bindings.capacity = 1; + obs_hotkey_dispatch(&dispatch_hotkey, false); + assert_int_equal(callback_calls, 2); + assert_false(events[1]); + assert_int_equal(binding.hotkey_id, 7); + assert_null(binding.hotkey); +} + +static void press_release_and_duplicates_are_forwarded(void **unused) +{ + (void)unused; + obs_hotkey_dispatch(&dispatch_hotkey, true); + obs_hotkey_dispatch(&dispatch_hotkey, true); + obs_hotkey_dispatch(&dispatch_hotkey, false); + obs_hotkey_dispatch(&dispatch_hotkey, false); + assert_int_equal(callback_calls, 4); + assert_true(events[0]); + assert_true(events[1]); + assert_false(events[2]); + assert_false(events[3]); + assert_int_equal(dispatch_hotkey.pressed, 0); + assert_false(binding.pressed); +} + +static void routing_uses_current_router_and_id(void **unused) +{ + (void)unused; + core.hotkeys.reroute_hotkeys = true; + core.hotkeys.router_func = record_router; + core.hotkeys.router_func_data = &router_data; + /* Routed dispatch does not inspect the dispatch_hotkey's callback. */ + dispatch_hotkey.func = NULL; + dispatch_hotkey.data = NULL; + obs_hotkey_dispatch(&dispatch_hotkey, true); + dispatch_hotkey.id = OBS_INVALID_HOTKEY_ID; + obs_hotkey_dispatch(&dispatch_hotkey, false); + assert_int_equal(router_calls, 2); + assert_int_equal(callback_calls, 0); + assert_true(events[0]); + assert_false(events[1]); + core.hotkeys.router_func = NULL; + obs_hotkey_dispatch(&dispatch_hotkey, true); + assert_int_equal(router_calls, 2); + dispatch_hotkey.func = record_callback; + dispatch_hotkey.data = &callback_data; + core.hotkeys.reroute_hotkeys = false; + obs_hotkey_dispatch(&dispatch_hotkey, false); + assert_int_equal(callback_calls, 1); + assert_false(events[0]); +} + +static void zero_state_and_null_no_router_branch(void **unused) +{ + (void)unused; + /* No startup or initialized mutex is needed by this function. */ + obs_hotkey_dispatch(&dispatch_hotkey, false); + assert_int_equal(callback_calls, 1); + assert_false(events[0]); + core.hotkeys.reroute_hotkeys = true; + /* This branch returns without touching even a NULL hotkey. */ + obs_hotkey_dispatch(NULL, true); + obs_hotkey_dispatch(NULL, false); + assert_int_equal(callback_calls, 1); + assert_int_equal(router_calls, 0); + assert_null(core.hotkeys.router_func); +} + +int main(void) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup(active_binding_delivers_without_mutation, setup), + cmocka_unit_test_setup(absent_binding_still_delivers, setup), + cmocka_unit_test_setup(press_release_and_duplicates_are_forwarded, setup), + cmocka_unit_test_setup(routing_uses_current_router_and_id, setup), + cmocka_unit_test_setup(zero_state_and_null_no_router_branch, setup), + }; + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/tests.d/test_hotkey_dispatch.cmake b/test/cmocka/tests.d/test_hotkey_dispatch.cmake new file mode 100644 index 0000000000..296d1e26d6 --- /dev/null +++ b/test/cmocka/tests.d/test_hotkey_dispatch.cmake @@ -0,0 +1 @@ +# Defined in ../build/test-graph.json.