Skip to content

libobs: Translate the arrow key names and skip empty hotkey templates - #1673

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

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

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

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 by test_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.

  • The arrow keys are translated. 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 "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 its key_descriptions table), so neither platform changes.
  • An empty or padding-only template no longer crashes. For "", dstr_copy() leaves the numpad or mouse template's dstr NULL, and for a padding-only string dstr_depad() frees it; dstr_find() then called strstr(NULL, "%1") and crashed obs_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.
  • Compatibility. No format, API or header change. struct obs_hotkeys_translations and 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).
  • Upstream. OBS master has the same code in libobs/obs-hotkey.c (no arrow-key ADD_TRANSLATION, and the same dstr_copy/dstr_depad/dstr_find sequence). 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.c that pinned bug 1, and adds the bug-2 cases as new cases, modelled on #1649:

  • arrow_keys_not_applied → arrow_keys_translated: after setting left, right, up and down to "Links", "Rechts", "Hoch" and "Runter", its four assertions now expect those names for OBS_KEY_LEFT, OBS_KEY_RIGHT, OBS_KEY_UP and OBS_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 the named_keys comment.
  • The header comment that left the empty template out of the test ("Not covered here, on purpose: ...") now describes the new cases.

New cases (bug 2), which must not crash:

  • empty_templates_keep_defaults, run second, right after defaults_before_any_set and 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.
  • Both set through a new helper, 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_keys still leaves out the arrow keys, so every_member and 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).

Build Case Result
master 1921d4e + RED, libobs (C backend), hybrid libobs, libobs-c-reference test_hotkey_translations 3 of 16 fail in each: arrow_keys_translated (OBS_KEY_LEFT: got "Left", expected "Links"), empty_templates_keep_defaults and empty_templates_keep_names (obs_hotkeys_set_translations_s crashed: signal 11)
This branch, libobs (C backend), hybrid libobs, libobs-c-reference test_hotkey_translations 16/16, 3 runs each
This branch, the same three 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: 0cbb77c test: Expect translated arrow keys and no crash on empty hotkey templates. On master, test_hotkey_translations fails 3 of 16 against libobs with OBS_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.
  • GREEN: ccdfac3 (rebased onto 59fb798, ci: retain Ubuntu OFF and ON compiler caches independently #1671; both trees rebuilt, and the hotkey tests and the symbol comparison passed again). test_hotkey_translations 16/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_translation stays local. Full ctest -j4, 358 tests:
Lane Library ctest
OBS_LIBOBS_BACKEND=C libobs 357/358: test_effect_parser_lifecycle_rust not built (see below)
HYBRID, OBS_BUILD_C_REFERENCE=ON hybrid libobs 357/358: test_audio_controls flaky (see below)
HYBRID, OBS_BUILD_C_REFERENCE=ON libobs-c-reference 358/358

None 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) links libobs_rust-static unconditionally, and that target does not exist with OBS_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_controls sometimes fails in source_setup (obs_startup()/obs_reset_audio(), "Test setup failed" on channel_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.
  • Also run: uv run ci/local_gate.py --lane lint passed, and --lane cross passed. clang-format 23.1 is clean on the changed files.
  • Real app (UI, protocol output or logging changes): not run. The Settings > Hotkeys names come from obs_key_to_str(), which test_hotkey_translations reads through the public API of the real libobs; no headless check of the dialog's labels was done. So this is Refs, 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() and setrlimit() are POSIX.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • 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 (the characterization is libobs: Move the hotkey key-name translations into obs-hotkey-translations.c #1657)
  • User-visible change: its line in docs/features.md is added or updated (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 (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: no port here)

…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
@rdoupe
rdoupe requested a review from zackees as a code owner October 21, 2026 23:09
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
rdoupe force-pushed the fix/hotkey-translations branch from c06701e to ccdfac3 Compare October 21, 2026 23:09
@zackees
zackees enabled auto-merge October 21, 2026 23:11
@zackees
zackees added this pull request to the merge queue Oct 21, 2026
Merged via the queue into obs-rust:master with commit b8f97ed Oct 21, 2026
23 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.

2 participants