Repository navigation
Description
Port the hotkey key-name translations of libobs/obs-hotkey.c.h to the existing crate rust/obs-hotkey as a new module, translations. At startup the frontend passes obs_hotkeys_set_translations() its translated names of the named keys (Insert, Page Up, Shift, Numpad /, ...) and two templates, "Numpad %1" and "Mouse %1". libobs stores each name and expands the templates into the names of NUM0-NUM9 and MOUSE1-MOUSE29. Settings > Hotkeys shows these names through obs_key_to_str() and obs_key_combination_to_str().
obs_hotkeys_set_translations_s(EXPORT): it copiesmin(size, sizeof)bytes of the public struct, so an older, shorter struct reads as NULL tails. Then it applies theADD_TRANSLATIONtable (with the#ifdef __APPLE__keypad block) and expands the numpad and mouse templates. The expansion depads the template (only' ','\t','\n'and'\r'), appends" %1"if it has no%1, and replaces every%1, left to right and without rescanning, with the digits.
About 130 lines. These stay C:
- the store,
obs_set_key_translation(itbfrees andbstrdups intoobs->hotkeys.translations[]). It becomes a hidden wrapper,obs_hotkeys_store_key_translation(); obs_get_hotkey_translation, and the platformkey_to_strfunctions that read the array (obs-nix-x11.c.h,obs-nix-wayland.c.h,obs-windows.c.h,obs-cocoa.m.h);obs_hotkeys_set_audio_hotkeys_translationsandobs_hotkeys_set_sceneitem_hotkeys_translations, which are plain setters.
Phase and position
Phase 6 (#444), libobs core through opaque seams. It joins rust/obs-hotkey, which already holds the key name map, the Wayland key state, the portal shortcut id codec and the binding codec (#1621). It is part of a large file, so it goes in through function extraction (testing-policy.md, "Extracting a function before porting it"). Its Rust tests join the crate's existing tests/hotkey/ binary. No new test binary.
Dependencies and existing tests
struct obs_hotkeys_translations(obs-hotkey.h) is a public, stable layout of 38const char *. Its size-prefixed copy is kept as it is. The struct is#ifndef SWIG, so scripts never pass it.- One accessor: the hidden store wrapper
obs_hotkeys_store_key_translation(obs_key_t, const char *), declared inobs-internal.hwithoutEXPORT. Rust exportsobs_hotkeys_set_translations_sand calls the wrapper with each formatted string. No struct internals are exposed. - The template expansion needs
dstr_depadanddstr_replacesemantics. The safe core implements them over bytes, for examplefn expand(template: &[u8], digits: &str) -> Option<Vec<u8>>plus the key table. It needs no obs-util dependency.%1is not a printf format, and the port must keep it that way: no template is ever passed throughformat!or printf. - Today there is no test of the translations. The frontend calls them once, in
OBSBasic::InitHotkeys().test_hotkey_load,test_wayland_hotkeysandtest_portal_shortcutscompileobs-hotkey.c.hinto themselves but never set translations. PR 1 adds a real-libobs test. - The input is trusted: the strings come from the frontend's own installed locale files (
frontend/data/locale/*.ini). No locale shipped today has an empty or padding-only numpad or mouse template, here or upstream (all 136 entries in the 77 locales have%1). A plugin could call the exported function, but plugins run in-process anyway.
Plan
- Characterization and extraction PR (behaviour-neutral, one PR, as in libobs: Move the hotkey binding codec into obs-hotkey-bindings.c #1622):
- New test
test_hotkey_translations, linkingOBS::libobswithobs_startup()(under xvfb-run on Linux) and using only the public API. It sets translations throughobs_hotkeys_set_translations_s()and reads them back throughobs_key_to_str()andobs_key_combination_to_str(). It pins the English defaults, every named key,NUM0-NUM9andMOUSE1-MOUSE29, and these template cases: with and without%1,%1twice,"%1%1","%%1","%11", padded,\v(which is not padding), printf-like text, UTF-8 and non-UTF-8 bytes. It also pins a NULL member (the old name is kept), a NULL struct, a short and a largersize, setting twice, an empty name, theapple_*members (ignored off macOS), and combinations. obs_hotkeys_set_translations_smoves verbatim intolibobs/obs-hotkey-translations.c.h, in the same unity group (libobs.core, just beforeobs-hotkey.c.h). The store becomes the hiddenobs_hotkeys_store_key_translation().test_hotkey_load,test_wayland_hotkeysandtest_portal_shortcutscompile the new file next toobs-hotkey.c.h. The__APPLE__conditional moves with the code, so the platform-ifdef baseline goes from 1 to 1.
- New test
- Fix PR, in C, before the port (RED, then GREEN). It fixes both bugs below. The RED commit flips the arrow-key case in
test_hotkey_translationsand adds the empty and padding-only template cases, which crash on master. The GREEN commit has two parts:- It skips an empty or padding-only numpad or mouse template as if it were NULL. The keys keep their names, so a translation that was never filled in shows the English default.
- It adds the four arrow-key
ADD_TRANSLATIONlines.
- Port PR (RED, then GREEN):
obs_hotkey::translationsgets the safe core, andsrc/ffi/translations.rsthe exportedobs_hotkeys_set_translations_s. The C file moves to its own ported group,libobs.ported-hotkey-translations, with its own.pch.h,source-sets.jsonentry and export fragment (rust-exports.map,rust-hidden.txt,rust-unexports-macos.txt), aslibobs.ported-hotkey-bindingshas.- Tests:
- Tier 1 ports every
test_hotkey_translationsexpectation 1:1. - Tier 3 checks parity against the C file, through an oracle over the moved C with a stub store that records each (key, string) pair. A proptest covers the template bytes (
%,1, padding, NUL-free UTF-8 and non-UTF-8) with each member set to NULL or a value, and thesizecut at each member boundary. - Tier 2 runs with
OBS_LIBOBS_BACKEND=Cand in the hybrid withlibobs-c-reference, unchanged;test_hotkey_translationssees the swap. - Tier 4 does not apply (no protocol change).
- Tier 1 ports every
- The
__APPLE__block becomescfg(target_os = "macos"). 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 the platform conditionals inobs-hotkey.c.h, so its checkbox stays with 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. - Docs: the
rust/README.mdrow, and thedocs/rust-port/naming.mdrow forrust/obs-hotkey(addobs-hotkey-translations.c.h).
The plan could also have been four PRs: the crash fix in C (2), the port (3), then the arrow-key fix (4). One fix PR before the port is better, for four reasons:
- Both bugs are in the same 130-line function and are pinned by the same new test. A fix PR touches the same test cases either way.
- With both bugs fixed first, the port only has to copy fixed C. Its Tier 1 and Tier 3 tests carry no "characterized, not endorsed" cases. Fixed after the port, the arrow-key fix has to be made twice, in the C (still the
libobs-c-referenceandOBS_LIBOBS_BACKEND=Ccopy) and in the Rust, plus the Tier 1 port of the test, as libobs: Drop empty hotkey bindings and signal when a load clears them #1649 had to. - Neither fix waits on the other or on the port. The crash fix must not wait for the port, and the arrow-key fix is spec-following (the struct and the frontend already supply the strings).
- Precedent: libobs: Drop empty hotkey bindings and signal when a load clears them #1649 made two fixes found by the same characterization in one PR.
The cost is a slightly larger fix PR with two independent changes. Each has its own test cases and its own docs/features.md line, so either can be reverted alone.
The move and the port make no intended behaviour change. PR 1 pins two behaviours, and PR 2 fixes them:
- The arrow keys are never translated.
obs_hotkeys_set_translations_s()has noADD_TRANSLATIONforleft,right,upordown, though the struct has them and the frontend sets them (Hotkeys.Leftand the others). So on Linux (X11 and Wayland) Settings > Hotkeys always shows English "Left", "Right", "Up" and "Down", whatever the language. Windows takes these names from the OS, and macOS shows glyphs for them, so neither is affected. Upstream OBS has the same code. This is cosmetic. - An empty or padding-only numpad or mouse template crashes. For
"",dstr_copy()leaves the template'sdstrNULL, and for a padding-only stringdstr_depad()frees it.dstr_find()then callsstrstr(NULL, "%1"), which crashesobs_hotkeys_set_translations_s(), and with it the app at startup. This is pinned by a comment only: as a test case it would crash the test. No locale shipped today (here or upstream) has such a template, so users can hit it only through a hand-edited or third-party locale file, or a plugin passing the struct. Upstream OBS has the same code.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 21, 2026
Claiming: #1656
test_hotkey_translations(14 cases, real libobs), and the translations moved verbatim intolibobs/obs-hotkey-translations.c.h. Opening it now.rust/obs-hotkey'stranslationsmodule, as its own PR.libobs: Move the hotkey key-name translations into obs-hotkey-transla…
libobs: Translate the arrow key names and skip empty hotkey templates
libobs: Translate the arrow key names and skip empty hotkey templates (…
libobs: Port the hotkey key-name translations to obs-hotkey (obs-rust…