Repository navigation
libobs: Port the portal shortcut id codec to obs-hotkey - #1519
Merged
Merged
Conversation
RED for the port of libobs/obs-nix-portal-shortcut-ids.c.h to the obs-hotkey crate. The safe core (obs_hotkey::portal_shortcut_ids) has bindable, shortcut_id, shortcut_combo and shortcut_trigger, generic over the Text an id or trigger is written to, so the C ABI shim can run them on the caller's dstr with the same dstr calls as the C. Its functions are todo!() stubs. obs-hotkey's build.rs now also emits OBS_KEY_MOUSE1 and OBS_KEY_MOUSE29 from obs-hotkeys.h. The first fifteen cases mirror test_portal_shortcut_ids 1:1, including its "characterized, not endorsed" cases, with a counting Text in place of the C test's bnum_allocs teardown. The rest pin the edges: the modifier table, keys at the ends of the range, Vec<u8> as a Text, key names holding a NUL, and segments that only look like known modifiers. soldr cargo test -p obs-data --test obs-tests-core hotkey::portal_shortcut_ids fails 19 of 20 with "not yet implemented" (the modifier table case passes). Refs obs-rust#1517
libobs/obs-nix-portal-shortcut-ids.c.h moves to obs_hotkey::portal_shortcut_ids. Its three functions, obs_nix_portal_shortcut_id, obs_nix_portal_shortcut_combo and obs_nix_portal_shortcut_trigger, are what obs-nix-portal-shortcuts.c calls to name a key combination as a GlobalShortcuts shortcut id, parse an id back, and offer the combination as the preferred trigger. bindable() stays the static inline in obs-nix-portal-shortcuts.h; the core has the same check, and the oracle compares the two. The core is generic over the Text an id or trigger is written to. The shim writes the caller's dstr with the C's calls in the C's order (dstr_free, one dstr_cat per piece, dstr_cat_dstr for the key name), so bytes, length and capacity match; the key name comes from the caller's callback into a zeroed dstr, as in C. Key names come from the name map port. A null id or trigger dstr, a null id string or a null combo out-pointer returns false, where C dereferences them. The file moves from libobs.nix-portal-shortcut-ids to its own ported group, libobs.ported-nix-portal-shortcut-ids (same PCH contents, renamed with it). The group is LIBOBS_WAYLAND_GIO_PORTED_SOURCES, added to libobs only under ENABLE_WAYLAND with GIO (os-linux.cmake, os-freebsd.cmake), and followed by obs-build's Linux C variant and rust/tools/ported_sources.py (new --without-gio; the group also needs Wayland, which linux-validate already turns off). The shims call nothing from GIO, so they are built on every host with no Cargo feature. The three symbols are not EXPORT, so they go in rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. Tier 3 (oracle/portal_shortcut_ids.c) compares bindable over every key and random ones, the key codes and modifier bits, the modifier table, and random combinations, id strings (known and near-miss modifier names, key names, arbitrary bytes), key name callbacks and starting dstrs: the result, the output bytes, length and capacity, the combo out-value and the callback calls. test_portal_shortcut_ids and test_portal_shortcuts compile the C into themselves and are unchanged. Fixes obs-rust#1517
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.
Base: master
Fixes #1517 (PR 2 of 2; PR 1, #1518, moved the codec into its own file and added its characterization test)
What and why
This PR ports
libobs/obs-nix-portal-shortcut-ids.c.h, the GlobalShortcuts portal shortcut id and trigger codec, to the existingrust/obs-hotkeycrate. The file has three functions:obs_nix_portal_shortcut_id,obs_nix_portal_shortcut_comboandobs_nix_portal_shortcut_trigger. The portal clientobs-nix-portal-shortcuts.ccalls them to name a key combination as a shortcut id (ctrl+shift+OBS_KEY_F13), to parse an id back, and to offer the combination as the preferred trigger (CTRL+SHIFT+F13).libobs-with-rustdrops the C file and links the Rust shims.obs-hotkeyalready holds the name-map (rust: Port libobs/obs-hotkey-name-map.c to obs-hotkey #833) and Wayland key state (libobs: Port the Wayland hotkey key state to obs-hotkey #1516) ports, so the naming.md row now listsobs-nix-portal-shortcut-ids.c.htoo. No new crate and no new dependency.build.rsnow also emitsOBS_KEY_MOUSE1andOBS_KEY_MOUSE29fromobs-hotkeys.h.src/portal_shortcut_ids.rs):bindable,shortcut_id,shortcut_comboandshortcut_trigger, plus theMODIFIER_NAMEStable.Texttrait (free,cat,cat_text,is_empty: the fourdstroperations the C uses).Vec<u8>implements it for Rust callers.key_name,key_from_name).cfg, nounsafe.src/ffi/portal_shortcut_ids.rs):struct dstr, written with the C's calls in the C's order:dstr_free, onedstr_catper piece, anddstr_cat_dstrfor the key name. So the bytes, the length and the capacity come out the same as in C. The key name callback gets a zeroeddstr, as in C.bindablestays thestatic inlineinobs-nix-portal-shortcuts.h, because the binding collection uses it too. The core has the same check, and the oracle compares the two.EXPORT, so the three symbols are hidden: listed inrust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt, with norust-exports.dfragment (as in libobs: Port obs_bounds_fit_scale to Rust #1486, libobs: Port the PulseAudio stream flags to obs-audio-monitoring #1513 and libobs: Port the Wayland hotkey key state to obs-hotkey #1516). In bothlibobs.sobuilds they are local (t).gioCargo feature. They are built on every host and unused where the portal client is not, like the libobs: Port the Wayland hotkey key state to obs-hotkey #1516 shims.libobs.nix-portal-shortcut-ids(from libobs: Move the portal shortcut id codec into obs-nix-portal-shortcut-ids.c #1518) becomeslibobs.ported-nix-portal-shortcut-ids, and its PCH is renamed with it (same contents: no<gio/gio.h>, so the C tests and the oracle compile the file on their own).LIBOBS_WAYLAND_GIO_PORTED_SOURCESinsource-sets.json. It is added tolibobsonly, underENABLE_WAYLANDwith GIO, inos-linux.cmakeandos-freebsd.cmake.libobs.nix-portal-shortcutsstays inlibobs-objects.wayland && gio.rust/tools/ported_sources.pygets--without-gio; the set is only included with Wayland, solinux-validate/validate.sh(which builds withENABLE_WAYLAND=OFFand passes--without-wayland) needs no new flag, only an updated comment.ci/test_ported_sources.pycovers both flags.oracle/portal_shortcut_ids.c): it renames the three functions with#defines and includes the original file. It also wrapsbindable, and exports the key codes, the fourINTERACT_*_KEYbits and themodifier_namestable. Thedstrfunctions andobs_key_to_name/obs_key_from_namekeep their real names, so undercargo testthey are the Rust ports (each has its own parity test). That keeps the oracle away from the C name map's globalobstoggle, which the name-map parity test changes.idortriggerdstr, a null id string, or a nullcomboout-pointer returns false, and a nulltriggerdoes not callkey_name. These are listed in the shim docs, the parity test header and therust/README.mdrow. Nothing else differs. The two "characterized, not endorsed" behaviours from libobs: Move the portal shortcut id codec into obs-nix-portal-shortcut-ids.c #1518 are kept: modifier bits other than ctrl, alt, shift and super are dropped, and the parser takes modifiers in any order and repeated.test_portal_shortcut_ids(15) andtest_portal_shortcutscompile the C into themselves and are unchanged. They pass in every lane, but they cannot see the swap, so Tier 3 is the swap's proof, as with #1486, #1513 and #1516.RED → GREEN
a8d682790libobs: Add Tier 1 tests for the portal shortcut id codec port. The safe core hastodo!()bodies.soldr cargo test -p obs-data --test obs-tests-core hotkey::portal_shortcut_idsfails 19 of 20 with "not yet implemented" (the modifier table case passes).tests/hotkey/portal_shortcut_ids.rs) mirrorstest_portal_shortcut_ids1:1, with the same fifteen test names and cases. The C test's teardown checksbnum_allocs; here a countingTextchecks that every buffer the codec allocates is freed (the callback's name included).i32range,Vec<u8>as aText, key names holding a NUL (copied whole; a leading NUL is an empty name), and segments that only look like known modifiers.obs-tests-core. No new test binary:ci/test_binary_cap.pyreports 8 of 8.50fbe9bf8libobs: Port the portal shortcut id codec to obs-hotkey.hotkey::portal_shortcut_idspasses 20/20, and the wholeobs-tests-corebinary passes (200/200).tests/hotkey/portal_shortcut_ids_parity.rs), both sides compared after every call:bindablefor every key from -300 toOBS_KEY_LAST_VALUE + 300and thei32extremes, with three modifier sets, then 2048 random cases;modifier_namestable against the oracle;OBS_KEY_LAST_VALUE + 1with three modifier sets: the id, then a parse of that id back;i32), modifiers (subsets of the four bits, with extra bits, anyu32) and a startingdstr(zeroed, empty, random text); parses of random ids built from known and near-miss modifier names (CTRL,ctr,superr, ...), key names (bindable or not) and random bytes, or plain random bytes; triggers with random callback behaviour (none, write exact bytes NULs included, leave the name, return true or false);comboout-value, and the callback's calls (key, and the name's state on entry).OBS_KEY_LAST_VALUEbound off by one, modifiers in reverse order, nodstr_freebefore an id, no empty-name check, case-insensitive modifier matching,-in place of+in triggers;dstr_freeleaving the capacity (the run aborts on the first trigger case),dstr_is_emptyignoring a leading NUL, an extra bit written to thecomboout-value.ENABLE_RUST_LIBOBS=OFFandON,ENABLE_WAYLAND=ON, GIO found). Each tree runs the full cmocka suite againstlibobs(OFF) andlibobs-with-rust(ON):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)No test was skipped or not run in any of the four runs. The export lists are also identical across the two lanes, and none of them has a
obs_nix_portal_shortcut_*symbol.test_portal_shortcut_ids,test_portal_shortcuts,test_wayland_hotkeysandtest_wayland_multiseatpass in all four runs.libobs.ported-nix-portal-shortcut-ids+.h.cis linked intolibobsand not intolibobs-with-rust; inlibobs-with-rustthe three symbols are local and come from the Rust core.Environment: headless (private Xvfb, private D-Bus, fresh HOME).
ci/local_gate.py:--lane lint(clang-format, gersemi, rustfmt, clippy-D warnings, Dylints, ifdef ratchet, test-binary cap): passed.--lane cross(clippy and Dylints forx86_64-pc-windows-msvcandaarch64-apple-darwin, plus a link of every test binary, oracle included): passed.--lane cross-release: passed.--lane rust-test(soldr cargo test --workspace --locked, plus a--no-runlink forx86_64-pc-windows-gnu): passed.obs-tests-core200/200. The obs-util harness 668/668, including theexport_listcheck that every shim is exported or hidden.ci/test_build_groups.py,ci/test_naming.py,ci/test_ported_sources.py,ci/test_rust_scope.py,ci/test_binary_cap.py,ci/test_cmocka_includes.py: OK.Real app: not applicable (no behaviour change).
Checklist
master(or the description starts with a Stacked: note)test_portal_shortcut_idslanded in libobs: Move the portal shortcut id codec into obs-nix-portal-shortcut-ids.c #1518)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable