gfx.xkb

index · gfx

Overview

An xkb keymap reader: the text a Wayland compositor sends for its keyboard, turned into what a key types. No libxkbcommon.

A compositor sends a resolved keymap: no includes and no rules. Of its four sections the reader takes the key codes, the types, the compat section's interpret blocks and the symbols, with modifier_map. It skips every action, since the compositor tracks the modifier state and sends it with each change.

The parts it computes, in the order xkbcommon computes them:

A level that holds more than one keysym resolves to its first.

Functions

NameSignature
parseparse(text) -> keymap, err
basebase(code) -> key

parse(text) -> keymap, err

Parse an xkb keymap

text is a resolved keymap: the text after xkb_keymap {, as a compositor sends it, with or without the trailing NUL. Returns nil and an error naming the line when the text does not parse, or when it holds an include, which only an unresolved keymap has.

keymap field or methoddescription
km:key(code, depressed, latched, locked, group)what the evdev code types under the four values of wl_keyboard.modifiers
km:mods(depressed, latched, locked)the named modifiers in force, the set km:key reports as mods
km:repeats(code)true when a held key repeats
km.groupsthe groups' names, km.groups[1] the first, as the keymap names them
km.unknownthe count of keysym names the tables do not hold; each reads as NoSymbol

km:key returns a table:

fielddescription
codethe evdev code
keysymthe keysym at the level in force; 0 for none
keythe key's name for a named keysym (ENTER, F1, KP_1, LEFT_SHIFT), else the character of the first level of the group
shiftedthe character of the second level, when it types one
textthe character the key types now, or nil
basethe key on a US layout: its character, or the key's name
modsa set of shift, caps_lock, ctrl, alt, super, hyper, meta, num_lock
group, levelthe group and the level in force, from 1

The group wraps: past the keymap's groups, then past the key's. The level is the one the group's type maps the modifiers in force to. text is nil for a control character, and while Ctrl is in force and the type does not take it: the caller encodes Ctrl. Alt leaves the text. Caps Lock changes a letter only through its type; xkbcommon's case change for a type without Lock is not made. Meta on the same real modifier as Alt is left out of mods, and Hyper on Super's.

base(code) -> key

The key a physical key has on a US layout

The character on a US keyboard of the evdev code, for the keys that type one; nil for any other. km:key falls back to the key's name.