Repository navigation
libobs: Port the Wayland hotkey key state to obs-hotkey - #1516
Merged
Merged
Conversation
RED for the port of libobs/obs-nix-hotkey-state.c.h to the obs-hotkey crate. The safe core (obs_hotkey::nix_hotkey_state) is generic over where the state lives and over the hotkey lock, so the C ABI shim can run it on the C struct and take obs->hotkeys.mutex exactly where the C does. Its functions are todo!() stubs. obs-hotkey's build.rs now also emits OBS_KEY_LAST_VALUE and the four modifier key codes from obs-hotkeys.h. The first eight cases mirror test_wayland_hotkeys 1:1, with a model of one hotkey poll cycle (query_hotkeys and handle_binding with strict modifiers, the lock held for the cycle) in place of the real thread. The rest pin the edges: out-of-range keys are ignored without locking, each change locks once and free not at all, modifier keys read the modifier bits, the shortcut state machine (repeat activation, release pending until observed, erase once observed), flush order and its return value, and modifier-only combinations. soldr cargo test -p obs-data --test obs-tests-core hotkey::nix_hotkey_state fails 17 of 17 with "not yet implemented". Refs obs-rust#1514
libobs/obs-nix-hotkey-state.c.h moves to obs_hotkey::nix_hotkey_state. Its seven functions (free, set_key, set_modifiers, clear_keys, set_shortcut, flush, is_pressed) are what obs-nix-wayland.c and obs-nix-portal-shortcuts.c call to tell the hotkey thread which keys and GlobalShortcuts are held. The safe core runs on any Store (the owned KeyState, or the C struct through the shim) and takes the HotkeyLock exactly where the C takes obs->hotkeys.mutex: once per call, none for an out-of-range key or for free. The shim's lock is libobs's hidden obs_hotkeys_mutex_lock/unlock (obs-rust#1515); it never reads obs. The struct and its bmalloc darray stay the caller's: the shim borrows the fields only after the lock is taken, and grows and erases the darray as da_push_back and da_erase do. A null state returns (false) without locking, where C dereferences it. The file leaves libobs.nix-wayland for its own group, libobs.ported-nix-hotkey-state, whose PCH holds only the file's header so the oracle and the C tests can compile it without Wayland. The group is LIBOBS_WAYLAND_PORTED_SOURCES, added to libobs only under ENABLE_WAYLAND (os-linux.cmake, os-freebsd.cmake), and followed by obs-build's Linux C variant and rust/tools/ported_sources.py (new --without-wayland, which linux-validate passes as it builds with ENABLE_WAYLAND=OFF). The seven symbols are not EXPORT, so they go in rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. The shims are built on every host and unused off Wayland. Tier 3 (oracle/nix_hotkey_state.c) compares the layout of the three structs, the key codes and modifier bits, and random sequences of key, modifier, focus, shortcut, flush, poll and free events: after every step the result, the lock calls, the keys, the modifiers and the darray (count, capacity, items). test_wayland_hotkeys, test_portal_shortcuts and test_wayland_multiseat compile the C into themselves and are unchanged. Fixes obs-rust#1514
This was referenced Oct 20, 2026
This was referenced Oct 29, 2026
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 #1514 (PR 2 of 2; PR 1, #1515, added the hidden lock accessor this port calls)
What and why
This PR ports
libobs/obs-nix-hotkey-state.c.h, the Linux/FreeBSD Wayland key and shortcut state machine, to the existingrust/obs-hotkeycrate. The file has seven functions:obs_nix_hotkey_state_free,_set_key,_set_modifiers,_clear_keys,_set_shortcut,_flushand_is_pressed.obs-nix-wayland.candobs-nix-portal-shortcuts.ccall them to tell the hotkey thread which keys and GlobalShortcuts are held.libobs-with-rustdrops the C file and links the Rust shims.obs-hotkeyalready holds the hotkey name-map port (rust: Port libobs/obs-hotkey-name-map.c to obs-hotkey #833), so the naming.md row now readslibobs/obs-hotkey-name-map.c,obs-nix-hotkey-state.c.h→rust/obs-hotkey. No new crate. obs-util moves from a dev-dependency to a dependency, because the shortcut list is abmallocdarray (obs_util::ffi::darray).build.rsnow also emitsOBS_KEY_LAST_VALUEand the four modifier key codes fromobs-hotkeys.h, so they cannot drift from the C enum.src/nix_hotkey_state.rs):Store: the ownedKeyState, or the C struct through the shim) and over the lock (HotkeyLock).key <= OBS_KEY_NONE || key >= OBS_KEY_LAST_VALUE) or forfree.cfg, nounsafe.src/ffi/nix_hotkey_state.rs):#[repr(C)]obs_key_combination,obs_nix_hotkey_shortcutandobs_nix_hotkey_state. The darray field is a#[repr(transparent)]wrapper ofstruct darray, grown and erased asda_push_backandda_erasedo.obs->hotkeys.mutex, taken through libobs's hiddenobs_hotkeys_mutex_lock/obs_hotkeys_mutex_unlock(libobs: Lock the hotkey mutex through a hidden accessor #1515). The Rust side never readsobs.&mutborrows of the same struct never overlap.EXPORT, so the seven symbols are hidden: they are listed inrust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt, and there is norust-exports.dfragment (same as libobs: Port obs_bounds_fit_scale to Rust #1486 and libobs: Port the PulseAudio stream flags to obs-audio-monitoring #1513). In bothlibobs.sobuilds they are local (t).ENABLE_WAYLANDcall them.obs_hotkeys_mutex_lockis defined inobs-hotkey.c.hon every host, so Windows and macOS link as before (thecrossandcross-releaselanes pass).libobs.nix-waylandfor its own group,libobs.ported-nix-hotkey-state. That group's PCH,libobs-ported-nix-hotkey-state.pch.h, holds only the file's own header. That way the oracle and the C tests compile the file without Wayland. Inlibobs-wayland.pch.h, theobs-nix-hotkey-state.hinclude moves to theobs-nix-wayland.csection, because that file uses the struct too.LIBOBS_WAYLAND_PORTED_SOURCESinsource-sets.json. It is added tolibobsonly, underENABLE_WAYLAND, inos-linux.cmakeandos-freebsd.cmake. This mirrorsLIBOBS_PULSE_PORTED_SOURCES.rust/tools/ported_sources.py, which drives the Tier 2 "compiled into libobs, not into libobs-with-rust" object check.ported_sources.pygets a new--without-waylandflag, andci/test_ported_sources.pyis extended to cover it.linux-validate/validate.shpasses the flag, because its build configuresENABLE_WAYLAND=OFF.oracle/nix_hotkey_state.c): it renames the seven functions with#defines and includes the original file. It also exports the key codes, the modifier bits, and the size, alignment and field offsets of the three structs.obs_hotkeys_mutex_lock/_unlockandbmallocstay the real symbols. Undercargo test, the hotkey test module defines the lock pair as per-thread counters. The C oracle and the Rust shim call the same pair, so the parity test can compare their lock calls.statereturns (false fromflushandis_pressed) without locking. C dereferences it, and no caller passes null. This is listed in the shim docs, the parity test header and therust/README.mdrow. Nothing else differs.test_wayland_hotkeys(8),test_portal_shortcuts(28) andtest_wayland_multiseatcompile the C into themselves and are unchanged (the multiseat test keepshotkey_mutex_stub.cfrom #1515). They pass in every lane, but they cannot see the swap, so Tier 3 is the swap's proof, as with #1486 and #1513.RED → GREEN
be58806c4libobs: Add Tier 1 tests for the Wayland hotkey key state port. The safe core hastodo!()bodies.soldr cargo test -p obs-data --test obs-tests-core hotkey::nix_hotkey_statefails 17 of 17 with "not yet implemented".tests/hotkey/nix_hotkey_state.rs) mirrorstest_wayland_hotkeys1:1, with the same eight test names. The C test runs the real hotkey thread. Here one poll cycle is modelled onquery_hotkeys/handle_bindingwith strict modifiers (the C test's setting): the lock is held for the whole cycle, and the four modifier keys are queried first.freedoes not lock;clear_keyskeeps shortcuts, andfreekeeps keys.obs-tests-core. No new test binary:ci/test_binary_cap.pyreports 8 of 8.04a97a980libobs: Port the Wayland hotkey key state to obs-hotkey.hotkey::passes 28/28, and the wholeobs-tests-corebinary passes (171/171).obs_key_combination_t,struct obs_nix_hotkey_shortcutandstruct obs_nix_hotkey_stateare compared with the C header.OBS_KEY_LAST_VALUE, the four modifier key codes and the fourINTERACT_*_KEYbits are compared with the oracle.tests/hotkey/nix_hotkey_state_parity.rs):OBS_KEY_LAST_VALUE);i32), and modifiers are subsets of the four bits or anyu32;SetShortcut(.., false)step;is_pressed: the first mismatch is the lock calls, on the firstIsPressedstep.ENABLE_RUST_LIBOBS=OFFandON,ENABLE_WAYLAND=ON). Each tree runs the full cmocka suite againstlibobs(OFF) andlibobs-with-rust(ON):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)test_wayland_hotkeys,test_portal_shortcutsandtest_wayland_multiseatpass in all four runs.libobs.ported-nix-hotkey-state+.h.cis linked intolibobsand not intolibobs-with-rust. Thelibobs-with-rustsymbols come from the Rust core.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-core171/171. 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: OK.Checklist
master(or the description starts with a Stacked: note)test_wayland_hotkeys,test_portal_shortcutsandtest_wayland_multiseat)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable