Repository navigation
Description
Unit
Port the macOS key map and pressed check of libobs/obs-cocoa.m.h to rust/obs-hotkey, as a new module cocoa_keys, next to the X11 key map port (#2901). On macOS, libobs uses them in the event tap callback (which modifier keys are down, which key a key code is), in the hotkey thread's "is this key down" poll, and in the public obs_key_from_virtual_key / obs_key_to_virtual_key. These decisions move:
KeyboardEventProc's modifier map: the Shift, Option, Command and Control flag bits toOBS_KEY_SHIFT,OBS_KEY_ALT,OBS_KEY_METAandOBS_KEY_CONTROL.obs_key_to_virtual_key(): the table code when the entry is valid, elseINVALID_KEY(0xFF).obs_key_from_virtual_key(): the first valid table entry with the code, elseOBS_KEY_NONE.obs_hotkeys_platform_is_pressed()'s decisions: the mouse key range and its button bit, then the key range gate.
These stay in C: the tables (virtual_keys, key_descriptions, key_glyphs), the key-name functions (obs_key_to_localized_string, key_code_to_string, obs_key_to_str), InputMethodChangedProc, obs_hotkeys_platform_init/_free, every CGEvent*, TIS and CF call, [NSEvent pressedMouseButtons], the writes to the key state, the NULL platform check and every log.
Phase and position
Phase 6, macOS host code; the macOS counterpart of the X11 key map port (#2901). Tracking: #4.
Dependencies and existing tests
- No dependency to land first.
- Real libobs: no test covers these on macOS.
- No characterization:
test_cocoa_keys_stepslands first in the same PR, builds the moved C file on its own (plain C, no Carbon or CoreGraphics header) and runs on every OS.
Notes
One PR, separate commits: the behaviour-neutral move into libobs/obs-cocoa-keys.c.h (hidden functions on plain values; the flag bits, the mouse key range and INVALID_KEY are _Static_asserted against the macOS headers in obs-cocoa.m.h), characterization, RED, GREEN (group libobs.ported-cocoa-keys in the macOS ported sources), Tier 3 (every key value, every 7-bit virtual code, proptests over flag words and button masks), docs.
Intentional differences, both fixed in the port:
obs_key_to_virtual_keyon macOS returnsINVALID_KEYfor a key outside0 .. OBS_KEY_LAST_VALUE - 1; C indexes the table with it.- A mouse-button hotkey on macOS tests the wrong bit of
[NSEvent pressedMouseButtons]: C takeskey - 1(the key's enum value, hundreds) as the bit and shifts anintby it, which is undefined. The port tests bitkey - OBS_KEY_MOUSE1(MOUSE1 is the left button, bit 0).
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 29, 2026
Claiming: #2914
Plan, one PR with separate commits:
libobs: Movethe modifier map, the two virtual key lookups and the pressed check's decisions intolibobs/obs-cocoa-keys.c.h: hidden functions on plain values, no Carbon or CoreGraphics header, behaviour-neutral (checked by building master's and the moved functions side by side on the same inputs).test_cocoa_keys_steps, building the moved file on its own, on every OS.obs_hotkey::cocoa_keysagainsttodo!()stubs.src/ffi/cocoa_keys.rs, grouplibobs.ported-cocoa-keysin the macOS ported sources, with the key range check and the mouse button bit fix.I expect the draft PR today, within a few hours.
libobs: Move the macOS key map and pressed check
test: Characterize the macOS key map
obs-hotkey: Add Tier 1 tests for macOS keys
obs-hotkey: Port the macOS key map
obs-hotkey: Check the macOS key port against the C
docs: Record the macOS key map port
libobs: Move the macOS key map and pressed check
test: Characterize the macOS key map
obs-hotkey: Add Tier 1 tests for macOS keys
obs-hotkey: Port the macOS key map
obs-hotkey: Check the macOS key port against the C
docs: Record the macOS key map port
rdoupe commentedon Oct 29, 2026
Fixed by #2917 (merged through the merge queue as 9055956). The macOS key map and pressed check now live in
rust/obs-hotkeyascocoa_keys; libobs calls them through six hidden functions inlibobs/obs-cocoa-keys.c.h. Tier 1 (26 cases), the unchanged C tests, and Tier 3 parity against the C (7 cases, 15 mutants all killed) pass. Two intentional differences are listed indocs/features.md: a mouse-button hotkey now tests bitkey - OBS_KEY_MOUSE1of[NSEvent pressedMouseButtons], andobs_key_to_virtual_keyreturnsINVALID_KEYfor a key OBS does not have.Left, by design: the tables (
virtual_keys,key_descriptions,key_glyphs), the key names,InputMethodChangedProc, the event tap, every CGEvent, TIS, CF and NSEvent call, the key state, the NULL platform check and every log stay in C. There is no follow-up issue for them. Everything ran on Linux plus a mac-arm64 cross-compile; nothing was run on a Mac.obs-hotkey: Port the macOS key map (obs-rust#2917)