plat/linux_xkb.rs (Linux)#
Source: lib/plat/linux_xkb.rs
linux_xkb -- minimal XKB keymap parser and key translation (Wayland keyboard; the X11
backend fills the same table from the core keyboard mapping) [src/plat/linux/xkb.s]
xkb_parse(text) -> 0 ok / -1 parse an xkbcommon text keymap (format 1)
xkb_use_fallback() built-in evdev -> US English table
xkb_set_mods(depressed, latched, locked, group) -> MOD_* bits (also wl_mods())
xkb_key(evdev) -> (VK, text codepoint) for the current modifiers (text 0 = none)
xkb_key_typed(evdev) -> (VK, [text; 2]) a key press with the dead keys composed (below)
xkb_dead_reset() forget a pending dead key (focus change)
xkb_dead_keysym(spacing) -> X keysym the dead keysym of a dead key's spacing character
xkb_is_modifier(evdev) -> bool the key is a modifier (never auto-repeats)
xkb_mod_bit(evdev) -> MOD_* bit the key holds (Shift / Ctrl / Alt / Super / AltGr) or 0
xkb_dump() print the parsed table to stdout (tests)
wl_mods() / wl_mods_set(m) the MOD_* bits of the events (g_wl_mods)
X11 backend: xkb_begin(), xkb_set_key(evdev, levels, nlev), xkb_set_roles(alt, num,
super, level3)
Parsed: xkb_keycodes (`<NAME> = code;`, `alias <A> = <B>;`, names <= 4 chars, codes
< 264), xkb_symbols (first level list of group 1 per key, `type=`, `modifier_map`).
xkb_types / xkb_compatibility are skipped; key types are classified by name (ONE_LEVEL,
CTRL+ALT, PC_* -> one level; *KEYPAD* -> keypad; *ALPHABETIC* -> Caps Lock applies) or,
without an explicit type, like xkbcomp does (1 symbol -> one level, KP_* -> keypad, a/A
pair -> alphabetic).
Level: ONE -> 1; KEYPAD -> (Shift ^ NumLock) ? 2 : 1;
else s = Shift ^ (ALPHA && Caps && !Level3), level = (Level3 ? 3 : 1) + s.
Text is produced for codepoints >= 0x20 (not 0x7F) unless Ctrl / Alt / Super is held
without Level3 (AltGr may arrive as Ctrl + Mod5 from Windows hosts). Dead keys: xkb_key
gives their spacing character; xkb_key_typed composes like Windows does -- a dead key is
held back, the next letter becomes the accented one (´ e -> é, ^ o -> ô, ¨ u -> ü, ...),
Space or the same dead key gives the spacing character, anything else both; a key without
text (Backspace, Esc, a shortcut) drops it. (An input method, IBus through text-input-v3,
composes before the keys reach us.) VK codes: layout-following for a-z / 0-9
(level-1 symbol, like Win32) and for + , - . (VK_OEM_PLUS/COMMA/MINUS/PERIOD); otherwise
by key position; keypad keys give navigation VKs while Num Lock is off.
The table is process state behind a lock (both display backends and the tests use it).
// symbol values: codepoint | flags
KV_CP: u32 = 0x1FFFFF
KV_KP: u32 = 0x2000_0000
KV_DEAD: u32 = 0x4000_0000
KV_MODSHIFT: u32 = 24
fn wl_mods() -> u32the MOD_* bits the events carry (g_wl_mods)fn wl_mods_set(m: u32)set the MOD_* bits of the events (a modifier key's own event, wl_input)fn xkb_parse(text: &[u8]) -> i32parse an xkbcommon text keymap -> 0 ok / -1 (fewer than 20 keys found) [xkb_parse]fn xkb_use_fallback()evdev -> US English symbols (used when no keymap parses) [xkb_use_fallback]fn xkb_begin()(X11 backend) empty key table and modifier roles, before xkb_set_key [xkb_begin]fn xkb_set_key(evdev: u32, levels: &[u32; 4], nlev: u32)(X11 backend) define one key: 4 symbol values (as the keymap parser makes them), nlev = number of levels listed [xkb_set_key]fn xkb_set_roles(alt: u32, num: u32, sup: u32, level3: u32)(X11 backend) real-modifier masks of the modifier roles (0 = the Wayland default) [xkb_set_roles]fn xkb_set_mods(depressed: u32, latched: u32, locked: u32, _group: u32) -> u32the real modifier state -> MOD_* bits (also the events' modifiers) [xkb_set_mods]fn xkb_is_modifier(evdev: u32) -> boolthe key's level-1 symbol is a modifier [xkb_is_modifier]fn xkb_mod_bit(evdev: u32) -> u32MOD_* bit of a held modifier key (0 for other keys and locks) [xkb_mod_bit]fn xkb_key(evdev: u32) -> (u32, u32)evdev code -> (VK code, text codepoint (0 = none)) [xkb_key]fn xkb_key_y(evdev: u32) -> i32(E2) evdev code -> Event::y of its key event: the KL_* location and the character the key gives with the current Shift, Caps Lock, AltGr and Num Lock but without Ctrl, Alt and Super (plat::key_y)fn xkb_dead_reset()forget a pending dead key (the keyboard focus changed)fn xkb_key_typed(evdev: u32) -> (u32, [u32; 2])a key press with the dead keys composed -> (VK, up to two codepoints, 0 = none)fn xkb_is_dead(evdev: u32) -> boolthe key gives a dead key now (with the current modifiers)fn xkb_dead_keysym(spacing: u32) -> u32the X keysym of a dead key from its spacing character (0 = none)fn xkb_vk_keys(vk: u32) -> alloc::vec::Vec<u32>the evdev codes of the keys that give vk without modifiers (keypad keys: with Num Lock on) -- the keys a global shortcut grabs (linux_x11_screen.rs)fn xkb_dump()print every defined key: evdev, VK, flags, modifier id, 4 levels [xkb_dump]