Repository navigation
libobs: Lock the hotkey mutex through a hidden accessor - #1515
Merged
zackees merged 1 commit intoOct 20, 2026
Merged
Conversation
Behavior-neutral seam before the Rust port of obs-nix-hotkey-state: obs_hotkeys_mutex_lock() and obs_hotkeys_mutex_unlock(), declared in obs-internal.h next to the other hotkey platform-client helpers and defined in obs-hotkey.c, lock and unlock obs->hotkeys.mutex. They are not EXPORT, so -fvisibility=hidden keeps them out of libobs. obs-nix-hotkey-state.c locks through them instead of reading the obs_core field, so the port does not need the obs_core layout. Like the old code, they do not check obs for NULL. Nothing else changes, and the exported symbol set stays the same. test_wayland_hotkeys and test_portal_shortcuts already compile obs-hotkey.c with obs=hotkey_test_obs, so the accessor locks the test core there. test_wayland_multiseat compiles obs-nix-hotkey-state.c without obs-hotkey.c, so its harness gains hotkey_mutex_stub.c, which locks its test core's mutex the same way. No test case changes. Refs obs-rust#1514
6 of 7 tasks
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 20, 2026
* libobs: Add Tier 1 tests for the Wayland hotkey key state port 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: Port the Wayland hotkey key state to obs-hotkey 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 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
Refs #1514 (PR 1 of 2: the accessor; the port follows once this lands)
What and why
obs-nix-hotkey-state.c.hlocksobs->hotkeys.mutex, a field ofobs-internal.h. The testing policy says a C caller that reaches intoobs-internal.hgets a behaviour-neutral internal accessor in its own PR before the unit is ported. This is that PR. It has no Rust, and no public header or signature changes.obs_hotkeys_mutex_lock()/obs_hotkeys_mutex_unlock()are declared inobs-internal.h, next to the other hotkey platform-client helpers (obs_hotkeys_background_clear_shortcuts,obs_hotkeys_background_status_changed), and defined inobs-hotkey.c.hbeside its file-locallock()/unlock(). They are notEXPORT, so-fvisibility=hiddenkeeps them out oflibobs.so, as withobs_hotkey_name_map_free.obs-nix-hotkey-state.c.h'shotkey_state_lock()/hotkey_state_unlock()call them instead of touching the field. As before, there is no NULL check onobs(unlikelock()in obs-hotkey.c). The mutex is the same recursive one, and the lock is taken and released at the same points.obs-nix-portal-shortcuts.c.handobs-cocoa.m.hstill lock the field directly. They are outside this unit and unchanged.Tests:
test_wayland_hotkeysandtest_portal_shortcutsalready compileobs-hotkey.c.hwithobs=hotkey_test_obs, so the accessor locks their test core with no change.test_wayland_multiseatcompilesobs-nix-hotkey-state.c.hwithoutobs-hotkey.c.h, so its harness getstest/cmocka/hotkey_mutex_stub.c: the same two functions, built with the test'sobs=wayland_test_obs, which lock that core's mutex as before. It is one extra source line intests.d/test_wayland_multiseat.cmake. No test case changes.RED → GREEN
ENABLE_RUST_LIBOBS=OFFandON), headless (private Xvfb, private D-Bus, fresh HOME). Each runs the full cmocka suite againstlibobsand againstlibobs-with-rust:ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)No test was skipped or not run. The export lists are also identical across the two lanes.
obs_hotkeys_mutex_lock/_unlockshow up in the static symbol table of all fourlibobs.sobuilds and in none of the dynamic export tables.test_wayland_hotkeys,test_portal_shortcuts,test_wayland_multiseat: pass in all four runs.uv run ci/local_gate.py --lane lint: ok (42 s).Checklist
mastertest_wayland_hotkeysandtest_portal_shortcuts)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable