Repository navigation
libobs: Move the hotkey binding codec into obs-hotkey-bindings.c - #1622
Merged
Merged
Conversation
Behavior-neutral extraction before the Rust port: the hotkey binding
codec, which turns one item of a hotkey's saved bindings array into an
obs_key_combination_t and back, moves from libobs/obs-hotkey.c.h into
libobs/obs-hotkey-bindings.c.h. load_modifier() and save_modifier() move
verbatim and stay static inline. The parse of load_binding(), the
primary mouse button rule of create_binding() and the per-binding body of
save_bindings_helper() move verbatim into three functions, declared in
obs-internal.h without EXPORT:
- obs_hotkey_combination_from_data(): false where load_binding()
returned without a binding;
- obs_hotkey_combination_bindable(): the MOUSE1/MOUSE2 rule, for JSON
and API bindings alike;
- obs_hotkey_combination_to_data().
load_binding(), create_binding() and save_bindings_helper() call them
and keep the bindings array, the hotkey and the signals. The new file
joins libobs.core just before obs-hotkey.c.h (alphabetical), with
libobs.pch.h. No group, PCH or CMake source list change; the exported
symbols are unchanged. test_hotkey_load, test_wayland_hotkeys and
test_portal_shortcuts compile obs-hotkey.c.h on its own, so they now
compile the new file next to it (CMake and the obs-build manifest).
New characterization test test_hotkey_bindings_codec. test_hotkey_load
compiles the C into itself, so it cannot see a Rust swap; the new test
links the real libobs (obs_startup) and uses the public API only:
obs_hotkey_load/obs_hotkey_save, obs_hotkey_load_bindings, the pair
load and save, and a source's hotkey data (obs_source_create,
obs_hotkeys_save_source). It compares the saved JSON byte for byte and
checks that save -> load -> save gives the same bytes. It pins each
modifier alone, all 16 modifier sets and the saved key order (shift,
control, alt, command, key); that only a JSON true sets a modifier;
every key name; unknown, empty, missing and non-string keys; {} and
modifier-only bindings; MOUSE1 and MOUSE2 rejected with and without
modifiers, MOUSE3 kept; duplicates and load order; items that are not
objects; that a load replaces only its own hotkey's bindings; an empty
save; pairs; a source's hotkeys; and when hotkey_bindings_changed is
sent.
Characterized, not endorsed:
- load_binding()'s check meant to drop an item with no modifiers and no
known key tests the address of the modifiers, which is never NULL, so
it drops nothing: {} and an unknown, empty or missing key load as an
OBS_KEY_NONE binding and are saved back as {"key":"OBS_KEY_NONE"};
- an empty or missing array clears the bindings without
hotkey_bindings_changed, since load_bindings() signals only when the
array has items.
Refs obs-rust#1621
zackees
enabled auto-merge
October 21, 2026 15:11
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 21, 2026
This was referenced Oct 21, 2026
Closed
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.
Refs #1621 (PR 1 of the plan: the characterization and the extraction; the port follows)
What and why
Behaviour-neutral extraction before the Rust port, as the testing policy asks for part of a large file: the hotkey binding codec moves from
libobs/obs-hotkey.c.hintolibobs/obs-hotkey-bindings.c.h. The codec turns one item of a hotkey's saved bindings array into anobs_key_combination_tand back, so this is the on-disk hotkey format of every profile and scene collection. The move comes with a real-libobs characterization test,test_hotkey_bindings_codec. No Rust, no format or behaviour change, and no public header change.What moves:
load_modifier()andsave_modifier(), verbatim, stillstatic inline;load_binding(), verbatim, asobs_hotkey_combination_from_data(). It returns false whereload_binding()returned without a binding;create_binding()(ours), verbatim, asobs_hotkey_combination_bindable(). It still covers JSON andobs_hotkey_load_bindings()bindings alike;save_bindings_helper()asobs_hotkey_combination_to_data(). The lines are the same, withbinding->key.modifiersandbinding->key.keyread from thecomboargument.The three functions are declared in
obs-internal.hwithoutEXPORT. They are the entry points the port will replace.Not moved:
load_binding(),create_binding()(theda_push_back_new),load_bindings()(thehotkey_bindings_changedsignal),save_bindings_helper()and every load and save entry point. They keepobs->hotkeys.bindings, the uthash tables andstruct obs_hotkey, and now call the three functions.Build: the new file joins the existing
libobs.coregroup just beforeobs-hotkey.c.h(alphabetical), withlibobs.pch.hlike every member of that group. It needs nothing that header does not already give. No group, PCH,source-sets.jsonor CMake source list change.obs-buildbuilds the same group file, so the Rust lane needs no change either.ci/test_build_groups.pypasses.Tests that compile
obs-hotkey.c.hon their own:test_hotkey_load,test_wayland_hotkeysandtest_portal_shortcutsnow compileobs-hotkey-bindings.c.hnext to it (CMake, and the obs-build C test manifest fortest_hotkey_load). Their test files are unchanged.Exported symbols: unchanged (1766 in both lanes, both libraries). The three new functions are hidden.
test_hotkey_loadcompiles the C into itself, so it cannot see a Rust swap. The new test links the real libobs (obs_startup(), under xvfb-run on Linux liketest_missing_files) and uses only the public API:obs_hotkey_load/obs_hotkey_saveon a frontend hotkey,obs_hotkey_load_bindings,obs_hotkey_pair_load/obs_hotkey_pair_save, and a source's hotkey data (obs_source_createwith hotkey data,obs_hotkeys_save_source). The saved JSON is compared byte for byte, and in most cases save → load → save must give the same bytes again. The 18 cases:truesets one (a string,1,1.0,null,{}and[]do not); misspelt or differently cased names are dropped; API bits other than the four are dropped.obs_key_from_name(obs_key_to_name(k)) == k, and the array is a fixpoint); unknown, wrongly cased, padded, empty, numeric, bool, null and object keys;{}; modifier-only bindings.[]and an unknown id saves nothing; whenhotkey_bindings_changedis sent.[], and a second source made from the saved data saving the same bytes.Characterized, not endorsed (comments in the test, and in the issue):
load_binding()means to drop an item with no modifiers and no known key, but its check,!modifiers, tests the address ofcombo.modifiers, which is never NULL. So it drops nothing:{}and an unknown, empty, missing or non-string key load as a binding ofOBS_KEY_NONEand are saved back as{"key":"OBS_KEY_NONE"}. Such a binding never fires (handle_binding()resets a modifier-lessOBS_KEY_NONE), so the cost is a dead entry that survives every save.hotkey_bindings_changed, becauseload_bindings()signals only when the array has items.obs_hotkey_load_bindings()does signal when it removed bindings, and a non-empty array signals even when every item is rejected.Both are kept here and by the port; each gets its own PR with its own test change after the port.
RED → GREEN
909ae93e7libobs: Move the hotkey binding codec into obs-hotkey-bindings.c.test_hotkey_bindings_codec: 18/18, run 3 times in each lane against both libraries, all passing. It also passes, 18/18, against a libobs built from master'sobs-hotkey.c.h(the libobs changes reverted, the test kept), so the move changes nothing it can see.!modifierscheck made!*modifiers(the fix of the first quirk); MOUSE1 or MOUSE2 dropped from the rule; the rule bypassed increate_binding();commandloaded as alt;controlloaded under another name;shiftnot saved; control and alt saved in swapped order;keynot saved forOBS_KEY_NONE;load_bindings()signalling for an empty array.ENABLE_RUST_LIBOBS=OFFandON, full builds). Each runs the full cmocka suite againstlibobsand againstlibobs-with-rust, headless (private Xvfb, private D-Bus, fresh HOME):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)Nothing was skipped or failed to run. These runs are on master at #1619; a final rebase onto #1620 (the caption text port, no hotkey file) was rebuilt in both lanes, and the new test, the hotkey, portal, Wayland and caption tests, the export counts (1766) and
ci/test_build_groups.pypassed again on it.test_hotkey_load,test_wayland_hotkeys,test_portal_shortcutsandtest_portal_shortcut_idspass in all four, unchanged.uv run ci/local_gate.py --lane lint: passed.--lane cross: passed. clang-format 23.1 is clean on the changed files, gersemi is clean on the CMake files, andci/test_build_groups.pypasses (group order).Windows/macOS: not built there. The moved code has no host conditionals. The new test is portable C (no cmocka range assertions) and uses only the public libobs API. On Linux it runs under xvfb-run when it is installed; without a display
obs_startup()fails and the test prints a skip and exits 0, astest_output_caption_textdoes.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-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)