Repository navigation
libobs: Translate the arrow key names and skip empty hotkey templates - #1673
Merged
Merged
Conversation
…ates
test_hotkey_translations pins two behaviours of
obs_hotkeys_set_translations_s(): the arrow keys are never translated
("characterized, not endorsed"), and an empty or padding-only numpad
or mouse template crashes (described in a comment only, since as a
case it would crash the test). This changes the first expectation to
the intended behaviour and adds the second as cases; the fix follows.
- The struct has left, right, up and down and the frontend sets them,
but there is no ADD_TRANSLATION for them, so on Linux Settings >
Hotkeys shows English arrow key names in every language.
arrow_keys_not_applied (renamed arrow_keys_translated) now expects
the four translated names.
- For "", dstr_copy() leaves the template NULL, and for a padding-only
one dstr_depad() frees it; dstr_find() then calls strstr(NULL, "%1").
New cases: empty_templates_keep_defaults ("", " ", " \t\r\n ", before
any other set: the English names stay) and empty_templates_keep_names
("", " ", "\t", "\r\n" after a set: the names stay, while the other
template and a named key in the same struct still apply). They set
through set_checked(), which runs the set in a forked child first, so
a crash fails the case instead of aborting the binary.
Refs obs-rust#1656
obs_hotkeys_set_translations_s() had two bugs, pinned by test_hotkey_translations. - The struct has left, right, up and down, and the frontend sets them (Hotkeys.Left and the others), but there was no ADD_TRANSLATION for them. On Linux (X11 and Wayland), where obs_key_to_str() shows the stored name, Settings > Hotkeys showed English arrow key names in every language. They are now stored like the other named keys. Windows takes these names from the OS and macOS shows glyphs, so neither changes. - An empty numpad or mouse template leaves the dstr NULL after dstr_copy(), and a padding-only one is freed by dstr_depad(), so dstr_find() called strstr(NULL, "%1") and crashed. Such a template is now skipped like a NULL one, and those keys keep their names (the English defaults when nothing was set). No shipped locale has one; a hand-edited or third-party locale file, or a plugin, can. Upstream OBS master has the same code. Refs obs-rust#1656
rdoupe
force-pushed
the
fix/hotkey-translations
branch
from
October 21, 2026 23:09
c06701e to
ccdfac3
Compare
zackees
enabled auto-merge
October 21, 2026 23:11
6 of 7 tasks
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 2 of the plan: the C fix of the two bugs that #1657 pinned. The port, step 3, follows and closes the issue.)
What and why
Two fixes in
obs_hotkeys_set_translations_s()(libobs/obs-hotkey-translations.c.h), both pinned bytest_hotkey_translations(#1657) and described on #1656. This is C only: the file has no Rust port yet, so the port copies the fixed C and its Tier 1 and Tier 3 tests need no exceptions.left,right,upanddown, and the frontend sets them (Hotkeys.Leftand the others), but there was noADD_TRANSLATIONfor them. On Linux (X11 and Wayland), whereobs_key_to_str()shows the stored name, Settings > Hotkeys showed "Left", "Right", "Up" and "Down" in English whatever the language. The four lines are added, after Pause in struct order. Windows takes these names from the OS (GetKeyNameTextW), and macOS shows glyphs (the arrows are not in itskey_descriptionstable), so neither platform changes."",dstr_copy()leaves the numpad or mouse template'sdstrNULL, and for a padding-only stringdstr_depad()frees it;dstr_find()then calledstrstr(NULL, "%1")and crashedobs_hotkeys_set_translations_s(), and with it OBS at startup. Such a template is now skipped like a NULL one (dstr_is_empty()after the depad), so NUM0-NUM9 or MOUSE1-MOUSE29 keep their names: the English defaults when nothing else was set. No shipped locale has such a template (all 136 entries in the 77 locales contain%1, here and upstream), so only a hand-edited or third-party locale file, or a plugin passing the struct, can reach it. The input is the frontend's own installed locale or in-process plugin code, so this is a local crash, not untrusted input.struct obs_hotkeys_translationsand its size-prefixed copy are unchanged. A non-empty template expands exactly as before (the 14 existing cases pass unchanged apart from the arrow-key one).libobs/obs-hotkey.c(no arrow-keyADD_TRANSLATION, and the samedstr_copy/dstr_depad/dstr_findsequence). There is no upstream report: searched obsproject/obs-studio issues for "hotkey arrow key translation", "arrow keys english", "Left Right Up Down hotkeys translated", "arrow keys", "hotkey translation", "hotkeys translated", "Hotkeys.Left", "Pfeiltaste" and more.This deliberately changes an existing test (needs maintainer sign-off). The RED commit changes only the assertions in
test/cmocka/test_hotkey_translations.cthat pinned bug 1, and adds the bug-2 cases as new cases, modelled on #1649:arrow_keys_not_applied→arrow_keys_translated: after settingleft,right,upanddownto "Links", "Rechts", "Hoch" and "Runter", its four assertions now expect those names forOBS_KEY_LEFT,OBS_KEY_RIGHT,OBS_KEY_UPandOBS_KEY_DOWN, not the English "Left", "Right", "Up" and "Down". Its "characterized, not endorsed" comment is replaced, and so is the pointer to it in thenamed_keyscomment.New cases (bug 2), which must not crash:
empty_templates_keep_defaults, run second, right afterdefaults_before_any_setand before any other set (the store can't be cleared):""," "and" \t\r\n "as both templates leave "Numpad 0", "Numpad 9", "Mouse 1" and "Mouse 29".empty_templates_keep_names, run last: after a set,""," ","\t"and"\r\n"as one template keep that template's names, while the other template and a named key (insert) in the same struct still apply.set_checked(), which runs the set in a forked child first (default crash signal actions, no core file) and fails the case if the child dies, then repeats the set in the test process. So on master the RED run reports a failed case with the signal instead of aborting the binary.No other test changes. The other 13 cases are unchanged and pass.
named_keysstill leaves out the arrow keys, soevery_memberand the other table-driven cases do not cover them; the port's Tier 1 test can add them there.Headless (private Xvfb, private D-Bus, fresh HOME).
test_hotkey_translationsarrow_keys_translated(OBS_KEY_LEFT: got "Left", expected "Links"),empty_templates_keep_defaultsandempty_templates_keep_names(obs_hotkeys_set_translations_s crashed: signal 11)test_hotkey_translationstest_hotkey_bindings_codec,test_hotkey_load,test_wayland_hotkeys,test_portal_shortcutsRED → GREEN
test: Expect translated arrow keys and no crash on empty hotkey templates. On master,test_hotkey_translationsfails 3 of 16 against libobs withOBS_LIBOBS_BACKEND=C, and against hybrid libobs and libobs-c-reference (HYBRID,OBS_BUILD_C_REFERENCE=ON): the arrow-key case, and the two empty-template cases, whose forked child dies with SIGSEGV.test_hotkey_translations16/16 in both lanes and against all three libraries, 3 runs each. Exported symbols of libobs (C backend), hybrid libobs and libobs-c-reference identical (1766);obs_hotkeys_store_key_translationstays local. Fullctest -j4, 358 tests:OBS_LIBOBS_BACKEND=Ctest_effect_parser_lifecycle_rustnot built (see below)HYBRID,OBS_BUILD_C_REFERENCE=ONtest_audio_controlsflaky (see below)HYBRID,OBS_BUILD_C_REFERENCE=ONNone skipped. Both failures are outside this change and also happen without it:
test_effect_parser_lifecycle_rust(rust: port effect parser lifecycle to obs-graphics #1650) linkslibobs_rust-staticunconditionally, and that target does not exist withOBS_LIBOBS_BACKEND=C, so the C-backend build of master fails to link it (cannot find -llibobs_rust-static). It failed the same way at the RED commit, which has no libobs change.test_audio_controlssometimes fails insource_setup(obs_startup()/obs_reset_audio(), "Test setup failed" onchannel_count_clamps_test): 2 to 5 of 10 isolated runs in each lane. It never sets translations; it passed in the C-backend and libobs-c-reference full runs.uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed. clang-format 23.1 is clean on the changed files.obs_key_to_str(), whichtest_hotkey_translationsreads through the public API of the real libobs; no headless check of the dialog's labels was done. So this isRefs, and the port closes the issue.Windows/macOS: not built there. The arrow-key lines change nothing on either (above); the empty-template skip is portable C. The test stays Linux and FreeBSD only;
fork(),waitpid()andsetrlimit()are POSIX.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (Fixed upstream bugs, Scenes and UI)-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)