Repository navigation
libobs: Move the hotkey key-name translations into obs-hotkey-translations.c - #1657
Merged
zackees merged 1 commit intoOct 21, 2026
Merged
Conversation
…tions.c
Behavior-neutral extraction before the Rust port:
obs_hotkeys_set_translations_s() moves verbatim from libobs/obs-hotkey.c.h
into libobs/obs-hotkey-translations.c.h. It stores the frontend's
translated names of the named keys and expands the numpad and mouse
templates ("Numpad %1", "Mouse %1") into the names of NUM0-NUM9 and
MOUSE1-MOUSE29. The store, obs_set_key_translation(), stays in
obs-hotkey.c.h as obs_hotkeys_store_key_translation(), declared in
obs-internal.h without EXPORT; the moved code calls it under that name.
The ADD_TRANSLATION, ADD_NUMPAD_NUM and ADD_MOUSE_NUM #undefs move with
the macros.
The new file joins libobs.core just before obs-hotkey.c.h, with
libobs.pch.h. No group, PCH or source-sets.json change; the exported
symbols are unchanged and the store is hidden. The __APPLE__ keypad block
moves with the code (platform-ifdef baseline 1 -> 1). test_hotkey_load,
test_wayland_hotkeys and test_portal_shortcuts compile obs-hotkey.c.h on
their own, so they now compile the new file next to it (CMake and the
obs-build manifest).
New characterization test test_hotkey_translations. It links the real
libobs (obs_startup, under xvfb-run) and uses the public API only: it sets
translations with obs_hotkeys_set_translations_s() and reads them through
obs_key_to_str() and obs_key_combination_to_str(). Linux and FreeBSD
only, where obs_key_to_str() shows the stored name of every key the
struct names. It pins the English defaults; every named key, NUM0-NUM9
and MOUSE1-MOUSE29; the numpad and mouse templates with and without %1,
%1 twice, "%1%1", "%%1", "%11", padded, \v (not padding), printf-like
text, UTF-8 and non-UTF-8 bytes; a NULL member and a NULL struct (names
kept); a short and a larger size; setting twice; an empty name; the
apple_* members (ignored off macOS); and combinations.
Characterized, not endorsed: the struct's left, right, up and down are
never stored, so the arrow keys always show English names on Linux.
Not in the test: an empty or padding-only numpad or mouse template leaves
the template string NULL, and strstr(NULL, "%1") then crashes. That gets
its own fix.
Refs obs-rust#1656
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 #1656 (PR 1 of the plan: the characterization and the extraction. The fix PR and the port follow.)
What and why
This is a behaviour-neutral extraction before the Rust port, as the testing policy asks for part of a large file. The hotkey key-name translations move from
libobs/obs-hotkey.c.hintolibobs/obs-hotkey-translations.c.h. At startup the frontend passes in its translated names of the named keys and two templates,"Numpad %1"and"Mouse %1". Settings > Hotkeys shows the names throughobs_key_to_str(). The move comes with a real-libobs characterization test,test_hotkey_translations. There is no Rust, no behaviour change and no public header change.obs_hotkeys_set_translations_s(), verbatim, with itsADD_TRANSLATION,ADD_NUMPAD_NUMandADD_MOUSE_NUMmacros and their#undefs. The only edit is the name of the store it calls (below).obs_set_key_translation(), stays inobs-hotkey.c.hunder a new name,obs_hotkeys_store_key_translation(), with the same body. It is declared inobs-internal.hwithoutEXPORT, so it is hidden. It is the one accessor the port will call.obs_get_hotkey_translation(), the platformkey_to_strfunctions that readobs->hotkeys.translations[], and the audio and scene item translation setters also stay.libobs.coregroup just beforeobs-hotkey.c.h, in alphabetical order, withlibobs.pch.hlike every member of that group. The group, the PCH,source-sets.jsonand the CMake source lists are unchanged, andci/test_build_groups.pypasses.#ifdef __APPLE__keypad block moves with the code, so the platform-ifdef baseline goes from 1 to 1: its entry moves fromobs-hotkey.c.hto the new file. facade: libobs top-level files (obs-module, obs-display, obs-hotkey, obs-source, obs-internal, gpu-encode, audio-controls, media-remux): move 14 platform conditionals #870 tracks the facade move of this conditional; this PR leaves that to facade: libobs top-level files (obs-module, obs-display, obs-hotkey, obs-source, obs-internal, gpu-encode, audio-controls, media-remux): move 14 platform conditionals #870.obs-hotkey.c.hthemselves:test_hotkey_load,test_wayland_hotkeysandtest_portal_shortcutsnow compileobs-hotkey-translations.c.hnext to it, as they doobs-hotkey-bindings.c.h(CMake, and the obs-build C test manifest fortest_hotkey_load). Their test files are unchanged.obs_hotkeys_store_key_translationis a local (t) symbol.test_hotkey_translationslinks the real libobs. It callsobs_startup()(under xvfb-run on Linux, liketest_hotkey_bindings_codec) and uses only the public API: it sets translations withobs_hotkeys_set_translations_s()and reads them back throughobs_key_to_str()andobs_key_combination_to_str(). It is built on Linux and FreeBSD only, because thereobs_key_to_str()shows the stored name of every key the struct names. Windows shows only the mouse buttons, Pause and the Windows key, and macOS only some of the keys (Space, the keypad and the mouse buttons, for example). The 14 cases:NUM0-NUM9andMOUSE1-MOUSE29. A second set replaces every name it sets.size0 reads nothing.sizecut atleft, atmouse_numand atescapereads only the members before the cut, so an older, shorter struct reads as NULL tails.sizelarger than the struct reads only the struct.%1,%1twice,"%1%1","%%1"and"%11"(replaced left to right, without rescanning),"%2","% 1"and"100%";' ','\t','\r'and'\n', which are depadded, and\v, which is not;"%d %s", which is kept as text;apple_*members: on Linux they change nothing.Characterized, not endorsed (a comment in the test, and in the issue):
left,right,upanddown, and the frontend sets them, butobs_hotkeys_set_translations_s()has noADD_TRANSLATIONfor them. So on Linux (X11 and Wayland) the arrow keys always show English "Left", "Right", "Up" and "Down". Upstream has the same code.Left out of the test on purpose, and the follow-up fix:
"",dstr_copy()leaves the template NULL, and for" "dstr_depad()frees it.dstr_find()then callsstrstr(NULL, "%1"). As a test case it would crash the test, so it is described here and in a comment instead. No locale shipped today, here or upstream, has such a template: all 136Hotkeys.NumpadNum,Hotkeys.AppleKeypadNumandHotkeys.MouseButtonentries in the 77 locales contain%1. The input comes from the frontend's installed locale files, so this is a local crash, not untrusted input.RED → GREEN
239924e47libobs: Move the hotkey key-name translations into obs-hotkey-translations.c.test_hotkey_translationspasses 14/14, run 3 times against each of libobs with the C backend, the hybrid libobs and libobs-c-reference. It also passes 14/14 against a libobs built from master'sobs-hotkey.c.h(the libobs changes reverted, the test kept), so the move changes nothing the test can see." %1"not appended to the mouse template;sizeignored;MOUSE29not expanded;"%1 ".OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON, both full builds. Fullctest -j4, headless (private Xvfb, private D-Bus, fresh HOME):OBS_LIBOBS_BACKEND=CHYBRID,OBS_BUILD_C_REFERENCE=ONHYBRID,OBS_BUILD_C_REFERENCE=ONNothing was skipped or failed to run.
test_hotkey_bindings_codec(18/18),test_hotkey_load(7/7),test_wayland_hotkeys(8/8) andtest_portal_shortcuts(28/28) pass, unchanged, against all three. After the final rebase onto b133a77 (#1655), both trees were rebuilt, and the hotkey tests and the symbol comparison passed again.uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed. clang-format 23.1 and gersemi are clean on the changed files.ci/test_build_groups.pypasses, and so doesci/platform_ifdef_ratchet.py.Windows/macOS: not built there. The moved code's one host conditional (
__APPLE__) is unchanged. The new test is built for Linux and FreeBSD only, and it is portable C (no cmocka range assertions). Without a display,obs_startup()fails, and the test prints a skip and exits 0, astest_hotkey_bindings_codecdoes.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 (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change; the platform-ifdef baseline entry only moves with the code)