Repository navigation
libobs: Port the portal shortcut combination sets to obs-hotkey - #1800
Merged
Merged
Conversation
RED for the port of libobs/obs-nix-portal-shortcut-sets.c.h to a new
module, portal_shortcut_sets, of rust/obs-hotkey. The safe core is a
stub (todo!()): same_combo(); has(); unchanged(), whether a sync leaves
the portal session as it is, with the retry override; request(), the
positions of current to ask the desktop for, and whether that is only
part; and partition(), what is bound again after a declined dialog and
what is declined. A combination is any Combination (KeyCombination, or
the C struct in the shim), and a description is any T: PartialEq, None
for a NULL one, so the shim can compare C strings in place.
tests/hotkey/portal_shortcut_sets.rs ports test_portal_shortcut_sets 1:1,
its 12 cases under the same names, in the same order, with the same
inputs and expectations, the sentinel checks past current's size
included. Kept as characterized, not endorsed: {A, A} is the same set as
{A}, a NULL description is not the same as another NULL, and the
partition counts duplicates.
Edge cases: every modifier bit and any key code in same_combo; the
partition's first pass leaving the filtered approved positions after
part, as the C's in-place filter does; short buffers losing only the
positions past their end, never the counts; descriptions of any type;
and proptests of each function against a model.
The tests are a module of the existing core category binary,
obs-tests-core; no new test binary.
soldr cargo test -p obs-data --test obs-tests-core
hotkey::portal_shortcut_sets fails 20 of 20 with "not yet implemented".
Refs obs-rust#1783
Ports libobs/obs-nix-portal-shortcut-sets.c.h to the portal_shortcut_sets module of rust/obs-hotkey. On every sync of the hotkey bindings the GlobalShortcuts portal client (Wayland with GIO, Linux and FreeBSD) asks it whether the session is bound again, which keys the new request asks for, and what is bound again after the desktop's dialog is declined; the Activated handler asks whether a set holds a combination. The portal client, every GDBus call, the portal thread and every allocation stay C in obs-nix-portal-shortcuts.c.h; the hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/portal_shortcut_sets.rs): same_combo() (every modifier bit, any key), has(), and the C's covered_by(), description_of(), same_set() and select_combos(), behind unchanged(), request() and partition(). Descriptions are compared only where the C compares them, and a combination without one, or with a NULL one, is never the same. The partition fills part with every approved position and filters it in place, as the C does, so the entries past num_part are the C's too. It allocates nothing, keeps no state and takes no lock, and denies clippy's panic, indexing and arithmetic lints: every position goes through a bounds check, and the counts never depend on the room. Shim (src/ffi/portal_shortcut_sets.rs): obs_nix_portal_sets_has, _unchanged, _request and _partition with the C signatures. The views struct obs_nix_portal_combos and struct obs_nix_portal_descriptions are #[repr(C)]; the arrays are borrowed as slices, a description entry as an Option<Description> (a transparent NonNull<c_char>, the layout of const char *) compared with the bytes up to its NUL, as strcmp == 0. Nothing is copied, so no darray or bmem crosses the boundary. Intentional differences, where C has undefined behavior only: a null view, or a view with a null array and a nonzero count, is an empty set, and a null count out-pointer or position buffer is not written (C dereferences them); the portal client passes neither. Kept as characterized, not endorsed (obs-rust#1784): {A, A} is the same set as {A}, a NULL description is not the same as another NULL, and the partition counts duplicates in |part| and takes |request| as given. C side: the group libobs.nix-portal-shortcut-sets becomes the ported group libobs.ported-nix-portal-shortcut-sets (its PCH renamed to match, still without <gio/gio.h>), in LIBOBS_WAYLAND_GIO_PORTED_SOURCES next to the shortcut ids: CMake on Linux and FreeBSD, and obs-build's C variant, compile it for the C backend and libobs-c-reference only. The four functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. The exported symbol sets are unchanged (1766). ci/test_ported_sources.py checks the group. test_portal_shortcut_sets and test_portal_shortcuts still compile the C into themselves, unchanged. A test_portal_shortcut_sets_rust against libobs_rust-static, as test_scene_bounds_place_rust does, does not link on its own: the shims' archive members pull in the rest of obs-hotkey, obs-data and obs-util, and with them jansson, libuuid, GIO and libobs's hidden hotkey seams (obs_hotkeys_mutex_lock, obs_hotkey_binding_fields, obs_hotkeys_store_key_translation), which no test executable can resolve. The test registration says so; Tier 3 compares the shims with the C instead. Refs obs-rust#1783
Oracle (oracle/portal_shortcut_sets.c): the original obs-nix-portal-shortcut-sets.c.h, unmodified, with its four entry points renamed to oracle_*, plus the layouts of struct obs_nix_portal_combos and struct obs_nix_portal_descriptions. It needs no GIO, so it is built on every host. Tier 3 (tests/hotkey/portal_shortcut_sets_parity.rs): both sides get the same arrays through the same views. After each call it compares the return value, the counts and every entry of the position buffers, which start as a sentinel and have two more entries than current, so the entries past the counts (the partition's first pass leaves approved positions there) and any write past current's size are compared too. Runs: - the layouts, and that Option<Description> is a const char *; - has: every sequence of up to three combinations from a pool with OBS_KEY_NONE (alone and with Ctrl), a mouse button with bit 31, a key alone, with Ctrl and with Caps Lock and Shift, against every pool entry and two more; - unchanged with a session: every pair of sets up to two entries with every description array up to three entries (NULL, "x", another "x" at another address, "y"), so fewer and more descriptions than combinations, for each flag with a session; - every pair of descriptions from the whole pool (empty, NFC and NFD, case, a prefix, bytes that are not UTF-8, the same bytes at two addresses, NULL), on one combination and on two in both orders; - unchanged without a session: every current and declined set up to three entries, with every retry and partly-declined flag; - request: every current set up to four entries and declined set up to two, partly declined or not; - partition: every current and request set up to three entries and approved set up to two; - NULL arrays for empty views, and NULL position buffers for an empty current, which C defines; - 3000 random cases of each function: up to eight combinations (from the pool, small keys with stray bits, or any key and modifiers) and up to nine descriptions (the pool, NULL or random bytes), sometimes with bound a rotation of current so the descriptions decide. Excluded, the intentional differences: a null view, a null array with a nonzero count, and null outputs C would write through (checked on the Rust side). Mutation check (done once, not committed): 32 of 32 mutants of the core and the shim fail the parity tests, 25 of them Tier 1 as well: same_combo ignoring the modifiers; has skipping the last entry; the same set covered one way only, ignoring descriptions, NULL equal to NULL, the last match, the first match with a description, by position, or with an off-by-one description guard; without a session ignoring the declined set or binding an empty set; the retry override dropped, without its session check or without its partly-declined check; the request always or never filtered, the filter inverted, partly as <=; the partition without the request filter, binding the whole request, binding an empty part, <= the request, declining all of current or the part, or without its first pass; the count stopping at the room; and in the shim, descriptions compared by address, num_request not written, the request buffer one short, part and declined swapped, bound's descriptions read as current's, and a view's count cut short. Refs obs-rust#1783
The rust/README.md rows for rust/obs-hotkey (crate table and port table), the naming.md row and the crate description now include libobs/obs-nix-portal-shortcut-sets.c.h. The port row lists what stays C (the portal client, its GDBus calls and allocations), the views the shims read and the positions they write, the byte-wise description compare, the in-place partition, what the characterization pins and the port keeps, the intentional differences (null views and null outputs, undefined in C), what Tier 3 compares, and why there is no test_portal_shortcut_sets_rust. Fixes obs-rust#1783
This was referenced Oct 22, 2026
This was referenced Oct 29, 2026
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.
Fixes #1783 (PR 2 of 2; #1784 moved the combination sets into
libobs/obs-nix-portal-shortcut-sets.c.hbehind hidden entry points and addedtest_portal_shortcut_sets)What and why
This PR ports
libobs/obs-nix-portal-shortcut-sets.c.h, the combination set logic of the GlobalShortcuts portal client (Wayland with GIO, Linux and FreeBSD), to a newportal_shortcut_setsmodule ofrust/obs-hotkey. On every sync of the hotkey bindings it decides:The Activated handler also asks it whether a set holds a combination. The portal client stays C in
obs-nix-portal-shortcuts.c.h, with every GDBus call, the portal thread and every allocation. The hybrid libobs drops the C file and links the Rust shims in its place.src/portal_shortcut_sets.rs):same_combo(): the same key and every modifier bit, not only the four the portal knows.has().unchanged(),request()andpartition(). They are built from the C'scovered_by(),description_of(),same_set()andselect_combos().Combination: the safeKeyCombination, or the C struct in the shim. A description is anyT: PartialEq, withNonefor a NULL one. So the shim compares the caller's C strings in place, and only where the C compares them.partwith every approved position, then filters it in place, as the C does. So the entries pastnum_partare the same as the C's too.arithmetic_side_effects,indexing_slicing,unwrap_used,expect_used,panic,todo,unimplementedandunreachable. No hostcfg, nounsafe.src/ffi/portal_shortcut_sets.rs):obs_nix_portal_sets_has,_unchanged,_requestand_partition, with the C signatures.struct obs_nix_portal_combosandstruct obs_nix_portal_descriptionsare#[repr(C)], with a layout test against the C. The arrays are borrowed as slices.Option<Description>: a transparentNonNull<c_char>, which has the layout ofconst char *. Two descriptions are equal when their bytes up to the NUL are equal, which isstrcmp(...) == 0.libobs.nix-portal-shortcut-setsbecomes the ported grouplibobs.ported-nix-portal-shortcut-sets. Its PCH is renamed to match and still has no<gio/gio.h>.LIBOBS_WAYLAND_GIO_PORTED_SOURCES, next to the shortcut ids. So CMake (Linux and FreeBSD) and obs-build's C variant compile it only for the C backend and libobs-c-reference.test_portal_shortcut_setsandtest_portal_shortcutsstill compile it into themselves, unchanged.ci/test_ported_sources.pychecks the group: it is there with Wayland and GIO, and absent without either and on Windows.obs-nix-portal-shortcuts.hwithoutEXPORT. So the shims are hidden throughrust-hidden.txt, thelocal:list ofrust-exports.mapandrust-unexports-macos.txt(export_listpasses).nmshows them as local (t) in all three libraries. The exported symbol sets are unchanged (1766).oracle/portal_shortcut_sets.c): the original file, unmodified, with the four entry points renamed tooracle_*, plus the layouts of the two views. It needs no GIO.src/ffi/portal_shortcut_sets.rsand therust/README.mdrow list them:numentries through it);{A, A}is{A}, and each copy is compared with the description of the first copy on the other side;test_portal_shortcut_sets_rust. The plan was to link the unchangedtest_portal_shortcut_sets.cagainstlibobs_rust-static, astest_scene_bounds_place_rustdoes. It does not link on its own.obs_hotkeys_mutex_lock,obs_hotkey_binding_fieldsandobs_hotkeys_store_key_translation. No test executable can resolve those.--gc-sectionsdoes not help: the archive's copies of symbols that libobs.so also defines keep their sections alive.test_scene_bounds_place_rustlinks only because obs-scene's codegen unit happens not to reach that far. There is no narrower staticlib, sincelibobs-rustis the only one.rust/README.mdrows (crate table and port table), thedocs/rust-port/naming.mdrow and the crate's Cargodescription. Nodocs/features.mdline: there is no user-visible change.RED → GREEN
0baa8885elibobs: Add Tier 1 tests for the portal shortcut combination sets port. The core istodo!().soldr cargo test -p obs-data --test obs-tests-core hotkey::portal_shortcut_setsfails 20 of 20 with "not yet implemented".tests/hotkey/portal_shortcut_sets.rs) ports the 12 cases oftest_portal_shortcut_sets1:1, under the same names, in the same order, with the same inputs and expectations, the sentinel checks past current's size included.same_combo;obs-tests-core. No new test binary.51d3f137dlibobs: Port the portal shortcut combination sets to obs-hotkey.hotkey::portal_shortcut_setspasses 20/20.ee2c2b53elibobs: Check the portal shortcut combination sets port against the C(tests/hotkey/portal_shortcut_sets_parity.rs).hasover every sequence of up to three combinations from a pool:OBS_KEY_NONEalone and with Ctrl, a mouse button with bit 31, and a key alone, with Ctrl, and with Caps Lock and Shift;unchangedwith a session: every pair of sets up to two entries, with every description array up to three entries (NULL,"x", another"x"at another address,"y"), for every flag. That covers fewer and more descriptions than combinations;unchangedwithout a session: every current and declined set up to three entries;request: every current set up to four entries and declined set up to two;partition: every current and request set up to three entries and approved set up to two;hotkey::passes 208/208 (32 of themhotkey::portal_shortcut_sets).same_comboignoring the modifiers;hasskipping the last entry;partlyas<=;<=the request, declining all of current, declining the part, or without its first pass;num_requestnot written, the request buffer one short, part and declined swapped, bound's descriptions read as current's, and a view's count cut short.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. The ported group is compiled only into libobs-c-reference and the C-backend libobs.
The portal and hotkey tests pass against all three libraries, unchanged:
test_portal_shortcut_setstest_portal_shortcutstest_portal_shortcut_idstest_wayland_hotkeystest_wayland_multiseattest_hotkey_loadtest_hotkey_bindings_codectest_hotkey_translationstest_x11_hotkey_layouttest_hotkey_press_stepstest_hotkey_press_stateEach compiles the C or goes through other units, so none of them sees this swap; Tier 3 is what compares it.
uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed.soldr cargo test -p obs-data --test obs-tests-core hotkey::passes 208/208.export_listpasses, as doci/test_build_groups.pyandci/test_ported_sources.py.ci/platform_ifdef_ratchet.pyreports only the CrashHandler baseline that master reports too.Windows/macOS: not built there. The core and shims have no host conditional and are built on every host, unused outside Linux and FreeBSD with Wayland and GIO. The oracle needs no GIO, so Tier 3 runs in the
rust-testsjob on all three. The ported group is Linux and FreeBSD only.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)