diff --git a/ci/test_hotkey_register_extraction.py b/ci/test_hotkey_register_extraction.py index 9c4c2b3797..effde6f92e 100644 --- a/ci/test_hotkey_register_extraction.py +++ b/ci/test_hotkey_register_extraction.py @@ -45,7 +45,9 @@ def test_isolated_cores_compile_registration_in_the_same_translation_unit(self): self.assertIn(EXTRACTED, target["sources"]) self.assertEqual(target.get("pch"), "libobs/build/libobs.pch.h") groups = list(target.get("unity_groups", {}).values()) - self.assertIn([EXTRACTED, ORIGINAL], groups) + self.assertIn( + [EXTRACTED, "libobs/obs-hotkey-background-state.c.h", ORIGINAL], groups + ) self.assertCountEqual( [source for group in groups for source in group], target["sources"] ) diff --git a/libobs/build/libobs.core+.h.c b/libobs/build/libobs.core+.h.c index 401b587f52..4f39379c9b 100644 --- a/libobs/build/libobs.core+.h.c +++ b/libobs/build/libobs.core+.h.c @@ -23,6 +23,7 @@ #include "libobs/obs-hotkey-background-enum-fields.c.h" #include "libobs/obs-hotkey-background-error-fields.c.h" #include "libobs/obs-hotkey-background-press-fields.c.h" +#include "libobs/obs-hotkey-background-state.c.h" #include "libobs/obs-hotkey-background-trigger-fields.c.h" #include "libobs/obs-hotkey-enum-fields.c.h" #include "libobs/obs-hotkey-identity-fields.c.h" diff --git a/libobs/obs-hotkey-background-state.c.h b/libobs/obs-hotkey-background-state.c.h new file mode 100644 index 0000000000..3edcf3fc09 --- /dev/null +++ b/libobs/obs-hotkey-background-state.c.h @@ -0,0 +1,19 @@ +#include "libobs/build/libobs.pch.h" + +/* Defined in obs-hotkey.c.h, later in the same unity group. */ +static inline bool lock(void); +static inline void unlock(void); + +enum obs_hotkeys_background_state obs_hotkeys_get_background_state(uint32_t *flags) +{ + if (flags) + *flags = 0; + if (!lock()) + return OBS_HOTKEYS_BACKGROUND_NATIVE; + + enum obs_hotkeys_background_state state = obs->hotkeys.background.state; + if (flags) + *flags = obs->hotkeys.background.flags; + unlock(); + return state; +} diff --git a/libobs/obs-hotkey.c.h b/libobs/obs-hotkey.c.h index 1ad9226ed3..9b73669900 100644 --- a/libobs/obs-hotkey.c.h +++ b/libobs/obs-hotkey.c.h @@ -475,20 +475,6 @@ void obs_hotkeys_background_status_changed(void) signal_handler_signal(obs->hotkeys.signals, "hotkey_background_status_changed", NULL); } -enum obs_hotkeys_background_state obs_hotkeys_get_background_state(uint32_t *flags) -{ - if (flags) - *flags = 0; - if (!lock()) - return OBS_HOTKEYS_BACKGROUND_NATIVE; - - enum obs_hotkeys_background_state state = obs->hotkeys.background.state; - if (flags) - *flags = obs->hotkeys.background.flags; - unlock(); - return state; -} - char *obs_hotkey_combination_get_background_id(obs_key_combination_t combo) { if (!lock()) 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 52cfb3bef3..7678262dd7 100644 --- a/rust/obs-build/tests/native/registration/headless_characterizations_expected.json +++ b/rust/obs-build/tests/native/registration/headless_characterizations_expected.json @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -74,6 +75,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 f8739454cf..939027a17b 100644 --- a/rust/obs-build/tests/native/registration/portal_output_expected.json +++ b/rust/obs-build/tests/native/registration/portal_output_expected.json @@ -86,6 +86,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -158,6 +159,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 f8fba99b4b..e04204e27f 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -59,6 +60,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 32662e5f4c..ca7835ce9f 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -59,6 +60,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 a4655ccb99..b1082cd601 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -59,6 +60,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 219db6f27f..a277a863e3 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -57,6 +58,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 9b9bde4b4f..eb5d068c01 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -55,6 +56,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 fa61c91145..d3c28d9896 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -54,6 +55,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 51e20dc06a..9fb3c2acad 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -57,6 +58,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 7837fef54f..a5bd7e5e08 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -57,6 +58,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 6ef5c72a38..d0069da039 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 @@ -8,6 +8,7 @@ "libobs/obs-hotkey-background-query.c.h", "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -56,6 +57,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 0ac19ed317..4151c47d38 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 @@ -13,6 +13,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -79,6 +80,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 a532206a74..4130bec955 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 @@ -9,6 +9,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -68,6 +69,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.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 b3a477afe2..15f5ce1597 100644 --- a/test/cmocka/build/test-graph.json +++ b/test/cmocka/build/test-graph.json @@ -5855,6 +5855,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -5905,6 +5906,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6004,6 +6006,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6054,6 +6057,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6130,6 +6134,24 @@ } ] }, + "test_hotkey_background_state": { + "libraries": [ + "OBS::libobs", + "OBS::caption", + "Uthash::Uthash", + "OBS::native-test-cmocka", + { + "name": "OBS::w32-pthreads", + "requires": "OS_WINDOWS" + } + ], + "sources": [ + "test/cmocka/test_hotkey_background_state.c" + ], + "header_libraries": [ + "SIMDe::SIMDe" + ] + }, "test_hotkey_background_trigger": { "sources": [ "libobs/obs-hotkey-binding-press.c.h", @@ -6138,6 +6160,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6188,6 +6211,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6333,6 +6357,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6387,6 +6412,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6517,6 +6543,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6568,6 +6595,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6686,6 +6714,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6736,6 +6765,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6861,6 +6891,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -6915,6 +6946,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -6980,6 +7012,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -7034,6 +7067,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -7113,6 +7147,7 @@ "libobs/obs-hotkey-background-query.c.h", "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -7166,6 +7201,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister_entry": [ @@ -11950,6 +11986,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -12022,6 +12059,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -20827,6 +20865,7 @@ "libobs/obs-hotkey-register.c.h", "libobs/obs-hotkey-background-control-fields.c.h", "libobs/obs-hotkey-unregister.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h", "libobs/obs-hotkey-unregister-entry-fields.c.h", "libobs/obs-hotkey-inject-entry-fields.c.h", @@ -20892,6 +20931,7 @@ ], "hotkey_registration": [ "libobs/obs-hotkey-register.c.h", + "libobs/obs-hotkey-background-state.c.h", "libobs/obs-hotkey.c.h" ], "hotkey_unregister": [ @@ -24153,6 +24193,12 @@ ], "suite": "core" }, + "test_hotkey_background_state": { + "command": [ + "${target}" + ], + "target": "test_hotkey_background_state" + }, "test_hotkey_background_trigger": { "target": "test_hotkey_background_trigger", "command": [ diff --git a/test/cmocka/test_hotkey_background_state.c b/test/cmocka/test_hotkey_background_state.c new file mode 100644 index 0000000000..80d13d720a --- /dev/null +++ b/test/cmocka/test_hotkey_background_state.c @@ -0,0 +1,119 @@ +/* Characterize the C wrapper before its Rust swap, without a desktop or threads. + * The recording core accessor rejects eager/background reads outside the lock. */ +#include +#include +#include +#include +#include +#include "libobs/build/libobs.pch.h" + +static struct obs_core core; +static bool lock_result, locked; +static unsigned locks, unlocks, reads; +static uint32_t *output; +static uint32_t expected_flags; +static enum obs_hotkeys_background_state expected_state; + +static struct obs_core *record_core(void) +{ + assert_true(locked); + reads++; + return &core; +} + +static inline bool lock(void) +{ + assert_false(locked); + assert_int_equal(locks, 0); + assert_int_equal(reads, 0); + /* Clearing the optional output precedes even a failed lock attempt. */ + if (output) + assert_int_equal(*output, 0); + locks++; + locked = lock_result; + /* Fields become current only when the lock succeeds. */ + core.hotkeys.background.state = expected_state; + core.hotkeys.background.flags = expected_flags; + return lock_result; +} + +static inline void unlock(void) +{ + assert_true(locked); + assert_int_equal(locks, 1); + assert_int_equal(unlocks, 0); + assert_int_equal(reads, output ? 2 : 1); + if (output) + assert_int_equal(*output, expected_flags); + /* The returned state must be captured before releasing the lock. */ + core.hotkeys.background.state = OBS_HOTKEYS_BACKGROUND_NATIVE; + core.hotkeys.background.flags = 0; + locked = false; + unlocks++; +} + +#ifndef HOTKEY_BACKGROUND_STATE_EXTERNAL +#ifndef HOTKEY_BACKGROUND_STATE_SOURCE +#define HOTKEY_BACKGROUND_STATE_SOURCE "libobs/obs-hotkey-background-state.c.h" +#endif +#define obs record_core() +#include HOTKEY_BACKGROUND_STATE_SOURCE +#undef obs +#endif + +static void query(bool success, bool with_flags, enum obs_hotkeys_background_state state, uint32_t flags) +{ + memset(&core, 0, sizeof(core)); + lock_result = success; + locked = false; + locks = unlocks = reads = 0; + expected_state = state; + expected_flags = flags; + uint32_t value = UINT32_MAX; + output = with_flags ? &value : NULL; + enum obs_hotkeys_background_state result = obs_hotkeys_get_background_state(output); + assert_int_equal(result, success ? state : OBS_HOTKEYS_BACKGROUND_NATIVE); + assert_int_equal(value, with_flags ? (success ? flags : 0) : UINT32_MAX); + assert_int_equal(locks, 1); + assert_int_equal(unlocks, success ? 1 : 0); + assert_int_equal(reads, success ? (with_flags ? 2 : 1) : 0); + assert_false(locked); +} + +static void failed_lock(void **unused) +{ + (void)unused; + query(false, true, OBS_HOTKEYS_BACKGROUND_ACTIVE, UINT32_MAX); + query(false, false, OBS_HOTKEYS_BACKGROUND_ACTIVE, UINT32_MAX); +} + +static void states_and_flags(void **unused) +{ + (void)unused; + const enum obs_hotkeys_background_state states[] = { + OBS_HOTKEYS_BACKGROUND_NATIVE, + OBS_HOTKEYS_BACKGROUND_ACTIVE, + OBS_HOTKEYS_BACKGROUND_STARTING, + OBS_HOTKEYS_BACKGROUND_IDLE, + OBS_HOTKEYS_BACKGROUND_WAITING, + OBS_HOTKEYS_BACKGROUND_DECLINED, + OBS_HOTKEYS_BACKGROUND_CLOSED, + OBS_HOTKEYS_BACKGROUND_FAILED, + OBS_HOTKEYS_BACKGROUND_UNAVAILABLE, + /* Characterized, not endorsed: unknown native enum values pass through. */ + (enum obs_hotkeys_background_state)12345, + }; + const uint32_t flags[] = {0, 1, UINT32_C(0x80000000), UINT32_C(0xa5a51234), UINT32_MAX}; + for (size_t s = 0; s < sizeof(states) / sizeof(states[0]); s++) { + for (size_t f = 0; f < sizeof(flags) / sizeof(flags[0]); f++) { + query(true, true, states[s], flags[f]); + query(true, false, states[s], flags[f]); + } + } +} + +int main(void) +{ + const struct CMUnitTest tests[] = {cmocka_unit_test(failed_lock), cmocka_unit_test(states_and_flags)}; + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/test/cmocka/tests.d/test_hotkey_background_state.cmake b/test/cmocka/tests.d/test_hotkey_background_state.cmake new file mode 100644 index 0000000000..097d1362a9 --- /dev/null +++ b/test/cmocka/tests.d/test_hotkey_background_state.cmake @@ -0,0 +1 @@ +# Both target and test are declared in ../build/test-graph.json.