Repository navigation
Description
Port the combination set logic of the GlobalShortcuts portal client (libobs/obs-nix-portal-shortcuts.c.h, Wayland with GIO, Linux and FreeBSD) to the existing crate rust/obs-hotkey as a new module, portal_shortcut_sets. This logic decides, on every sync of the hotkey bindings (500 ms after the last change), whether the portal session is left as it is or bound again, which keys go into a new BindShortcuts request, and what is bound again after the desktop's dialog is declined. If it is wrong, the desktop's dialog comes back on every sync (GNOME lists every shortcut again in it), or a changed binding is never bound. The id codec in the same client was ported in #1517.
The unit, about 90 lines:
same_combo(),has_combo()andcovered_by(): combination equality (key and every modifier bit), membership, and "every combination of a is in b".description_of()andsame_set(): the same combinations, compared as sets (a duplicate counts once), each with the same description. A description is compared withstrcmp, as bytes. A missing or NULL description on either side is "not the same".select_combos(): the combinations in a filter (or not in it), with"OBS"for one without a description.- The partition inside
bind_approved(): part = current ∩ approved ∩ request. It binds part again only when0 < |part| < |request|, and the rest of current is declined. - The decisions inside
sync_shortcuts():unchanged(with a session, the same set as the one bound; without one, nothing to bind or all of it declined before; and a retry of a partly declined set always binds anew), the request filter (keys declined while others stay bound are left out until Ask again), andpartly(the request is only part of the bindings).
These stay C: the description copies (copy_descriptions, free_descriptions, and the bstrdup of select_combos), collect_bindings() and action_label(), everything that calls GDBus, set_state() and set_flag() (they take the hotkeys mutex), and the portal thread.
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, the binding codec and the key-name translations; the press state machine (#1751) is in flight there and touches other files. It is part of a large file, so it goes in through function extraction (testing-policy.md, "Extracting a function before porting it"), as the id codec did (#1518, #1519). Its Rust tests join the crate's existing tests/hotkey/ binary. No new test binary.
Dependencies and existing tests
combo_array_tisDARRAY(obs_key_combination_t)anddescription_array_tisDARRAY(char *), both file-local. The moved code reads them through two views declared inobs-nix-portal-shortcuts.h,struct obs_nix_portal_combos(pointer and count) andstruct obs_nix_portal_descriptions(pointer toconst char *and count), and returns positions in them. C keeps every allocation, so the port needs no darray or bmem across the boundary.obs_key_combination_tis public (obs-hotkey.h) and already has a layout test inobs-hotkey.- The moved file calls nothing from GIO. It is built under the same
ENABLE_WAYLAND+ GIO condition as the portal client, with no Cargo feature, as the id codec is. - Today:
test_portal_shortcuts(28 cases, a fake portal on a private bus) covers the flows end to end: declined, declined then asked again, a declined new key keeping the approved keys, description changes, pause and probe. It compiles the C into itself (obs=hotkey_test_obs), so it cannot see a swap. Nothing tests the set logic on its own. PR 1 adds tests (below). - Input: combinations come from the user's own hotkey bindings (profiles, scene collections, the frontend, plugins), and descriptions are action labels built from hotkey and source names, which may be any bytes. The unit only compares them; it indexes nothing by them.
Plan
- Characterization and extraction PR (behaviour-neutral, two commits):
- Four new end-to-end cases in
test_portal_shortcuts, on the unchanged C: a reordered set is not bound again; descriptions are compared as bytes; only declined keys left binds nothing; a declined dialog for a set with no new key unbinds the approved key (characterized, not endorsed, below). - The move: the helpers and the three decisions go into
libobs/obs-nix-portal-shortcut-sets.c.h, as hidden entry points (declared withoutEXPORT):obs_nix_portal_sets_unchanged(),obs_nix_portal_sets_request(),obs_nix_portal_sets_partition()andobs_nix_portal_sets_has()(for the Activated handler).same_combo()goes intoobs-nix-portal-shortcuts.h, stillstatic inline, asbindable()did. The file gets its own unity group,libobs.nix-portal-shortcut-sets, next tolibobs.nix-portal-shortcuts, with a precompiled header without<gio/gio.h>.test_portal_shortcutscompiles it next to the client. - New test
test_portal_shortcut_sets, which compiles the moved file with no GIO, D-Bus or libobs core and calls only the entry points. It pins empty sets on either side, order independence, the same key with other modifiers (every bit), duplicates, fewer descriptions than combinations, NULL descriptions, byte-wise compare (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 and each branch of the partition.
- Four new end-to-end cases in
- Port PR (RED, then GREEN):
obs_hotkey::portal_shortcut_sets, a safe core over&[obs_key_combination_t]and&[Option<&CStr>]that returns bools and position lists, andsrc/ffi/portal_shortcut_sets.rsfor the four entry points. Descriptions are compared asCStrbytes, never asstr. The C file moves to its own ported group,libobs.ported-nix-portal-shortcut-sets, inLIBOBS_WAYLAND_GIO_PORTED_SOURCES, with its.pch.h,source-sets.jsonentry and export fragment, aslibobs.ported-nix-portal-shortcut-idshas;ci/test_ported_sources.pygets the object.- Tests:
- Tier 1 ports every
test_portal_shortcut_setsexpectation 1:1. - Tier 3 checks parity against the moved C through
obs-c-oracle(oracle/portal_shortcut_sets.c): a proptest over random combination arrays (keys includingOBS_KEY_NONEand mouse buttons, all modifier bits, duplicates), description arrays of other lengths with NULLs and arbitrary bytes, and every flag combination, comparing the results and the position lists. - Tier 2:
test_portal_shortcut_sets_rust, the unchangedtest_portal_shortcut_sets.clinked againstlibobs_rust-staticinstead of the C, astest_scene_bounds_place_rustdoes, so the hybrid build runs the characterization against the Rust code.test_portal_shortcutskeeps running on the C copy. - Tier 4 does not apply (no protocol change).
- Tier 1 ports every
- Docs: the
rust/README.mdrow, and thedocs/rust-port/naming.mdrow forrust/obs-hotkey(addobs-nix-portal-shortcut-sets.c.h).
For the reviewer to decide
- Seam shape. The decisions take views of the arrays and return positions, so C keeps the darrays, the copies and the
"OBS"fallback, and the Rust core is pure. The alternative, Rust owning the darrays, would need darray and bmem across the boundary for no gain. - What reaches the hybrid build. The entry points are hidden, so a test linking
libobs.socannot call them. PR 1'stest_portal_shortcut_setscalls nothing else, so the port can link the same file against the Rust staticlib (test_scene_bounds_place_rustpattern). The 28 + 4 end-to-end cases compile the client and keep running on the C copy; they also compileobs-hotkey.c.hand the other ported hotkey files into themselves, so linking them against the staticlib as well could define the same symbols twice. I don't plan that; Tier 3 and the_rusttest cover the swap, as for the id codec. - Behaviours the characterization pins, not endorses (none is changed by this plan):
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:
collect_bindings()holds each combination once, and its request is a subset of it. - The desktop's dialog for a set with no new key (an action moved onto an approved key, so only a description changed) is cancelled: the approved key is not bound again, because
bind_approved()binds only a strict part of the request, so every key stops working until Ask again. Binding it again with the description it was approved with would keep it working without a dialog. That would change behaviour, so it needs its own issue and a user-visible check on GNOME and KDE first; I propose no fix before the port.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 22, 2026
Claiming: #1783
libobs/obs-nix-portal-shortcut-sets.c.hbehind hidden entry points, with 4 new end-to-end cases intest_portal_shortcutsand a newtest_portal_shortcut_sets(12 cases, no GIO/D-Bus). No behaviour change.rust/obs-hotkey(moduleportal_shortcut_sets), withtest_portal_shortcut_sets_rustlinked against the Rust library and oracle parity tests.libobs: Move the portal shortcut combination sets into obs-nix-portal…
rdoupe commentedon Oct 22, 2026
Port is up in #1800. Intentional differences from C, only for inputs that are undefined there and that the portal client never passes: a null view, or a null array with a nonzero count, is read as an empty set, and a null count or position buffer is not written. The three behaviours pinned as not endorsed in #1784 are kept.
libobs: Port the portal shortcut combination sets to obs-hotkey (obs-…