Skip to content

libobs: Move the portal shortcut id codec into obs-nix-portal-shortcut-ids.c - #1518

Merged
zackees merged 3 commits into
obs-rust:masterfrom
rdoupe:refactor/portal-shortcut-codec-move
Oct 20, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
rdoupe:refactor/portal-shortcut-codec-move

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #1517

What and why

Behavior-neutral extraction before the Rust port, as the testing policy asks for a partial-file port: obs_nix_portal_shortcut_id, obs_nix_portal_shortcut_combo and obs_nix_portal_shortcut_trigger, with the modifier_names table and NUM_MODIFIERS, move verbatim from libobs/obs-nix-portal-shortcuts.c.h into libobs/obs-nix-portal-shortcut-ids.c.h. No Rust, no signature or behavior change, and no public header change.

  • bindable(): the binding collection (collect_binding) uses it too, so it can't go into the codec file alone. It moves verbatim, still static inline, into obs-nix-portal-shortcuts.h (internal, not installed), where both files see it. The codec's declarations stay where they were.
  • Build: the codec gets its own unity group, libobs.nix-portal-shortcut-ids, built next to libobs.nix-portal-shortcuts under the same ENABLE_WAYLAND + GIO condition: CMake on Linux and FreeBSD, and obs-build's Linux libobs. Its precompiled header libobs-nix-portal-shortcut-ids.pch.h has no <gio/gio.h>, so a C test (and later the C oracle) can compile the codec on its own. That is the only reason it isn't in the existing group.
  • NUM_MODIFIERS is now #undef'd at the end of the new file instead of the old one (BUILD.md rule 5).
  • Test build: test_portal_shortcuts compiles the C into itself, so it now compiles both files. The test source is unchanged.
  • Ifdef ratchet: the moved code has no host conditionals.
  • Exported symbols: unchanged. The three functions are not EXPORT, so they are not in the dynamic symbol table, before or after.

New characterization test test_portal_shortcut_ids (tests.d/ fragment, Linux and FreeBSD, plus the Cargo C-test manifest). It needs no GIO, no D-Bus and no libobs core: with no core, obs_key_from_name uses its table fallback. Before this, only shortcut_ids_round_trip inside the GIO portal test covered the codec. 15 cases:

  • bindable() over every key: OBS_KEY_NONE, the 29 mouse buttons and out-of-range keys are not bindable, modifiers never matter, and the key right after OBS_KEY_MOUSE29 is bindable again;
  • ids for plain keys, modifier keys used as the key, each modifier, and all 16 modifier sets (always ctrl, alt, shift, super);
  • unbindable combinations (no key with or without modifiers, mouse buttons, out of range) return false and leave the output alone; a successful call replaces what the dstr held;
  • parsing: canonical ids, and the rejects: empty, modifiers with no key, empty and unknown modifier segments, wrong case, spaces, trigger-style names, non-OBS_KEY_ names, unknown key names, anything after the key, and known but unbindable keys (OBS_KEY_NONE, mouse buttons). A failed parse leaves the output alone;
  • a round trip of every bindable key with seven modifier sets, checking the id string as well;
  • triggers for each modifier and all 16 sets (always CTRL, ALT, SHIFT, LOGO), the key name used as given, the callback called once with the key; no callback, no name, an empty or unset name return false and leave the output alone; the callback is not called for an unbindable combination; a name filled in before returning false is freed;
  • every case checks that bnum_allocs() is back where it started.

Characterized, not endorsed:

  • modifier bits other than ctrl, alt, shift and super (caps, numlock, the mouse and keypad flags) are dropped from ids and triggers, so two combinations that differ only in them share an id. Saved bindings carry only the four (load_modifier in obs-hotkey.c) and the frontend's key capture sets only those, so no user can reach this. I am not filing it as a bug;
  • the parser accepts modifiers in any order and repeated (shift+ctrl+OBS_KEY_A, ctrl+ctrl+OBS_KEY_A). The ids it makes are canonical, so this only matters for ids from elsewhere.

No defects found.

RED → GREEN

  • No RED commit: this is a move plus a characterization test, which passes on the moved code. The move is byte-for-byte: the moved block of obs-nix-portal-shortcuts.c.h before = obs-nix-portal-shortcut-ids.c.h minus its license, include and trailing #undef, plus bindable() in the header. The test also passes against the v0.1.0-beta.20261018 release's libobs.so.30, both the C one and the obs-studio-rust/ one.
  • Local, two build trees (ENABLE_RUST_LIBOBS=OFF and ON, GIO on, full builds). Each runs the full ctest suite against libobs and against libobs-with-rust, headless (private Xvfb, private D-Bus):
Lane libobs libobs-with-rust Exported symbols
C (ENABLE_RUST_LIBOBS=OFF) 330/330 330/330 IDENTICAL (1766)
Rust (ENABLE_RUST_LIBOBS=ON) 330/330 330/330 IDENTICAL (1766)

Nothing was skipped. test_portal_shortcuts (28/28, shortcut_ids_round_trip included), test_wayland_hotkeys and test_wayland_multiseat pass in all four, unchanged.

  • test_portal_shortcut_ids: 15/15 in all four, and 20 repeated runs in each mode.
  • Mutation check of the new test: 10 of 11 mutants of the codec and bindable() fail it (bounds of the mouse and NONE ranges, an extra modifier in the table, unknown modifiers accepted, ids and triggers not reset, the trigger separator, an empty name accepted, the key name leaked). The survivor drops the OBS_KEY_ prefix check, which is equivalent: every key name starts with OBS_KEY_, so obs_key_from_name returns OBS_KEY_NONE for the same inputs.
  • ./lint (ci/local_gate.py --lane lint): passed (45 s)
  • Real app: not applicable (no behavior change).

Windows/macOS: not built there. The codec is Linux and FreeBSD only (Wayland with GIO).

Checklist

  • Base is master
  • 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
  • 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): not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not applicable (no port here)

…t-ids.c

Behavior-neutral extraction before the Rust port:
obs_nix_portal_shortcut_id, obs_nix_portal_shortcut_combo and
obs_nix_portal_shortcut_trigger, with the modifier_names table and
NUM_MODIFIERS, move verbatim from libobs/obs-nix-portal-shortcuts.c.h into
libobs/obs-nix-portal-shortcut-ids.c.h. The binding collection also uses
bindable(), so it moves verbatim into obs-nix-portal-shortcuts.h, still
static inline, where both files see it. The declarations stay where they
were.

The codec gets its own unity group, libobs.nix-portal-shortcut-ids, 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 the
codec on its own. NUM_MODIFIERS is now #undef'd at the end of the new
file instead of the old one. test_portal_shortcuts compiles both files.

New characterization test test_portal_shortcut_ids, with no GIO, D-Bus
or libobs core: bindable() over every key, ids and triggers for plain
keys and all 16 modifier sets, unbindable combinations (no key, mouse
buttons, out of range) leaving the output untouched, the parser's
rejects, a round trip of every bindable key, the key name callback
(missing, empty, not called for unbindable combinations), and no leaked
allocations. Characterized, not endorsed: modifier bits other than ctrl,
alt, shift and super are dropped from ids and triggers, and the parser
accepts modifiers in any order and repeated.

Refs obs-rust#1517
@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 13:39
@zackees
zackees enabled auto-merge October 20, 2026 13:41
obs-internal.h includes caption/caption.h; add deps/libcaption to the test's
include directories as the other obs-internal.h tests do.
@zackees

zackees commented Oct 20, 2026

Copy link
Copy Markdown
Member

Coordinator fixup: Tier 2 failed with libobs/obs-internal.h:44:10: fatal error: caption/caption.h: No such file or directory while compiling test_portal_shortcut_ids. Pushed a fixup: commit adding ${CMAKE_SOURCE_DIR}/deps/libcaption to its include directories, as test_output_caption_text and the other obs-internal.h tests do. Auto-merge stays on.

The previous fixup also moved the submodule pointer from 0c3b7000 to
1e313ae, which this PR does not intend. Put it back to master's commit.

Refs obs-rust#1517
@rdoupe

rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks for the include fix. That fixup (37a79a2) also moved plugins/obs-browser from master's 0c3b7000 to 1e313ae, which this PR doesn't intend, so da66960 puts the pointer back. The diff against master no longer touches the submodule.

@zackees
zackees added this pull request to the merge queue Oct 20, 2026
@zackees

zackees commented Oct 20, 2026

Copy link
Copy Markdown
Member

Thanks for catching that, my mistake: I committed with -a in a checkout whose plugins/obs-browser was locally modified. I'll stage files by path from now on.

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.

2 participants