Repository navigation
obs-hotkey: Port X11 keysyms and mouse answers - #3060
Merged
Merged
Conversation
Behaviour-neutral extraction before the Rust port. The keysym table and the mouse button answers of the X11 hotkey platform move from libobs/obs-nix-x11.c.h into libobs/obs-nix-x11-input.c.h, as hidden functions on plain values declared without EXPORT in the new libobs/obs-nix-x11-input.h: - obs_nix_x11_input_keysym(): get_keysym(), with MOUSE_1 to MOUSE_5; - obs_nix_x11_input_mouse_pressed(): mouse_button_pressed()'s switch with XInput, each mouse key's slot in this poll's pressed array or the held one (button_pressed); - obs_nix_x11_input_commit(): its loop that commits each updated slot; - obs_nix_x11_input_mask_pressed(): its switch without XInput, on the QueryPointer reply's mask. obs-nix-x11.c keeps fill_base_keysyms()'s loop, the raw event drain (every event read and store, each free), the two memsets, the QueryPointer request with its reply, error and frees, every log, key_pressed(), fill_keycodes(), the key names and the vtable. The answer is still asked after the drain and before the commit, and the mask is still read only when the reply has no error. The new file includes no X header, so the C tests and the C oracle compile it on their own: each keysym is written as its value with the X header's name beside it, and the three pointer button masks are defined in the header, which obs-nix-x11.c _Static_asserts against xcb/xproto.h. It gets its own unity group, libobs.nix-x11-input, in the Linux sources (Linux and FreeBSD). Checked with a harness: master's get_keysym() and mouse_button_pressed() and the moved functions with the new mouse_button_pressed(), extracted over logging stand-ins for the event queue, the QueryPointer request and reply, root_window() and blog(), built with gcc and clang at -O0, -O2 and under ASan and UBSan, with and without XInput. Each run logs the keysym of every key (and of values outside the keys), then 20,000 polls of random mouse and other keys over random drains (0 to 6 events: presses, releases and other XInput events, GE and non-GE, buttons 1 to 40), random masks and failed replies, with the three arrays after each poll: identical logs on 3 seeds in all 12 builds (about 125,800 lines a run with XInput, about 103,200 without). 14 planted mutants (12 in the moved file, 2 in the caller: the answer after the commit, the commit's arguments swapped) all change the log. The exported symbols are the same on the C, hybrid and C reference libobs (1767 each); the new functions are local. Refs #3054. Co-authored-by: Lain <[email protected]> Co-authored-by: Shaolin <[email protected]> Co-authored-by: René Rebe <[email protected]> Co-authored-by: Kurt Kartaltepe <[email protected]>
test_nix_x11_input_steps builds the moved libobs/obs-nix-x11-input.c.h into itself and calls its four hidden functions with arrays set by hand as the raw event drain sets them (a press: pressed and update; a release: update), so it needs no X server and runs on every platform (11 cases): - the keysym of a sample of keys from each part of the table, the upper-case keysym for a letter, the XF86 and Sun keysyms; - two pairs of keys that share a keysym, Quoteleft and Asciitilde on XK_grave, Cedilla and Ccedilla on XK_cedilla (characterized, not endorsed: a keysym lookup of the base table finds only the first); - Mouse 1 to 5 as their number shifted left by 16, Mouse 6 to 29 and any key the table doesn't name (Meta, none, out of range) as 0; - the slot each mouse key reads, in the pressed array and in the held one, against every slot: Mouse 1 slot 0, Mouse 2 slot 2, Mouse 3 slot 1, Mouse 4 to 29 slots 7 to 32; - Mouse 29 never pressed, since the drain fills slots 0 to 31 only (characterized, not endorsed); - any other key never pressed, whatever the arrays hold; - a press and its release in later polls: pressed in the poll of the press, held between, still pressed in the poll of the release (the answer comes before the commit), released after; - a release with no press before it; - the commit: an updated slot takes this poll's pressed state, every other slot keeps its held state, and pressed and update are left; - the mask answer without XInput: Mouse 1 on button 1's bit, Mouse 2 on button 3's, Mouse 3 on button 2's, nothing for Mouse 4 or any other key, and the three mask values. Passes on the C libobs build. The real-libobs X11 tests (test_x11_hotkey_layout under Xvfb, test_x11_volume_keys, test_x11_keymap, test_hotkey_volume_keys) pass with the move. Refs #3054.
RED for the port of libobs/obs-nix-x11-input.c.h to a new module, nix_x11_input, of rust/obs-hotkey. The safe core is a stub (todo!()): keysym(), get_keysym()'s table; slot(), the slot each obs mouse key reads in the per-button arrays; mouse_pressed(), the answer with XInput (pressed in this poll, or held from an earlier one); commit(), which stores each updated slot's pressed state as held; and mask_pressed(), the answer without XInput on a QueryPointer mask. Keys are obs_key_t as i32 and the three arrays are [bool; MOUSE_LEN], so the shim can pass the platform's arrays in place. The table needs every key's code by name, so build.rs now writes a pub const for each key of obs-hotkeys.h with an upper-case name (all but the raw OBS_KEY_0x.. codes), not only the ones other modules named. tests/hotkey/nix_x11_input.rs ports test_nix_x11_input_steps 1:1, its 11 cases under the same names, in the same order, with the same inputs and expectations. Kept as characterized, not endorsed: two pairs of keys share a keysym, and Mouse 29 reads a slot the raw event drain never fills. Edge cases: the table names exactly 285 keys and gives 0 for every value outside the keys, Mouse 6 to 29 have no keysym, no slot outside Mouse 1 to 29 and none for the wheel buttons, a commit with nothing or everything updated, and the modifier and wheel bits of the mask. Proptests check slot(), mouse_pressed(), commit(), mask_pressed() and the keysym of non-keys against models written from the C. The tests are a module of the existing core category binary, obs-tests-core; no new test binary. soldr cargo test -p obs-data --test obs-tests-core hotkey::nix_x11_input fails 21 of 21 with "not yet implemented". Refs #3054.
GREEN for #3054. Ports libobs/obs-nix-x11-input.c.h, the keysym table and mouse button answers of the X11 hotkey platform, to the nix_x11_input module of rust/obs-hotkey. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/nix_x11_input.rs): - keysym(): one match arm per key of get_keysym(), each keysym its X header value with the name beside it; 0 for any other value; - slot(): Mouse 1 slot 0, Mouse 2 slot 2, Mouse 3 slot 1, Mouse 4 to 29 slots 7 to 32, none for any other key; - mouse_pressed(): the slot pressed in this poll, else held; - commit(): each updated slot takes this poll's pressed state; - mask_pressed(): Mouse 1 to 3 on buttons 1, 3 and 2's mask bits. It keeps no state, takes no lock, allocates nothing, reads only the arrays it is given and denies clippy's arithmetic, indexing, as-conversion, unwrap, expect, panic and unreachable lints. Shim (src/ffi/nix_x11_input.rs): the four functions with the C signatures. The three per-button arrays cross as XINPUT_MOUSE_LEN bools read in place, and only the held one is written, by the commit. A null array reads as all released, and a commit into a null array does nothing, where C would dereference it. No other difference. C side: the file leaves libobs.nix-x11-input for its own ported group, libobs.ported-nix-x11-input, registered in libobs/build/ported-source-sets/nix-x11-input.json for Linux and FreeBSD. The functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. ci/test_ported_sources.py checks the group is ported on Linux only. test_nix_x11_input_steps still compiles the C file into itself, unchanged. There is no _rust variant, as for test_nix_x11_keys_steps: the archive member does not link on its own, so the Tier 3 tests compare the shims with the C. The real-libobs X11 tests see the swap through the hybrid. Tier 1 hotkey::nix_x11_input passes 21/21. On the hybrid and the C reference libobs, the 22 hotkey and X11 tests pass under Xvfb (test_x11_hotkey_layout, test_x11_volume_keys, test_x11_keymap, test_hotkey_volume_keys and test_nix_x11_input_steps among them); the exported symbols are identical on the C, hybrid and C reference builds (1767 each), with the four functions local in all three. Refs #3054. Co-authored-by: Lain <[email protected]> Co-authored-by: Shaolin <[email protected]> Co-authored-by: René Rebe <[email protected]> Co-authored-by: Kurt Kartaltepe <[email protected]>
Oracle (oracle/nix_x11_input.c): the original obs-nix-x11-input.c.h, unmodified, with its four functions renamed to oracle_*, and a getter for the values the C sees. Tier 3 (tests/hotkey/nix_x11_input_parity.rs, 7 tests): - the values against the C: OBS_KEY_LAST_VALUE, OBS_KEY_NONE, the mouse key range, XINPUT_MOUSE_LEN, the three pointer masks and the size of a bool; - exhaustive over every key, the values just outside them and the int extremes: the keysym (285 keys with one on both sides), and the XInput answer with the button pressed in only one slot, then held in only one slot, for every slot; - the poll as the X11 platform runs it, on both sides: the C drain's stores (a press sets pressed and update, a release update), the answer of every mouse key and the keys around them, then the commit, comparing the held array; exhaustive over every drain of up to four press and release events of buttons 1, 2 and 32 (1,555 drains) from each of the 8 held states of those slots, each followed by an empty poll; - the commit with every update, pressed and held state of a slot in every slot; - the mask answer of every 16-bit mask for every mouse key, the keys around them and three other values; - proptests: three polls in a row with up to six events of any button each, from a random held array, and random arrays for the answer and the commit (256 cases each). No intentional difference: nothing is excluded. Null arrays, which C dereferences, are not passed. Mutation check (done once, not committed); failing tests per mutant: | Mutant | Tier 1 | Tier 3 | |---|---|---| | keysym: Return off by one | 1 | 1 | | keysym: Mouse 3 as Mouse 2 | 2 | 1 | | keysym: no Volume Up | 2 | 1 | | keysym: other keys 1 | 5 | 1 | | slot: Mouse 2 slot 1 | 4 | 4 | | slot: Mouse 29 slot 31 | 4 | 4 | | slot: Mouse 4 on a wheel slot | 4 | 3 | | answer: held ignored | 4 | 4 | | answer: and for or | 4 | 4 | | commit: non-updated slots | 5 | 4 | | commit: always held | 5 | 4 | | commit: slots shifted | 5 | 4 | | mask: Mouse 2 on button 2 | 2 | 1 | | mask: button 1 bit | 2 | 2 | | shim: held read from pressed | 0 | 4 | | shim: commit arguments swapped | 0 | 4 | | shim: keysym of the next key | 0 | 1 | | shim: mask shifted | 0 | 1 | All 18 are killed; the shim mutants only by Tier 3, the tier that reaches the shims. Swapping the answer's two arrays in the shim is an equivalent mutant (pressed or held reads the same both ways), so it is not in the table. The proptest regression files keep the seeds the mutants failed on. Tier 1 and Tier 3 pass (21/21 and 7/7) in 0.05 s. Test cost: longest run of both modules 0.07 s in the debug build with OBS_PARITY_CASES=reduced, peak RSS 24 MB over 25 runs, no threads of their own. Refs #3054.
The rust/README.md crate table now lists libobs/obs-nix-x11-input.c.h among the rust/obs-hotkey units, and its port table has a row for it, before the X11 key map row: the four functions, what stays C in obs-nix-x11.c (the base keysym fill loop, the raw event drain, the memsets, the QueryPointer request, every log, key_pressed(), fill_keycodes(), the key names and the vtable), the keysyms written as their values and the pointer masks asserted against xcb, how the arrays cross, the two characterized-not-endorsed cases (keys that share a keysym; Mouse 29's unfilled slot), the intentional difference for null arrays, what Tier 3 compares and which C tests see the swap. The X11 key map row no longer says obs-nix-x11.c keeps the keysym table. naming.md's rust/obs-hotkey row, the crate's description and its lib.rs module docs add the file and the module. port_comparison gets benches/port_comparison/nix_x11_input.rs: the base keysym fill of every key and 64 polls (the answer of all 29 mouse keys and the commit), folded into a checksum both sides must match. Linux x86_64: Rust 4.7 us, C 6.3 us. It allocates nothing with bmalloc. No docs/features.md line: a port with no change in behaviour. Fixes #3054.
rdoupe
force-pushed
the
fix/rust-port-x11-keysym-table-and-m-298
branch
from
October 30, 2026 13:19
a231f1b to
8660f81
Compare
rdoupe
marked this pull request as ready for review
October 30, 2026 14:42
This was referenced Oct 30, 2026
This was referenced Oct 30, 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.
Fixes #3054
What and why
Ports the X11 keysym table and the mouse button answers of the X11 hotkey platform (
libobs/obs-nix-x11.c.h, Linux and FreeBSD) to a new module,nix_x11_input, ofrust/obs-hotkey, next to the key map lookups ported in #2903. No upstream issue.get_keysym(): the X keysym of each obs key, which fills the base keysym table thatnix_x11_keyssearches at hotkey init.C keeps
fill_base_keysyms()'s loop, the raw event drain (every event read and store, each free), the two memsets, the QueryPointer request with its reply, error and frees, every log,key_pressed(),fill_keycodes(), the key names and the vtable. The answer is still asked after the drain and before the commit.Commits:
libobs: Move X11 keysyms and mouse button answers: behaviour-neutral move intolibobs/obs-nix-x11-input.c.h(hidden functions on plain values, no X header; each keysym written as its value with the X name beside it; the three pointer masks_Static_asserted against xcb). Checked with a harness: master's and the moved functions over logging stand-ins for the event queue, QueryPointer,root_window()andblog(), gcc and clang at -O0, -O2 and ASan/UBSan, with and without XInput, every key's keysym plus 20,000 random polls on 3 seeds: identical logs in all 12 builds; 14 planted mutants all caught. Export sets identical on C, hybrid and C reference (1767 each), the new functions local.test: Characterize X11 keysyms and mouse answers:test_nix_x11_input_steps(11 cases), builds the moved file on its own, every OS.obs_hotkey::nix_x11_inputagainsttodo!().obs-hotkey: Port X11 keysyms and mouse answers: the safe core (one match arm per key of the table, the slot map, the answer, the commit and the mask answer; no state, no allocation, clippy's arithmetic, indexing, as-conversion and panic lints denied) andsrc/ffi/nix_x11_input.rs; the file moves to its own ported group,libobs.ported-nix-x11-input(Linux and FreeBSD), and the four shims are hidden (rust-hidden.txt,rust-exports.map'slocal:,rust-unexports-macos.txt).ci/test_ported_sources.pychecks the group is ported on Linux only.obs-hotkey: Check the X11 input port against the C: oracleoracle/nix_x11_input.cand 7 parity tests (below), with the mutation check.docs: Record the X11 keysym and mouse answer port: therust/README.mdrows (and the X11 key map row, which still said C kept the keysym table),naming.md, the crate description andlib.rs, and aport_comparisonbench (Linux x86_64: Rust 4.7 us, C 6.3 us for the base keysym fill plus 64 polls; nobmalloc).Review fixes, folded into the commits they belong to: the commit loop reads a slot's pressed flag only inside its update check, as the C does (GREEN); the export list entries are sorted (GREEN); both proptest modules go through
obs_c_oracle::parity::cases(256)(RED and Tier 3).rust/obs-hotkey/build.rsnow writes apub constfor every key ofobs-hotkeys.hwith an upper-case name (all but the rawOBS_KEY_0x..codes), since the table names nearly all of them.Tier 3 (
tests/hotkey/nix_x11_input_parity.rs): the values (XINPUT_MOUSE_LEN, the mouse key range, the three masks,sizeof(bool)); exhaustive over every key plus the values around them and theintextremes (keysym, and the answer with one slot pressed or held, for every slot); every drain of up to four press and release events of buttons 1, 2 and 32 from each of the 8 held states, run as the platform runs a poll (the C drain's stores, the answer of every mouse key, the commit, then an empty poll); every slot state of the commit; every 16-bit mask for every mouse key; proptests over three polls in a row and random arrays. No intentional difference in behaviour; null arrays, which C dereferences, read as all released (not passed to the C).Mutation check (done once, not committed): 18 mutants (14 in the core, 4 in the shim) all killed; the shim mutants only by Tier 3. The table is in the Tier 3 commit message.
Test cost: new tests (Tier 1 and Tier 3 together): longest run 0.07 s in the debug build with
OBS_PARITY_CASES=reduced, peak RSS 24 MB over 25 runs, no threads of their own.Upstream authors of the ported code (Lain, Shaolin, René Rebe, Kurt Kartaltepe) are credited on the move and the port commits.
Characterized, not endorsed (kept): two pairs of keys share a keysym (Quoteleft and Asciitilde on
XK_grave, Cedilla and Ccedilla onXK_cedilla), and Mouse 29 reads slot 32, which no raw event fills, so it never reads as pressed with XInput.RED → GREEN
obs-hotkey: Add Tier 1 tests for X11 input port):soldr cargo test -p obs-data --test obs-tests-core hotkey::nix_x11_inputfails 21 of 21 with "not yet implemented"; the local test-diff gate on it shows exactly those 21 failing (5249 passed, 6 skipped) and the lint lane passes.test_x11_hotkey_layout,test_x11_volume_keys,test_x11_keymap,test_hotkey_volume_keys,test_nix_x11_input_steps,test_nix_x11_keys_stepsamong them) pass on the C, hybrid and C reference libobs, none skipped. Exported symbols identical on the three builds (1767 each), the four functions local in all three. Local gates:--test-diff5277/5277 (6 skipped),--lane lint,--lane crossandsoldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targetspass. Runs were on 8660f81 (rebased on current master):./lint, the./unittestRust lanes (5309 and 857 tests, 6 skipped),--lane lint,--lane cross, the Windows clippy, theport_comparisonbench test, the export comparison and the hotkey and X11 Tier 2 tests above. Tier 2 in Docker could not run on this host, so the head is not stamped and PR CI runs the full suite.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable