Skip to content

libobs: Drop empty hotkey bindings and signal when a load clears them - #1649

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/hotkey-binding-load
Oct 21, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/hotkey-binding-load

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

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" by test_hotkey_bindings_codec (#1622) and listed as follow-ups on #1621.

  • Empty bindings are dropped. obs_hotkey_combination_from_data(), the parse of load_binding(), tested !modifiers, the address of combo.modifiers, which is never NULL. So the drop that the 2014 code meant (no modifiers, and the key is OBS_KEY_NONE or out of range) 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() returns None for the same items.
  • Modifier-only bindings stay. {"shift":true} (key OBS_KEY_NONE with 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.
  • A load that clears signals. 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 the listeners (Settings > Hotkeys, the Wayland global-shortcut sync). They now pass on what remove_bindings() returned, and load_bindings() signals if (count || removed), the rule obs_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 pass false and are unchanged.
  • Compatibility. No format change. Existing profiles and scene collections with {"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.
  • Upstream. OBS master has the same code in libobs/obs-hotkey.c (load_binding() and load_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).
  • Tier 3: bindings_parity compares 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 of load_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.c and its Tier 1 port rust/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): skips OBS_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 one hotkey_bindings_changed when 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 for obs_hotkey_load_bindings(NULL, 0).
  • Tier 1 only, the edge tests that pinned "never None": from_fields_never_drops → from_fields_drops_only_empty (no modifiers gives None for every unknown name; any modifiers give OBS_KEY_NONE), from_fields_every_key_name (OBS_KEY_NONE alone gives None), and to_fields_then_from_fields (a saved binding with no modifiers and no known key comes back as None).

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.

Build Case Result
v0.1.0-beta.20261018 AppImage real app, the collection above mute saved as [{"key":"OBS_KEY_NONE"},{"key":"OBS_KEY_NONE"}]; unmute keeps {"key":"OBS_KEY_NONE"} next to F7
v0.1.0-beta.20261018 AppImage (its libobs) test_hotkey_bindings_codec with the RED expectations 3 of 18 fail
master d412d8b + RED, libobs (C backend), hybrid libobs, libobs-c-reference test_hotkey_bindings_codec 3 of 18 fail (unknown_or_missing_key_dropped, empty_array_clears_with_signal, pair_round_trip)
This branch, C backend and hybrid real app, the collection above mute saved as []; unmute [{"key":"OBS_KEY_F7"}]; push-to-talk keeps {"shift":true,"key":"OBS_KEY_NONE"}; clean quit
This branch, libobs (C backend), hybrid libobs, libobs-c-reference test_hotkey_bindings_codec, test_hotkey_load, test_wayland_hotkeys, test_portal_shortcuts 18/18, 7/7, 8/8, 28/28 in each

RED → GREEN

  • RED commit: eae3f7c test: Expect empty hotkey bindings dropped and empty loads to signal. On master, test_hotkey_bindings_codec fails 3 of 18 against libobs with OBS_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).
  • GREEN: 28bd4f6. test_hotkey_bindings_codec 18/18 in both lanes and both libraries; exported symbols of libobs (C backend), hybrid libobs and libobs-c-reference identical (1766); full ctest -j4 352/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.
  • Real app: the run above. No UI or log change; the saved collection no longer keeps the junk entries.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • User-visible change: its line in docs/features.md is added (Fixed upstream bugs, Scenes and UI)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-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)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (none new; the README row drops the kept behaviour)

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
@rdoupe
rdoupe requested a review from zackees as a code owner October 21, 2026 19:40
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
rdoupe force-pushed the fix/hotkey-binding-load branch from 1c86871 to 28bd4f6 Compare October 21, 2026 19:40
@zackees
zackees enabled auto-merge October 21, 2026 19:41
@zackees
zackees added this pull request to the merge queue Oct 21, 2026
Merged via the queue into obs-rust:master with commit 865938d Oct 21, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: hotkey loading keeps empty bindings and clears without hotkey_bindings_changed

2 participants