Skip to content

libobs: Port the portal shortcut combination sets to obs-hotkey - #1800

Merged
zackees merged 4 commits into
obs-rust:masterfrom
rdoupe:port/portal-shortcut-sets
Oct 22, 2026
Merged

zackees merged 4 commits into
obs-rust:masterfrom
rdoupe:port/portal-shortcut-sets

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1783 (PR 2 of 2; #1784 moved the combination sets into libobs/obs-nix-portal-shortcut-sets.c.h behind hidden entry points and added test_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 new portal_shortcut_sets module of rust/obs-hotkey. On every sync of the hotkey bindings it decides:

  • whether the portal session is bound again;
  • which keys the new request asks for;
  • what is bound again after the desktop's dialog is declined.

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.

  • Safe core (src/portal_shortcut_sets.rs):
    • same_combo(): the same key and every modifier bit, not only the four the portal knows.
    • has().
    • unchanged(), request() and partition(). They are built from the C's covered_by(), description_of(), same_set() and select_combos().
    • A combination is any Combination: the safe KeyCombination, or the C struct in the shim. A description is any T: PartialEq, with None for a NULL one. So the shim compares the caller's C strings in place, and only where the C compares them.
    • The partition fills part with every approved position, then filters it in place, as the C does. So the entries past num_part are the same as the C's too.
    • Every position goes through a bounds check, and the counts never depend on the room. The module allocates nothing, keeps no state and takes no lock. It denies clippy's arithmetic_side_effects, indexing_slicing, unwrap_used, expect_used, panic, todo, unimplemented and unreachable. No host cfg, no unsafe.
  • Shim (src/ffi/portal_shortcut_sets.rs): obs_nix_portal_sets_has, _unchanged, _request and _partition, with the C signatures.
    • struct obs_nix_portal_combos and struct obs_nix_portal_descriptions are #[repr(C)], with a layout test against the C. The arrays are borrowed as slices.
    • A description entry is an Option<Description>: a transparent NonNull<c_char>, which has the layout of const char *. Two descriptions are equal when their bytes up to the NUL are equal, which is strcmp(...) == 0.
    • Nothing is copied, so no darray or bmem crosses the boundary. The shims call nothing from GIO, so they are built on every host, with no Cargo feature.
  • C side:
    • The group libobs.nix-portal-shortcut-sets becomes the ported group libobs.ported-nix-portal-shortcut-sets. Its PCH is renamed to match and still has no <gio/gio.h>.
    • The group is in 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.
    • The only change to the file is that include, plus a comment. test_portal_shortcut_sets and test_portal_shortcuts still compile it into themselves, unchanged.
    • ci/test_ported_sources.py checks the group: it is there with Wayland and GIO, and absent without either and on Windows.
  • Symbols: the four functions are declared in obs-nix-portal-shortcuts.h without EXPORT. So the shims are hidden through rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt (export_list passes). nm shows them as local (t) in all three libraries. The exported symbol sets are unchanged (1766).
  • Oracle (oracle/portal_shortcut_sets.c): the original file, unmodified, with the four entry points renamed to oracle_*, plus the layouts of the two views. It needs no GIO.
  • Intentional differences, all of them inputs that are undefined in C. The parity test header, src/ffi/portal_shortcut_sets.rs and the rust/README.md row list them:
    • a null view, or a view with a null array and a nonzero count, is an empty set (C reads num entries through it);
    • a null count out-pointer, or a null position buffer, is not written (C writes through it). The portal client passes neither.
    • Nothing else. The behaviour libobs: Move the portal shortcut combination sets into obs-nix-portal-shortcut-sets.c #1784 pins as "characterized, not endorsed" is kept as it is:
      • the same set compares combinations as sets, so {A, A} is {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;
      • cancelling the dialog for a set with no new key leaves the key approved before unbound (in the C portal client, which stays C).
  • No test_portal_shortcut_sets_rust. The plan was to link the unchanged test_portal_shortcut_sets.c against libobs_rust-static, as test_scene_bounds_place_rust does. It does not link on its own.
    • The shims share their codegen unit with the rest of obs-hotkey. That pulls in obs-data and obs-util archive members, and with them jansson, libuuid and GIO.
    • It also pulls in libobs's hidden hotkey seams: obs_hotkeys_mutex_lock, obs_hotkey_binding_fields and obs_hotkeys_store_key_translation. No test executable can resolve those.
    • --gc-sections does not help: the archive's copies of symbols that libobs.so also defines keep their sections alive.
    • test_scene_bounds_place_rust links only because obs-scene's codegen unit happens not to reach that far. There is no narrower staticlib, since libobs-rust is the only one.
    • The test registration says so in a comment. Tier 3 compares the shims with the C instead.
  • Docs: the rust/README.md rows (crate table and port table), the docs/rust-port/naming.md row and the crate's Cargo description. No docs/features.md line: there is no user-visible change.

RED → GREEN

  • RED commit: 0baa8885e libobs: Add Tier 1 tests for the portal shortcut combination sets port. The core is todo!(). soldr cargo test -p obs-data --test obs-tests-core hotkey::portal_shortcut_sets fails 20 of 20 with "not yet implemented".
    • Tier 1 (tests/hotkey/portal_shortcut_sets.rs) ports the 12 cases of test_portal_shortcut_sets 1:1, under the same names, in the same order, with the same inputs and expectations, the sentinel checks past current's size included.
    • 8 new cases:
      • every modifier bit and any key code in same_combo;
      • the partition's first pass leaving the filtered approved positions after part;
      • short buffers losing only the positions past their end, never the counts;
      • descriptions of any type;
      • four 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.
  • GREEN: 51d3f137d libobs: Port the portal shortcut combination sets to obs-hotkey. hotkey::portal_shortcut_sets passes 20/20.
  • Tier 3: ee2c2b53e libobs: Check the portal shortcut combination sets port against the C (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. The buffers start as a sentinel and have two more entries than current. So the entries past the counts, and any write past current's size, are compared too.
    • The cases:
      • the layouts;
      • has over every sequence of up to three combinations from a pool: OBS_KEY_NONE alone and with Ctrl, a mouse button with bit 31, and a key alone, with Ctrl, and with Caps Lock and Shift;
      • 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"), for every flag. That covers fewer and more descriptions than combinations;
      • every pair of descriptions from the whole pool: empty, NFC and NFD, case, a prefix, non-UTF-8, the same bytes at two addresses, and NULL;
      • unchanged without 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;
      • NULL arrays for empty views and NULL buffers for an empty current, which C defines;
      • 3000 random cases of each function: up to eight combinations (any key and modifiers included) and up to nine descriptions (random bytes included), sometimes with bound a rotation of current, so that the descriptions decide.
    • Excluded: only the intentional differences above, which are checked on the Rust side.
    • hotkey:: passes 208/208 (32 of them hotkey::portal_shortcut_sets).
  • Deliberate-break check (not committed): 32 of 32 mutants of the core and the shim fail Tier 3, and 25 of them fail Tier 1 too. Each was applied, tested and restored.
    • Core:
      • 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 that has a description, compared 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 filtered, never filtered, the filter inverted, or partly as <=;
      • the partition: without the request filter, binding the whole request, binding an empty part, <= the request, declining all of current, declining the part, or without its first pass;
      • the count stopping at the room.
    • Shim (Tier 3 only, as Tier 1 does not see 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.
  • Local, two build trees: OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON, both full builds. Full ctest -j4, headless (private Xvfb, private D-Bus, fresh HOME):
Lane Library ctest Exported symbols
OBS_LIBOBS_BACKEND=C libobs 367/367 IDENTICAL (1766)
HYBRID, OBS_BUILD_C_REFERENCE=ON hybrid libobs 369/369 IDENTICAL (1766)
HYBRID, OBS_BUILD_C_REFERENCE=ON libobs-c-reference 369/369 IDENTICAL (1766)

Nothing 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 Passed
test_portal_shortcut_sets 12/12
test_portal_shortcuts 32/32
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
test_x11_hotkey_layout 4/4
test_hotkey_press_steps 11/11
test_hotkey_press_state 18/18

Each compiles the C or goes through other units, so none of them sees this swap; Tier 3 is what compares it.

  • Also run: uv run ci/local_gate.py --lane lint passed, and --lane cross passed.
    • soldr cargo test -p obs-data --test obs-tests-core hotkey:: passes 208/208.
    • export_list passes, as do ci/test_build_groups.py and ci/test_ported_sources.py.
    • ci/platform_ifdef_ratchet.py reports only the CrashHandler baseline that master reports too.
    • clang-format and rustfmt are clean on the changed files.
  • Real app (UI, protocol output or logging changes): not applicable (no behaviour change).

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-tests job on all three. The ported group is Linux and FreeBSD only.

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 portal shortcut combination sets into obs-nix-portal-shortcut-sets.c #1784)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (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)

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

rust: Port the portal shortcut combination sets in obs-nix-portal-shortcuts.c to obs-hotkey

2 participants