Repository navigation
libobs: Move the portal shortcut combination sets into obs-nix-portal-shortcut-sets.c - #1784
Merged
Merged
Conversation
Characterization before the combination set logic of the GlobalShortcuts portal client (same_set, covered_by, select_combos, the partition in bind_approved and the decisions in sync_shortcuts) moves to its own file and is ported to obs-hotkey. test_portal_shortcuts covers the main flows; four new cases, on the same fake portal and private bus, pin what it did not: - the same keys with the same descriptions in another order are not bound again, and a new key then binds them in their new order; - descriptions are compared as bytes: the same name in another Unicode normalization binds again, the same bytes do not; - partly declined, then the approved key's binding goes away: only declined keys are left, so the session closes, nothing is asked for and the state is declined; Ask again binds the rest; - the dialog for a set with no new key (an action moved onto an approved key) is cancelled: the state is declined and the key is unbound until Ask again. Characterized, not endorsed: in the last case, the key approved before is not bound again, because bind_approved() binds only a strict part of the request. Refs obs-rust#1783
…-shortcut-sets.c
Behavior-neutral extraction before the Rust port. The combination set
logic of the GlobalShortcuts portal client moves from
libobs/obs-nix-portal-shortcuts.c.h into
libobs/obs-nix-portal-shortcut-sets.c.h: has_combo, covered_by,
description_of and same_set verbatim, select_combos without its
allocations, and the three decisions as hidden entry points:
- obs_nix_portal_sets_unchanged(): whether a sync leaves the session as
it is (sync_shortcuts' unchanged, with the retry override);
- obs_nix_portal_sets_request(): the bindings to ask for, without the
declined ones while partly declined, and whether that is only part;
- obs_nix_portal_sets_partition(): what bind_approved() binds again after
a declined dialog, the rest of the bindings, and whether to bind;
plus obs_nix_portal_sets_has() for the Activated handler.
The moved code reads the arrays through two views,
struct obs_nix_portal_combos and struct obs_nix_portal_descriptions
(pointer and count, declared in obs-nix-portal-shortcuts.h), and returns
positions in them, so the portal client keeps every allocation and the
port needs no darray or bmem across the boundary. The only edits to the
moved bodies are those parameter types, and select_combos and the
partition returning positions instead of copies; take_combos() in the
portal client makes the copies, with "OBS" for a missing description, as
before. same_combo() moves verbatim into obs-nix-portal-shortcuts.h,
still static inline, as the binding collection and the trigger update
also use it. The entry points are declared without EXPORT, so
-fvisibility=hidden keeps them local, and the exported symbols do not
change.
The new file gets its own unity group, libobs.nix-portal-shortcut-sets,
built next to libobs.nix-portal-shortcuts under the same ENABLE_WAYLAND
+ GIO condition (CMake on Linux and FreeBSD, and obs-build). Its
precompiled header has no <gio/gio.h>, so a C test and later the C
oracle compile it on their own. test_portal_shortcuts compiles it next
to the portal client.
New characterization test test_portal_shortcut_sets (12 cases), with no
GIO, D-Bus or libobs core. It calls only the entry points, so the port
can run the same file against the Rust staticlib. It pins: empty sets on
either side; order independence; the same key with other modifiers, and
every modifier bit; fewer descriptions than combinations; a NULL
description; byte-wise compare of descriptions (Unicode normalization,
case, bytes that are not UTF-8); the no-session branch; every
combination of the session, retry and partly-declined flags; the request
filter; each branch of the partition; and that nothing past the arrays'
size is written and nothing is allocated.
Characterized, not endorsed:
- same_set compares combinations as sets, so {A, A} is the same as {A},
and each copy is compared with the description of the first copy on
the other side;
- a NULL description is not the same as another NULL;
- the partition counts duplicates in |part|, and takes |request| as
given, so two copies of an approved key can stop the partial rebind.
The portal client passes neither (its bindings hold each combination
once).
Refs obs-rust#1783
This was referenced Oct 22, 2026
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 22, 2026
…rust#1800) * libobs: Add Tier 1 tests for the portal shortcut combination sets port 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 * libobs: Port the portal shortcut combination sets to obs-hotkey 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 * libobs: Check the portal shortcut combination sets port against the C 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 * docs: Record the portal shortcut combination sets port 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 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 #1783 (PR 1 of the plan: the characterization and the extraction. The port follows.)
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 combination set logic of the GlobalShortcuts portal client (Wayland with GIO, Linux and FreeBSD) moves from
libobs/obs-nix-portal-shortcuts.c.hintolibobs/obs-nix-portal-shortcut-sets.c.h. On every sync of the hotkey bindings it decides whether the portal session is bound again, which keys the new request asks for, and what is bound again after the desktop's dialog is declined. The move comes with characterization tests, because nothing tested this logic on its own. There is no Rust, no behaviour change and no public header change (obs-nix-portal-shortcuts.his internal).has_combo(),covered_by(),description_of()andsame_set()verbatim;select_combos()without its copies; and three decisions as hidden entry points:obs_nix_portal_sets_unchanged(session, retry, partly_declined, current, …, bound, …, declined):sync_shortcuts()'sunchanged, with the retry override;obs_nix_portal_sets_request(current, partly_declined, declined, request, &num): the request filter, returningpartly;obs_nix_portal_sets_partition(current, approved, request, part, &num_part, declined, &num_declined): whatbind_approved()binds again and what it declines, returning whether to bind;obs_nix_portal_sets_has(), which the Activated handler uses.obs-nix-portal-shortcuts.h,struct obs_nix_portal_combos(array,num) andstruct obs_nix_portal_descriptions(const char *const *array,num). It returns positions in them instead of copies. So the portal client keeps every allocation: the newtake_combos()makes the copies, with"OBS"for a missing description, asselect_combos()did. The port will need no darray or bmem across the boundary. The view fields are named like the darray's, so the four moved helpers differ from the old ones only in their parameter types.select_combos()and the partition return positions; the partition keeps part in current's order (a forward filter instead of erasing backwards) and declines the same combinations.copy_descriptions()andfree_descriptions(),collect_bindings()andaction_label(), everything that calls GDBus,set_state()andset_flag()(they take the hotkeys mutex), and the portal thread.same_combo()moves verbatim intoobs-nix-portal-shortcuts.h, stillstatic inline, because the binding collection and the trigger update use it too (asbindable()did in libobs: Move the portal shortcut id codec into obs-nix-portal-shortcut-ids.c #1518).EXPORT, so-fvisibility=hiddenkeeps them local (tsymbols inlibobs.so). The tests that compile the client into themselves build each.c.has its own translation unit, so the moved code has to be reachable through functions, notstaticones.libobs.nix-portal-shortcut-sets, built next tolibobs.nix-portal-shortcutsunder the sameENABLE_WAYLAND+ GIO condition (CMake on Linux and FreeBSD, and obs-build's Linux libobs). Its precompiled header has no<gio/gio.h>, so a C test and later the C oracle compile the file on its own. That is the only reason it is not in the existing group. The moved code has no platform conditional.test_portal_shortcutscompiles the new file next to the client (tests.d/test_wayland_hotkeys.cmake).Four new cases in
test_portal_shortcuts(their own commit before the move, on the unchanged C, with the same fake portal on a private bus). They pin what its 28 cases did not:test_portal_shortcut_sets(new, with the move) compiles the moved file with no GIO, no D-Bus and no libobs core, and calls only the entry points. That is so the port can link the same file against the Rust staticlib (astest_scene_bounds_place_rustdoes) and run the characterization against the hybrid build: the 32 end-to-end cases compile the C, so they cannot see the swap. Its 12 cases:has: an empty set, the same key with other modifiers, every modifier bit (also ones the portal does not know), onlynumentries read;i < numguards on both sides), NULL descriptions, the empty description, and byte-wise compare (precomposed and decomposed é, case, a prefix, bytes that are not UTF-8);Characterized, not endorsed (a comment in the tests, and in the issue). None is changed here:
same_set()compares combinations as sets, so{A, A}is the same as{A}, and each copy is compared with the description of the first copy on the other side.bind_approved()binds only a strict part of the request. Every key then stops working until Ask again. The issue lists it as a possible follow-up.RED → GREEN
4bca70285test: Characterize when the portal client binds its shortcuts again, andtest_portal_shortcutspasses 32/32 there on the unchanged C. The move is8a8516484libobs: Move the portal shortcut combination sets into obs-nix-portal-shortcut-sets.c.same_combo,has_combo,covered_by,description_of,same_setandselect_combos, with master'sunchanged, request and partition code, against the new entry points, over 300,000 random cases (five combinations includingOBS_KEY_NONEand a CapsLock bit, duplicates, shorter description arrays, NULL, empty and non-UTF-8 descriptions, all flags). It compared the results, the positions with the copies master made, and the descriptions: 0 differences, 0 leaked allocations.test_portal_shortcut_sets12/12 andtest_portal_shortcuts32/32, each run 4 times (once before and 3 times after the final rebase) against libobs with the C backend, the hybrid libobs and libobs-c-reference.test_portal_shortcut_sets; 16 of them also failtest_portal_shortcuts. Each mutant ofobs-nix-portal-shortcut-sets.c.h(andsame_combo()in the header) was built into both tests:same_combo()ignoring the modifiers;has_combo()skipping the last entry (both);same_set()covering one way only, ignoring descriptions, comparing them by position (the reordered case catches it end to end), case-insensitively, or with an off-by-one description guard; a NULL description equal to NULL;description_of()taking the last match;partlyas<=;<=the request, declining all of current, or declining the part.The 8 that only the new test sees:
same_combo()ignoring the modifiers, NULL equal to NULL, the last match, the case-insensitive compare, the empty set without a session, both weakened retry overrides, and the partition without the request filter. The end-to-end flows don't produce those inputs (the client deduplicates the bindings and never has a NULL description), or the fake portal cannot tell the results apart.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_portal_shortcut_ids(15/15),test_wayland_hotkeys(8/8),test_wayland_multiseat(6/6),test_hotkey_load(7/7),test_hotkey_bindings_codec(18/18),test_hotkey_translations(16/16) andtest_x11_hotkey_layout(4/4) pass, unchanged, against all three. After the final rebase onto b39a4e0 (#1775, with #1752), both trees were rebuilt, the full suite and the symbol comparison were run again (the numbers above), and the portal and hotkey tests 3 more times against each library.uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed.ci/test_build_groups.pyandci/test_ported_sources.pypass;ci/platform_ifdef_ratchet.pyreports only the CrashHandler baseline that master reports too. clang-format 22.1.3 and gersemi are clean on the changed files.Windows/macOS: not built there. The moved code is Linux and FreeBSD only (Wayland with GIO), and both new and changed tests are registered for Linux and FreeBSD only.
test_portal_shortcut_setsis portable C (no cmocka range assertions, nofail_msg()).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)