Repository navigation
libobs: Drop empty hotkey bindings and signal when a load clears them - #1649
Merged
Merged
Conversation
test_hotkey_bindings_codec and its Tier 1 port pin two load behaviours
as "characterized, not endorsed". This changes those expectations to
the intended behaviour; the fix follows.
- load_binding() means to drop an item with no modifiers and no known
key: the 2014 check is `!modifiers && (key == OBS_KEY_NONE || ...)`,
but `modifiers` is the address of combo.modifiers, never NULL, so
nothing is dropped. {} and an unknown, empty, missing or non-string
key load as a binding of OBS_KEY_NONE that never fires and is saved
back as {"key":"OBS_KEY_NONE"}. Now such items, the saved
{"key":"OBS_KEY_NONE"} included, are expected to load as nothing.
Modifier-only bindings stay: handle_binding() fires them.
- An empty or missing array clears the hotkey's bindings without
hotkey_bindings_changed, because load_bindings() signals only when
the array has items, while obs_hotkey_load_bindings() also signals
when it removed bindings. Now an empty or NULL load is expected to
signal when it removed bindings, and not when there were none.
Changed assertions: unknown_or_missing_key_kept_as_none (renamed
unknown_or_missing_key_dropped) expects "[]"; every_key_name skips
OBS_KEY_NONE alone; pair_round_trip expects {} dropped;
empty_array_clears_without_signal (renamed
empty_array_clears_with_signal) expects a signal per clear that removed
bindings, and none for a clear of nothing. In the Tier 1 port the same
cases, plus the edge tests that pinned "never None":
from_fields_never_drops (renamed from_fields_drops_only_empty),
from_fields_every_key_name and to_fields_then_from_fields.
soldr cargo test -p obs-data --test obs-tests-core hotkey::bindings
fails 6 of 35: unknown_or_missing_key_dropped,
empty_array_clears_with_signal, pair_round_trip and the three edge
tests (every_key_name passes either way). test_hotkey_bindings_codec
fails 3 of 18 (the same three cases) against libobs of both lanes and
libobs-c-reference.
Refs obs-rust#1648
Two hotkey load fixes, in the C and in the Rust port of the codec alike.
obs_hotkey_combination_from_data() (the parse of load_binding()) tested
`!modifiers`, the address of combo.modifiers, which is never NULL, so
the drop the 2014 code meant (no modifiers and no known key) never
happened. {} and an unknown, empty, missing or non-string key loaded as
a binding of OBS_KEY_NONE that handle_binding() never fires, and every
save wrote it back as {"key":"OBS_KEY_NONE"}. It now tests
combo.modifiers, and combo_from_fields() in rust/obs-hotkey returns None
for the same items, so such items load as nothing and are gone after
the next save. Files that have them still load: the entries are just
dropped. Modifier-only bindings (OBS_KEY_NONE with modifiers) are kept;
handle_binding() fires them.
load_bindings() sent hotkey_bindings_changed only when the array had
items, so obs_hotkey_load() and obs_hotkey_pair_load() with an empty or
NULL array removed the hotkey's bindings without telling anyone
(Settings > Hotkeys, the Wayland global-shortcut sync). They now pass
what remove_bindings() returned, and load_bindings() also signals when
it removed bindings, as obs_hotkey_load_bindings() does since 2023.
Registration and a source's hotkey data remove nothing first, so they
pass false and are unchanged.
The Tier 1 model of load_bindings() follows the C. The Tier 3 parity
test compares the Rust codec against the same C file, so it needs no
exclusion. rust/README.md no longer lists the kept behaviour.
test_hotkey_bindings_codec: 18/18 against libobs (C backend), hybrid
libobs and libobs-c-reference; exported symbols identical (1766).
hotkey:: tests in obs-tests-core: 92/92.
Fixes obs-rust#1648
rdoupe
force-pushed
the
fix/hotkey-binding-load
branch
from
October 21, 2026 19:40
1c86871 to
28bd4f6
Compare
zackees
enabled auto-merge
October 21, 2026 19:41
This was referenced Oct 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1648
What and why
Two hotkey load fixes, made identically in the C (
libobs/obs-hotkey-bindings.c.h,libobs/obs-hotkey.c.h) and in the Rust port of the codec (obs-hotkey::bindings, #1628). Both were pinned as "characterized, not endorsed" bytest_hotkey_bindings_codec(#1622) and listed as follow-ups on #1621.obs_hotkey_combination_from_data(), the parse ofload_binding(), tested!modifiers, the address ofcombo.modifiers, which is never NULL. So the drop that the 2014 code meant (no modifiers, and the key isOBS_KEY_NONEor out of range) never happened:{}and an unknown, empty, missing or non-string"key"loaded as a binding ofOBS_KEY_NONEthathandle_binding()never fires, and every save wrote it back as{"key":"OBS_KEY_NONE"}. It now testscombo.modifiers, andcombo_from_fields()returnsNonefor the same items.{"shift":true}(keyOBS_KEY_NONEwith modifiers) is a real hotkey:handle_binding()has a modifiers-only path that fires it, and the 2014 check only ever meant to drop items with no modifiers. It loads and saves as before.load_bindings()senthotkey_bindings_changedonly when the array had items, soobs_hotkey_load()andobs_hotkey_pair_load()with an empty or NULL array removed the hotkey's bindings without telling the listeners (Settings > Hotkeys, the Wayland global-shortcut sync). They now pass on whatremove_bindings()returned, andload_bindings()signalsif (count || removed), the ruleobs_hotkey_load_bindings()has used since upstream's "Do not send hotkey_bindings_changed if nothing changed" (2023). Clearing a hotkey that had no bindings still sends nothing. Registration and a source's hotkey data (enum_load_bindings) remove nothing first, so they passfalseand are unchanged.{"key":"OBS_KEY_NONE"}(or{}, or an unknown key name) load without error; those entries are dropped and are not saved back, and the bindings next to them are kept. Such an entry never fired, so no hotkey stops working.libobs/obs-hotkey.c(load_binding()andload_bindings()). There is no upstream report (searched obsproject/obs-studio issues for "OBS_KEY_NONE", "hotkey_bindings_changed", "hotkeys not saved", "obs_hotkey_load", "hotkey binding empty" and more).bindings_paritycompares the Rust codec against the same C file (the oracle includes it), so both sides change together and it needs no exclusion. The Tier 1 model ofload_bindings()follows the C. The rust/README.md row no longer lists the kept behaviour.This deliberately changes existing tests (needs maintainer sign-off). The RED commit changes only the assertions that pinned these two behaviours, in
test/cmocka/test_hotkey_bindings_codec.cand its Tier 1 portrust/obs-hotkey/tests/hotkey/bindings.rs, modelled on #1508:unknown_or_missing_key_kept_as_none→unknown_or_missing_key_dropped(C and Tier 1): its 13 inputs ({}, unknown, empty, non-string and"OBS_KEY_NONE"keys) now save as[], not[{"key":"OBS_KEY_NONE"}]. That{"key":"OBS_KEY_NONE"}input is the compatibility case: it loads and is dropped.pair_round_trip(C and Tier 1): the pair's second array[{"command":true,"key":"OBS_KEY_2"},{}]now saves without the{}(it was{"key":"OBS_KEY_NONE"}); this is also the mixed case, the real binding next to the junk is kept.every_key_name(C and Tier 1): skipsOBS_KEY_NONE, which it wrote with no modifiers, as it skips MOUSE1 and MOUSE2. Alone it is no binding now; with a modifier it still round-trips (modifiers_only, unchanged).empty_array_clears_without_signal→empty_array_clears_with_signal(C and Tier 1):obs_hotkey_load()with[]and with NULL each count onehotkey_bindings_changedwhen they removed bindings (the counts after them go up by one each), and a second clear of the now-empty hotkey, added for each, counts none, the same pattern the test already used forobs_hotkey_load_bindings(NULL, 0).None":from_fields_never_drops→from_fields_drops_only_empty(no modifiers givesNonefor every unknown name; any modifiers giveOBS_KEY_NONE),from_fields_every_key_name(OBS_KEY_NONEalone givesNone), andto_fields_then_from_fields(a saved binding with no modifiers and no known key comes back asNone).No other test changes.
modifiers_only,source_round_trip(whose modifier-only"nope"key stays) and the other cases are unchanged and pass.Headless (private Xvfb, private D-Bus, fresh HOME). The real-app case: a scene collection whose media source has
"libobs.mute":[{},{"key":"bogus"}],"libobs.unmute":[{"key":"OBS_KEY_NONE"},{"key":"OBS_KEY_F7"}]and"libobs.push-to-talk":[{"shift":true}]; start OBS, quit, read the saved collection.[{"key":"OBS_KEY_NONE"},{"key":"OBS_KEY_NONE"}]; unmute keeps{"key":"OBS_KEY_NONE"}next to F7test_hotkey_bindings_codecwith the RED expectationstest_hotkey_bindings_codecunknown_or_missing_key_dropped,empty_array_clears_with_signal,pair_round_trip)[]; unmute[{"key":"OBS_KEY_F7"}]; push-to-talk keeps{"shift":true,"key":"OBS_KEY_NONE"}; clean quittest_hotkey_bindings_codec,test_hotkey_load,test_wayland_hotkeys,test_portal_shortcutsRED → GREEN
test: Expect empty hotkey bindings dropped and empty loads to signal. On master,test_hotkey_bindings_codecfails 3 of 18 against libobs withOBS_LIBOBS_BACKEND=C, and against hybrid libobs and libobs-c-reference (HYBRID,OBS_BUILD_C_REFERENCE=ON).soldr cargo test -p obs-data --test obs-tests-core hotkey::bindings: 29 passed, 6 failed (the three mirrored cases and the three edge tests).test_hotkey_bindings_codec18/18 in both lanes and both libraries; exported symbols of libobs (C backend), hybrid libobs and libobs-c-reference identical (1766); fullctest -j4352/352 in the C-backend lane and in the hybrid lane against libobs and against libobs-c-reference, none skipped.hotkey::tests (Tiers 1 and 3): 92/92.uv run ci/local_gate.py --lane lint,--lane cross,--lane rust-test(1923 tests, 0 failed): ok.Checklist
masterdocs/features.mdis added (Fixed upstream bugs, Scenes and UI)-W..., ratchets): built with scripting ON (a flag change under cmake/ or build-aux/ runs the full builds) and cross-checked with clang and MSVC (not applicable: no flag change)