kc3-lang/libxkbcommon/doc/keymap-text-format-v1-v2.md

Download

The XKB keymap text format, V1 and V2 {#keymap-text-format-v1-v2}

This document describes the following [keymap] formats, as implemented by libxkbcommon:

`::XKB_KEYMAP_FORMAT_TEXT_V1` @anchor keymap-text-format-v1
The classic XKB text format, as generated by `xkbcomp -xkb`. See @ref xkbcommon-compatibility "" for further information.
`::XKB_KEYMAP_FORMAT_TEXT_V2` @anchor keymap-text-format-v2
Xkbcommon extensions of the classic XKB text format, **incompatible with X11**. See @ref xkbcommon-compatibility "" for further information.

@see For an overview of the role of this format, please see “@ref xkb-the-config “””.

@see For examples of keymaps in this format, please see “@ref user-configuration “””. For further examples see xkeyboard-config, the standard database of keyboard configuration data.

@note Due to the complexity of the format, this document is still is construction. Some additional resources are:

@note

@tableofcontents{html:2}

[terminology]: @ref terminology [introduction]: @ref introduction-to-the-xkb-text-format [xkb_keymap]: @ref the-xkb_keymap-block [xkb_keycodes]: @ref the-xkb_keycodes-section [xkb_types]: @ref the-xkb_types-section [xkb_compat]: @ref the-xkb_compat-section [xkb_symbols]: @ref the-xkb_symbols-section [virtual modifier statements]:@ref virtual-modifier-statements [actions]: @ref key-actions

Terminology {#terminology}

Keycode
Code that identifies a physical key on a keyboard. - _Raw_ keycodes are the numeric identifiers used as input in XKB. They are the result of the low-level processing of the data that keyboards send to a computer. For instance `36` may represent the return key. - _XKB_ keycodes are _symbolic_ names assigned to raw keycodes in order to facilitate their mapping to symbols. For instance the keycode for the return key is the abbreviation `RTRN`. See [xkb_keycodes] for further details.
Symbols
A _keysym_ (short for “key symbol”) is a numeric encoding of a symbol on the cap of a key. Some keysyms have a canonical name for convenience. The complete list of canonical names is defined in `xkbcommon/xkbcommon-keysyms.h`. Common types of keysyms are: - A _character:_ e.g. `a` and `A` for Latin scripts, `alpha` “α” and `ALPHA` “Α” for Greek, etc. - A _dead key:_ e.g. `dead_grave` and `dead_diaeresis`, corresponding respectively to the [grave accent](https://en.wikipedia.org/wiki/Grave_accent) and the [diaeresis](https://en.wikipedia.org/wiki/Diaeresis_%28diacritic%29) diacritics. A [dead key](https://en.wikipedia.org/wiki/Dead_key) is a special kind of key that does not generate a character by itself, but modifies the character generated by the key struck(s) immediately after. - A [modifier]⁠: e.g. `Shift_L`, `Control_R`, `Caps_Lock`. See hereinafter. - A _system action:_ e.g. the arrow `Left`, `Pause`, `Escape`, `F1`. @sa [xkb_symbols] for further details on binding keysyms to keycodes. @sa [Keysym syntax][@ref keysym-syntax]
Modifier
A _modifier key_ is a key that modifies the effect of other keys: e.g. Shift, Control, Caps Lock, etc. The state of a modifier key (active/inactive) is encoded as a _modifier index_ (or modifier bit or simply modifier) and has an associated _unique name_. For historical reasons, modifiers are divided in two categories:
Real modifiers
They are the 8 _predefined_ (AKA *core*, *X11*) modifiers (see [usual modifiers] hereinafter). Real modifiers ensure backward compatibility: indeed they are the actual bits used to compute the [levels][level] and are communicated via the API of xkbcommon. Some are generic modifiers (`Mod[1-5]`) that do not have a conventional interpretation and are the motivation of the introduction of [virtual modifiers].
Virtual modifiers
They are the modifiers that are _not_ predefined.

Each modifier has an associated [encoding][modifier encoding]. In keymaps compatible with X11, the encoding can be interpreted as a mapping to one or multiple real modifier. Real modifiers map to themselves: they are [canonical modifiers][canonical modifier]. See the “@ref modifiers-encoding “”” section for further information.

The following table lists the <a name=”usual-modifiers”>usual modifiers</a> present in the standard keyboard configuration. Note that this is provided for information only, as it may change depending on the user configuration.

Modifier Type Usual mapping Comment
Shift Real Shift (fixed) The usual Shift
Lock Real Lock (fixed) The usual Caps Lock
Control Real Control (fixed) The usual Control
Mod1 Real Mod1 (fixed) Not conventional
Mod2 Real Mod2 (fixed) Not conventional
Mod3 Real Mod3 (fixed) Not conventional
Mod4 Real Mod4 (fixed) Not conventional
Mod5 Real Mod5 (fixed) Not conventional
Alt Virtual Mod1 The usual Alt
Meta Virtual Mod1 The legacy Meta key
NumLock Virtual Mod2 The usual NumLock
Super Virtual Mod4 The usual Super/GUI
LevelThree Virtual Mod5 ISO level 3, aka AltGr
LevelFive Virtual Mod3 ISO level 5

[usual modifiers]: @ref usual-modifiers

A modifier key can report its state in one of the following 3 ways:

<dl>

<dt><a name="depressed-mod-def">Depressed</a></dt>
<dd>Active while depressed; e.g. the usual Shift.</dd>
<dt><a name="latched-mod-def">Latched</a></dt>
<dd>
  Activated when pressed and deactivated after the next
  non-modifier key press.
</dd>
<dt><a name="locked-mod-def">Locked</a></dt>
<dd>
  Activated when pressed and deactivated when pressed again;
  e.g. the usual Caps Lock.
</dd>

See [modifiers declaration and binding] for further details.

[depressed]: @ref depressed-mod-def [latched]: @ref latched-mod-def [locked]: @ref locked-mod-def

<dt><a name=”level-def”>Shift Level</a></dt> <dd> A key may produce different results depending of the active modifiers: e.g. for a Latin script, pressing the key A produces “a” and holding Shift while pressing A produces “A”.

This various results are organized in an ordered list; the index of each entry is called a <a name=”level-index-def”>shift level</a> or simply level. By convention the lowest level is the result when no modifier is active. Example for the key A on a latin script keyboard:

Level Description Keysym Active key modifiers
1 Lower case letters a None
2 Upper case letters. A Shift
3 Alternative lower case letters ae AltGr
4 Alternative upper case letters AE Shift + AltGr

A key shift level is the logical state of a key corresponding to the current shift level it used.

Key shift levels are derived from the modifiers states, but not necessarily in the same way for all keys. For example, for Latin script the Caps Lock modifier selects the level 2 for alphabetic keys such as A but has no effect on a numeric key.

There are groups of keys with the same characteristics: letters, punctuation, numeric keypad, etc. The meaning of their levels is identical and thus can be shared: this generalization is called a key type (see hereinafter).

<dt><a name=”key-type-def”>Key type</a></dt> <dd> A key type defines the levels available for a key and how to derive the active level from the modifiers states. Examples:

  • ONE_LEVEL: the key has only one level, i.e. it is not affected by any modifiers. Example: the modifiers themselves.
  • [TWO_LEVEL][TWO_LEVEL]: the key has two levels:
    • Level 1: default level, active when the Shift modifier is not active.
    • Level 2: level activated with the Shift modifier.
  • [FOUR_LEVEL][FOUR_LEVEL]: see the example in the previous section.

See [xkb_types] for further details.

<dt><a name=”layout-def”>Layout</a></dt> <dd> A mapping of keycodes to symbols, actions and key types.

A user who deals with multiple languages may need two or more different layouts: e.g. a layout for Arabic and another one for English. In this context, layouts are called groups in XKB, as defined in the standard ISO/IEC&nbsp;9995.

Layouts are ordered and identified by their index. Example:

  • Layout 1: Arabic
  • Layout 2: English

<dt><a name=”key-action-def”>Key Action</a></dt> <dd> In XKB world, a key action defines the effect a key has on the state of the keyboard or the state of the display server. Examples:

  • Change the state of a modifier.
  • Change the active group.
  • Move the mouse pointer.

See the section “[Key actions][actions]” for further details.

<dt><a name=”indicator-def”>Indicator</a></dt> <dd> A keyboard indicator is a mean to report a specific aspect of the keyboard state.

<dl>

<dt><em>Physical</em> indicator</dt>
<dd>
Typically a labelled LED on the keyboard, e.g. “Caps Lock” and
“Num Lock”.
</dd>
<dt><em>Logical</em> indicator</dt>
<dd>
A customizable derived state of the keyboard.
Its changes creates events that can be monitored.

There are two categories:

- _Real_ indicators are those associated to a physical indicator.
  For example, the “Caps Lock” logical modifier controls the
  corresponding physical LED.

  Because indicators are customizable, if one misses a “Num Lock”
  LED, one could define instead the “Caps Lock” _indicator_ to
  activate its LED when the “Num Lock” _modifier_ is active.
- _Virtual_ indicators are not associated to a physical indicator.
  Their effect is only visible for programs monitoring them.

Note that the meanings of _real_ and _virtual_ is slightly
different than the one used for [modifier].
</dd>

See: <code>[xkb_keycodes][indicator name]</code> to define indicators and <code>[xkb_compat][indicator effect]</code> to define their effects.

<dt><a name=”keymap-def”>Keymap</a></dt> <dd> The complete definition of the mapping of raw keycodes to symbols and actions. It fully defines the behavior of a keyboard.

Depending of the context, a keymap may refer to:

  • the software object defined and managed by libxkbcommon;
  • the text configuration used to create this software object.

See @ref keymap-components-intro and [xkb_keymap] for further details.

<dt>Keyboard configuration database @anchor database-def</dt> <dd>

A database that provides the [keymap components](@ref keymap-components-intro).
\*nix OSs uses the _standard_ database [xkeyboard-config]. One may extend
this database with _custom_ layouts: see “@ref user-configuration ""” for
further details.

[keycode]: @ref keycode-def [keysym]: @ref keysym-def [keysyms]: @ref keysym-def [modifier]: @ref modifier-def [modifiers]: @ref modifier-def [real modifier]: @ref real-modifier-def [real modifiers]: @ref real-modifier-def [virtual modifier]: @ref virtual-modifier-def [virtual modifiers]: @ref virtual-modifier-def [level]: @ref level-def [shift level]: @ref level-def [level index]: @ref level-index-def [key type]: @ref key-type-def [key types]: @ref key-type-def [layout]: @ref layout-def [action]: @ref key-action-def [indicator]: @ref indicator-def [keymap]: @ref keymap-def [database]: @ref database-def

Introduction to the XKB text format

The XKB text format uses a syntax similar to the C programming language. Note that the similarity with C stops here: the XKB text format is only a configuration format and is not intended for programming.

The XKB text format is used to configure a keyboard keymap, which is introduced in “@ref xkb-the-config “””. It has the following two main use cases, illustrated in the diagram hereinafter:

  • Server: Load a keymap from the keymap configuration database, then handle input events by updating the keyboard state. The keymap is assembled from an [RMLVO configuration][RMLVO] and its corresponding <strong>[KcCGST components][KcCGST]</strong> files.

    @see xkb_keymap::xkb_keymap_new_from_names2

    @see xkeyboard-config for the implementation of the standard keymap configuration database.

    @see “@ref user-configuration “”” to add a custom layout or option.

  • Client: Load the active keymap from the server, then handle update events sent by the server. The <strong>[complete keymap]</strong> is directly available in a self-contained file.

    @see xkb_keymap::xkb_keymap_new_from_string

@anchor xkb-keymap-components-diagram @dotfile xkb-keymap-components “XKB text format use cases”

[RMLVO]: @ref RMLVO-intro [KcCGST]: @ref KcCGST-intro [complete keymap]: @ref keymap-intro

XKB file

There are two kinds of files for the XKB text format:

Keymap file @anchor keymap-file-def
A file with the _complete_ description of the [keymap] object. It is the kind of file that the server sends to the client (see the [diagram](@ref xkb-keymap-components-diagram) above). Its top-level structure consists of the [xkb_keymap] block.
Keymap _component_ file @anchor keymap-component-file-def
A file with the description of a _particular_ [KcCGST component][KcCGST]. It is the kind of file that the server uses to assemble a [keymap file]. Its top-level structure consists of a _single type_ of [keymap sections]. A component file may contain multiple such sections.

[keymap file]: @ref keymap-file-def [keymap component file]: @ref keymap-component-file-def [keymap sections]: @ref keymap-section-def [section]: @ref keymap-section-def [keymap components]: @ref keymap-component-def

Keymap components {#keymap-components-intro}

[Keymap components][keymap components] are described with [keymap sections]. They are grouped in [keymap component files][keymap component file] to form a [keyboard configuration database][database].

Keymap _component_ @anchor keymap-component-def
A part of the keymap _object_. The set of keymap components is referred as [KcCGST]. They are presented in the [table hereinafter][keymap components table].
Keymap _section_ @anchor keymap-section-def
A part of the keymap _text configuration_ dedicated to one of the [keymap components][keymap components table].
Component _folder_
A folder in the [keymap configuration database][database], dedicated to files with partial definitions of the same keymap section.

[keymap components table]: @ref keymap-components-table

@anchor keymap-components-table

Keymap components
[Component](@ref keymap-component-def) [Section][section] in a [keymap][xkb_keymap] Folder in a keymap configuration database Description
Key codes [xkb_keycodes] `keycodes` A translation of the raw [key codes][keycode] from the keyboard into symbolic names.
Compatibility [xkb_compat] `compat` A specification of what internal actions modifiers and various special-purpose keys produce.
(Geometry) xkb_geometry `geometry` A description of the physical layout of a keyboard. @attention This legacy feature is [not supported](@ref geometry-support) by _xkbcommon_.
Key symbols [xkb_symbols] `symbols` A translation of symbolic [key codes][keycode] into actual [key symbols][keysyms] (keysyms).
Key types [xkb_types] `types` Types describe how a pressed key is affected by active [modifiers] such as Shift, Control, Alt, etc.

Comments

Comments are introduced following either // or # until the end of the line.

Literals

String literal @anchor keymap-string-literal
A string is surrounded by double quotes: “"”. The following _escape sequences_ are supported: | Escape sequence | Meaning | | ------------------ | -------------------------------------------------------- | | `\\` | Backslash “`\`” | | `\"` | Double quote “`"`” | | `\b` | Backspace | | `\e` | Escape | | `\f` | Form feed | | `\n` | Line feed (newline) | | `\r` | Carriage return | | `\t` | Horizontal tabulation | | `\v` | Vertical tabulation | | `\` + octal number | Corresponding ASCII character: `\1` → `SOH`, `\42` → `"`. Up to **4** octal digits `0‥7` are parsed. The result must fit into a byte. | | `\u{` + hexadecimal number + `}` | `\u{NNNN}` produce the corresponding [Unicode code point] `U+NNNN`, encoded in [UTF-8]. Supported code points are in the range `U+0001‥U+10FFFF`. | [Unicode code point]: https://en.wikipedia.org/wiki/Unicode#Codespace_and_code_points [UTF-8]: https://en.wikipedia.org/wiki/UTF-8 @note The string _encoding_ is unspecified and not validated, but for best results, stick to ASCII. @since \<1.9.0: Octal escape sequences accept up to **3** digits. @since 1.9.0: Octal escape sequences accept up to **4** digits. Added \\" and `\u{NNNN}` escape sequences.
Number literal
A number can be written in three forms: - _decimal integer:_ `1`, `123`, etc. - _decimal floating-point number:_ `1.23`, etc. - _hexadecimal integer:_ prefixed with `0x`: `0x123`, `0xff`, `0xAB`, etc.

Keysyms {#keysym-syntax}

[Keysyms][keysym] may be written in multiple ways:

Name
Keysym names are defined in `xkbcommon/xkbcommon-keysyms.h`; remove the `XKB_KEY_` prefix to get the name. Example: the keysym `0xffbe = XKB_KEY_F1` has the name `F1`.
Unicode
The *Unicode* syntax `Unnnn` denotes a keysym whose corresponding character is the Unicode code point `U+nnnn`, where `nnnn` is an hexadecimal number in the range `0x100 .. 0x10ffff`. The resulting keysym value is `0x01000000 + nnnn`. Example: `U1F3BA` has value `0x0101F3BA` and corresponds to the code point `U+1F3BA`: ‘🎺’ (TRUMPET).
String literal
A keysym or list of keysyms can be written as a *string literal*, with the following semantics: 1. The string must be encoded in UTF-8. 2. If the encoding is invalid, it raises a syntax error. 3. If the string expands to 0 Unicode code point, the resulting keysym is `NoSymbol`. 4. If the string expands to 1 Unicode code point, the resulting keysym is the output of `xkb_utf32_to_keysym`. 5. Otherwise the string expands to a list `{ ... }` with each Unicode code point converted via `xkb_utf32_to_keysym`. @note This is only possible where multiple keysyms is valid, e.g. in the @ref key-multiple-symbols-per-level "key symbols". Examples:
Keysym string Keysym name Keysym value
`""` `NoSymbol` `0x0000`
`"a"` `a` `0x0061`
`"ü"` `udiaeresis` `0x00dc`
`"🎺"` `U1F3BA` `0x0101F3BA`
`"g̃"` `{g, combining_tilde}` `{0x0101F3BA, 0x01000303}`
@sa @ref keysyms-string "Keysym strings" @since 1.9.0
Numeric value
A keysym can be written directly with its *numeric* value: e.g. `0x61` is `a`. @note Digits `0 .. 9` have a special treatment because they are interpreted as names, not values. E.g. `1` is the keysym with name `1` and value `0x31`. @warning This syntax should be avoided for its poor readability, except if it is not possible to write the keysym with the previous syntaxes.

Keywords

The following table presents the keywords used in the format. They are case-sensitive.

Keyword Use
action Action of an interpret statement
alias Keycode alias
alphanumeric_keys Section flag
alternate_group Section flag
alternate Merge mode qualifier for [include] statements
augment Merge mode qualifier for [include] statements
default Section flag
function_keys Section flag
group <span class=”todo”>TODO</span>
hidden Section flag
include [Include statement][include]
indicator Indicator statement in either the keycode section or the compatibility section
interpret [Interpret statement][interpret]
key Key statement
keypad_keys Section flag
keys Legacy [geometry element][xkb_geometry]
logo Legacy [geometry element][xkb_geometry]
mod_map Alias of modifier_map
modifier_keys Section flag
modmap Alias of modifier_map
modifier_map Real modifier bindings
outline Legacy [geometry element][xkb_geometry]
overlay Legacy [geometry element][xkb_geometry]
override Merge mode qualifier for [include] statements
partial Section flag
replace Merge mode qualifier for [include] statements
row Legacy [geometry element][xkb_geometry]
section Legacy [geometry element][xkb_geometry]
shape Legacy [geometry element][xkb_geometry]
solid Legacy [geometry element][xkb_geometry]
text Legacy [geometry element][xkb_geometry]
type Key type statement
virtual_modifiers Virtual modifiers mappings
virtual Flag for the indicator statement
xkb_compat_map Alias of xkb_compatibility_map
xkb_compat Alias of xkb_compatibility_map
xkb_compatibility_map Declare a [compatibility section][xkb_compat]
xkb_compatibility Alias of xkb_compatibility_map
xkb_geometry Declare a [geometry section][xkb_geometry]
xkb_keycodes Declare a [keycodes section][xkb_keycodes]
xkb_keymap Declare a [keymap block][xkb_keymap]
xkb_layout Declare a legacy [layout compound section][xkb_layout]
xkb_semantics Declare a legacy [semantics compound section][xkb_semantics]
xkb_symbols Declare a [symbols section][xkb_symbols]
xkb_types Declare a [key types section ][xkb_types]

[include]: @ref xkb-include [interpret]: @ref interpret-statements [interpretations]: @ref interpret-statements [xkb_geometry]: @ref the-xkb_geometry-section [xkb_layout]: @ref legacy-layout-section [xkb_semantics]: @ref legacy-semantics-section

Built-in settings

There are many built-in settings; they are explained in the following relevant sections.

These settings are case-insensitive, e.g. the following strings denote the same key word: SETMODS, SetMods, setMods and setmods.

Merge modes {#merge-mode-def}

Each statement has a merge mode property that defines how to handle conflicts with previous statements. This property can be set explicitly by prefixing the statement with one of the merge modes presented hereinafter.

@anchor merge-mode-augment augment
If two declarations conflict, update the properties which are *explicitly* defined in the *new* declaration, *only* if they were *implicit* in the *old* declaration. ```c key { [a , NoSymbol , ae ] }; augment key { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] }; // Result key { [a , Greek_ALPHA, ae , AE] }; ```
@anchor merge-mode-override override
If two declarations conflict, update only the properties which are *explicitly* defined in the *new* declaration. @note @anchor merge-mode-default Override is the *default* merge mode. ```c key { [a , NoSymbol , ae ] }; // Explicit merge mode override key { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] }; // Result key { [Greek_alpha, Greek_ALPHA, ae , AE] }; ``` ```c key { [a , NoSymbol , ae ] }; // Implicit merge mode is override key { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] }; // Result key { [Greek_alpha, Greek_ALPHA, ae , AE] }; ```
@anchor merge-mode-replace replace
If two declarations conflict, ignore the old declaration and use the new one. ```c key { [a , NoSymbol , ae ] }; replace key { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] }; // Result key { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] }; ```
@anchor merge-mode-alternate alternate
Legacy merge mode for keycodes. Its purpose is to allow to assign the same key name to multiple key codes, which is not allowed otherwise. This is unfortunately poorly documented and not used in xkeyboard-config. The xkblib specification implies that this was part of the overlay functionality, which is currently not supported by libxkbcommon. @warning This merge mode is not supported by libxkbcommon and is ignored.
[default merge mode]: @ref merge-mode-default ### The include mechanism {#xkb-include} #### Syntax Statements of the form: ```c // Implicit section name: use the default map include "" // Explicit section name include "()" ``` will merge data from another [section] of the *same type*, possibly located in another file. Note that the statement does not have a trailing semicolon. If no section name is provided, the [default map] is looked up. [default map]: @ref default-map-def The path is usually relative to its corresponding directory in a XKB configuration: e.g. given the configuration directory ``, files of section type `xkb_symbols` are looked up in `/symbols`. Since 1.11, the paths can also be absolute or use **%-expansion**: @anchor keymap-include-percent-expansion
`%%`
A literal %.
\%H
The value of the `$HOME` environment variable.
\%S
The *main* system-installed XKB directory of the corresponding [component] \(usually `/usr/share/X11/xkb/`). This enables e.g. to override a system file using @ref user-configuration "" with the exact *same name*: ```c // File: ~/.config/xkb/symbols/de xkb_symbols "basic" { // Include the system file /usr/share/X11/xkb. // // Note that it is not be possible to use `include "de(basic)"` because // it would create an include *loop*. include "%S/de(basic)" // Override the system file entries key { [z, Z] }; key { [y, Y] }; } ```
\%E
The *extra* system-wide XKB directory of the corresponding [component] \(usually `/etc/xkb/`).
[component]: @ref keymap-components-table @warning Absolute paths and `%`-expansion are supported by libxkbcommon but not by the legacy X11 tools. The `include` keyword uses the *default* [merge mode]. The following keywords can be used instead to use the corresponding *explicit* [merge modes][]: - [`augment`][augment] - [`override`][override] - [`replace`][replace] [merge mode]: @ref merge-mode-def [merge modes]: @ref merge-mode-def [augment]: @ref merge-mode-augment [override]: @ref merge-mode-override [replace]: @ref merge-mode-replace *Multiple files* can be included using the same statement. They are separated using one of the following [merge mode] prefixes: - ‘|’ selects the [augment] merge mode. - ‘+’ selects the [override] merge mode (default). - ‘^’ selects the [replace] merge mode. The following example illustrates the complete syntax: ```c // Default merge mode, 1 file with an implicit section name include "" // Augment merge mode, 1 file with an implicit section name augment "()" // Absolute path and %-expansion include "/usr/share/X11/xkb/symbols/pc" include "%S/pc" // Override merge mode, 2 files: a first file with an implicit section name merged // using the augment mode with a second file with an explicit section name override "|() ``` #### Processing @important Since xkbcommon 1.9.0 the included files are processed in *isolation* and are not affected by the parent file (e.g. defaults), except for the virtual modifiers indices. @important Since xkbcommon 1.9.0 local merge modes are *not* propagated outside the section scope, i.e. an included file does not leaks its local merge modes to its parent. The statement is processed as follow: 1. Set PARENT as the current [section] containing the include statement. 2. Set INCLUDED_MERGE_MODE to the merge mode corresponding to the keyword. 3. Initialize an empty [section] as INCLUDED. 4. Select the first file as the current file to process. 5. Set CURRENT_MERGE_MODE to the merge mode corresponding to the current file merge mode *prefix*. 6. The current file path is searched sequentially in the [XKB configuration path list]: - If a section name is provided, select the first *exact match* of file + section. - If no section name is provided, select the first *explicit* [default map] in matched files, else if no exact match was found in the path list, then fallback to the first *implicit* [default map] as a weak match. Then if no match is found, raise an error; else go to the next step. 7. The current file is processed and results in the CURRENT [section]. 8. The INCLUDED [section] is merged with the CURRENT [section] using the merge mode CURRENT_MERGE_MODE. 9. If they are more files, select the next file as the current file and go to step 5). Else go to step 10). 10. Once all files have been processed, merge PARENT with INCLUDED using the merge mode INCLUDED_MERGE_MODE. [XKB configuration path list]: @ref xkb_context::xkb_context_include_path_append() #### Example: include path list Let’s illustrate using the following [XKB configuration path list][]: 1. `/home//.config/xkb`: user configuration directory (see @ref user-configuration ""). 2. `/usr/share/X11/xkb`: system directory. The relevant directory structure is: - `/home//.config/xkb` - `symbols` - `es` - `my_own_file` - `/usr/share/X11/xkb` - `symbols` - `es` - `it` Then the following file: ```c xkb_symbols { include "it" // Exists only in system directory include "my_own_file" // Exists only in user directory include "es" // Exists in both user and system directory }; ``` is equivalent to: ```c xkb_symbols { include "/usr/share/X11/xkb/symbols/it" include "/home//.config/xkb/symbols/my_own_file" include "/home//.config/xkb/symbols/es" }; ``` #### Example: simple include Given the following files: - `symbols/A` ```c xkb_symbols { key
{ [a, A, ae, AE] }; include "B(S2)" }; ``` - `symbols/B` ```c // This section is not used (does not match) xkb_symbols "S1" { key { [b, B] }; }; // This section will be included (match the included section name) xkb_symbols "S2" { key { [Greek_alpha, Greek_ALPHA] }; key { [Greek_beta , Greek_BETA ] }; }; ``` the resulting section in `A` will be: ```c xkb_symbols { // Key overridden: mix of old + new key { [Greek_alpha, Greek_ALPHA, ae, AE] }; // New key key { [Greek_beta , Greek_BETA ] }; }; ``` #### Example: merge modes Given the same file `symbols/B` of the previous example, the following section:
Input Output
```c xkb_symbols { key { [a, A, ae, AE] }; augment "B(S2)" }; ``` ```c xkb_symbols { // Key unchanged key { [a, A, ae, AE] }; // New key key { [Greek_beta , Greek_BETA] }; }; ```
```c xkb_symbols { key { [a, A, ae, AE] }; replace "B(S2)" }; ``` ```c xkb_symbols { // Key replaced key { Greek_alpha, Greek_ALPHA] }; // New key key { [Greek_beta , Greek_BETA ] }; }; ```
```c xkb_symbols { key { [a, A, ae, AE] }; // Two files merged together with the merge mode // augment, then the result is merged this the // statement above using the override merge mode include "B(S1)|B(S2)" }; ``` ```c xkb_symbols { // Key overridden: mix of old + new key { [Greek_alpha, Greek_ALPHA, ae, AE] }; // New key; "B(2)" had no effect with the // merge mode augment "|" key { [b, B] }; }; ```
## The “xkb_keymap” block {#the-xkb_keymap-block} A [keymap file] consists of a single top-level `xkb_keymap` block, under which are nested the following sections:
[xkb_keycodes]
A translation of the hardware/evdev scancodes from the keyboard into XKB symbolic keycodes.
[xkb_types]
A specification of the modifier mask, target level and preserved modifiers various modifiers combination produce.
[xkb_compat]
A specification of what actions various special-purpose keys produce.
[xkb_symbols]
A translation of symbolic key codes into actual symbols and actions.
Overview of a keymap file: ```c xkb_keymap { xkb_keycodes "XXX" { // ... } xkb_types "XXX" { // ... }; xkb_compatibility "XXX" { // ... }; xkb_symbols "XXX" { // ... }; }; ``` @since 1.9.0 All the component are optional. @remark The XKB file format historically supported the following compound section types:
- `xkb_semantics`: @anchor legacy-semantics-section *must* contain a [xkb_compat] section and *can* contain a [xkb_types] section. - `xkb_layout`: @anchor legacy-layout-section *must* contain [xkb_keycodes], [xkb_types] and [xkb_symbols] sections and *can* contain [xkb_geometry] section. - `xkb_keymap`: *must* contain [xkb_keycodes], [xkb_compat], [xkb_types] and [xkb_symbols] sections and *can* contain [xkb_geometry] section.
Since such distinction is purely semantic and would have niche use cases lost to history, these compound sections are treated equally as `xkb_keymap` in libxkbcommon. ## Section flags {#section-flags-def} A section can have various **flags** applied to it, separated by whitespaces: partial alphanumeric_keys xkb_symbols "basic" { ... } ### Generic flags The possible flags are:
partial@anchor section-flag-partial
Indicates that the map doesn’t cover a complete keyboard.
default@anchor section-flag-default
@anchor default-map-def Marks the symbol map as the *explicit* **default map** in the file. If no map is marked as a default, the first map in the file is the *implicit* default. Only **one** section can be marked as the default in each file.
hidden@anchor section-flag-hidden
Variant that can only be used internally.
### Symbols flags Additionally, `xkb_symbols` may also have the following flags:
alphanumeric_keys@anchor section-flag-alphanum
Indicates that the map contains alphanumeric keys.
modifier_keys@anchor section-flag-modifier
Indicates that the map contains modifier keys: Control, Shift, Alt, Meta, etc.
keypad_keys@anchor section-flag-keypad
Indicates that the map contains keypad keys.
function_keys@anchor section-flag-function
Indicates that the map contains function keys: F1, F2, etc.
alternate_group@anchor section-flag-alt-group
Indicates that the map contains keys for an alternate group.
If no `*_keys` flags are supplied, then the symbols section is assumed to cover a complete keyboard. At present, except for `default` (see: [default map]), none of the flags affect key processing in libxkbcommon, and only serve as *metadata*. ## The “xkb_keycodes” section {#the-xkb_keycodes-section} This is the simplest [section] type, and is the first one to be compiled. The purpose of this is mostly to map between the hardware/evdev scancodes and XKB [keycodes][keycode]. Each key is given a name by which it can be referred to later, e.g. in the symbols section. ### Keycode statements Statements of the form: = 49; = 10; The above would let 49 and 10 be valid keycodes in the keymap, and assign them the names `TLDE` and `AE01` respectively. The format `` is always used to refer to a key by name. The naming convention `` is based on the [standard ISO/IEC 9995-1][ISO9995-1]. It denotes the position of the key in the keyboard grid. It means: the main alphanumeric section (`A`), row `E` and column `01`. The following figure illustrates the grid on a staggered standard US QWERTY keyboard. `` corresponds to the key `1`. ``` \ 99 \ 00 \ 01 \ 02 \ 03 \ 04 \ 05… \ \ \ \ \ \ \ ----------------------------------------- E \ \ ^ \ 1 \ 2 \ 3 \ 4 \ 5… ------------------------------------------ D \ Tab \ Q \ W \ E \ R \ T… ------------------------------------------- C \Caps \ A \ S \ D \ F \ G… -------------------------------------------- B \Shift \ Z \ X \ C \ V \ B… --------------------------------------------- A \Ctrl\GUI \Alt \Space… ---------------------------------------------- ``` [ISO9995-1]: https://en.wikipedia.org/wiki/ISO/IEC_9995#ISO/IEC_9995-1 In the common case this just maps to the evdev scancodes from `/usr/include/linux/input.h`, e.g. the following definitions: #define KEY_GRAVE 41 #define KEY_1 2 correspond to the ones above. Similar definitions appear in the xf86-input-keyboard driver. Note that in all current keymaps there’s a constant offset of 8 (for historical reasons). Note that contrary to xkbcommon, the X11 protocol supports keycodes only up to `255`. Therefore, when interfacing with X11, keymaps and applications using keycodes beyond `255` should expect warnings. If there’s a conflict, like the same name given to different keycodes, or same keycode given different names, it is resolved according to the [merge mode] which applies to the definitions. ### Alias statements {#keycode-alias} Statements of the form: alias
= ; Allows to refer to a previously defined key (here ``) by another name (here ``). Conflicts are handled similarly to keycode statements. ### LED name statements {#indicator-name} [indicator name]: @ref indicator-name Statements of the form: indicator 1 = "Caps Lock"; indicator 2 = "Num Lock"; indicator 3 = "Scroll Lock"; Assigns a name to the keyboard LED (AKA [indicator]) with the given index. The LED may be referred by this name later in the compat section and by the user. @todo `virtual` flag ## The “xkb_types” section {#the-xkb_types-section} This [section] is the second to be processed, after `xkb_keycodes`. However, it is completely independent and could have been the first to be processed (it does not refer to specific keys as specified in the `xkb_keycodes` section). This section defines [key types], which, given a key and a keyboard state (i.e. modifier state and group), determine the [shift level] to be used in translating the key to [keysyms]. These types are assigned to each group in each key, in the `xkb_symbols` section. Key types are called this way because, in a way, they really describe the “type” of the key (or more correctly, a specific group of the key). For example, an ordinary keymap will provide a type called `KEYPAD`, which consists of two levels, with the second level being chosen according to the state of the Num Lock (or Shift) modifiers. Another example is a type called `ONE_LEVEL`, which is usually assigned to keys such as Escape; these have just one level and are not affected by the modifier state. Yet more common examples are [`TWO_LEVEL`][TWO_LEVEL] (with Shift choosing the second level), [`ALPHABETIC`][ALPHABETIC] (where Caps Lock may also choose the second level), etc. ### How key types work Key types define a _mapping_ between the [modifiers] and [shift levels]. Key types have four parameters:
@ref key-type-level-name "Shift level names"
Declare [shift levels]. Mainly for documentation.
@ref key-type-modifiers "Modifiers filter"
Declare what modifiers should be taken into account in the mapping.
@ref key-type-map "Modifiers mapping"
Lookup table to translate modifiers combinations into shift levels.
@ref key-type-preserve "Modifiers preservation"
Tweak the computation of [consumed modifiers].
[consumed modifiers]: @ref consumed-modifiers [shift levels]: @ref level-def Key types are used to compute: - the [shift level][]: see xkb_state::xkb_state_key_get_level(). - the [consumed modifiers][]: see xkb_state::xkb_state_key_get_consumed_mods() and xkb_state::xkb_state_key_get_consumed_mods2(). The following diagram presents an overview of theses computations: @anchor xkb-types-explanation-diagram @dotfile xkb-types-explanation "Use of key types to compute shift level and consumed modifiers" ### Type definitions {#key-type-statement} Statements of the form: type "FOUR_LEVEL" { ... } The above would create a new type named [`FOUR_LEVEL`][FOUR_LEVEL]. The body of the definition may include statements of the following forms: #### “level_name” statements {#key-type-level-name} level_name[Level1] = "Base"; Mandatory for each level in the type. Gives each level in this type a descriptive name. It isn’t used for anything. Note: A level may be specified as Level\[1-8\] or just a number (can be more than 8). #### “modifiers” statement {#key-type-modifiers} modifiers = Shift+Lock+LevelThree; Mandatory, should be specified only once. A mask of real and virtual [modifiers]. These are the only modifiers being considered when matching the modifier state against the type. The other modifiers, whether active or not, are masked out in the calculation. #### “map” entry statements {#key-type-map} map[Shift+LevelThree] = Level4; Should have at least as many mappings as there are levels in the type. If the active modifiers, masked with the type’s modifiers (as stated above), match (i.e. equal) the modifiers inside the `map[]` statement, then the level in the right hand side is chosen. For example, in the above, if in the current keyboard state the `Shift` and `LevelThree` modifiers are active, while the `Lock` modifier is not, then the keysym(s) in the 4th level of the group will be returned to the user. #### “preserve” statements {#key-type-preserve} map[Shift+Lock+LevelThree] = Level5; preserve[Shift+Lock+LevelThree] = Lock; When a key type is used for keysym translation, its modifiers are said to be [consumed](@ref consumed-modifiers) in this translation. For example, in a simple US keymap, the “G” key is assigned an ordinary [`ALPHABETIC`][ALPHABETIC] key type, whose modifiers are `Shift` and `Lock`; then for the “G” key, these two modifiers are consumed by the translation. This information is relevant for applications which further process the modifiers, since by then the consumed modifiers have already “done their part” and should be masked out. However, sometimes even if a modifier had already affected the key translation through the type, it should *not* be reported as consumed, for various reasons. In this case, a `preserve[]` statement can be used to augment the map entry. The modifiers inside the square brackets should match one of the `map[]` statements in the type (if there is no matching map entry, one mapping to Level1 is implicitly added). The right hand side should consists of modifiers from the type’s modifiers; these modifiers are then “preserved” and not reported as consumed. @attention Consuming a *locked* modifier does *not* unlock it and it can be consumed again in further keysym translations. @note Remember that @ref keysym-transformations may affect the resulting keysym when some modifiers are not [consumed](@ref consumed-modifiers). @remark `preserve` statements may be used to tweak keyboard shorcuts. @remark@figure @figcaption Example of use of `preserve` to tweak `Control` shortcuts. Note it would require further work in order to support other modifiers. @endfigcaption ```c xkb_types { // ... type "TWO_LEVEL_PLUS_CONTROL" { modifiers = Shift + Control; map[None] = Level1; map[Shift] = Level2; map[Control] = Level3; map[Control+Shift] = Level4; // Using preserve will make Control not consumed and allow // applications to detect keyboard shortcuts with alternative // keysyms in levels 3 and 4 rather than the levels 1 and 2. preserve[Control] = Control; preserve[Control+Shift] = Control; level_name[Level1] = "Base"; level_name[Level2] = "Shift"; level_name[Level3] = "Tweaked Control"; level_name[Level4] = "Tweaked Control + Shift"; }; }; xkb_symbols { // ... // The following key would produce Greek keysym on Base and Shift levels, // but will produce the corresponding ASCII Latin keysyms when using Control. key { type[Group1]="TWO_LEVEL_PLUS_CONTROL", [Greek_alpha, Greek_ALPHA, a, A] }; }; ``` @endfigure ### Key types examples {#key-type-examples} #### Definitions examples @note The convention is that `Lock` affect only “alphabetic” types. For such types, `Lock` “cancels” `Shift` by default, i.e. `Shift+Lock` has the same result as neither modifier. “semi-alphabetic” types have an asymmetry: their first two levels are alphabetic while the next are not. ##### Two levels The following examples compare two basic types with *two levels*: [`TWO_LEVEL`][TWO_LEVEL] and [`ALPHABETIC`][ALPHABETIC]. They differ on their handling of the `Lock` modifier. See the [next section](@ref key-type-mappings-examples) for an illustration with concrete layouts. [TWO_LEVEL]: @ref TWO_LEVEL [ALPHABETIC]: @ref ALPHABETIC
`TWO_LEVEL` @anchor TWO_LEVEL
@figure@figcaption Definition code ([source][two-type-src]) @endfigcaption ```c type "TWO_LEVEL" { // Only care about Shift; Lock will be filter out modifiers = Shift; // Define mapping map[None] = Level1; // No modifier -> level 1 map[Shift] = Level2; // Exactly Shift -> level 2 // (no map entry with Lock) // Define level names level_name[Level1] = "Base"; level_name[Level2] = "Shift"; }; ``` @endfigure @figure@figcaption Mapping test @endfigcaption | *Active* modifiers | *Filtered* modifiers | Match? | Shift level | | ------------------ | -------------------- | ------ | ----------- | | (none) | (none) | Yes | 1 | | `Shift` | `Shift` | Yes | 2 | | `Lock` | (none) | Yes | 1           | | `Shift + Lock` | `Shift` | Yes | 2 | @endfigure
`ALPHABETIC` @anchor ALPHABETIC
@figure@figcaption Definition code ([source][alphabetic-type-src]) @endfigcaption ```c type "ALPHABETIC" { // Only care about Shift and Lock modifiers = Shift + Lock; // Define mapping map[None] = Level1; // No modifier -> level 1 map[Shift] = Level2; // Exactly Shift -> level 2 map[Lock] = Level2; // Exactly Lock -> level 2 // Define level names level_name[Level1] = "Base"; level_name[Level2] = "Caps"; }; ``` @endfigure @figure@figcaption Mapping test @endfigcaption | *Active* modifiers | *Filtered* modifiers | Match? | Shift level | | ------------------ | -------------------- | ------ | ----------- | | (none) | (none) | Yes | 1 | | `Shift` | `Shift` | Yes | 2 | | `Lock` | `Lock` | Yes | 2           | | `Shift + Lock` | `Shift + Lock` | No | 1 | @endfigure
##### Four levels The following examples compare basic types with *four levels*: [`FOUR_LEVEL`][FOUR_LEVEL], [`FOUR_LEVEL_SEMIALPHABETIC`][FOUR_LEVEL_SEMIALPHABETIC] and [`FOUR_LEVEL_ALPHABETIC`][FOUR_LEVEL_ALPHABETIC]. They differ on their handling of the `Lock` modifier. See the [next section](@ref key-type-mappings-examples) for an illustration with concrete layouts. [FOUR_LEVEL]: @ref FOUR_LEVEL [FOUR_LEVEL_SEMIALPHABETIC]: @ref FOUR_LEVEL_SEMIALPHABETIC [FOUR_LEVEL_ALPHABETIC]: @ref FOUR_LEVEL_ALPHABETIC
`FOUR_LEVEL` @anchor FOUR_LEVEL
@figure@figcaption Definition code ([source][four-level-src]) @endfigcaption ```c type "FOUR_LEVEL" { modifiers = Shift + LevelThree; map[None] = Level1; map[Shift] = Level2; // (no map entry with Lock) // (no map entry with Lock) map[LevelThree] = Level3; map[Shift+LevelThree] = Level4; // (no map entry with Lock) // (no map entry with Lock) // (no preserve entry with Lock) // (no preserve entry with Lock) level_name[Level1] = "Base"; level_name[Level2] = "Shift"; level_name[Level3] = "AltGr"; level_name[Level4] = "Shift AltGr"; }; ``` @endfigure @figure@figcaption Mapping test @endfigcaption | *Active* modifiers | *Filtered* modifiers | Match? | Shift level | | ----------------------- | -------------------- | ------ | ----------- | | (none) | (none) | Yes | 1 | | `Shift` | `Shift` | Yes | 2 | | `Lock` | (none) | Yes | 1           | | `Shift+Lock` | `Shift` | Yes | 2 | | `LevelThree` | `LevelThree` | Yes | 3 | | `LevelThree+Shift` | `LevelThree+Shift` | Yes | 4 | | `LevelThree+Lock` | `LevelThree` | Yes | 3 | | `LevelThree+Shift+Lock` | `LevelThree+Shift` | Yes | 4 | @endfigure
`FOUR_LEVEL_SEMIALPHABETIC` @anchor FOUR_LEVEL_SEMIALPHABETIC
@figure@figcaption Definition code ([source][four-level-semialphabetic-src]) @endfigcaption ```c type "FOUR_LEVEL_SEMIALPHABETIC" { modifiers = Shift + Lock + LevelThree; map[None] = Level1; map[Shift] = Level2; map[Lock] = Level2; map[Shift+Lock] = Level1; map[LevelThree] = Level3; map[Shift+LevelThree] = Level4; map[Lock+LevelThree] = Level3; map[Shift+Lock+LevelThree] = Level4; preserve[Lock+LevelThree] = Lock; preserve[Shift+Lock+LevelThree] = Lock; level_name[Level1] = "Base"; level_name[Level2] = "Shift"; level_name[Level3] = "AltGr"; level_name[Level4] = "Shift AltGr"; }; ``` @endfigure @figure@figcaption Mapping test @endfigcaption | *Active* modifiers | *Filtered* modifiers | Match? | Shift level | | ----------------------- | ----------------------- | ------ | ----------- | | (none) | (none) | Yes | 1 | | `Shift` | `Shift` | Yes | 2 | | `Lock` | `Lock` | Yes | 2           | | `Shift+Lock` | `Shift+Lock` | Yes | 1 | | `LevelThree` | `LevelThree` | Yes | 3 | | `LevelThree+Shift` | `LevelThree+Shift` | Yes | 4 | | `LevelThree+Lock` | `LevelThree+Lock` | Yes | 3 | | `LevelThree+Shift+Lock` | `LevelThree+Shift+Lock` | Yes | 4 | @endfigure
`FOUR_LEVEL_ALPHABETIC` @anchor FOUR_LEVEL_ALPHABETIC
@figure@figcaption Definition code ([source][four-level-alphabetic-src]) @endfigcaption ```c type "FOUR_LEVEL_ALPHABETIC" { modifiers = Shift + Lock + LevelThree; map[None] = Level1; map[Shift] = Level2; map[Lock] = Level2; map[Shift+Lock] = Level1; map[LevelThree] = Level3; map[Shift+LevelThree] = Level4; map[Lock+LevelThree] = Level4; map[Shift+Lock+LevelThree] = Level3; // (no preserve entry with Lock) // (no preserve entry with Lock) level_name[Level1] = "Base"; level_name[Level2] = "Shift"; level_name[Level3] = "AltGr"; level_name[Level4] = "Shift AltGr"; }; ``` @endfigure @figure@figcaption Mapping test @endfigcaption | *Active* modifiers | *Filtered* modifiers | Match? | Shift level | | ----------------------- | ----------------------- | ------ | ----------- | | (none) | (none) | Yes | 1 | | `Shift` | `Shift` | Yes | 2 | | `Lock` | `Lock` | Yes | 2           | | `Shift+Lock` | `Shift+Lock` | Yes | 1 | | `LevelThree` | `LevelThree` | Yes | 3 | | `LevelThree+Shift` | `LevelThree+Shift` | Yes | 4 | | `LevelThree+Lock` | `LevelThree+Lock` | Yes | 4 | | `LevelThree+Shift+Lock` | `LevelThree+Shift+Lock` | Yes | 3 | @endfigure
[two-type-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/basic#L14 [alphabetic-type-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/basic#L21 [four-level-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/extra#L8 [four-level-alphabetic-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/extra#L20 [four-level-semialphabetic-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/extra#L36 #### Examples with standard keyboard layouts {#key-type-mappings-examples}
See the detailed table of mappings The following table compares the mappings of various key types for the modifiers `Shift`, `Lock` and `LevelThree`, using the standard layouts [`us`][us-layout] (US English) and [`es`][es-layout] (Spanish). [us-layout]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/symbols/us#L3 [es-layout]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/symbols/es#L3 | Key | Layout | Key type | Active modifiers | Level | Keysym | Comment | | ------ | ------ | ------------------------------- | ------------------------------- | ----- | ------------ | ----------- | | `AE01` | [`us`][us-layout] | [`TWO_LEVEL`][TWO_LEVEL] | (none) | 1 | `1` | | | ^ | ^ | ^ | `Shift` | 2 | `exclam` | | | ^ | ^ | ^ | `Lock` | 1 | `1` | `Lock` filtered out | | ^ | ^ | ^ | `Shift` + `Lock` | 2 | `exclam` | `Lock` filtered out | | ^ | ^ | ^ | `LevelThree` | 1 | `1` | `LevelThree` filtered out | | ^ | ^ | ^ | `LevelThree` + `Shift` | 2 | `exclam` | `LevelThree` filtered out | | ^ | ^ | ^ | `LevelThree` + `Lock` | 1 | `1` | Modifiers `LevelThree` and `Lock` filtered out | | ^ | ^ | ^ | `LevelThree` + `Shift` + `Lock` | 2 | `exclam` | Modifiers `LevelThree` and `Lock` filtered out | | ^ | [`es`][es-layout] | [`FOUR_LEVEL`][FOUR_LEVEL] | (none) | 1 | `1` | | | ^ | ^ | ^ | `Shift` | 2 | `exclam` | | | ^ | ^ | ^ | `Lock` | 1 | `1` | `Lock` filtered out | | ^ | ^ | ^ | `Shift` + `Lock` | 2 | `exclam` | `Lock` filtered out | | ^ | ^ | ^ | `LevelThree` | 3 | `bar` | | | ^ | ^ | ^ | `LevelThree` + `Shift` | 4 | `exclamdown` | | | ^ | ^ | ^ | `LevelThree` + `Lock` | 3 | `bar` | `Lock` filtered out | | ^ | ^ | ^ | `LevelThree` + `Shift` + `Lock` | 4 | `exclamdown` | `Lock` filtered out | | `AD01` | [`us`][us-layout] | [`ALPHABETIC`][ALPHABETIC] | (none) | 1 | `q` | | | ^ | ^ | ^ | `Shift` | 2 | `Q` | | | ^ | ^ | ^ | `Lock` | 2 | `Q` | | | ^ | ^ | ^ | `Shift` + `Lock` | 1 | `q` | `Lock` cancelled by `Shift` | | ^ | ^ | ^ | `LevelThree` | 1 | `q` | `LevelThree` filtered out | | ^ | ^ | ^ | `LevelThree` + `Shift` | 1 | `q` | `LevelThree` filtered out | | ^ | ^ | ^ | `LevelThree` + `Lock` | 2 | `Q` | `LevelThree` filtered out | | ^ | ^ | ^ | `LevelThree` + `Shift` + `Lock` | 1 | `q` | `LevelThree` filtered out, `Lock` cancelled by `Shift` | | ^ | [`es`][es-layout] | [`FOUR_LEVEL_SEMIALPHABETIC`][FOUR_LEVEL_SEMIALPHABETIC] | (none) | 1 | `q` | | | ^ | ^ | ^ | `Shift` | 2 | `Q` | | | ^ | ^ | ^ | `Lock` | 2 | `Q` | | | ^ | ^ | ^ | `Shift` + `Lock` | 1 | `q` | `Lock` cancelled by `Shift` | | ^ | ^ | ^ | `LevelThree` | 3 | `at` | | | ^ | ^ | ^ | `LevelThree` + `Shift` | 4 | `Greek_OMEGA`| | | ^ | ^ | ^ | `LevelThree` + `Lock` | 3 | `at` | `Lock` does not affect `LevelThree` combos | | ^ | ^ | ^ | `LevelThree` + `Shift` + `Lock` | 4 | `Greek_OMEGA`| `Lock` does not affect `LevelThree` combos | | `AD05` | [`us`][us-layout] | [`ALPHABETIC`][ALPHABETIC] | (none) | 1 | `t` | | | ^ | ^ | ^ | `Shift` | 2 | `T` | | | ^ | ^ | ^ | `Lock` | 2 | `T` | | | ^ | ^ | ^ | `Shift` + `Lock` | 1 | `t` | `Lock` cancelled by `Shift` | | ^ | ^ | ^ | `LevelThree` | 1 | `t` | `LevelThree` filtered out | | ^ | ^ | ^ | `LevelThree` + `Shift` | 1 | `t` | `LevelThree` filtered out | | ^ | ^ | ^ | `LevelThree` + `Lock` | 2 | `T` | `LevelThree` filtered out | | ^ | ^ | ^ | `LevelThree` + `Shift` + `Lock` | 1 | `t` | `LevelThree` filtered out, `Lock` cancelled by `Shift` | | ^ | [`es`][es-layout] | [`FOUR_LEVEL_ALPHABETIC`][FOUR_LEVEL_ALPHABETIC] | (none) | 1 | `t` | | | ^ | ^ | ^ | `Shift` | 2 | `T` | | | ^ | ^ | ^ | `Lock` | 2 | `T` | | | ^ | ^ | ^ | `Shift` + `Lock` | 1 | `t` | `Lock` cancelled by `Shift` | | ^ | ^ | ^ | `LevelThree` | 3 | `tslash` | | | ^ | ^ | ^ | `LevelThree` + `Shift` | 4 | `Tslash` | | | ^ | ^ | ^ | `LevelThree` + `Lock` | 4 | `Tslash` | | | ^ | ^ | ^ | `LevelThree` + `Shift` + `Lock` | 3 | `tslash` | `Lock` cancelled by `Shift` |
## The “xkb_compat” section {#the-xkb_compat-section} This [section] is the third to be processed, after `xkb_keycodes` and `xkb_types`. ### Interpret statements {#interpret-statements} Statements of the form: interpret Num_Lock+Any { ... } interpret Shift_Lock+AnyOf(Shift+Lock) { ... } The [xkb_symbols] section (see below) allows the keymap author to perform, among other things, the following things for each key: - Bind a sequence of [actions], like `SetMods` or `LockGroup`, to the key. Actions, like symbols, are specified for each level of each group in the key separately. - Add a [virtual modifier] to the key’s virtual modifier mapping (`vmodmap`). - Specify whether the key should repeat or not. However, doing this for each key (or level) is tedious and inflexible. Interpret’s are a mechanism to apply these settings to a bunch of keys/levels at once. @anchor interpret-mechanism Each interpret specifies a condition by which it attaches to certain levels. The condition consists of two parts: - A [keysym]. If the level has a different (or more than one) keysym, the match fails. Leaving out the keysym is equivalent to using the special value `Any` or the `NoSymbol` keysym, which always matches successfully. - A [modifier] predicate. The predicate consists of: - A __mask__ of _real_ modifiers: a `+`-separated list of modifiers or the special value `all`, which denotes all the modifiers. The modifiers are matched against the key’s modifier map (`modmap`). - A __matching operation__, that is one of the following: * `AnyOfOrNone` – The modmap must either be empty or include at least one of the specified modifiers. * `AnyOf` – The modmap must include at least one of the specified modifiers. * `Any` – Alias for `AnyOf(all)`. * `NoneOf` – The modmap must not include any of the specified modifiers. * `AllOf` – The modmap must include all of the specified modifiers (but may include others as well). * `Exactly` – The modmap must be exactly the same as the specified modifiers. Leaving out the predicate is equivalent to using `AnyOfOrNone(all)`. Leaving out just the matching condition is equivalent to using `Exactly`. An interpret may also include `useModMapMods = level1;` – see below. If a [level] fulfils the conditions of several interprets, only the most specific one is used: - A specific keysym will always match before a generic `NoSymbol` condition. - If the keysyms are the same, the interpret with the more specific matching operation is used. The above list is sorted from least to most specific. - If both the keysyms and the matching operations are the same (but the modifiers are different), the first interpret is used. As described above, once an interpret “attaches” to a level, it can bind an action to that level, add one virtual modifier to the key’s vmodmap, or set the key’s repeat setting. You should note the following: - The key repeat is a property of the entire key; it is not level-specific. In order to avoid confusion, it is only inspected for the first level of the first group; the interpret’s repeat setting is ignored when applied to other levels. - If one of the above fields was set directly for a key in `xkb_symbols`, the explicit setting takes precedence over the interpret. The body of the statement may include statements of the following forms (all of which are optional): #### “useModMapMods” statement useModMapMods = level1; When set to `level1`, the interpret will only match keysyms which are on the first level of the first group of the keys. This can be useful in conjunction with e.g. a [`virtualModifier`](@ref interpret-virtualModifier) statement, because `virtualModifier` is an attribute of the key rather than a specific level. Note: the other possible value is `any` and is the default value. See [virtual modifier map] for further information. #### “virtualModifier” statement {#interpret-virtualModifier} virtualModifier = NumLock; Add this virtual modifier to the key’s `vmodmap`. The given virtual modifier must be declared at the top level of the file with a `virtual_modifiers` statement, e.g.: virtual_modifiers NumLock; See [virtual modifier map] for further information. #### “repeat” statement {#interpret-repeat} repeat = True; Set whether the key should repeat or not. Must be a boolean value. #### “action” statement {#interpret-action} action = LockMods(modifiers=NumLock); Bind this action to the matching levels. See [key actions][actions] for the list of available key actions. Since 1.9.0, it is also possible to assign a sequence of actions, mirroring the feature used in the [key statement](@ref key-multiple-symbols-per-level). action = {SetMods(modifiers=NumLock),SetGroup(group=2)}; ### LED map statements {#indicator-effect} [indicator effect]: @ref indicator-effect Statements of the form: indicator "Shift Lock" { ... } This statement specifies the behavior and binding of the LED (AKA [indicator]) with the given name (“Shift Lock” above). The name should have been declared previously in the `xkb_keycodes` section (see [LED name][indicator name] statement), and given an index there. If it wasn’t, it is created with the next free index. The body of the statement describes the conditions of the keyboard state which will cause the LED to be lit. It may include the following statements: #### “modifiers” statement modifiers = ScrollLock; If the given [modifiers] are in the required state (see below), the LED is lit. #### “whichModState” statement whichModState = Latched+Locked; Can be any combination of: * `base`, `latched`, `locked`, `effective` * `any` (i.e. all of the above) * `none` (i.e. none of the above) * `compat` (legacy value, treated as effective) This will cause the respective portion of the modifier state (see `struct xkb_state`) to be matched against the modifiers given in the `modifiers` statement. Here’s a simple example: indicator "Num Lock" { modifiers = NumLock; whichModState = Locked; }; Whenever the NumLock modifier is locked, the Num Lock LED will light up. #### “groups” statement groups = All - group1; If the given groups are in the required state (see below), the LED is lit. #### “whichGroupState” statement whichGroupState = Effective; Can be any combination of: * `base`, `latched`, `locked`, `effective` * `any` (i.e. all of the above) * `none` (i.e. none of the above) This will cause the respective portion of the group state (see `struct xkb_state`) to be matched against the groups given in the `groups` statement. Note: the above conditions are disjunctive, i.e. if any of them are satisfied the LED is lit. ### Set default values One may change the default values of the following statements: - `interpret`: use `interpret.FIELD = VALUE;` - `indicator`: use `indicator.FIELD = VALUE;` - actions: use `ACTION_NAME.FIELD = VALUE;`. E.g. `setMods.clearLocks= True;`. ## The “xkb_symbols” section {#the-xkb_symbols-section} This [section] is the fourth to be processed, after `xkb_keycodes`, `xkb_types` and `xkb_compat`. Statements of the form: xkb_symbols "basic" { ... } Declare a symbols map named `basic`. Statements inside the curly braces only affect the symbols map. ### Name statements Statements of the form: name[Group1] = "US/ASCII"; groupName[1] = "US/ASCII"; Gives the name “US/ASCII” to the first group of symbols. Other groups can be named using a different group index (ex: `Group2`), and with a different name. A group must be named. `group` and `groupName` mean the same thing, and the `Group` in `Group1` is optional. ### Key statement {#key-statement} Statements of the form: key { ... }; defines the *key description* of the [keycode] `` and is the main type of record of the `xkb_symbols` section. The possible keycodes are defined in the [`xkb_keycodes`](@ref the-xkb_keycodes-section) section. A key description consists of:
Groups
Each key may have one or more associated [groups]. Each group can be configured with the following parameters: - @ref key-type-setting "Type" - @ref key-symbols-table "Symbols" - @ref key-actions-table "Actions"
Additional attributes
These attributes are usually set via the [xkb_compat] section, but may be also set directly: - @ref key-virtual-modifiers "Virtual modifiers" - @ref key-repeat "Repeat"
@warning Using multiple groups in *symbols* files is not recommended, because some tools rely on the assumption that an `xkb_symbols` section only affect a single group. It is fine with a *keymap* file though. @note In what follows we assume the common use case with a *single* group, which benefits from a special syntax. See the section @ref key-groups "Multiple groups" for the general syntax. [groups]: @ref layout-def #### Symbols {#key-symbols-table} The main part of the key description is the *symbols table*. It maps shift levels to keysyms, e.g.: ```c key { [ q, Q ] }; // Level 1 → `q`, Level 2 → `Q` ``` Symbols are named using the symbolic names from the `xkbcommon/xkbcommon-keysyms.h` file. See the @ref keysym-syntax "keysym syntax" for further information. A group of symbols is enclosed in brackets and separated by commas. Each element of the symbol arrays corresponds to a different [shift level]. In this example, the symbol (keysym) `XKB_KEY_q` for level 1 and `XKB_KEY_Q` for level 2. These levels are configured by the @ref key-type-setting "key type", presented in the next section. @remark Remember that @ref keysym-transformations may affect the resulting keysym when some modifiers are not [consumed](@ref consumed-modifiers). @remark Trailing `NoSymbol` are dropped. @anchor key-multiple-symbols-per-level As an extension to the XKB legacy format, libxkbcommon supports multiple key symbols and actions per level (the latter since version 1.8.0): ```c key { [ {i, j} , U0132 ] }; // IJ Dutch digraph key { [ {g, U0303} , {G, U0303} ] }; // G̃ Guarani letter key { [ {U0644, U0627}, {U0644, U0622}] }; // ⁧لا⁩ ⁧لآ⁩ Arabic Lam-Alef ligatures decomposed key { [ {c, U2019, h} , {C, U2019, h} ] }; // C’H Breton trigraph ``` In this example, the keycode `` produces two symbols on level 1 (`XKB_KEY_i` and `XKB_KEY_j`) and one symbol (Unicode keysym `U0132` for “IJ”) on level 2. `` and `` produce letters that have no *precomposed* code point in Unicode. Key `` avoids the need of using Compose. @anchor keysyms-string Since 1.9.0, UTF-8-encoded *strings* may be used to denote a list of keysyms corresponding to the encoded Unicode code points. E.g. the previous example can be also written more intuitively as: ```c key { [ "ij" , "IJ" ] }; // IJ Dutch digraph key { [ "g̃" , "G̃" ] }; // G̃ Guarani letter // NOTE: We use U+200E LEFT-TO-RIGHT MARK in order to display the strings in // in the proper order. key { [ "لا"‎ , "لآ"‎ ] }; // ⁧لا⁩ ⁧لآ⁩ Arabic Lam-Alef ligatures decomposed key { [ "c’h", "C’h" ] }; // C’H Breton trigraph ``` When no actions are explicitly given, they are automatically filled thanks to [interpretations] from the [compat section][xkb_compat]. In the following example, key { [ { Control_L, ISO_Group_Shift } ] }; is equivalent to (given standard definitions from `xkeyboard-config`): key { symbols[1] = [ { Control_L, ISO_Group_Shift } ], actions[1] = [ { SetMods(modifiers=Control), SetGroup(group=+1) } ] }; When using this example with e.g. two layouts `fr,us` (respectively Azerty and Qwerty layouts), typing `Control + A` in the first layout `fr` will in fact result in `Control + Q`, because the actions are run sequentially: first set the base modifiers to Control, then switch to the second layout while `Control` is pressed. @remark Given a level, keysyms and actions may have a *different count*. For instance, the following would achieve the same effect than the former example with only 1 keysym, but it requires to use 2 explicit actions: ```c key { symbols[1] = [ Control_L ], actions[1] = [ { SetMods(modifiers=Control), SetGroup(group=+1) } ] }; ``` @note There are some *limitations* with this extension: - For now, *at most one* action of each following categories is allowed per level: - [modifier actions][]: `SetMods`, `LatchMods`, `LockMods`; - [group actions][]: `SetGroup`, `LatchGroup`, `LockGroup`. Some examples of actions combination: - `SetMods` + `SetGroup`: ok - `SetMods` + `SetMods`: *error* - `SetMods` + `LockMods`: *error* - `SetMods` + `LockGroup`: ok - Multiple actions are only supported from version 1.8.0.
@since 1.8.0: When using multiple keysyms or actions per level, `NoSymbol` and `NoAction()` are dropped in order to normalize the levels: ```c // Before normalization key <> { [{NoSymbol}, {a, NoSymbol}, {NoSymbol,b}, {a, NoSymbol, b}] }; // After normalization key <> { [NoSymbol, a, b, {a, b}] }; ```
@since 1.9.0: Trailing `NoSymbol` and `NoAction()` are dropped in groups: ```c // Before normalization key <> { [a, NoSymbol] }; // After normalization key <> { [a] }; ``` This affects the automatic key type detection.
@since 1.9.0: Added support for keysyms and actions lists of length 0 and 1, respectively `{}` and `{a}`. `{}` is equivalent to the corresponding `NoSymbol` or `NoAction()`.
@warning Keymaps containing multiple key symbols per level are not supported by the various X11-related tools (`setxkbmap`, `xkbcomp`, etc.). [symbols table]: @ref key-symbols-table #### Type {#key-type-setting} Each key has a [key type] set per group. This key type is defined in the [xkb_types] section. Its associated [shift levels] are used to index the [symbols table] presented in the previous section. A key type is set using the following syntax: ```c key { type[Group1] = "TWO_LEVEL", // Type [q, Q] // Symbols }; ``` The name of the key type is enclosed between double quotes. The key type may be omitted and will default to: - `key.type` global defaults, if set. - a standard type using the following **heuristic**: - **1** keysym: `ONE_LEVEL` - **2** keysyms: - if the two keysyms are letter and the first is lower case and the other upper case, then [`ALPHABETIC`][ALPHABETIC]; - if one of the keysyms is numpad, then `KEYPAD` else [`TWO_LEVEL`][TWO_LEVEL]. - **3 or 4** keysyms (a missing 4th keysym is set to `NoSymbol`): - if the first two keysyms are letters and the first is lower case and the other upper case: - if the last two keysyms are letters and the first is lower case and the other upper case then [`FOUR_LEVEL_ALPHABETIC`][FOUR_LEVEL_ALPHABETIC]; - else [`FOUR_LEVEL_SEMIALPHABETIC`][FOUR_LEVEL_SEMIALPHABETIC]. - if one of the first two keysyms is numpad, then `FOUR_LEVEL_KEYPAD`; - else [`FOUR_LEVEL`][FOUR_LEVEL]. @figure@figcaption Commented examples for inferred types: @endfigcaption ```c // 1 to 2 keysyms key { [Shift_L] }; // Type: ONE_LEVEL key { [1, exclam] }; // Type: TWO_LEVEL key { [q, Q] }; // Type: ALPHABETIC key { [KP_End, KP_1] }; // Type: KEYPAD // Edge case: this is consider alphabetic, although // the lower case does not correspond to the upper case. key { [q, N] }; // Type: ALPHABETIC // 3 to 4 keysyms key { [1, exclam, bar] }; // Type: FOUR_LEVEL key { [1, exclam, bar, exclamdown] }; // Type: FOUR_LEVEL key { [q, Q, at] }; // Type: FOUR_LEVEL_SEMIALPHABETIC key { [q, Q, at, Greek_OMEGA] }; // Type: FOUR_LEVEL_SEMIALPHABETIC key { [t, T, tslash, Tslash] }; // Type: FOUR_LEVEL_ALPHABETIC // The inferred type is `FOUR_LEVEL`, but using `LevelThree+Lock` // will produce `Q`, because of the keysyms transformations and // the corresponding internal capitalization processing. key { [1, exclam, q, Q] }; // Type: FOUR_LEVEL // Won’t work, because there is no heuristic for more than 4 keysyms // It will trigger the warnings XKB-183 and XKB-516 and default to ONE_LEVEL, // ignoring all the keysyms but the first one. key {[q, Q, at, any, masculine, U2642]}; // Will work as expected key { type[Group1] = "EIGHT_LEVEL_SEMIALPHABETIC", [q, Q, at, any, masculine, U2642] }; ``` @endfigure #### Actions {#key-actions-table} @note This is usually not set explicitly but via the [interpret mechanism] by using the [`action`](@ref interpret-action) statement in the [xkb_compat] section. @figure@figcaption Example: Set the modifier action of the key `` manually. @endfigcaption ```c key { symbols[Group1]=[Alt_L], actions[Group1]=[SetMods(modifiers=modMapMods)] }; ``` @endfigure For further details see [key actions][actions]. @remark Trailing `NoAction()` are dropped. #### Multiple groups {#key-groups} Each group represents a list of symbols mapped to a keycode: name[Group1]= "US/ASCII"; name[Group2]= "Russian"; ... key { [ q, Q ], [ Cyrillic_shorti, Cyrillic_SHORTI ] }; A long-form syntax can also be used: key { symbols[Group1]= [ q, Q ], symbols[Group2]= [ Cyrillic_shorti, Cyrillic_SHORTI ] }; Groups can also be omitted, but the brackets must be present. The following statement only defines the Group3 of a mapping: key { [], [], [ q, Q ] }; @warning Using multiple groups in *symbols* files is not recommended, because some tools rely on the assumption that an `xkb_symbols` section only affect a single group. It is fine with a *keymap* file though. #### Virtual modifiers {#key-virtual-modifiers} @note This is usually not set explicitly but via the [interpret mechanism] by using the [`virtualModifier`](@ref interpret-virtualModifier) statement from the [xkb_compat] section. @remarks When setting a [modifier action](@ref modifiers-actions), it is required to declare the corresponding virtual modifier using a [`virtual_modifiers`](@ref virtual-modifier-statements) statement. @figure@figcaption Example: Set the virtual modifier of the key `` to `Alt`. @endfigcaption ```c // Declare the virtual modifier that will be used virtual_modifiers Alt; key { virtualModifiers = Alt, [ Alt_L ] }; ``` @endfigure See [virtual modifier map] for further information. [interpret mechanism]: @ref interpret-mechanism #### Repeat {#key-repeat} @note This is usually not set explicitly but via the [interpret mechanism] by using the [`repeat`](@ref interpret-repeat) statement in the [xkb_compat] section. @figure@figcaption Example: make the `` key not repeating. @endfigcaption ```c key { repeat = False, [ Alt_L ] }; ``` @endfigure ### Real Modifier map {#modmap-statement} Bind a [*real* modifier](@ref real-modifier) to a key, e.g.: ```c // Bind the real modifier `Control` to the key `` and/or the first key with // the keysym `Control_L`. modifier_map Control { , Control_L }; ``` See [real modifier map] for further information. ### Set default values One may change the default values of the following statements: - `key`: use `key.FIELD = VALUE;`. E.g. `key.type = "ALPHABETIC";`. - `action`: use `ACTION_NAME.FIELD = VALUE;`. E.g. `setMods.clearLocks= True;`. ## Modifiers declaration and binding {#modifiers-declaration-and-binding} [modifiers declaration and binding]: @ref modifiers-declaration-and-binding ### Real and virtual modifiers [Modifiers] are a particularly tricky part of XKB and deserve their own section. For historical reasons they are divided in two categories:
Real modifier
They are the **8** *predefined* (AKA *core*, *X11*) modifiers: | Name | Index/Bit | Mask | Description | | --------- | --------- | ------ | -------------------------- | | `Shift` | 0 | `0x01` | Used to type upper case letters of [bicameral scripts]; keyboard shortcuts | | `Lock` | 1 | `0x02` | Used to type upper case letters of [bicameral scripts]: “Caps Lock” | | `Control` | 2 | `0x04` | Used in keyboard shortcuts | | `Mod1` | 3 | `0x08` | Generic modifier 1 | | `Mod2` | 4 | `0x10` | Generic modifier 2 | | `Mod3` | 5 | `0x20` | Generic modifier 3 | | `Mod4` | 6 | `0x40` | Generic modifier 4 | | `Mod5` | 7 | `0x80` | Generic modifier 5 | [bicameral scripts]: https://en.wikipedia.org/wiki/Letter_case#Bicameral_script They are the modifiers defined in the [*core* X11 protocol][X11 Core Protocol]. They are qualified as “real”, because in the XKB protocol they denote the *bits* that *encode* the modifiers state. See @ref modifiers-encoding "" for further information. Since they are predefined, they require no [explicit declaration](@ref virtual-modifier-statements) and have a *fixed* [encoding](@ref modifiers-encoding).
Virtual modifier
They are the modifiers that are *not* predefined. They require an [*explicit* declaration](@ref virtual-modifier-statements) and their [encoding](@ref modifiers-encoding) is *user-defined*. Note that in X11, the maximum of virtual modifiers is **16** (see `XkbNumVirtualMods`), whereas up to **24** virtual modifiers can be defined in libxkbcommon, for a total of **32** modifiers (real + virtual).
### Modifiers declarations {#virtual-modifier-statements} *Virtual* modifiers must be declared before their first use with the `virtual_modifiers` statement: - Declare a *single* modifier: ```c virtual_modifiers MyModifier; ``` - Declare *multiple* modifiers using a comma-separated list: ```c virtual_modifiers M1, M2, M3. ``` Furthermore, it is possible to set the [explicit modifier encoding] with the following syntax: - Use a *real* modifier mask: ```c // Single modifier: real modifier virtual_modifiers M1 = Mod3; // Single modifier: using mask as a plus-separated list virtual_modifiers M2 = Mod4+Mod5; // Multiple modifiers virtual_modifiers M1 = Mod3, M2 = Mod4+Mod5; ``` - Use a *numeric* mask: ```c virtual_modifiers M1 = 0x20; virtual_modifiers M2 = 0xC0; virtual_modifiers M1 = 0x20, M2 = 0xC0; ``` - Use `none`, an alias for `0`: ```c virtual_modifiers M1 = none; // Equivalent to: M1 = 0; ``` This can be done in the [`xkb_types`][xkb_types], [`xkb_compat`][xkb_compat] and [`xkb_symbols`][xkb_symbols] sections. ### Modifiers key bindings {#modifiers-bindings} [modifiers bindings]: @ref modifiers-bindings Each key has two **modifiers maps**:
*Real* modifier map
List the [*real* modifiers](@ref real-modifier) associated to the key. It is used as a compatibility layer for the X11 core protocol and to apply [interpretations]. See @ref set-real-mod-map "" for further information.
*Real* modifier map
List the [*virtual* modifiers](@ref virtual-modifier) associated to the key. It is used to set the [implicit encoding](@ref implicit-modifier-encoding) of virtual modifiers. See @ref set-virtual-mod-map "" for further information.
[real modifier map]: @ref real-modifier-map [real modifier maps]: @ref real-modifier-map [virtual modifier map]: @ref virtual-modifier-map #### Setting the real modifier map {#set-real-mod-map} The [real modifier map] is set in the [`xkb_symbols`][xkb_symbols] section using the `modifier_map` statement: - Bind *directly* to a **keycode**, e.g.: ```c // Bind `Mod1` to the keycode . modifier_map Mod1 { }; ``` - Bind *indirectly* via a **keysym**, e.g.: ```c // Bind `Mod1` looking up for the keysym `Alt_L` modifier_map Mod1 { Alt_L }; ``` Indirect bindings require to be resolved to a *single direct* bindings. Given a keysym, there can be multiple keys that generate it, so the corresponding key is chosen following this order: 1. by lowest group in which the keysym appears, 2. by lowest level, 3. by lowest key code. - Bind using a comma-separated **list** of keycodes and keysyms: ```c // Bind `Mod1` diretly to keycode and indirectly via the keysym `Alt_L` modifier_map Mod1 { , Alt_L }; ``` @note A key can be associated to _at most **one**_ real modifier. There is also a special entry, `None`, that enable *deleting* a previous entry: ```c modifier_map None { }; ``` @note `None` must use the *exact* same target (keycode or keysym) in order to delete the corresponding previous entry: ```c xkb_symbols { key { [Alt_L] }; modifier_map Mod1 { }; // Does *not* delete previous entry (expected keycode, got keysym) modifier_map None { Alt_L }; // *Does* delete previous entry (correct expected keycode) modifier_map None { }; }; ``` #### Setting the virtual modifier map {#set-virtual-mod-map} The [virtual modifier map] can be set in 2 ways: - *Directly* in the [`xkb_symbols`][xkb_symbols] section using the `virtualModifiers` key property: ```c xkb_symbols { // Virtual modifiers must be declared before use virtual_modifiers Alt; key { // Explicit virtual modifier map virtualModifiers = Alt, ... }; }; ``` - *Indirectly* using [interpretations] in [`xkb_compat`][xkb_compat] and the corresponding [`xkb_symbols`][xkb_symbols] keysyms: ```c xkb_compat { // Virtual modifiers must be declared before use virtual_modifiers Alt, Super; interpret Alt_L { // Bind the virtual modifier… virtualModifier = Alt; // … independently of the group and level (default) useModMap = AnyLevel; }; interpret Super_L { // Bind the virtual modifier… virtualModifier = Super; // … only if the keysym is on the first level of the first group useModMap = Level1; }; }; xkb_symbols { // Successful bindings key { [Alt_L] }; key { [No,Symbol, Alt_L] }; // independent of group and level key { [], [NoSymbol, Alt_L] }; // independent of group and level key { [Super_L] }; // Unsuccessful bindings key { [NoSymbol, Super_L] }; // requires first level key { [], [Super_L] }; // requires first group }; ``` ### Modifiers encoding {#modifiers-encoding} [modifier encoding]: @ref modifiers-encoding Each modifier has an associated **32 bit mask** used to *encode* it in the keyboard state. The keyboard state represents active modifiers with the bitwise OR of the encoding of each active modifiers. @note Display servers may use a different encoding in their protocols: - **Wayland protocol:** use the same *32-bit* encoding as libxkbcommon and support its full range of modifiers. - **X11 protocol:** use a *8-bit* encoding. It supports only using [real modifiers](@ref real-modifier) to encode [virtual modifiers](@ref virtual-modifier). @important - [Real modifiers](@ref real-modifier) have a *fixed predefined* encoding. - [Virtual modifiers](@ref virtual-modifier) have a *user-defined* encoding. Virtual modifiers require to be encoded by the user, *implicitly* (using the [auto mode](@ref auto-modifier-encoding) and/or the [legacy mode](@ref implicit-modifier-encoding)) and/or [*explicitly*](@ref explicit-modifier-encoding), the combination resulting in their [*effective*](@ref effective-modifier-encoding) encoding.
*Implicit* modifier encoding
Virtual modifiers *always* compute their implicit encoding, which is defined for a given virtual modifier by the bitwise OR of all the [real modifier maps] where the virtual modifier is in the [virtual modifier map] of the corresponding key. Example: ```c xkb_symbols { virtual_modifiers Alt; // Virtual modifier map: Alt is bound to // Note: alternatively one can use xkb_compat interpretations. key { virtualModifier = Alt }; // Real modifier map: Mod1 is bound to modifier_map Mod1 { }; // Implicit encoding: Alt = Mod1 }; ```
*Explicit* modifier encoding
Virtual modifiers can optionally define an initial mapping using the [`virtual_modifiers`](@ref virtual-modifier-statements) statements: ```c virtual_modifiers M1 = Mod1; // Single real modifier virtual_modifiers M2 = Mod4+Mod5;// Real modifier mask virtual_modifiers M3 = 0x400; // Numeric mask ``` See @ref virtual-modifier-statements "" for further information. @warning Although it is explicit, this may not be the [effective encoding][effective modifier encoding], detailed hereinafter.
*Effective* modifier encoding
The effective encoding is the bitwise OR of the [explicit modifier encoding] and the [implicit modifier encoding]. @note @anchor auto-modifier-encoding If using `::XKB_KEYMAP_FORMAT_TEXT_V2`, virtual modifiers that were not mapped either *implicitly* using the `virtualModifier`/`modifier_map` feature hereinabove or [*explicitly*](@ref explicit-modifier-encoding), then they are mapped to their [*canonical* mapping](@ref canonical-modifier-def). Example: ```c xkb_symbols { virtual_modifiers Alt, Meta, Super = none, Hyper = 0x1000, Useless = none; // Virtual modifier maps // Note: alternatively one can use xkb_compat interpretations. key { virtualModifier = Alt }; // Alt is bound to key { virtualModifier = Super }; // Super is bound to key { virtualModifier = Super }; // Super is bound to key { virtualModifier = Hyper }; // Hyper is bound to // Real modifier maps modifier_map Mod1 { }; // Mod1 is bound to modifier_map Mod4 { }; // Mod4 is bound to modifier_map Mod5 { }; // Mod5 is bound to modifier_map Mod3 { }; // Mod3 is bound to }; ```
Modifiers encoding of the previous example
Modifier Index Encoding
Canonical Explicit Implicit Effective
(xkbcommon) `::XKB_KEYMAP_FORMAT_TEXT_V1` `::XKB_KEYMAP_FORMAT_TEXT_V2`
Alt 8 `0x100` `Mod1` `Mod1` `Mod1`
Meta 9 `0x200` 0 (unmapped) `0x200` (canonical, xkbcommon value)
Super 10 `0x400` 0 `Mod4 + Mod5` `Mod4 + Mod5` `Mod4 + Mod5`
Hyper 11 `0x800` `0x1000` `0x1000` `0x1000`
Useless 12 `0x1000` 0 0 (unmapped) 0 (explicit mapping)
[explicit modifier encoding]: @ref explicit-modifier-encoding [implicit modifier encoding]: @ref implicit-modifier-encoding [effective modifier encoding]: @ref effective-modifier-encoding ### Canonical and non-canonical modifiers @anchor canonical-modifier-def A **canonical modifier** have an encoding defined by: `1 << mod_index`, where `mod_index` is: - Fixed for the *real* modifiers, in order to match the X11 values. See [real modifiers mapping](@ref real-modifier). - Implementation-dependent for the the *virtual* modifiers. See @ref xkbcommon-vmod-encoding "" for further details. [canonical modifier]: @ref canonical-modifier-def ### Usual modifiers and associated keysyms {#usual-modifiers-keysyms} The following table summarizes the modifiers defined in [`xkeyboard-config` 2.44][xkeyboard-config]: | Modifier | Type | Compat files | Associated keysyms | |--------------|---------|------------------|-----------------------------------------------------------| | `Shift` | Real | `compat/basic` | `Shift_L`, `Shift_R` | | ^ | ^ | `compat/iso9995` | `Shift_L`, `Shift_R`, `ISO_Level2_Latch` | | `Lock` | Real | `compat/basic`, | `Caps_Lock` | | ^ | ^ | `compat/caps` | ^ | | `Control` | Real | `compat/basic` | `Control_L`, `Control_R` | | `Alt` | Virtual | `compat/misc`, | `Alt_L`, `Alt_R` | | ^ | ^ | `compat/pc` | ^ | | `Meta` | Virtual | `compat/misc` | `Meta_L`, `Meta_R` | | `Super` | Virtual | `compat/misc` | `Super_L`, `Super_R` | | `Hyper` | Virtual | `compat/misc` | `Hyper_L`, `Hyper_R` | | `ScrollLock` | Virtual | `compat/misc` | `Scroll_Lock` | | `NumLock` | Virtual | `compat/basic`, | `Num_Lock`, | | ^ | ^ | `compat/level5` | (`ISO_Level5_Lock`) | | `LevelThree` | Virtual | `compat/iso9995` | `ISO_Level3_Shift`, `ISO_Level3_Latch`, `ISO_Level3_Lock` | | `LevelFive` | Virtual | `compat/level5` | `ISO_Level5_Shift`, `ISO_Level5_Latch`, `ISO_Level5_Lock` | | `Kana_Lock` | Virtual | `compat/japan` | `Kana_Lock` | | `Square` | Virtual | `compat/olpc` | `KP_Home` | | `Cross` | Virtual | `compat/olpc` | `KP_Next` | | `Circle` | Virtual | `compat/olpc` | `KP_End` | | `Triangle` | Virtual | `compat/olpc` | `KP_Prior` | ### Modifiers portability {#modifiers-portability} #### Avoid using numeric modifier masks @note Any field that accept virtual modifier *names* is a virtual modifier *mask*, denoting virtual modifiers *indices*. These indices are implementation-specific and should not be leaked. Therefore any *numeric* value used for these fields should be interpreted equally as a virtual modifier mask, and is thus implementation-specific. @important In order to preserve [modifier encoding] *portability*, XKB implementations are recommended to **avoid *numeric* modifier masks** and to **use virtual modifiers *names* whenever possible** when serializing the keymap. This avoids *leaking* the indices of the modifiers. #### xkbcomp and libxkbcommon implementations {#xkbcommon-vmod-encoding} @attention This section is not part of the keymap text format specification and presents libxkbcommon’s *implementation details* that may change, solely for the purpose of informing other XKB implementation. **Users should not rely on this!** Both X11 xkbcomp and libxkbcommon currently implement modifiers indices as follow: 1. Real modifiers have the following indices: @anchor real-modifier-indices | Name | Index | | --------- | ----- | | `Shift` | 0 | | `Lock` | 1 | | `Control` | 2 | | `Mod1` | 3 | | `Mod2` | 4 | | `Mod3` | 5 | | `Mod4` | 6 | | `Mod5` | 7 | 2. Virtual modifiers names are assigned to virtual modifier indices following their order of appearance in a keymap component, if that name was not previously assigned. 3. Indices are assigned in *ascending order*, from 0. 4. If an index is already assigned to a different name, then the next free index is used. 5. The order of the relevant keymap components used for virtual mods assignment is: 1. [xkb_types] 2. [xkb_compat] 3. [xkb_symbols] 6. A virtual modifier *mask* always denotes virtual modifiers *indices*. @note It suffices to declare all virtual modifiers in [xkb_types] \(or if empty, whatever non-empty section afterwards, in the order specified above) in their ascending indices order to use virtual modifiers indices **compatible with libxkbcommon**. ### Example: define and use a modifier, step by step We will use the example of the _real_ modifier `Shift` and the virtual modifier `LevelThree` in `xkeyboard-config`. In order to define and use a modifier, one must: 1. Define its behavior and [keysym] binding in the [xkb_compat] section: ```c // Declare virtual modifiers. Shift being real modifier, // we do not need to add it here. virtual_modifiers LevelThree; // Set defaults. They are overridden if set directly in the xkb_symbols. interpret.repeat= False; // only applied on first level setMods.clearLocks= True; latchMods.clearLocks= True; latchMods.latchToLock= True; // Default statement for real modifiers: any key bound to a real // modifier via modifier_map will set this modifier at all its // levels. // Here only to illustrate: do not add it! interpret Any + Any { action= SetMods(modifiers=modMapMods); }; // Shift being real modifier, we do not need a corresponding // interpret statement because the previous one suffices. // Let’s associate LevelThree to the keysym ISO_Level3_Shift // First, match the keys and their levels with the // ISO_Level3_Shift keysym and with any real modifier // (Any = AnyOf(all)) in its modmap. interpret ISO_Level3_Shift+Any { // Only match the first level of the first group useModMapMods= level1; // Add the virtual modifier to the key’s vmodmap virtualModifier= LevelThree; // Activate the LevelThree modifier (depressed mode) action= SetMods(modifiers=LevelThree); }; // Then for keys and their levels with the // ISO_Level3_Shift keysym but with either no real modifier // in its modmap or a level higher than 1. // Indeed: // • In case the level is higher than 1 there is no match // in the previous statement. // • The condition is equivalent to // ISO_Level3_Shift+AnyOfOrNone(all), but since // the previous statement ISO_Level3_Shift+Any is more // specific, it will be matched before this one. interpret ISO_Level3_Shift { // Activate the LevelThree modifier (depressed mode) action= SetMods(modifiers=LevelThree); }; ``` 2. Define [key types] that use it in the [xkb_types] section: ```c // Declare virtual modifiers. Shift being real modifier, // we do not need to add it here. virtual_modifiers LevelThree; type "FOUR_LEVEL" { // Key type modifier mask: all the modifiers used in the key type modifiers = Shift + LevelThree; map[None] = Level1; map[Shift] = Level2; map[LevelThree] = Level3; map[Shift+LevelThree] = Level4; level_name[Level1] = "Base"; level_name[Level2] = "Shift"; level_name[Level3] = "AltGr"; level_name[Level4] = "Shift AltGr"; }; ``` 3. Bind it to a [keycode] in the [xkb_symbols] section: 1. Map [keysyms] used in the `xkb_compat` section hereinabove. 2. Bind [real modifiers] to keys using these keysyms with `modifier_map`. _Note:_ Only one key binding to real modifier is required. The corresponding keysym must then be on the first level of the first Group. _Note:_ One can optionally bind directly a virtual modifier to a key using `virtualmodifiers` instead of doing it in the `xkb_compat` section. But the recommended way is to use the `xkb_compat` section. ```c // Shift: defined in pc symbols key {[ Shift_L ]}; key {[ Shift_R ]}; modifier_map Shift { Shift_L, Shift_R }; // The previous will resolve to: // modifier_map Shift { , }; // Thus the real modifier Shift is added to the modmap of // and . // The “Any + Any” interpret statement matches and , // therefore these keys set the Shift modifier. // LevelThree: defined in pc symbols // With the following 2 lines: // 1. The modifier keysym is on the first level of the first group. // 2. The real modifier Mod5 is bound to , // i.e. Mod5 is added to its modmap. // 3. It matches the interpret statement “ISO_Level3_Shift+Any”, // which adds the LevelThree modifier to the vmodmap of . // 4. The mapping of LevelThree to real modifiers is the union // of modmaps with corresponding vmodmaps containing // LevelThree. In our case there is only one: therefore // LevelThree maps to Mod5. key {[ ISO_Level3_Shift ]}; modifier_map Mod5 { }; // LevelThree: defined in level3 symbols // Not bound to a real modifier, so interpret statement // “ISO_Level3_Shift” applies. key {[ISO_Level3_Shift], type[group1]="ONE_LEVEL" }; // Note: we could have the following line, but it is not necessary // because we have the mappings of . // modifier_map Mod5 { }; // Warning: if we had the for example the following line, the // mapping of LevelThree to real modifiers would be “Mod1+Mod5”. // modifier_map Mod1 { }; // Alternative definitions, without using interpret statements virtual_modifiers LevelThree; key { virtualmodifiers=LevelThree , repeats=False , symbols[Group1] = [ISO_Level3_Shift] , actions[Group1] = [SetMods(modifiers=LevelThree)] }; modifier_map Mod5 { }; key { repeat=False , symbols[Group1] = [ISO_Level3_Shift] , actions[Group1] = [SetMods(modifiers=LevelThree)] , type[group1]="ONE_LEVEL" }; // FOUR_LEVEL key type example from latin symbols key {[b, B, leftdoublequotemark, leftsinglequotemark]}; ``` ## Key actions {#key-actions} The following table provide an overview of the available actions: | Category | Action name | Alias | Description | |----------|---------------------|------------------|------------------------------------| | [Ineffectual action] | [`NoAction`][NoAction] | | **Default action**: *implicitly* do nothing | | ^ | [`VoidAction`][VoidAction] | | *Explicitly* do nothing | | [Modifier action] | [`SetMods`][SetMods] | | Modifies the [depressed] modifiers | | ^ | [`LatchMods`][Latchmods] | | Modifies the [latched] modifiers | | ^ | [`LockMods`][LockMods] | | Modifies the [locked] modifiers | | [Group action] | [`SetGroup`][SetGroup] | | Modifies the _base_ group | | ^ | [`LatchGroup`][LatchGroup] | | Modifies the _latched_ group | | ^ | [`LockGroup`][LockGroup] | | Modifies the _locked_ group | | [Legacy action] | `MovePointer`| `MovePtr` | Move the mouse pointer | | ^ | `PointerButton` | `PtrBtn` | Simulate a mouse button press | | ^ | `LockPointerButton` | `LockPtrBtn` | Simulate a mouse button press, locked until the action’s key is pressed again. | | ^ | `SetPointerDefault` | `SetPtrDflt` | Set the default select button (???)| | ^ | [`SetControls`][SetControls] | | Set the standard XKB controls | | ^ | [`LockControls`][LockControls] | | Lock the standard XKB controls | | ^ | [`TerminateServer`][TerminateServer] | `Terminate` | Shut down the X server | | ^ | `SwitchScreen` | | Switch virtual X screen | | ^ | [`Private`][Private]| | Raw encoding of an action | | [Unsupported legacy action]| [`RedirectKey`][redirectkey] | `Redirect` | Emulate pressing a key with a different key code | | ^ | `ISOLock` | | Convert ordinary modifier key actions into lock actions while this action is active | | ^ | `DeviceButton` | `DevBtn` | Emulate an event from an arbitrary input device such as a joystick | | ^ | `LockDeviceButton` | `LockDevBtn` | Emulate an event from an arbitrary input device such as a joystick | | ^ | `DeviceValuator` | `DevVal` | TODO | | ^ | `MessageAction` | `Message` | Generate an arbitrary special-purpose XKB event | Common syntax: - Boolean values: - `true`, `yes`, `on` - `false`, `no`, `off` ### Ineffectual actions {#ineffectual-actions} [ineffectual action]: @ref ineffectual-actions [NoAction]: @ref no-action [VoidAction]: @ref void-action
`NoAction` @anchor no-action
**Default action**: *implicitly* do nothing. Does *not* override previous actions and is dropped. No parameters.
`VoidAction` @anchor void-action
*Explicitly* do nothing. *Does* override previous actions and is not dropped. No parameters. @note This is a libxkbcommon *extension*. In order to maintain backward-compatibility, it serializes to `LockControls(controls=none,affect=neither)`. @since 1.10.0
### Modifiers actions {#modifiers-actions} [modifier action]: @ref modifiers-actions [modifier actions]: @ref modifiers-actions [SetMods]: @ref set-mods-action [LatchMods]: @ref latch-mods-action [LockMods]: @ref lock-mods-action There are 3 modifiers actions:
`SetMods` @anchor set-mods-action
Modifies the [depressed] modifiers.
Parameters
Name Aliases Data type Default value Description
`modifiers` `mods` Modifier mask `none` (0) The list of modifiers to modify, separated by `+`, or the special value `modMapMods`. The latter means the parameter value has to be read from the `vmodmap` attribute of the key.
`clearLocks` boolean `false` See its use [hereinafter](@ref set-modifier-action-effects)
`unlockOnPress` boolean `false` Control whether [locked] modifiers are unlocked on key press or release (default). See [hereinafter](@ref set-modifier-action-effects) for further details. @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
`LatchMods` @anchor latch-mods-action
Modifies the [latched] modifiers
Parameters
Name Aliases Data type Default value Description
`modifiers` `mods` Modifier mask `none` (0) see [`SetMods`][SetMods].
`clearLocks` boolean `false` See its use [hereinafter](@ref latch-modifier-action-effects)
`latchToLock` boolean `false` See its use [hereinafter](@ref latch-modifier-action-effects)
`latchOnPress` boolean `false` Control whether [latched] modifiers are latched on key press or release (default). See [hereinafter](@ref latch-modifier-action-effects) for further details. @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
`unlockOnPress` boolean `false` Control whether [locked] modifiers are unlocked on key press or release (default). See [hereinafter](@ref latch-modifier-action-effects) for further details. @note It is *implied* if both `latchOnPress=true` and `clearLocks=true`. @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
`LockMods` @anchor lock-mods-action
Modifies the [locked] modifiers.
Parameters
Name Aliases Data type Default value Description
`modifiers` `mods` Modifier mask `none` (0) see [`SetMods`][SetMods]
`affect` enumeration: - `lock` - `unlock` - `both` - `neither` `both` - `lock`: the action only locks the modifier, but cannot unlock it. - `unlock`: the action only unlocks modifier, but cannot lock it. - `both`: the first key press locks the modifier and the second key press releases the modifier.. - `neither`: do not lock nor unlock, i.e. do nothing.
`unlockOnPress` boolean `false` Control whether [locked] modifiers are unlocked on key press or release. See [hereinafter](@ref lock-modifier-action-effects) for further details. @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
@todo highlight that there is reference counting for the modifiers, e.g. to manage multiple physical keys for the same modifier. These actions perform different tasks on key press and on key release:
Effects of modifiers actions @anchor modifier-actions-effects
Action On key press On key release
`SetMods` @anchor latch-modifier-action-effects - If `clearLocks` and `unlockOnPress` are true, unlock the target modifiers. - Adds modifiers to [depressed] modifiers that were not unlocked. - Removes modifiers added on press from [depressed] modifiers, provided that no other key which affects the same modifiers is logically down. - If `clearLocks` is true, `unlockOnPress` is false and no other key were operated simultaneously with this key, then the modifiers will be removed as well from the [locked] modifiers.
`LatchMods` @anchor set-modifier-action-effects - If `unLockOnPress` and `clearLocks` are true and target modifiers were locked, then unlocks them and clear the action. - Otherwise if `latchOnPress` is true, then adds modifiers to the [latched] modifiers. - Otherwise adds modifiers to [depressed] modifiers. - If `latchOnPress` is false, then: - Removes modifiers from [depressed] modifiers. - If no keys were operated simultaneously with the latching modifier key: - If `clearLocks` is true and `unLockOnPress` is false and target modifiers were locked, then unlock then stop here and clear the action. - Otherwise add modifiers to [latched] modifiers. - If `latchToLock` is true and if the target modifiers are latched, then unlatch them and [lock][locked] them. - Latch target modifiers that were not used by `clearLocks` and `latchToLock`. - Otherwise unlatch the target modifiers and clear the action.
`LockMods` @anchor lock-modifier-action-effects - If `unlockOnPress` is true and some of the target modifiers were [locked] before the key press, then unlock them if `noUnlock` false. - Otherwise: - add target modifiers to [depressed] modifiers; - if `noLock` is false, add target modifiers to the [locked] modifiers. - If `unlockOnPress` is true and triggered unlocking on key press, do nothing. - Otherwise: - remove modifiers from the [depressed] modifiers, if no other key that affect the same modifiers is down; - if `noUnlock` is false and if any target modifiers was locked before the key press, *[unlock][locked]* them.
### Group actions {#group-actions} [group action]: @ref group-actions [group actions]: @ref group-actions [SetGroup]: @ref set-group-action [LatchGroup]: @ref latch-group-action [LockGroup]: @ref lock-group-action There are 3 group actions:
`SetGroup` @anchor set-group-action
Modifies the *base* group.
Parameters
Name Data type Default value Description
`group` Group index: - 1-based numbering - either absolute (no sign) or relative (`+`/`-` sign) 0 Target group or group delta
`clearLocks` boolean `false` See its use [hereinafter](@ref set-group-action-effects)
`LatchGroup` @anchor latch-group-action
Modifies the *latched* group.
Parameters
Name Data type Default value Description
`group` Group index (see [`SetGroup`][SetGroup]) 0 Target group or group delta
`clearLocks` boolean `false` See its use [hereinafter](@ref latch-group-action-effects)
`latchToLock` boolean `false` See its use [hereinafter](@ref latch-group-action-effects)
`LockGroup` @anchor lock-group-action
Modifies the *locked* group.
Parameters
Name Data type Default value Description
`group` Group index (see [`SetGroup`][SetGroup]) 0 Target group or group delta
`lockOnRelease` boolean false Control whether to trigger the group change on key press (default) or release. See further details [hereinafter](@ref lock-group-action-effects) @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
Effects of group actions
Action On key press On key release
`SetGroup` @anchor set-group-action-effects - If the `group` parameter is *absolute*, key press events sets the *base* keyboard group to `group`. - Otherwise, it adds `group` to the *base* keyboard group. In either case, the resulting *effective* keyboard group is brought back into range depending on the value of the `GroupsWrap` control for the keyboard. If *no* keys were operated simultaneously with this key and the `clearLocks` parameter is set, key release also sets the *locked* keyboard group to `Group1`.
`LatchGroup` @anchor latch-group-action-effects Same as `SetGroup`. Same as `SetGroup`. If no keys were operated simultaneously with the latching group key and the `clearLocks` parameter was not set or had no effect, key release has the following additional effects: - If `latchToLock` parameter is set and the *latched* keyboard group is not the first group, the key release adds the *delta* applied by the corresponding key press to the locked keyboard group and subtracts it from the latched keyboard group. The *locked* and *effective* keyboard group are brought back into range according to the value of the global `GroupsWrap` control for the keyboard. - Otherwise, key release adds the key press *delta* to the latched keyboard group.
`LockGroup` @anchor lock-group-action-effects - If `lockOnRelease` is set, then key press has no effect. - Otherwise: - if the `group` is absolute, key press sets the *locked* keyboard group to `group`; - otherwise, key press adds `group` to the *locked* keyboard group. In either case, the resulting *locked* and *effective* group is brought back into range depending on the value of the `GroupsWrap` control for the keyboard. - If `lockOnRelease` is not set, then key release has no effect. - Otherwise, if any other key was *pressed* after the locking key, then key release has no effect.
This enables e.g. using `Alt+Shift` combination in any order. - `Shift` down, `Alt` down, `Alt` up, `Shift` up - `Shift` down, `Alt` down, `Shift` up, `Alt` up - `Alt` down, `Shift` down, `Shift` up, `Alt` up - `Alt` down, `Shift` down, `Alt` up, `Shift` up This would not be possible if locking was cancelled by key *release* too.
- Otherwise, it has the same effect than a key press *without* `lockOnRelease` set.
### Legacy X11 actions {#legacy-x11-actions} [legacy action]: @ref legacy-x11-actions @attention The following legacy actions are kept for compatibility only: they are parsed and validated but have no effect. This allows to use keymaps defined in [xkeyboard-config] for both X11 and Wayland. #### Pointer actions
`MovePointer`
`MovePtr`
Move the mouse pointer @todo MovePointer parameters
`PointerButton`
`PtrBtn`
Simulate a mouse button press @todo PointerButton parameters
`LockPointerButton`
`LockPointerBtn`
`LockPtrButton`
`LockPtrBtn`
Simulate a mouse button press, locked until this actiion’s key is pressed again @todo LockPointerButton parameters
`SetPointerDefault`
`SetPtrDflt`
Set the default select button (???) @todo SetPointerDefault parameters
#### Control flags actions [SetControls]: @ref set-controls-action [LockControls]: @ref lock-controls-action
`SetControls` @anchor set-controls-action
Set the standard XKB controls
Parameters
Name Alias Data type Default value Description
`controls` `ctrls` Mask of the following enumeration: - `RepeatKeys` - `Repeat` - `AutoRepeat` - `SlowKeys` - `BounceKeys` - `StickyKeys` - `MouseKeys` - `MouseKeysAccel` - `AccessXKeys` - `AccessXTimeout` - `AccessXFeedback` - `AudibleBell` - `IgnoreGroupLock` - `Overlay1` - `Overlay2` Plus 2 special values: - `all` - `none` 0 Standard XKB controls
`LockControls` @anchor lock-controls-action
Lock the standard XKB controls
Parameters
Name Alias Data type Default value Description
`controls` `ctrls` Mask (see [`SetControls`][SetControls]) 0 Standard XKB controls
`affect` enumeration: - `lock` - `unlock` - `both` - `neither` `both` TODO
#### Server actions [TerminateServer]: @ref terminate-server-action
`TerminateServer` @anchor terminate-server-action
Shut down the X server No parameters.
`SwitchScreen`
@todo SwitchScreen
#### Private action {#private-action} [Private]: @ref private-action Raw encoding of an action. Aimed to support arbitrary action unknown to the XKB compiler. @warning This assumes that the corresponding action’s C `struct` is laid out in memory exactly as described in the XKB specification and libraries. However, libxkbcommon have changed these `struct`s in various ways, so this assumption is no longer true and the actions defined in the XKB protocol are unsupported.
Parameters
Name Data type Default value Description
`type` integer 0 Action type, as encoded in the XKB protocol
`data` byte array or a string of *exactly 7 bytes* "0000000" Raw byte encoding of the action following the XKB protocol
Examples: - `Private(type=123, data="abcdefg");` - `Private(type=123, data[1]=0, data[2]=100, data[3]=12);` ### Unsupported legacy X11 actions {#unsupported-legacy-x11-actions} [unsupported legacy action]: @ref unsupported-legacy-x11-actions @attention The following legacy actions are **unsupported**: they are parsed and but *not validated* and are then completely *ignored*. #### Redirect key {#redirect-key-action} [redirectkey]: @ref redirect-key-action `RedirectKey` emulates pressing a key with a different key code. `RedirectKey` normally redirects to another key on the *same device* as the key or button which caused the event, else on the *core* keyboard device.
Parameters
Name Aliases Data type Default value Description
`key` `keycode`, `kc` keycode 0 Target keycode to emulate
`clearmodifiers` `clearmods` modifier mask `none` (0) Modifiers to clear
`modifiers` `mods` modifier mask `none` (0) Modifiers to add
Effects
On key *press* On key *release*
Key press causes a key press event for the key specified by the `key` parameter instead of for the actual key. The state reported in this event reports of the current *effective* modifiers changed as follow: - Modifiers in the `clearmodifiers` parameter are cleared. - Modifiers in the `modifiers` parameter are set. Key release causes a key release event for the key specified by the `key` parameter; the state field for this event consists of the *effective* modifiers at the time of the release, changed as described on the key press.
#### ISO lock @todo `ISOLock` #### Device actions
`DeviceButton`
@todo DeviceButton
`LockDeviceButton`
@todo LockDeviceButton
`DeviceValuator`
@todo DeviceValuator
#### Message @todo `ActionMessage` ## The “xkb_geometry” section {#the-xkb_geometry-section} This section aims to describe the *physical* layout of a keyboard and its main use case is to produce a picture of the keyboard via e.g. the `xkbprint` program. @warning libxkbcommon does not support this section: while it can parse the syntax, it does not interpret it; the section is simply dropped so there is no API to query it and the keymap serialization does not contain it. @sa @ref geometry-support "Compatibility with X11".

Source

  • doc/keymap-text-format-v1-v2.md

  • 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    1378
    1379
    1380
    1381
    1382
    1383
    1384
    1385
    1386
    1387
    1388
    1389
    1390
    1391
    1392
    1393
    1394
    1395
    1396
    1397
    1398
    1399
    1400
    1401
    1402
    1403
    1404
    1405
    1406
    1407
    1408
    1409
    1410
    1411
    1412
    1413
    1414
    1415
    1416
    1417
    1418
    1419
    1420
    1421
    1422
    1423
    1424
    1425
    1426
    1427
    1428
    1429
    1430
    1431
    1432
    1433
    1434
    1435
    1436
    1437
    1438
    1439
    1440
    1441
    1442
    1443
    1444
    1445
    1446
    1447
    1448
    1449
    1450
    1451
    1452
    1453
    1454
    1455
    1456
    1457
    1458
    1459
    1460
    1461
    1462
    1463
    1464
    1465
    1466
    1467
    1468
    1469
    1470
    1471
    1472
    1473
    1474
    1475
    1476
    1477
    1478
    1479
    1480
    1481
    1482
    1483
    1484
    1485
    1486
    1487
    1488
    1489
    1490
    1491
    1492
    1493
    1494
    1495
    1496
    1497
    1498
    1499
    1500
    1501
    1502
    1503
    1504
    1505
    1506
    1507
    1508
    1509
    1510
    1511
    1512
    1513
    1514
    1515
    1516
    1517
    1518
    1519
    1520
    1521
    1522
    1523
    1524
    1525
    1526
    1527
    1528
    1529
    1530
    1531
    1532
    1533
    1534
    1535
    1536
    1537
    1538
    1539
    1540
    1541
    1542
    1543
    1544
    1545
    1546
    1547
    1548
    1549
    1550
    1551
    1552
    1553
    1554
    1555
    1556
    1557
    1558
    1559
    1560
    1561
    1562
    1563
    1564
    1565
    1566
    1567
    1568
    1569
    1570
    1571
    1572
    1573
    1574
    1575
    1576
    1577
    1578
    1579
    1580
    1581
    1582
    1583
    1584
    1585
    1586
    1587
    1588
    1589
    1590
    1591
    1592
    1593
    1594
    1595
    1596
    1597
    1598
    1599
    1600
    1601
    1602
    1603
    1604
    1605
    1606
    1607
    1608
    1609
    1610
    1611
    1612
    1613
    1614
    1615
    1616
    1617
    1618
    1619
    1620
    1621
    1622
    1623
    1624
    1625
    1626
    1627
    1628
    1629
    1630
    1631
    1632
    1633
    1634
    1635
    1636
    1637
    1638
    1639
    1640
    1641
    1642
    1643
    1644
    1645
    1646
    1647
    1648
    1649
    1650
    1651
    1652
    1653
    1654
    1655
    1656
    1657
    1658
    1659
    1660
    1661
    1662
    1663
    1664
    1665
    1666
    1667
    1668
    1669
    1670
    1671
    1672
    1673
    1674
    1675
    1676
    1677
    1678
    1679
    1680
    1681
    1682
    1683
    1684
    1685
    1686
    1687
    1688
    1689
    1690
    1691
    1692
    1693
    1694
    1695
    1696
    1697
    1698
    1699
    1700
    1701
    1702
    1703
    1704
    1705
    1706
    1707
    1708
    1709
    1710
    1711
    1712
    1713
    1714
    1715
    1716
    1717
    1718
    1719
    1720
    1721
    1722
    1723
    1724
    1725
    1726
    1727
    1728
    1729
    1730
    1731
    1732
    1733
    1734
    1735
    1736
    1737
    1738
    1739
    1740
    1741
    1742
    1743
    1744
    1745
    1746
    1747
    1748
    1749
    1750
    1751
    1752
    1753
    1754
    1755
    1756
    1757
    1758
    1759
    1760
    1761
    1762
    1763
    1764
    1765
    1766
    1767
    1768
    1769
    1770
    1771
    1772
    1773
    1774
    1775
    1776
    1777
    1778
    1779
    1780
    1781
    1782
    1783
    1784
    1785
    1786
    1787
    1788
    1789
    1790
    1791
    1792
    1793
    1794
    1795
    1796
    1797
    1798
    1799
    1800
    1801
    1802
    1803
    1804
    1805
    1806
    1807
    1808
    1809
    1810
    1811
    1812
    1813
    1814
    1815
    1816
    1817
    1818
    1819
    1820
    1821
    1822
    1823
    1824
    1825
    1826
    1827
    1828
    1829
    1830
    1831
    1832
    1833
    1834
    1835
    1836
    1837
    1838
    1839
    1840
    1841
    1842
    1843
    1844
    1845
    1846
    1847
    1848
    1849
    1850
    1851
    1852
    1853
    1854
    1855
    1856
    1857
    1858
    1859
    1860
    1861
    1862
    1863
    1864
    1865
    1866
    1867
    1868
    1869
    1870
    1871
    1872
    1873
    1874
    1875
    1876
    1877
    1878
    1879
    1880
    1881
    1882
    1883
    1884
    1885
    1886
    1887
    1888
    1889
    1890
    1891
    1892
    1893
    1894
    1895
    1896
    1897
    1898
    1899
    1900
    1901
    1902
    1903
    1904
    1905
    1906
    1907
    1908
    1909
    1910
    1911
    1912
    1913
    1914
    1915
    1916
    1917
    1918
    1919
    1920
    1921
    1922
    1923
    1924
    1925
    1926
    1927
    1928
    1929
    1930
    1931
    1932
    1933
    1934
    1935
    1936
    1937
    1938
    1939
    1940
    1941
    1942
    1943
    1944
    1945
    1946
    1947
    1948
    1949
    1950
    1951
    1952
    1953
    1954
    1955
    1956
    1957
    1958
    1959
    1960
    1961
    1962
    1963
    1964
    1965
    1966
    1967
    1968
    1969
    1970
    1971
    1972
    1973
    1974
    1975
    1976
    1977
    1978
    1979
    1980
    1981
    1982
    1983
    1984
    1985
    1986
    1987
    1988
    1989
    1990
    1991
    1992
    1993
    1994
    1995
    1996
    1997
    1998
    1999
    2000
    2001
    2002
    2003
    2004
    2005
    2006
    2007
    2008
    2009
    2010
    2011
    2012
    2013
    2014
    2015
    2016
    2017
    2018
    2019
    2020
    2021
    2022
    2023
    2024
    2025
    2026
    2027
    2028
    2029
    2030
    2031
    2032
    2033
    2034
    2035
    2036
    2037
    2038
    2039
    2040
    2041
    2042
    2043
    2044
    2045
    2046
    2047
    2048
    2049
    2050
    2051
    2052
    2053
    2054
    2055
    2056
    2057
    2058
    2059
    2060
    2061
    2062
    2063
    2064
    2065
    2066
    2067
    2068
    2069
    2070
    2071
    2072
    2073
    2074
    2075
    2076
    2077
    2078
    2079
    2080
    2081
    2082
    2083
    2084
    2085
    2086
    2087
    2088
    2089
    2090
    2091
    2092
    2093
    2094
    2095
    2096
    2097
    2098
    2099
    2100
    2101
    2102
    2103
    2104
    2105
    2106
    2107
    2108
    2109
    2110
    2111
    2112
    2113
    2114
    2115
    2116
    2117
    2118
    2119
    2120
    2121
    2122
    2123
    2124
    2125
    2126
    2127
    2128
    2129
    2130
    2131
    2132
    2133
    2134
    2135
    2136
    2137
    2138
    2139
    2140
    2141
    2142
    2143
    2144
    2145
    2146
    2147
    2148
    2149
    2150
    2151
    2152
    2153
    2154
    2155
    2156
    2157
    2158
    2159
    2160
    2161
    2162
    2163
    2164
    2165
    2166
    2167
    2168
    2169
    2170
    2171
    2172
    2173
    2174
    2175
    2176
    2177
    2178
    2179
    2180
    2181
    2182
    2183
    2184
    2185
    2186
    2187
    2188
    2189
    2190
    2191
    2192
    2193
    2194
    2195
    2196
    2197
    2198
    2199
    2200
    2201
    2202
    2203
    2204
    2205
    2206
    2207
    2208
    2209
    2210
    2211
    2212
    2213
    2214
    2215
    2216
    2217
    2218
    2219
    2220
    2221
    2222
    2223
    2224
    2225
    2226
    2227
    2228
    2229
    2230
    2231
    2232
    2233
    2234
    2235
    2236
    2237
    2238
    2239
    2240
    2241
    2242
    2243
    2244
    2245
    2246
    2247
    2248
    2249
    2250
    2251
    2252
    2253
    2254
    2255
    2256
    2257
    2258
    2259
    2260
    2261
    2262
    2263
    2264
    2265
    2266
    2267
    2268
    2269
    2270
    2271
    2272
    2273
    2274
    2275
    2276
    2277
    2278
    2279
    2280
    2281
    2282
    2283
    2284
    2285
    2286
    2287
    2288
    2289
    2290
    2291
    2292
    2293
    2294
    2295
    2296
    2297
    2298
    2299
    2300
    2301
    2302
    2303
    2304
    2305
    2306
    2307
    2308
    2309
    2310
    2311
    2312
    2313
    2314
    2315
    2316
    2317
    2318
    2319
    2320
    2321
    2322
    2323
    2324
    2325
    2326
    2327
    2328
    2329
    2330
    2331
    2332
    2333
    2334
    2335
    2336
    2337
    2338
    2339
    2340
    2341
    2342
    2343
    2344
    2345
    2346
    2347
    2348
    2349
    2350
    2351
    2352
    2353
    2354
    2355
    2356
    2357
    2358
    2359
    2360
    2361
    2362
    2363
    2364
    2365
    2366
    2367
    2368
    2369
    2370
    2371
    2372
    2373
    2374
    2375
    2376
    2377
    2378
    2379
    2380
    2381
    2382
    2383
    2384
    2385
    2386
    2387
    2388
    2389
    2390
    2391
    2392
    2393
    2394
    2395
    2396
    2397
    2398
    2399
    2400
    2401
    2402
    2403
    2404
    2405
    2406
    2407
    2408
    2409
    2410
    2411
    2412
    2413
    2414
    2415
    2416
    2417
    2418
    2419
    2420
    2421
    2422
    2423
    2424
    2425
    2426
    2427
    2428
    2429
    2430
    2431
    2432
    2433
    2434
    2435
    2436
    2437
    2438
    2439
    2440
    2441
    2442
    2443
    2444
    2445
    2446
    2447
    2448
    2449
    2450
    2451
    2452
    2453
    2454
    2455
    2456
    2457
    2458
    2459
    2460
    2461
    2462
    2463
    2464
    2465
    2466
    2467
    2468
    2469
    2470
    2471
    2472
    2473
    2474
    2475
    2476
    2477
    2478
    2479
    2480
    2481
    2482
    2483
    2484
    2485
    2486
    2487
    2488
    2489
    2490
    2491
    2492
    2493
    2494
    2495
    2496
    2497
    2498
    2499
    2500
    2501
    2502
    2503
    2504
    2505
    2506
    2507
    2508
    2509
    2510
    2511
    2512
    2513
    2514
    2515
    2516
    2517
    2518
    2519
    2520
    2521
    2522
    2523
    2524
    2525
    2526
    2527
    2528
    2529
    2530
    2531
    2532
    2533
    2534
    2535
    2536
    2537
    2538
    2539
    2540
    2541
    2542
    2543
    2544
    2545
    2546
    2547
    2548
    2549
    2550
    2551
    2552
    2553
    2554
    2555
    2556
    2557
    2558
    2559
    2560
    2561
    2562
    2563
    2564
    2565
    2566
    2567
    2568
    2569
    2570
    2571
    2572
    2573
    2574
    2575
    2576
    2577
    2578
    2579
    2580
    2581
    2582
    2583
    2584
    2585
    2586
    2587
    2588
    2589
    2590
    2591
    2592
    2593
    2594
    2595
    2596
    2597
    2598
    2599
    2600
    2601
    2602
    2603
    2604
    2605
    2606
    2607
    2608
    2609
    2610
    2611
    2612
    2613
    2614
    2615
    2616
    2617
    2618
    2619
    2620
    2621
    2622
    2623
    2624
    2625
    2626
    2627
    2628
    2629
    2630
    2631
    2632
    2633
    2634
    2635
    2636
    2637
    2638
    2639
    2640
    2641
    2642
    2643
    2644
    2645
    2646
    2647
    2648
    2649
    2650
    2651
    2652
    2653
    2654
    2655
    2656
    2657
    2658
    2659
    2660
    2661
    2662
    2663
    2664
    2665
    2666
    2667
    2668
    2669
    2670
    2671
    2672
    2673
    2674
    2675
    2676
    2677
    2678
    2679
    2680
    2681
    2682
    2683
    2684
    2685
    2686
    2687
    2688
    2689
    2690
    2691
    2692
    2693
    2694
    2695
    2696
    2697
    2698
    2699
    2700
    2701
    2702
    2703
    2704
    2705
    2706
    2707
    2708
    2709
    2710
    2711
    2712
    2713
    2714
    2715
    2716
    2717
    2718
    2719
    2720
    2721
    2722
    2723
    2724
    2725
    2726
    2727
    2728
    2729
    2730
    2731
    2732
    2733
    2734
    2735
    2736
    2737
    2738
    2739
    2740
    2741
    2742
    2743
    2744
    2745
    2746
    2747
    2748
    2749
    2750
    2751
    2752
    2753
    2754
    2755
    2756
    2757
    2758
    2759
    2760
    2761
    2762
    2763
    2764
    2765
    2766
    2767
    2768
    2769
    2770
    2771
    2772
    2773
    2774
    2775
    2776
    2777
    2778
    2779
    2780
    2781
    2782
    2783
    2784
    2785
    2786
    2787
    2788
    2789
    2790
    2791
    2792
    2793
    2794
    2795
    2796
    2797
    2798
    2799
    2800
    2801
    2802
    2803
    2804
    2805
    2806
    2807
    2808
    2809
    2810
    2811
    2812
    2813
    2814
    2815
    2816
    2817
    2818
    2819
    2820
    2821
    2822
    2823
    2824
    2825
    2826
    2827
    2828
    2829
    2830
    2831
    2832
    2833
    2834
    2835
    2836
    2837
    2838
    2839
    2840
    2841
    2842
    2843
    2844
    2845
    2846
    2847
    2848
    2849
    2850
    2851
    2852
    2853
    2854
    2855
    2856
    2857
    2858
    2859
    2860
    2861
    2862
    2863
    2864
    2865
    2866
    2867
    2868
    2869
    2870
    2871
    2872
    2873
    2874
    2875
    2876
    2877
    2878
    2879
    2880
    2881
    2882
    2883
    2884
    2885
    2886
    2887
    2888
    2889
    2890
    2891
    2892
    2893
    2894
    2895
    2896
    2897
    2898
    2899
    2900
    2901
    2902
    2903
    2904
    2905
    2906
    2907
    2908
    2909
    2910
    2911
    2912
    2913
    2914
    2915
    2916
    2917
    2918
    2919
    2920
    2921
    2922
    2923
    2924
    2925
    2926
    2927
    2928
    2929
    2930
    2931
    2932
    2933
    2934
    2935
    2936
    2937
    2938
    2939
    2940
    2941
    2942
    2943
    2944
    2945
    2946
    2947
    2948
    2949
    2950
    2951
    2952
    2953
    2954
    2955
    2956
    2957
    2958
    2959
    2960
    2961
    2962
    2963
    2964
    2965
    2966
    2967
    2968
    2969
    2970
    2971
    2972
    2973
    2974
    2975
    2976
    2977
    2978
    2979
    2980
    2981
    2982
    2983
    2984
    2985
    2986
    2987
    2988
    2989
    2990
    2991
    2992
    2993
    2994
    2995
    2996
    2997
    2998
    2999
    3000
    3001
    3002
    3003
    3004
    3005
    3006
    3007
    3008
    3009
    3010
    3011
    3012
    3013
    3014
    3015
    3016
    3017
    3018
    3019
    3020
    3021
    3022
    3023
    3024
    3025
    3026
    3027
    3028
    3029
    3030
    3031
    3032
    3033
    3034
    3035
    3036
    3037
    3038
    3039
    3040
    3041
    3042
    3043
    3044
    3045
    3046
    3047
    3048
    3049
    3050
    3051
    3052
    3053
    3054
    3055
    3056
    3057
    3058
    3059
    3060
    3061
    3062
    3063
    3064
    3065
    3066
    3067
    3068
    3069
    3070
    3071
    3072
    3073
    3074
    3075
    3076
    3077
    3078
    3079
    3080
    3081
    3082
    3083
    3084
    3085
    3086
    3087
    3088
    3089
    3090
    3091
    3092
    3093
    3094
    3095
    3096
    3097
    3098
    3099
    3100
    3101
    3102
    3103
    3104
    3105
    3106
    3107
    3108
    3109
    3110
    3111
    3112
    3113
    3114
    3115
    3116
    3117
    3118
    3119
    3120
    3121
    3122
    3123
    3124
    3125
    3126
    3127
    3128
    3129
    3130
    3131
    3132
    3133
    3134
    3135
    3136
    3137
    3138
    3139
    3140
    3141
    3142
    3143
    3144
    3145
    3146
    3147
    3148
    3149
    3150
    3151
    3152
    3153
    3154
    3155
    3156
    3157
    3158
    3159
    3160
    3161
    3162
    3163
    3164
    3165
    3166
    3167
    3168
    3169
    3170
    3171
    3172
    3173
    3174
    3175
    3176
    3177
    3178
    3179
    3180
    3181
    3182
    3183
    3184
    3185
    3186
    3187
    3188
    3189
    3190
    3191
    3192
    3193
    3194
    3195
    3196
    3197
    3198
    3199
    3200
    3201
    3202
    3203
    3204
    3205
    3206
    3207
    3208
    3209
    3210
    3211
    3212
    3213
    3214
    3215
    3216
    3217
    3218
    3219
    3220
    3221
    3222
    3223
    3224
    3225
    3226
    3227
    3228
    3229
    3230
    3231
    3232
    3233
    3234
    3235
    3236
    3237
    3238
    3239
    3240
    3241
    3242
    3243
    3244
    3245
    3246
    3247
    3248
    3249
    3250
    3251
    3252
    3253
    3254
    3255
    3256
    3257
    3258
    3259
    3260
    3261
    3262
    3263
    3264
    3265
    3266
    3267
    3268
    3269
    3270
    3271
    3272
    3273
    3274
    3275
    3276
    3277
    3278
    3279
    3280
    3281
    3282
    3283
    3284
    3285
    3286
    3287
    3288
    3289
    3290
    3291
    3292
    3293
    3294
    3295
    3296
    3297
    3298
    3299
    3300
    3301
    3302
    3303
    3304
    3305
    3306
    3307
    3308
    3309
    3310
    3311
    3312
    3313
    3314
    3315
    3316
    3317
    3318
    3319
    3320
    3321
    3322
    3323
    3324
    3325
    3326
    3327
    3328
    3329
    3330
    3331
    3332
    3333
    3334
    3335
    3336
    3337
    3338
    3339
    3340
    3341
    3342
    3343
    3344
    3345
    3346
    3347
    3348
    3349
    3350
    3351
    3352
    3353
    3354
    3355
    3356
    3357
    3358
    3359
    3360
    3361
    3362
    3363
    3364
    3365
    3366
    3367
    3368
    3369
    3370
    3371
    3372
    3373
    3374
    3375
    3376
    3377
    3378
    3379
    3380
    3381
    3382
    3383
    3384
    3385
    3386
    3387
    3388
    3389
    3390
    3391
    3392
    3393
    3394
    3395
    3396
    3397
    3398
    3399
    3400
    3401
    3402
    3403
    3404
    3405
    3406
    3407
    3408
    3409
    3410
    3411
    3412
    3413
    3414
    3415
    3416
    3417
    3418
    3419
    3420
    3421
    3422
    3423
    3424
    3425
    3426
    3427
    3428
    3429
    3430
    3431
    3432
    3433
    3434
    3435
    3436
    3437
    3438
    3439
    3440
    3441
    3442
    3443
    3444
    3445
    3446
    3447
    3448
    3449
    3450
    3451
    3452
    3453
    3454
    3455
    3456
    3457
    3458
    3459
    3460
    3461
    3462
    3463
    3464
    3465
    3466
    3467
    3468
    3469
    3470
    3471
    3472
    3473
    3474
    3475
    3476
    3477
    3478
    3479
    3480
    3481
    3482
    3483
    3484
    3485
    3486
    3487
    3488
    3489
    3490
    3491
    3492
    3493
    3494
    3495
    3496
    3497
    3498
    3499
    3500
    3501
    3502
    3503
    3504
    3505
    3506
    3507
    3508
    3509
    3510
    3511
    3512
    3513
    3514
    3515
    3516
    3517
    3518
    3519
    3520
    3521
    3522
    3523
    3524
    3525
    3526
    3527
    3528
    3529
    3530
    3531
    3532
    3533
    3534
    3535
    3536
    3537
    3538
    3539
    3540
    3541
    3542
    3543
    3544
    3545
    3546
    3547
    3548
    3549
    3550
    3551
    3552
    3553
    3554
    3555
    3556
    3557
    3558
    3559
    3560
    3561
    3562
    3563
    3564
    3565
    3566
    3567
    3568
    3569
    3570
    3571
    3572
    3573
    3574
    3575
    3576
    3577
    3578
    3579
    3580
    3581
    3582
    3583
    3584
    3585
    3586
    3587
    3588
    3589
    3590
    3591
    3592
    3593
    3594
    3595
    3596
    3597
    3598
    3599
    3600
    3601
    3602
    3603
    3604
    3605
    3606
    3607
    3608
    3609
    3610
    3611
    3612
    3613
    3614
    3615
    3616
    3617
    3618
    3619
    3620
    3621
    3622
    3623
    3624
    3625
    3626
    3627
    3628
    3629
    3630
    3631
    3632
    3633
    3634
    3635
    3636
    3637
    3638
    3639
    3640
    3641
    3642
    3643
    3644
    3645
    3646
    3647
    3648
    3649
    3650
    3651
    3652
    3653
    3654
    3655
    3656
    3657
    3658
    3659
    3660
    3661
    3662
    3663
    3664
    3665
    3666
    3667
    3668
    3669
    3670
    3671
    3672
    3673
    3674
    3675
    3676
    3677
    3678
    3679
    3680
    3681
    3682
    3683
    3684
    3685
    3686
    3687
    3688
    3689
    3690
    3691
    3692
    3693
    3694
    3695
    3696
    3697
    3698
    3699
    3700
    3701
    3702
    3703
    3704
    3705
    3706
    3707
    3708
    3709
    3710
    3711
    3712
    3713
    3714
    3715
    3716
    3717
    3718
    3719
    3720
    3721
    3722
    3723
    3724
    3725
    3726
    3727
    3728
    3729
    3730
    3731
    3732
    3733
    3734
    3735
    3736
    3737
    3738
    3739
    3740
    3741
    3742
    3743
    3744
    3745
    3746
    3747
    3748
    3749
    3750
    3751
    3752
    3753
    3754
    3755
    3756
    3757
    3758
    3759
    3760
    3761
    3762
    3763
    3764
    3765
    3766
    3767
    3768
    3769
    3770
    3771
    3772
    3773
    3774
    3775
    3776
    3777
    3778
    3779
    3780
    3781
    3782
    3783
    3784
    3785
    3786
    3787
    3788
    3789
    3790
    3791
    3792
    3793
    3794
    3795
    3796
    3797
    3798
    3799
    3800
    3801
    3802
    3803
    3804
    3805
    3806
    3807
    3808
    3809
    3810
    3811
    3812
    3813
    3814
    3815
    3816
    3817
    3818
    3819
    3820
    3821
    3822
    3823
    3824
    3825
    3826
    3827
    3828
    3829
    3830
    3831
    3832
    3833
    3834
    3835
    3836
    3837
    3838
    3839
    3840
    3841
    3842
    3843
    3844
    3845
    3846
    3847
    3848
    3849
    3850
    3851
    3852
    3853
    3854
    3855
    3856
    3857
    3858
    3859
    3860
    3861
    3862
    3863
    3864
    3865
    3866
    3867
    3868
    3869
    3870
    3871
    3872
    3873
    3874
    3875
    3876
    3877
    3878
    3879
    3880
    3881
    3882
    3883
    3884
    3885
    3886
    3887
    3888
    3889
    3890
    3891
    3892
    3893
    3894
    3895
    3896
    3897
    3898
    3899
    3900
    3901
    3902
    3903
    3904
    3905
    3906
    3907
    3908
    3909
    3910
    3911
    3912
    3913
    3914
    3915
    3916
    3917
    3918
    3919
    3920
    3921
    3922
    3923
    3924
    3925
    3926
    3927
    3928
    3929
    3930
    3931
    3932
    3933
    3934
    3935
    3936
    3937
    3938
    3939
    3940
    3941
    3942
    3943
    3944
    3945
    3946
    3947
    3948
    3949
    3950
    3951
    3952
    3953
    3954
    3955
    3956
    3957
    3958
    3959
    3960
    3961
    3962
    3963
    3964
    3965
    3966
    3967
    3968
    3969
    3970
    3971
    3972
    3973
    3974
    3975
    3976
    3977
    3978
    3979
    3980
    
    # The XKB keymap text format, V1 and V2 {#keymap-text-format-v1-v2}
    
    <!--
    NOTE:
    • The Markdown supported in Doxygen is limited and buggy.
      Current issues and solutions:
      • In headers, only plain text is supported.
    • Use the language tag “c” for block code to give them a nice (approximated)
      syntax highlighting.
    -->
    
    This document describes the following [keymap] formats, as implemented by libxkbcommon:
    
    <dl>
    <dt>
    
    `::XKB_KEYMAP_FORMAT_TEXT_V1` @anchor keymap-text-format-v1
    </dt>
    <dd>
    
    The classic XKB text format, as generated by `xkbcomp -xkb`.
    See @ref xkbcommon-compatibility "" for further information.
    </dd>
    <dt>
    
    `::XKB_KEYMAP_FORMAT_TEXT_V2` @anchor keymap-text-format-v2
    </dt>
    <dd>
    
    Xkbcommon extensions of the classic XKB text format, **incompatible with X11**.
    See @ref xkbcommon-compatibility "" for further information.
    </dd>
    </dl>
    
    @see For an overview of the role of this format, please see “@ref xkb-the-config ""”.
    
    @see For examples of keymaps in this format, please see “@ref user-configuration ""”.
    For further examples see [xkeyboard-config], the standard database of keyboard
    configuration data.
    
    @note Due to the complexity of the format, this document is still is construction.
    Some additional resources are:
    
    @note
    - [Ivan Pascal’s XKB documentation][ivan-pascal]
    - [An Unreliable Guide to XKB Configuration][unreliable-guide]
    - [The X Keyboard Extension: Protocol Specification][XKB Protocol]
    - [How to enhance XKB configuration][xkeyboard-config doc]
    - [ArchWiki XKB page][arch-wiki]
    
    [xkeyboard-config]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config
    [ivan-pascal]: https://web.archive.org/web/20190724015820/http://pascal.tsu.ru/en/xkb/
    [unreliable-guide]: https://www.charvolant.org/doug/xkb/html/index.html
    [XKB Protocol]: https://www.x.org/releases/current/doc/kbproto/xkbproto.html
    [X11 Core Protocol]: https://www.x.org/releases/current/doc/xproto/x11protocol.html
    [xkeyboard-config doc]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/master/docs/README.enhancing
    [arch-wiki]: https://wiki.archlinux.org/index.php/X_keyboard_extension
    
    
    @tableofcontents{html:2}
    
    [terminology]: @ref terminology
    [introduction]: @ref introduction-to-the-xkb-text-format
    [xkb_keymap]: @ref the-xkb_keymap-block
    [xkb_keycodes]: @ref the-xkb_keycodes-section
    [xkb_types]: @ref the-xkb_types-section
    [xkb_compat]: @ref the-xkb_compat-section
    [xkb_symbols]: @ref the-xkb_symbols-section
    [virtual modifier statements]:@ref virtual-modifier-statements
    [actions]: @ref key-actions
    
    ## Terminology {#terminology}
    
    <dl>
      <dt><a name="keycode-def">Keycode</a><dt>
      <dd>
      Code that identifies a physical key on a keyboard.
    
      - _Raw_ keycodes are the numeric identifiers used as input in XKB.
        They are the result of the low-level processing of the data that
        keyboards send to a computer. For instance `36` may represent
        the return key.
      - _XKB_ keycodes are _symbolic_ names assigned to raw keycodes in
        order to facilitate their mapping to symbols. For instance the
        keycode for the return key is the abbreviation `RTRN`.
    
      See [xkb_keycodes] for further details.
      </dd>
      <dt><a name="keysym-def">Symbols</a></dt>
      <dd>
      A _keysym_ (short for “key symbol”) is a numeric encoding of a
      symbol on the cap of a key.
    
      Some keysyms have a canonical name for convenience. The complete list of
      canonical names is defined in `xkbcommon/xkbcommon-keysyms.h`.
    
      Common types of keysyms are:
    
      - A _character:_ e.g. `a` and `A` for Latin scripts,
        `alpha` “α” and `ALPHA` “Α” for Greek, etc.
      - A _dead key:_ e.g. `dead_grave` and `dead_diaeresis`, corresponding
        respectively to the [grave accent](https://en.wikipedia.org/wiki/Grave_accent)
        and the [diaeresis](https://en.wikipedia.org/wiki/Diaeresis_%28diacritic%29)
        diacritics.
    
        A [dead key](https://en.wikipedia.org/wiki/Dead_key) is a special kind of key
        that does not generate a character by itself, but modifies the character
        generated by the key struck(s) immediately after.
      - A <em>[modifier]⁠:</em> e.g. `Shift_L`, `Control_R`, `Caps_Lock`.
        See hereinafter.
      - A _system action:_ e.g. the arrow `Left`, `Pause`, `Escape`, `F1`.
    
      @sa [xkb_symbols] for further details on binding keysyms to keycodes.
      @sa [Keysym syntax][@ref keysym-syntax]
      </dd>
      <dt><a name="modifier-def">Modifier</a></dt>
      <dd>
      A _modifier key_ is a key that modifies the effect of other keys:
      e.g. Shift, Control, Caps Lock, etc.
    
      The state of a modifier key (active/inactive) is encoded as a
      _modifier index_ (or modifier bit or simply modifier) and has
      an associated _unique name_.
    
      For historical reasons, modifiers are divided in two categories:
    
      <dl>
        <dt><a name="real-modifier-def">Real modifiers</a></dt>
        <dd>
        They are the 8 _predefined_ (AKA *core*, *X11*) modifiers
        (see [usual modifiers] hereinafter).
    
        Real modifiers ensure backward compatibility: indeed
        they are the actual bits used to compute the [levels][level]
        and are communicated via the API of xkbcommon.
    
        Some are generic modifiers (`Mod[1-5]`) that do not have a
        conventional interpretation and are the motivation of the
        introduction of [virtual modifiers].
        </dd>
        <dt><a name="virtual-modifier-def">Virtual modifiers</a>
        <dd>
        They are the modifiers that are _not_ predefined.
        </dd>
      </dl>
    
      Each modifier has an associated [encoding][modifier encoding]. In keymaps
      compatible with X11, the encoding can be interpreted as a _mapping_ to one or
      multiple _real_ modifier. Real modifiers map to themselves: they are
      [canonical modifiers][canonical modifier]. See the “@ref modifiers-encoding ""”
      section for further information.
    
      The following table lists the
      <a name="usual-modifiers">usual modifiers</a>
      present in the [standard keyboard configuration][xkeyboard-config].
      Note that this is provided for information only, as it may change
      depending on the user configuration.
    
      | Modifier     | Type    | Usual mapping     | Comment                     |
      | ------------ | ------- | ----------------- | --------------------------- |
      | `Shift`      | Real    | `Shift` (fixed)   | The usual [Shift]           |
      | `Lock`       | Real    | `Lock` (fixed)    | The usual [Caps Lock][Lock] |
      | `Control`    | Real    | `Control` (fixed) | The usual [Control]         |
      | `Mod1`       | Real    | `Mod1` (fixed)    | Not conventional            |
      | `Mod2`       | Real    | `Mod2` (fixed)    | Not conventional            |
      | `Mod3`       | Real    | `Mod3` (fixed)    | Not conventional            |
      | `Mod4`       | Real    | `Mod4` (fixed)    | Not conventional            |
      | `Mod5`       | Real    | `Mod5` (fixed)    | Not conventional            |
      | `Alt`        | Virtual | `Mod1`            | The usual [Alt]             |
      | `Meta`       | Virtual | `Mod1`            | The legacy [Meta] key       |
      | `NumLock`    | Virtual | `Mod2`            | The usual [NumLock]         |
      | `Super`      | Virtual | `Mod4`            | The usual [Super]/GUI       |
      | `LevelThree` | Virtual | `Mod5`            | [ISO][ISO9995] level 3, aka [AltGr] |
      | `LevelFive`  | Virtual | `Mod3`            | [ISO][ISO9995] level 5      |
    
      [usual modifiers]: @ref usual-modifiers
      [Shift]: https://en.wikipedia.org/wiki/Control_key
      [Lock]: https://en.wikipedia.org/wiki/Caps_Lock
      [Control]: https://en.wikipedia.org/wiki/Control_key
      [Alt]: https://en.wikipedia.org/wiki/Alt_key
      [AltGr]: https://en.wikipedia.org/wiki/AltGr_key
      [NumLock]: https://en.wikipedia.org/wiki/Num_Lock
      [Meta]: https://en.wikipedia.org/wiki/Meta_key
      [Super]: https://en.wikipedia.org/wiki/Super_key_(keyboard_button)
    
      A modifier key can report its state in one of the following 3 ways:
    
      <dl>
        <dt><a name="depressed-mod-def">Depressed</a></dt>
        <dd>Active while depressed; e.g. the usual Shift.</dd>
        <dt><a name="latched-mod-def">Latched</a></dt>
        <dd>
          Activated when pressed and deactivated after the next
          non-modifier key press.
        </dd>
        <dt><a name="locked-mod-def">Locked</a></dt>
        <dd>
          Activated when pressed and deactivated when pressed again;
          e.g. the usual Caps Lock.
        </dd>
      </dl>
    
      See [modifiers declaration and binding] for further details.
      </dd>
    
      [depressed]: @ref depressed-mod-def
      [latched]: @ref latched-mod-def
      [locked]: @ref locked-mod-def
    
      <dt><a name="level-def">Shift Level</a></dt>
      <dd>
      A key may produce different
      results depending of the active modifiers: e.g. for a Latin script,
      pressing the key A produces “a” and holding Shift while pressing A
      produces “A”.
    
      This various results are organized in an ordered list; the _index_
      of each entry is called a <a name="level-index-def">shift level</a>
      or simply level. By convention the lowest level is the result when
      no modifier is active.
      Example for the key `A` on a latin script keyboard:
    
      | Level | Description                    | Keysym | Active key modifiers |
      |-------|--------------------------------|--------|----------------------|
      | 1     | Lower case letters             | `a`    | None                 |
      | 2     | Upper case letters.            | `A`    | `Shift`              |
      | 3     | Alternative lower case letters | `ae`   | `AltGr`              |
      | 4     | Alternative upper case letters | `AE`   | `Shift` + `AltGr`    |
    
      A key shift level is the logical _state_ of a key corresponding to
      the current shift level it used.
    
      Key shift levels are derived from the modifiers states, but not
      necessarily in the same way for all keys. For example, for Latin
      script the Caps Lock modifier selects the level 2 for alphabetic
      keys such as `A` but has no effect on a numeric key.
    
      There are groups of keys with the same characteristics: letters,
      punctuation, numeric keypad, etc. The meaning of their levels is
      identical and thus can be shared: this generalization is called
      a _key type_ (see hereinafter).
      </dd>
      <dt><a name="key-type-def">Key type</a></dt>
      <dd>
      A key type defines the levels available for a key and
      how to derive the active level from the modifiers states. Examples:
      - `ONE_LEVEL`: the key has only one level, i.e. it is not affected
        by any modifiers. Example: the modifiers themselves.
      - [`TWO_LEVEL`][TWO_LEVEL]: the key has two levels:
        - Level 1: default level, active when the `Shift` modifier is _not_ active.
        - Level 2: level activated with the `Shift` modifier.
      - [`FOUR_LEVEL`][FOUR_LEVEL]: see the example in the previous section.
    
      See [xkb_types] for further details.
      </dd>
      <dt><a name="layout-def">Layout</a></dt>
      <dd>
      A mapping of keycodes to symbols, actions and key types.
    
      A user who deals with multiple languages may need two or more
      different layouts: e.g. a layout for Arabic and another one for
      English. In this context, layouts are called _groups_ in XKB,
      as defined in the [standard ISO/IEC&nbsp;9995][ISO9995].
    
      Layouts are ordered and identified by their index. Example:
    
      - Layout 1: Arabic
      - Layout 2: English
    
      </dd>
      <dt><a name="key-action-def">Key Action</a></dt>
      <dd>
      In XKB world, a key action defines the effect a key
      has on the state of the keyboard or the state of the display server.
      Examples:
    
      - Change the state of a modifier.
      - Change the active group.
      - Move the mouse pointer.
    
      See the section “[Key actions][actions]” for further details.
      </dd>
      <dt><a name="indicator-def">Indicator</a></dt>
      <dd>
      A keyboard indicator is a mean to report a specific aspect of the
      keyboard state.
    
      <dl>
        <dt><em>Physical</em> indicator</dt>
        <dd>
        Typically a labelled LED on the keyboard, e.g. “Caps Lock” and
        “Num Lock”.
        </dd>
        <dt><em>Logical</em> indicator</dt>
        <dd>
        A customizable derived state of the keyboard.
        Its changes creates events that can be monitored.
    
        There are two categories:
    
        - _Real_ indicators are those associated to a physical indicator.
          For example, the “Caps Lock” logical modifier controls the
          corresponding physical LED.
    
          Because indicators are customizable, if one misses a “Num Lock”
          LED, one could define instead the “Caps Lock” _indicator_ to
          activate its LED when the “Num Lock” _modifier_ is active.
        - _Virtual_ indicators are not associated to a physical indicator.
          Their effect is only visible for programs monitoring them.
    
        Note that the meanings of _real_ and _virtual_ is slightly
        different than the one used for [modifier].
        </dd>
      </dl>
    
      See: <code>[xkb_keycodes][indicator name]</code> to define indicators and
      <code>[xkb_compat][indicator effect]</code> to define their effects.
      </dd>
      <dt><a name="keymap-def">Keymap</a></dt>
      <dd>
      The _complete_ definition of the
      mapping of raw keycodes to symbols and actions.
      It fully defines the behavior of a keyboard.
    
      Depending of the context, a keymap may refer to:
    
      - the software object defined and managed by libxkbcommon;
      - the text configuration used to create this software object.
    
      See @ref keymap-components-intro and [xkb_keymap] for further details.
      </dd>
      <dt>Keyboard configuration database @anchor database-def</dt>
      <dd>
        A database that provides the [keymap components](@ref keymap-components-intro).
        \*nix OSs uses the _standard_ database [xkeyboard-config]. One may extend
        this database with _custom_ layouts: see “@ref user-configuration ""” for
        further details.
      </dd>
    </dl>
    
    [keycode]: @ref keycode-def
    [keysym]: @ref keysym-def
    [keysyms]: @ref keysym-def
    [modifier]: @ref modifier-def
    [modifiers]: @ref modifier-def
    [real modifier]: @ref real-modifier-def
    [real modifiers]: @ref real-modifier-def
    [virtual modifier]: @ref virtual-modifier-def
    [virtual modifiers]: @ref virtual-modifier-def
    [level]: @ref level-def
    [shift level]: @ref level-def
    [level index]: @ref level-index-def
    [key type]: @ref key-type-def
    [key types]: @ref key-type-def
    [layout]: @ref layout-def
    [action]: @ref key-action-def
    [indicator]: @ref indicator-def
    [keymap]: @ref keymap-def
    [database]: @ref database-def
    [ISO9995]: https://en.wikipedia.org/wiki/ISO/IEC_9995
    
    
    ## Introduction to the XKB text format
    
    The XKB text format uses a syntax similar to the [C programming language][C].
    Note that the similarity with C stops here: the XKB text format is only a
    _configuration_ format and is not intended for programming.
    
    The XKB text format is used to configure a _keyboard keymap_, which is
    introduced in “@ref xkb-the-config ""”. It has the following two main use cases,
    illustrated in the [diagram hereinafter](@ref xkb-keymap-components-diagram):
    
    - __Server:__ Load a keymap from the keymap configuration database, then handle
      input events by updating the keyboard state. The keymap is assembled from
      an [RMLVO configuration][RMLVO] and its corresponding
      <strong>[KcCGST components][KcCGST]</strong> files.
    
      @see xkb_keymap::xkb_keymap_new_from_names2
    
      @see [xkeyboard-config] for the implementation of the *standard* keymap
      configuration database.
    
      @see “@ref user-configuration ""” to add a *custom* layout or option.
    - __Client:__ Load the active keymap from the server, then handle update events
      sent by the server. The <strong>[complete keymap]</strong> is directly
      available in a _self-contained_ file.
    
      @see xkb_keymap::xkb_keymap_new_from_string
    
    @anchor xkb-keymap-components-diagram
    @dotfile xkb-keymap-components "XKB text format use cases"
    
    [C]: https://en.wikipedia.org/wiki/C_(programming_language)#Syntax
    [RMLVO]: @ref RMLVO-intro
    [KcCGST]: @ref KcCGST-intro
    [complete keymap]: @ref keymap-intro
    
    ### XKB file
    
    There are two kinds of files for the XKB text format:
    
    <!-- NOTE:
    The XKB protocol (https://www.x.org/releases/current/doc/kbproto/xkbproto.html)
    uses “Keyboard description” and “Keyboard components” rather than “keymap” and
    “keymap components”.
    -->
    
    <dl>
      <dt>Keymap file @anchor keymap-file-def</dt>
      <dd>
        A file with the _complete_ description of the [keymap] object.
        It is the kind of file that the server sends to the client (see
        the [diagram](@ref xkb-keymap-components-diagram) above).
        Its top-level structure consists of the [xkb_keymap] block.
      </dd>
      <!-- TODO: not sure of the following -->
      <!--
      <dt>Partial keymap</dt>
      <dd>
      A keymap text configuration with one or more keymap sections. Some
      sections may be missing and [include] statements may not be resolved.
      </dd>
      <dt>Complete keymap</dt>
      <dd>
      A keymap text configuration consisting of a `%xkb_keymap` block with all
      mandatory sections; all [include] statements are resolved so that it is
      self-contained.
    
      See the [xkb_keymap] block for further details.
      </dd>
      -->
      <dt>Keymap _component_ file @anchor keymap-component-file-def</dt>
      <dd>
        A file with the description of a _particular_ [KcCGST component][KcCGST].
        It is the kind of file that the server uses to assemble a [keymap file].
        Its top-level structure consists of a _single type_ of [keymap sections].
        A component file may contain multiple such sections.
      </dd>
    </dl>
    
    [keymap file]: @ref keymap-file-def
    [keymap component file]: @ref keymap-component-file-def
    [keymap sections]: @ref keymap-section-def
    [section]: @ref keymap-section-def
    [keymap components]: @ref keymap-component-def
    
    ### Keymap components {#keymap-components-intro}
    
    [Keymap components][keymap components] are described with [keymap sections].
    They are grouped in [keymap component files][keymap component file] to form a
    [keyboard configuration database][database].
    
    <dl>
      <dt>Keymap _component_ @anchor keymap-component-def</dt>
      <dd>
      A part of the keymap _object_. The set of keymap components is referred as
      [KcCGST]. They are presented in the [table hereinafter][keymap components table].
      </dd>
      <dt>Keymap _section_ @anchor keymap-section-def</dt>
      <dd>
      A part of the keymap _text configuration_ dedicated to one of the
      [keymap components][keymap components table].
      </dd>
      <dt>Component _folder_</dt>
      <dd>
      A folder in the [keymap configuration database][database], dedicated to files
      with partial definitions of the same keymap section.
      </dd>
    </dl>
    
    [keymap components table]: @ref keymap-components-table
    
    @anchor keymap-components-table
    <table>
      <caption>
        Keymap components
      </caption>
      <tr>
        <th>[Component](@ref keymap-component-def)</th>
        <th>[Section][section] in a [keymap][xkb_keymap]</th>
        <th>Folder in a keymap configuration database</th>
        <th>Description</th>
      </tr>
      <tr>
        <th><u>K</u>ey <u>c</u>odes</th>
        <td>[xkb_keycodes]</td>
        <td>`keycodes`</td>
        <td>
        A translation of the raw [key codes][keycode] from the keyboard into
        symbolic names.
        </td>
      </tr>
      <tr>
        <th><u>C</u>ompatibility</th>
        <td>[xkb_compat]</td>
        <td>`compat`</td>
        <td>
        A specification of what internal actions modifiers and various
        special-purpose keys produce.
        </td>
      </tr>
      <tr>
        <th>(<u>G</u>eometry)</th>
        <td>xkb_geometry</td>
        <td>`geometry`</td>
        <td>
        A description of the physical layout of a keyboard.
    
        @attention This legacy feature is [not supported](@ref geometry-support)
        by _xkbcommon_.
    
        </td>
      </tr>
      <tr>
        <th>Key <u>s</u>ymbols</th>
        <td>[xkb_symbols]</td>
        <td>`symbols`</td>
        <td>
        A translation of symbolic [key codes][keycode] into actual [key symbols][keysyms]
        (keysyms).
        </td>
      </tr>
      <tr>
        <th>Key <u>t</u>ypes</th>
        <td>[xkb_types]</td>
        <td>`types`</td>
        <td>
        Types describe how a pressed key is affected by active [modifiers]
        such as Shift, Control, Alt, etc.
        </td>
      </tr>
    </table>
    
    ### Comments
    
    Comments are introduced following either `//` or `#` until the end of the line.
    
    ### Literals
    
    <dl>
      <dt>String literal @anchor keymap-string-literal</dt>
      <dd>
      A string is surrounded by double quotes: “<code>&quot;</code>”.
      The following _escape sequences_ are supported:
    
      | Escape sequence    | Meaning                                                  |
      | ------------------ | -------------------------------------------------------- |
      | `\\`               | Backslash “`\`”                                          |
      | `\"`               | Double quote “`"`”                                       |
      | `\b`               | Backspace                                                |
      | `\e`               | Escape                                                   |
      | `\f`               | Form feed                                                |
      | `\n`               | Line feed (newline)                                      |
      | `\r`               | Carriage return                                          |
      | `\t`               | Horizontal tabulation                                    |
      | `\v`               | Vertical tabulation                                      |
      | `\` + octal number | Corresponding ASCII character: `\1` → `SOH`, `\42` → `"`. Up to **4** octal digits `0‥7` are parsed. The result must fit into a byte. |
      | `\u{` + hexadecimal number + `}` | `\u{NNNN}` produce the corresponding [Unicode code point] `U+NNNN`, encoded in [UTF-8]. Supported code points are in the range `U+0001‥U+10FFFF`. |
    
      [Unicode code point]: https://en.wikipedia.org/wiki/Unicode#Codespace_and_code_points
      [UTF-8]: https://en.wikipedia.org/wiki/UTF-8
    
      @note The string _encoding_ is unspecified and not validated, but for best
      results, stick to ASCII.
    
      @since \<1.9.0: Octal escape sequences accept up to **3** digits.
    
      @since 1.9.0: Octal escape sequences accept up to **4** digits.
      Added <code>\\&quot;</code> and `\u{NNNN}` escape sequences.
    
      <!-- TODO: check UTF-8 encoding result -->
    
      </dd>
      <dt>Number literal</dt>
      <dd>
      A number can be written in three forms:
    
      - _decimal integer:_ `1`, `123`, etc.
      - _decimal floating-point number:_ `1.23`, etc.
      - _hexadecimal integer:_ prefixed with `0x`: `0x123`, `0xff`, `0xAB`, etc.
      </dd>
    </dl>
    
    ### Keysyms {#keysym-syntax}
    
    [Keysyms][keysym] may be written in multiple ways:
    
    <dl>
    <dt>Name</dt>
    <dd>
    
    Keysym names are defined in `xkbcommon/xkbcommon-keysyms.h`; remove the
    `XKB_KEY_` prefix to get the name.
    
    Example: the keysym `0xffbe = XKB_KEY_F1` has the name `F1`.
    </dd>
    <dt>Unicode</dt>
    <dd>
    
    The *Unicode* syntax `Unnnn` denotes a keysym whose corresponding character is
    the Unicode code point `U+nnnn`, where `nnnn` is an hexadecimal number in the
    range `0x100 .. 0x10ffff`. The resulting keysym value is `0x01000000 + nnnn`.
    
    Example: `U1F3BA` has value `0x0101F3BA` and corresponds to the code point
    `U+1F3BA`: ‘🎺’ (TRUMPET).
    </dd>
    <dt>String literal</dt>
    <dd>
    
    A keysym or list of keysyms can be written as a *string literal*, with the
    following semantics:
    
    1. The string must be encoded in UTF-8.
    2. If the encoding is invalid, it raises a syntax error.
    3. If the string expands to 0 Unicode code point, the resulting keysym is
       `NoSymbol`.
    4. If the string expands to 1 Unicode code point, the resulting keysym is the
       output of `xkb_utf32_to_keysym`.
    5. Otherwise the string expands to a list `{ ... }` with each Unicode code point
       converted via `xkb_utf32_to_keysym`.
    
       @note This is only possible where multiple keysyms is valid, e.g. in the
       @ref key-multiple-symbols-per-level "key symbols".
    
    
    Examples:
    
    <table>
      <thead>
        <tr>
          <th>Keysym string</th>
          <th>Keysym name</th>
          <th>Keysym value</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>`""`</td>
          <td>`NoSymbol`</td>
          <td>`0x0000`</td>
        </tr>
        <tr>
          <td>`"a"`</td>
          <td>`a`</td>
          <td>`0x0061`</td>
        </tr>
        <tr>
          <td>`"ü"`</td>
          <td>`udiaeresis`</td>
          <td>`0x00dc`</td>
        </tr>
        <tr>
          <td>`"🎺"`</td>
          <td>`U1F3BA`</td>
          <td>`0x0101F3BA`</td>
        </tr>
        <tr>
          <td>`"g̃"`</td>
          <td>`{g, combining_tilde}`</td>
          <td>`{0x0101F3BA, 0x01000303}`</td>
        </tr>
      </tbody>
    </table>
    
    @sa @ref keysyms-string "Keysym strings"
    
    @since 1.9.0
    </dd>
    <dt>Numeric value</dt>
    <dd>
    
    A keysym can be written directly with its *numeric* value: e.g. `0x61` is `a`.
    
    @note Digits `0 .. 9` have a special treatment because they are interpreted as
    names, not values. E.g. `1` is the keysym with name `1` and value `0x31`.
    
    @warning This syntax should be avoided for its poor readability, except if it
    is not possible to write the keysym with the previous syntaxes.
    </dd>
    </dl>
    
    ### Keywords
    
    The following table presents the keywords used in the format. They are
    _case-sensitive_.
    
    <!-- NOTE: keywords are defined in `src/xkbcomp/keywords.gperf` -->
    
    | Keyword                 | Use                            |
    | ----------------------- | ------------------------------ |
    | `action`                | Action of an [interpret statement](@ref interpret-action) |
    | `alias`                 | [Keycode alias](@ref keycode-alias) |
    | `alphanumeric_keys`     | [Section flag](@ref section-flag-alphanum) |
    | `alternate_group`       | [Section flag](@ref section-flag-alt-group) |
    | `alternate`             | Merge mode qualifier for [include] statements |
    | `augment`               | Merge mode qualifier for [include] statements |
    | `default`               | [Section flag](@ref section-flag-default) |
    | `function_keys`         | [Section flag](@ref section-flag-function) |
    | `group`                 | <span class="todo">TODO</span> |
    | `hidden`                | [Section flag](@ref section-flag-hidden) |
    | `include`               | [Include statement][include]   |
    | `indicator`             | Indicator statement in either the [keycode section](@ref indicator-name) or the [compatibility section](@ref indicator-effect) |
    | `interpret`             | [Interpret statement][interpret] |
    | `key`                   | [Key statement](@ref key-statement) |
    | `keypad_keys`           | [Section flag](@ref section-flag-keypad) |
    | `keys`                  | Legacy [geometry element][xkb_geometry] |
    | `logo`                  | Legacy [geometry element][xkb_geometry] |
    | `mod_map`               | Alias of `modifier_map`        |
    | `modifier_keys`         | [Section flag](@ref section-flag-modifier) |
    | `modmap`                | Alias of `modifier_map`        |
    | `modifier_map`          | [Real modifier bindings](@ref modmap-statement) |
    | `outline`               | Legacy [geometry element][xkb_geometry] |
    | `overlay`               | Legacy [geometry element][xkb_geometry] |
    | `override`              | Merge mode qualifier for [include] statements |
    | `partial`               | [Section flag](@ref section-flag-partial) |
    | `replace`               | Merge mode qualifier for [include] statements |
    | `row`                   | Legacy [geometry element][xkb_geometry] |
    | `section`               | Legacy [geometry element][xkb_geometry] |
    | `shape`                 | Legacy [geometry element][xkb_geometry] |
    | `solid`                 | Legacy [geometry element][xkb_geometry] |
    | `text`                  | Legacy [geometry element][xkb_geometry] |
    | `type`                  | [Key type statement](@ref key-type-statement) |
    | `virtual_modifiers`     | [Virtual modifiers mappings](@ref virtual-modifier-statements) |
    | `virtual`               | Flag for the [indicator statement](@ref indicator-name) |
    | `xkb_compat_map`        | Alias of `xkb_compatibility_map` |
    | `xkb_compat`            | Alias of `xkb_compatibility_map` |
    | `xkb_compatibility_map` | Declare a [compatibility section][xkb_compat] |
    | `xkb_compatibility`     | Alias of `xkb_compatibility_map` |
    | `xkb_geometry`          | Declare a [geometry section][xkb_geometry] |
    | `xkb_keycodes`          | Declare a [keycodes section][xkb_keycodes] |
    | `xkb_keymap`            | Declare a [keymap block][xkb_keymap] |
    | `xkb_layout`            | Declare a legacy [layout compound section][xkb_layout] |
    | `xkb_semantics`         | Declare a legacy [semantics compound section][xkb_semantics] |
    | `xkb_symbols`           | Declare a [symbols section][xkb_symbols]   |
    | `xkb_types`             | Declare a [key types section ][xkb_types]  |
    
    [include]: @ref xkb-include
    [interpret]: @ref interpret-statements
    [interpretations]: @ref interpret-statements
    [xkb_geometry]: @ref the-xkb_geometry-section
    [xkb_layout]: @ref legacy-layout-section
    [xkb_semantics]: @ref legacy-semantics-section
    
    ### Built-in settings
    
    <!--
    TODO: SetMods is not a keyword, but how call it for user-facing doc?
    -->
    
    There are many built-in settings; they are explained in the following relevant
    sections.
    
    These settings are _case-insensitive_, e.g. the following strings denote
    the same key word: `SETMODS`, `SetMods`, `setMods` and `setmods`.
    
    ### Merge modes {#merge-mode-def}
    
    Each statement has a **merge mode** property that defines how to handle
    *conflicts* with previous statements. This property can be set explicitly by
    prefixing the statement with one of the merge modes presented hereinafter.
    
    <dl>
    <dt>@anchor merge-mode-augment augment</dt>
    <dd>
    
    If two declarations conflict, update the properties which are *explicitly*
    defined in the *new* declaration, *only* if they were *implicit* in the *old*
    declaration.
    
    ```c
    key <A>         { [a          , NoSymbol   , ae          ] };
    augment key <A> { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] };
    // Result
    key <A>         { [a          , Greek_ALPHA, ae      , AE] };
    ```
    </dt>
    <dt>@anchor merge-mode-override override</dt>
    <dd>
    
    If two declarations conflict, update only the properties which are
    *explicitly* defined in the *new* declaration.
    
    @note @anchor merge-mode-default Override is the *default* merge mode.
    
    ```c
    key <A>          { [a          , NoSymbol   , ae          ] };
    // Explicit merge mode
    override key <A> { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] };
    // Result
    key <A>          { [Greek_alpha, Greek_ALPHA, ae      , AE] };
    ```
    
    ```c
    key <A>          { [a          , NoSymbol   , ae          ] };
    // Implicit merge mode is override
    key <A>          { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] };
    // Result
    key <A>          { [Greek_alpha, Greek_ALPHA, ae      , AE] };
    ```
    </dt>
    <dt>@anchor merge-mode-replace replace</dt>
    <dd>
    
    If two declarations conflict, ignore the old declaration and use the new one.
    
    ```c
    key <A>         { [a          , NoSymbol   , ae          ] };
    replace key <A> { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] };
    // Result
    key <A>         { [Greek_alpha, Greek_ALPHA, NoSymbol, AE] };
    ```
    </dt>
    <dt>@anchor merge-mode-alternate alternate</dt>
    <dd>
    
    Legacy merge mode for keycodes. Its purpose is to allow to assign the same key
    name to multiple key codes, which is not allowed otherwise. This is unfortunately
    poorly documented and not used in xkeyboard-config. The xkblib specification
    implies that this was part of the overlay functionality, which is currently not
    supported by libxkbcommon.
    
    @warning This merge mode is not supported by libxkbcommon and is ignored.
    </dd>
    </dl>
    
    [default merge mode]: @ref merge-mode-default
    
    ### The include mechanism {#xkb-include}
    
    #### Syntax
    
    Statements of the form:
    
    ```c
    // Implicit section name: use the default map
    include "<PATH>"
    // Explicit section name
    include "<PATH>(<SECTION_NAME>)"
    ```
    
    will merge data from another [section] of the *same type*, possibly located in
    another file. Note that the statement does not have a trailing semicolon.
    
    If no section name is provided, the [default map] is looked up.
    
    [default map]: @ref default-map-def
    
    The path is usually relative to its corresponding directory in a XKB
    configuration: e.g. given the configuration directory `<XKB>`, files of
    section type `xkb_symbols` are looked up in `<XKB>/symbols`. Since 1.11,
    the paths can also be absolute or use **%-expansion**:
    @anchor keymap-include-percent-expansion
    
    <!--
    [WARNING]: Doxygen parsing is a mess. \% does not work as expected
    in Markdown code quotes, e.g. `\%H` gives `\H`. But using <code> tags
    or %%H seems to do the job though.
    -->
    <dl>
    <dt>`%%`</dt>
    <dd>A literal %.</dd>
    <dt><code>\%H</code></dt>
    <dd>The value of the `$HOME` environment variable.</dd>
    <dt><code>\%S</code></dt>
    <dd>
    The *main* system-installed XKB directory of the corresponding [component]
    \(usually `/usr/share/X11/xkb/<component>`).
    
    This enables e.g. to override a system file using @ref user-configuration ""
    with the exact *same name*:
    
    ```c
    // File: ~/.config/xkb/symbols/de
    xkb_symbols "basic" {
        // Include the system file /usr/share/X11/xkb.
        //
        // Note that it is not be possible to use `include "de(basic)"` because
        // it would create an include *loop*.
        include "%S/de(basic)"
        // Override the system file entries
        key <AB01> { [z, Z] };
        key <AD06> { [y, Y] };
    }
    ```
    </dd>
    <dt><code>\%E</code></dt>
    <dd>
    The *extra* system-wide XKB directory of the corresponding [component]
    \(usually `/etc/xkb/<component>`).
    </dd>
    </dl>
    
    [component]: @ref keymap-components-table
    
    @warning Absolute paths and `%`-expansion are supported by libxkbcommon but not
    by the legacy X11 tools.
    
    The `include` keyword uses the *default* [merge mode]. The following keywords
    can be used instead to use the corresponding *explicit* [merge modes][]:
    - [`augment`][augment]
    - [`override`][override]
    - [`replace`][replace]
    
    [merge mode]: @ref merge-mode-def
    [merge modes]: @ref merge-mode-def
    [augment]: @ref merge-mode-augment
    [override]: @ref merge-mode-override
    [replace]: @ref merge-mode-replace
    
    *Multiple files* can be included using the same statement. They are separated using one
    of the following [merge mode] prefixes:
    - ‘|’ selects the <strong>[augment]</strong> merge mode.
    - ‘+’ selects the <strong>[override]</strong> merge mode (default).
    - ‘^’ selects the <strong>[replace]</strong> merge mode.
    
    The following example illustrates the complete syntax:
    
    ```c
    // Default merge mode, 1 file with an implicit section name
    include "<PATH>"
    // Augment merge mode, 1 file with an implicit section name
    augment "<PATH>(<SECTION_NAME>)"
    // Absolute path and %-expansion
    include "/usr/share/X11/xkb/symbols/pc"
    include "%S/pc"
    // Override merge mode, 2 files: a first file with an implicit section name merged
    // using the augment mode with a second file with an explicit section name
    override "<PATH_1>|<PATH_2>(<SECTION_NAME>)
    ```
    
    #### Processing
    
    @important Since xkbcommon 1.9.0 the included files are processed in *isolation*
    and are not affected by the parent file (e.g. defaults), except for the virtual
    modifiers indices.
    
    @important Since xkbcommon 1.9.0 local merge modes are *not* propagated outside
    the section scope, i.e. an included file does not leaks its local merge modes to
    its parent.
    
    The statement is processed as follow:
    1. Set PARENT as the current [section] containing the include statement.
    2. Set INCLUDED_MERGE_MODE to the merge mode corresponding to the keyword.
    3. Initialize an empty [section] as INCLUDED.
    4. Select the first file as the current file to process.
    5. Set CURRENT_MERGE_MODE to the merge mode corresponding to the current file
       merge mode *prefix*.
    6. The current file path is searched sequentially in the
       [XKB configuration path list]:
    
       - If a section name is provided, select the first *exact match* of file +
         section.
       - If no section name is provided, select the first *explicit* [default map]
         in matched files, else if no exact match was found in the path list, then
         fallback to the first *implicit* [default map] as a weak match.
    
       Then if no match is found, raise an error; else go to the next step.
    7. The current file is processed and results in the CURRENT [section].
    8. The INCLUDED [section] is merged with the CURRENT [section] using the merge mode
       CURRENT_MERGE_MODE.
    9. If they are more files, select the next file as the current file and go to
       step 5). Else go to step 10).
    10. Once all files have been processed, merge PARENT with INCLUDED using the
       merge mode INCLUDED_MERGE_MODE.
    
    [XKB configuration path list]: @ref xkb_context::xkb_context_include_path_append()
    
    #### Example: include path list
    
    Let’s illustrate using the following [XKB configuration path list][]:
    1. `/home/<USER>/.config/xkb`: user configuration directory
       (see @ref user-configuration "").
    2. `/usr/share/X11/xkb`: system directory.
    
    The relevant directory structure is:
    - `/home/<USER>/.config/xkb`
      - `symbols`
        - `es`
        - `my_own_file`
    - `/usr/share/X11/xkb`
      - `symbols`
        - `es`
        - `it`
    
    Then the following file:
    
    ```c
    xkb_symbols {
        include "it"          // Exists only in system directory
        include "my_own_file" // Exists only in user directory
        include "es"          // Exists in both user and system directory
    };
    ```
    
    is equivalent to:
    
    ```c
    xkb_symbols {
        include "/usr/share/X11/xkb/symbols/it"
        include "/home/<USER>/.config/xkb/symbols/my_own_file"
        include "/home/<USER>/.config/xkb/symbols/es"
    };
    ```
    
    #### Example: simple include
    
    Given the following files:
    
    - `symbols/A`
    
      ```c
      xkb_symbols {
          key <A> { [a, A, ae, AE] };
          include "B(S2)"
      };
      ```
    - `symbols/B`
    
      ```c
      // This section is not used (does not match)
      xkb_symbols "S1" {
          key <B> { [b, B] };
      };
      // This section will be included (match the included section name)
      xkb_symbols "S2" {
          key <A> { [Greek_alpha, Greek_ALPHA] };
          key <B> { [Greek_beta , Greek_BETA ] };
      };
      ```
    
    the resulting section in `A` will be:
    
    ```c
    xkb_symbols {
        // Key overridden: mix of old + new
        key <A> { [Greek_alpha, Greek_ALPHA, ae, AE] };
        // New key
        key <B> { [Greek_beta , Greek_BETA         ] };
    };
    ```
    
    #### Example: merge modes
    
    Given the same file `symbols/B` of the previous example, the following section:
    
    <table>
    <thead>
    <tr>
      <th>Input</th>
      <th>Output</th>
    </tr>
    </thead>
    <tbody>
    <tr>
      <td>
    
      ```c
      xkb_symbols {
          key <A> { [a, A, ae, AE] };
          augment "B(S2)"
      };
      ```
      </td>
      <td>
    
      ```c
      xkb_symbols {
          // Key unchanged
          key <A> { [a, A, ae, AE] };
          // New key
          key <B> { [Greek_beta , Greek_BETA] };
      };
      ```
      </td>
    </tr>
    <tr>
      <td>
    
      ```c
      xkb_symbols {
          key <A> { [a, A, ae, AE] };
          replace "B(S2)"
      };
      ```
      </td>
      <td>
    
      ```c
      xkb_symbols {
          // Key replaced
          key <A> { Greek_alpha, Greek_ALPHA] };
          // New key
          key <B> { [Greek_beta , Greek_BETA ] };
      };
      ```
      </td>
    </tr>
    <tr>
      <td>
    
      ```c
      xkb_symbols {
          key <A> { [a, A, ae, AE] };
          // Two files merged together with the merge mode
          // augment, then the result is merged this the
          // statement above using the override merge mode
          include "B(S1)|B(S2)"
      };
      ```
      </td>
      <td>
    
      ```c
      xkb_symbols {
          // Key overridden: mix of old + new
          key <A> { [Greek_alpha, Greek_ALPHA, ae, AE] };
          // New key; "B(2)" had no effect with the
          // merge mode augment "|"
          key <B> { [b, B] };
      };
      ```
      </td>
    </tr>
    </tbody>
    </table>
    
    
    ## The “xkb_keymap” block {#the-xkb_keymap-block}
    
    A <strong>[keymap file]</strong> consists of a single top-level `xkb_keymap`
    block, under which are nested the following sections:
    
    <dl>
      <dt><code>[xkb_keycodes]</code></dt>
      <dd>
      A translation of the hardware/evdev scancodes from the keyboard into
      XKB symbolic keycodes.
      </dd>
      <dt><code>[xkb_types]</code></dt>
      <dd>
      A specification of the modifier mask, target level and preserved
      modifiers various modifiers combination produce.
      </dd>
      <dt><code>[xkb_compat]</code></dt>
      <dd>
      A specification of what actions various special-purpose keys produce.
      </dd>
      <dt><code>[xkb_symbols]</code></dt>
      <dd>
      A translation of symbolic key codes into actual symbols and actions.
      </dd>
    </dl>
    
    Overview of a keymap file:
    
    ```c
    xkb_keymap {
      xkb_keycodes "XXX" {
        // ...
      }
      xkb_types "XXX" {
        // ...
      };
      xkb_compatibility "XXX" {
        // ...
      };
      xkb_symbols "XXX" {
        // ...
      };
    };
    ```
    
    @since 1.9.0 All the component are optional.
    
    <!-- NOTE: do not use blank lines here! -->
    @remark The XKB file format historically supported the following compound
    section types:
    <div>
    - `xkb_semantics`: @anchor legacy-semantics-section *must* contain a [xkb_compat] section
       and *can* contain a [xkb_types] section.
    - `xkb_layout`: @anchor legacy-layout-section *must* contain [xkb_keycodes], [xkb_types]
      and [xkb_symbols] sections and *can* contain [xkb_geometry] section.
    - `xkb_keymap`: *must* contain [xkb_keycodes], [xkb_compat], [xkb_types] and
      [xkb_symbols] sections and *can* contain [xkb_geometry] section.
    </div>
    Since such distinction is purely semantic and would have niche use cases lost to
    history, these compound sections are treated equally as `xkb_keymap` in
    libxkbcommon.
    
    <!-- TODO: there might be several sections of the same type: explain syntax and how they are selected -->
    <!-- TODO: sections may be named -->
    
    ## Section flags {#section-flags-def}
    
    A section can have various **flags** applied to it, separated by whitespaces:
    
        partial alphanumeric_keys
        xkb_symbols "basic" {
            ...
        }
    
    ### Generic flags
    
    The possible flags are:
    
    <dl>
    <dt><code>partial</code>@anchor section-flag-partial</dt>
    <dd>Indicates that the map doesn’t cover a complete keyboard.</dd>
    <dt><code>default</code>@anchor section-flag-default</dt>
    <dd>
    
    @anchor default-map-def
    Marks the symbol map as the *explicit* **default map** in the file. If no map is
    marked as a default, the first map in the file is the *implicit* default. Only
    **one** section can be marked as the default in each file.
    </dd>
    <dt><code>hidden</code>@anchor section-flag-hidden</dt>
    <dd>Variant that can only be used internally.</dd>
    </dl>
    
    ### Symbols flags
    
    Additionally, `xkb_symbols` may also have the following flags:
    
    <dl>
    <dt><code>alphanumeric_keys</code>@anchor section-flag-alphanum</dt>
    <dd>Indicates that the map contains alphanumeric keys.</dd>
    <dt><code>modifier_keys</code>@anchor section-flag-modifier</dt>
    <dd>Indicates that the map contains modifier keys: Control, Shift, Alt, Meta, etc.</dd>
    <dt><code>keypad_keys</code>@anchor section-flag-keypad</dt>
    <dd>Indicates that the map contains keypad keys.</dd>
    <dt><code>function_keys</code>@anchor section-flag-function</dt>
    <dd>Indicates that the map contains function keys: F1, F2, etc.</dd>
    <dt><code>alternate_group</code>@anchor section-flag-alt-group</dt>
    <dd>Indicates that the map contains keys for an alternate group.</dd>
    </dl>
    
    If no `*_keys` flags are supplied, then the symbols section is assumed to cover
    a complete keyboard.
    
    At present, except for `default` (see: [default map]), none of the flags affect
    key processing in libxkbcommon, and only serve as *metadata*.
    
    ## The “xkb_keycodes” section {#the-xkb_keycodes-section}
    
    This is the simplest [section] type, and is the first one to be
    compiled. The purpose of this is mostly to map between the
    hardware/evdev scancodes and XKB [keycodes][keycode]. Each key is given a name
    by which it can be referred to later, e.g. in the symbols section.
    
    ### Keycode statements
    
    Statements of the form:
    
        <TLDE> = 49;
        <AE01> = 10;
    
    The above would let 49 and 10 be valid keycodes in the keymap, and
    assign them the names `TLDE` and `AE01` respectively. The format
    `<WXYZ>` is always used to refer to a key by name.
    
    The naming convention `<AE01>` is based on the
    [standard ISO/IEC&nbsp;9995-1][ISO9995-1]. It denotes the position of the
    key in the keyboard grid. It means: the main alphanumeric section
    (`A`), row `E` and column `01`.
    
    The following figure illustrates the grid on a staggered standard
    US QWERTY keyboard. `<AE01>` corresponds to the key `1`.
    
    ```
       \ 99 \ 00 \ 01 \ 02 \ 03 \ 04 \ 05…
        \    \    \    \    \    \    \
    -----------------------------------------
    E     \    \ ^  \ 1  \ 2  \ 3  \ 4  \ 5…
    ------------------------------------------
    D      \     Tab \ Q  \ W  \ E  \ R  \ T…
    -------------------------------------------
    C       \Caps     \ A  \ S  \ D  \ F  \ G…
    --------------------------------------------
    B        \Shift    \ Z  \ X  \ C  \ V  \ B…
    ---------------------------------------------
    A         \Ctrl\GUI \Alt \Space…
    ----------------------------------------------
    ```
    
    [ISO9995-1]: https://en.wikipedia.org/wiki/ISO/IEC_9995#ISO/IEC_9995-1
    
    In the common case this just maps to the evdev scancodes from
    `/usr/include/linux/input.h`, e.g. the following definitions:
    
        #define KEY_GRAVE            41
        #define KEY_1                2
    
    correspond to the ones above. Similar definitions appear in the
    xf86-input-keyboard driver. Note that in all current keymaps there’s a
    constant offset of 8 (for historical reasons).
    
    Note that contrary to xkbcommon, the X11 protocol supports keycodes
    only up to `255`. Therefore, when interfacing with X11, keymaps and applications
    using keycodes beyond `255` should expect warnings.
    
    If there’s a conflict, like the same name given to different keycodes,
    or same keycode given different names, it is resolved according to the
    [merge mode] which applies to the definitions.
    
    ### Alias statements {#keycode-alias}
    
    Statements of the form:
    
        alias <MENU> = <COMP>;
    
    Allows to refer to a previously defined key (here `<COMP>`) by another
    name (here `<MENU>`). Conflicts are handled similarly to keycode
    statements.
    
    ### LED name statements {#indicator-name}
    
    [indicator name]: @ref indicator-name
    
    Statements of the form:
    
        indicator 1 = "Caps Lock";
        indicator 2 = "Num Lock";
        indicator 3 = "Scroll Lock";
    
    Assigns a name to the keyboard LED (AKA [indicator]) with the given
    index. The LED may be referred by this name later in the compat
    section and by the user.
    
    @todo `virtual` flag
    
    ## The “xkb_types” section {#the-xkb_types-section}
    
    <!--
    Ivan Pascal’s doc:
    https://web.archive.org/web/20190724070654/http://pascal.tsu.ru/en/xkb/gram-types.html
    -->
    
    This [section] is the second to be processed, after `xkb_keycodes`.
    However, it is completely independent and could have been the first to
    be processed (it does not refer to specific keys as specified in the
    `xkb_keycodes` section).
    
    This section defines [key types], which, given a key and a keyboard
    state (i.e. modifier state and group), determine the [shift level] to
    be used in translating the key to [keysyms]. These types are assigned
    to each group in each key, in the `xkb_symbols` section.
    
    Key types are called this way because, in a way, they really describe
    the “type” of the key (or more correctly, a specific group of the
    key). For example, an ordinary keymap will provide a type called
    `KEYPAD`, which consists of two levels, with the second level being
    chosen according to the state of the Num Lock (or Shift) modifiers.
    Another example is a type called `ONE_LEVEL`, which is usually
    assigned to keys such as Escape; these have just one level and are not
    affected by the modifier state. Yet more common examples are
    [`TWO_LEVEL`][TWO_LEVEL] (with Shift choosing the second level),
    [`ALPHABETIC`][ALPHABETIC] (where Caps Lock may also choose the second
    level), etc.
    
    ### How key types work
    
    Key types define a _mapping_ between the [modifiers] and [shift levels].
    Key types have four parameters:
    
    <dl>
        <dt>@ref key-type-level-name "Shift level names"</dt>
        <dd>Declare [shift levels]. Mainly for documentation.</dd>
        <dt>@ref key-type-modifiers "Modifiers filter"</dt>
        <dd>Declare what modifiers should be taken into account in the mapping.</dd>
        <dt>@ref key-type-map "Modifiers mapping"</dt>
        <dd>Lookup table to translate modifiers combinations into shift levels.</dd>
        <dt>@ref key-type-preserve "Modifiers preservation"</dt>
        <dd>Tweak the computation of [consumed modifiers].</dd>
    </dl>
    
    [consumed modifiers]: @ref consumed-modifiers
    [shift levels]: @ref level-def
    
    Key types are used to compute:
    - the [shift level][]: see xkb_state::xkb_state_key_get_level().
    - the [consumed modifiers][]: see xkb_state::xkb_state_key_get_consumed_mods() and
      xkb_state::xkb_state_key_get_consumed_mods2().
    
    The following diagram presents an overview of theses computations:
    
    @anchor xkb-types-explanation-diagram
    @dotfile xkb-types-explanation "Use of key types to compute shift level and consumed modifiers"
    
    ### Type definitions {#key-type-statement}
    
    Statements of the form:
    
        type "FOUR_LEVEL" { ... }
    
    The above would create a new type named [`FOUR_LEVEL`][FOUR_LEVEL].
    The body of the definition may include statements of the following
    forms:
    
    #### “level_name” statements {#key-type-level-name}
    
        level_name[Level1] = "Base";
    
    Mandatory for each level in the type.
    
    Gives each level in this type a descriptive name. It isn’t used
    for anything.
    
    Note: A level may be specified as Level\[1-8\] or just a number (can
    be more than 8).
    
    #### “modifiers” statement {#key-type-modifiers}
    
        modifiers = Shift+Lock+LevelThree;
    
    Mandatory, should be specified only once.
    
    A mask of real and virtual [modifiers]. These are the only modifiers
    being considered when matching the modifier state against the type.
    The other modifiers, whether active or not, are masked out in the
    calculation.
    
    #### “map” entry statements {#key-type-map}
    
        map[Shift+LevelThree] = Level4;
    
    Should have at least as many mappings as there are levels in the type.
    
    If the active modifiers, masked with the type’s modifiers (as stated
    above), match (i.e. equal) the modifiers inside the `map[]` statement,
    then the level in the right hand side is chosen. For example, in the
    above, if in the current keyboard state the `Shift` and `LevelThree`
    modifiers are active, while the `Lock` modifier is not, then the
    keysym(s) in the 4th level of the group will be returned to the user.
    
    #### “preserve” statements {#key-type-preserve}
    
        map[Shift+Lock+LevelThree] = Level5;
        preserve[Shift+Lock+LevelThree] = Lock;
    
    When a key type is used for keysym translation, its modifiers are said
    to be [consumed](@ref consumed-modifiers) in this translation. For
    example, in a simple US keymap, the “G” key is assigned an ordinary
    [`ALPHABETIC`][ALPHABETIC] key type, whose modifiers are `Shift` and
    `Lock`; then for the “G” key, these two modifiers are consumed by the
    translation. This information is relevant for applications which
    further process the modifiers, since by then the consumed modifiers
    have already “done their part” and should be masked out.
    
    However, sometimes even if a modifier had already affected the key
    translation through the type, it should *not* be reported as consumed,
    for various reasons. In this case, a `preserve[]` statement can be
    used to augment the map entry. The modifiers inside the square
    brackets should match one of the `map[]` statements in the type (if
    there is no matching map entry, one mapping to Level1 is implicitly
    added). The right hand side should consists of modifiers from the
    type’s modifiers; these modifiers are then “preserved” and not
    reported as consumed.
    
    @attention Consuming a *locked* modifier does *not* unlock it and it
    can be consumed again in further keysym translations.
    
    @note Remember that @ref keysym-transformations may affect the resulting
    keysym when some modifiers are not [consumed](@ref consumed-modifiers).
    
    @remark `preserve` statements may be used to tweak keyboard shorcuts.
    @remark@figure
    @figcaption
    Example of use of `preserve` to tweak `Control` shortcuts. Note it would
    require further work in order to support other modifiers.
    @endfigcaption
    ```c
    xkb_types {
        // ...
        type "TWO_LEVEL_PLUS_CONTROL" {
            modifiers = Shift + Control;
            map[None]          = Level1;
            map[Shift]         = Level2;
            map[Control]       = Level3;
            map[Control+Shift] = Level4;
            // Using preserve will make Control not consumed and allow
            // applications to detect keyboard shortcuts with alternative
            // keysyms in levels 3 and 4 rather than the levels 1 and 2.
            preserve[Control]       = Control;
            preserve[Control+Shift] = Control;
            level_name[Level1] = "Base";
            level_name[Level2] = "Shift";
            level_name[Level3] = "Tweaked Control";
            level_name[Level4] = "Tweaked Control + Shift";
        };
    };
    xkb_symbols {
        // ...
        // The following key would produce Greek keysym on Base and Shift levels,
        // but will produce the corresponding ASCII Latin keysyms when using Control.
        key <AC01> {
            type[Group1]="TWO_LEVEL_PLUS_CONTROL",
            [Greek_alpha, Greek_ALPHA, a, A]
        };
    };
    ```
    @endfigure
    
    <!--
    Feature removed in libxkbcommon
    
    ### Set default values
    
    To change the default value of any key type field, use the following syntax:
    
    ```c
    type.FIELD = VALUE;
    ```
    
    E.g.
    
    ```c
    type.modifiers = Shift;
    ```
    -->
    
    ### Key types examples {#key-type-examples}
    
    #### Definitions examples
    
    <!-- The following examples come from the [xkeyboard-config] project. -->
    
    @note The convention is that `Lock` affect only “alphabetic” types.
    For such types, `Lock` “cancels” `Shift` by default, i.e. `Shift+Lock`
    has the same result as neither modifier. “<em>semi</em>-alphabetic”
    types have an asymmetry: their first two levels are alphabetic while the
    next are not.
    
    ##### Two levels
    
    The following examples compare two basic types with *two levels*:
    [`TWO_LEVEL`][TWO_LEVEL] and [`ALPHABETIC`][ALPHABETIC].
    They differ on their handling of the `Lock` modifier. See the
    [next section](@ref key-type-mappings-examples) for an illustration
    with concrete layouts.
    
    [TWO_LEVEL]:  @ref TWO_LEVEL
    [ALPHABETIC]: @ref ALPHABETIC
    
    <!-- NOTE: In the following code excerpts, the empty comments are intented
         to enable code alignment when scrren is large enough to display two
         example on the same row. -->
    
    <div class="example-container">
        <div class="example">
            <div class="example-inner">
                <div class="example-title">`TWO_LEVEL` @anchor TWO_LEVEL</div>
                @figure@figcaption
                Definition code ([source][two-type-src])
                @endfigcaption
    ```c
    type "TWO_LEVEL" {
        // Only care about Shift; Lock will be filter out
        modifiers = Shift;
        // Define mapping
        map[None]  = Level1; // No modifier   -> level 1
        map[Shift] = Level2; // Exactly Shift -> level 2
        // (no map entry with Lock)
        // Define level names
        level_name[Level1] = "Base";
        level_name[Level2] = "Shift";
    };
    ```
                @endfigure
                @figure@figcaption
                Mapping test
                @endfigcaption
    | *Active* modifiers | *Filtered* modifiers | Match? | Shift level |
    | ------------------ | -------------------- | ------ | ----------- |
    | (none)             | (none)               | Yes    | 1           |
    | `Shift`            | `Shift`              | Yes    | 2           |
    | `Lock`             | (none)               | Yes    | 1           |
    | `Shift + Lock`     | `Shift`              | Yes    | 2           |
                @endfigure
            </div>
        </div>
        <div class="example">
            <div class="example-inner">
                <div class="example-title">`ALPHABETIC` @anchor ALPHABETIC</div>
                @figure@figcaption
                Definition code ([source][alphabetic-type-src])
                @endfigcaption
    ```c
    type "ALPHABETIC" {
        // Only care about Shift and Lock
        modifiers = Shift + Lock;
        // Define mapping
        map[None]  = Level1; // No modifier   -> level 1
        map[Shift] = Level2; // Exactly Shift -> level 2
        map[Lock]  = Level2; // Exactly Lock  -> level 2
        // Define level names
        level_name[Level1] = "Base";
        level_name[Level2] = "Caps";
    };
    ```
                @endfigure
                @figure@figcaption
                Mapping test
                @endfigcaption
    | *Active* modifiers | *Filtered* modifiers | Match? | Shift level |
    | ------------------ | -------------------- | ------ | ----------- |
    | (none)             | (none)               | Yes    | 1           |
    | `Shift`            | `Shift`              | Yes    | 2           |
    | `Lock`             | `Lock`               | Yes    | 2           |
    | `Shift + Lock`     | `Shift + Lock`       | No     | 1           |
                @endfigure
            </div>
        </div>
    </div>
    
    ##### Four levels
    
    The following examples compare basic types with *four levels*:
    [`FOUR_LEVEL`][FOUR_LEVEL],
    [`FOUR_LEVEL_SEMIALPHABETIC`][FOUR_LEVEL_SEMIALPHABETIC] and
    [`FOUR_LEVEL_ALPHABETIC`][FOUR_LEVEL_ALPHABETIC].
    They differ on their handling of the `Lock` modifier.
    See the [next section](@ref key-type-mappings-examples)
    for an illustration with concrete layouts.
    
    [FOUR_LEVEL]:                @ref FOUR_LEVEL
    [FOUR_LEVEL_SEMIALPHABETIC]: @ref FOUR_LEVEL_SEMIALPHABETIC
    [FOUR_LEVEL_ALPHABETIC]:     @ref FOUR_LEVEL_ALPHABETIC
    
    <div class="example-container">
        <div class="example">
            <div class="example-inner">
                <div class="example-title">`FOUR_LEVEL` @anchor FOUR_LEVEL</div>
                @figure@figcaption
                Definition code ([source][four-level-src])
                @endfigcaption
    ```c
    type "FOUR_LEVEL" {
    	modifiers = Shift + LevelThree;
    	map[None] = Level1;
    	map[Shift] = Level2;
        // (no map entry with Lock)
        // (no map entry with Lock)
    	map[LevelThree] = Level3;
    	map[Shift+LevelThree] = Level4;
        // (no map entry with Lock)
        // (no map entry with Lock)
        // (no preserve entry with Lock)
        // (no preserve entry with Lock)
    	level_name[Level1] = "Base";
    	level_name[Level2] = "Shift";
    	level_name[Level3] = "AltGr";
    	level_name[Level4] = "Shift AltGr";
    };
    ```
                @endfigure
                @figure@figcaption
                Mapping test
                @endfigcaption
    | *Active* modifiers      | *Filtered* modifiers | Match? | Shift level |
    | ----------------------- | -------------------- | ------ | ----------- |
    | (none)                  | (none)               | Yes    | 1           |
    | `Shift`                 | `Shift`              | Yes    | 2           |
    | `Lock`                  | (none)               | Yes    | 1           |
    | `Shift+Lock`            | `Shift`              | Yes    | 2           |
    | `LevelThree`            | `LevelThree`         | Yes    | 3           |
    | `LevelThree+Shift`      | `LevelThree+Shift`   | Yes    | 4           |
    | `LevelThree+Lock`       | `LevelThree`         | Yes    | 3           |
    | `LevelThree+Shift+Lock` | `LevelThree+Shift`   | Yes    | 4           |
                @endfigure
            </div>
        </div>
        <div class="example">
            <div class="example-inner">
                <div class="example-title">`FOUR_LEVEL_SEMIALPHABETIC` @anchor FOUR_LEVEL_SEMIALPHABETIC</div>
                @figure@figcaption
                Definition code ([source][four-level-semialphabetic-src])
                @endfigcaption
    ```c
    type "FOUR_LEVEL_SEMIALPHABETIC" {
    	modifiers = Shift + Lock + LevelThree;
    	map[None] = Level1;
    	map[Shift] = Level2;
    	map[Lock] = Level2;
    	map[Shift+Lock] = Level1;
    	map[LevelThree] = Level3;
    	map[Shift+LevelThree] = Level4;
    	map[Lock+LevelThree] = Level3;
    	map[Shift+Lock+LevelThree] = Level4;
    	preserve[Lock+LevelThree] = Lock;
    	preserve[Shift+Lock+LevelThree] = Lock;
    	level_name[Level1] = "Base";
    	level_name[Level2] = "Shift";
    	level_name[Level3] = "AltGr";
    	level_name[Level4] = "Shift AltGr";
    };
    ```
                @endfigure
                @figure@figcaption
                Mapping test
                @endfigcaption
    | *Active* modifiers      | *Filtered* modifiers    | Match? | Shift level |
    | ----------------------- | ----------------------- | ------ | ----------- |
    | (none)                  | (none)                  | Yes    | 1           |
    | `Shift`                 | `Shift`                 | Yes    | 2           |
    | `Lock`                  | `Lock`                  | Yes    | 2           |
    | `Shift+Lock`            | `Shift+Lock`            | Yes    | 1           |
    | `LevelThree`            | `LevelThree`            | Yes    | 3           |
    | `LevelThree+Shift`      | `LevelThree+Shift`      | Yes    | 4           |
    | `LevelThree+Lock`       | `LevelThree+Lock`       | Yes    | 3           |
    | `LevelThree+Shift+Lock` | `LevelThree+Shift+Lock` | Yes    | 4           |
                @endfigure
            </div>
        </div>
        <div class="example">
            <div class="example-inner">
                <div class="example-title">`FOUR_LEVEL_ALPHABETIC` @anchor FOUR_LEVEL_ALPHABETIC</div>
                @figure@figcaption
                Definition code ([source][four-level-alphabetic-src])
                @endfigcaption
    ```c
    type "FOUR_LEVEL_ALPHABETIC" {
    	modifiers = Shift + Lock + LevelThree;
    	map[None] = Level1;
    	map[Shift] = Level2;
    	map[Lock] = Level2;
    	map[Shift+Lock] = Level1;
    	map[LevelThree] = Level3;
    	map[Shift+LevelThree] = Level4;
    	map[Lock+LevelThree] = Level4;
    	map[Shift+Lock+LevelThree] = Level3;
        // (no preserve entry with Lock)
        // (no preserve entry with Lock)
    	level_name[Level1] = "Base";
    	level_name[Level2] = "Shift";
    	level_name[Level3] = "AltGr";
    	level_name[Level4] = "Shift AltGr";
    };
    ```
                @endfigure
                @figure@figcaption
                Mapping test
                @endfigcaption
    | *Active* modifiers      | *Filtered* modifiers    | Match? | Shift level |
    | ----------------------- | ----------------------- | ------ | ----------- |
    | (none)                  | (none)                  | Yes    | 1           |
    | `Shift`                 | `Shift`                 | Yes    | 2           |
    | `Lock`                  | `Lock`                  | Yes    | 2           |
    | `Shift+Lock`            | `Shift+Lock`            | Yes    | 1           |
    | `LevelThree`            | `LevelThree`            | Yes    | 3           |
    | `LevelThree+Shift`      | `LevelThree+Shift`      | Yes    | 4           |
    | `LevelThree+Lock`       | `LevelThree+Lock`       | Yes    | 4           |
    | `LevelThree+Shift+Lock` | `LevelThree+Shift+Lock` | Yes    | 3           |
                @endfigure
            </div>
        </div>
    </div>
    
    [two-type-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/basic#L14
    [alphabetic-type-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/basic#L21
    [four-level-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/extra#L8
    [four-level-alphabetic-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/extra#L20
    [four-level-semialphabetic-src]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/types/extra#L36
    
    #### Examples with standard keyboard layouts {#key-type-mappings-examples}
    
    <details>
        <summary>See the detailed table of mappings</summary>
    The following table compares the mappings of various key types for the modifiers
    `Shift`, `Lock` and `LevelThree`, using the standard layouts [`us`][us-layout]
    (US English) and [`es`][es-layout] (Spanish).
    
    [us-layout]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/symbols/us#L3
    [es-layout]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config/-/blob/022c3ca1db12e505cbd5ce8bf19c432d6a70c7e5/symbols/es#L3
    
    | Key    | Layout | Key type                        | Active modifiers                | Level | Keysym       | Comment     |
    | ------ | ------ | ------------------------------- | ------------------------------- | ----- | ------------ | ----------- |
    | `AE01` | [`us`][us-layout] | [`TWO_LEVEL`][TWO_LEVEL]   | (none)               | 1     | `1`          | |
    | ^      | ^      | ^                               | `Shift`                         | 2     | `exclam`     | |
    | ^      | ^      | ^                               | `Lock`                          | 1     | `1`          | `Lock` filtered out |
    | ^      | ^      | ^                               | `Shift` + `Lock`                | 2     | `exclam`     | `Lock` filtered out |
    | ^      | ^      | ^                               | `LevelThree`                    | 1     | `1`          | `LevelThree` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Shift`          | 2     | `exclam`     | `LevelThree` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Lock`           | 1     | `1`          | Modifiers `LevelThree` and `Lock` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Shift` + `Lock` | 2     | `exclam`     | Modifiers `LevelThree` and `Lock` filtered out |
    | ^      | [`es`][es-layout] | [`FOUR_LEVEL`][FOUR_LEVEL] | (none)                    | 1     | `1`          | |
    | ^      | ^      | ^                               | `Shift`                         | 2     | `exclam`     | |
    | ^      | ^      | ^                               | `Lock`                          | 1     | `1`          | `Lock` filtered out |
    | ^      | ^      | ^                               | `Shift` + `Lock`                | 2     | `exclam`     | `Lock` filtered out |
    | ^      | ^      | ^                               | `LevelThree`                    | 3     | `bar`        | |
    | ^      | ^      | ^                               | `LevelThree` + `Shift`          | 4     | `exclamdown` | |
    | ^      | ^      | ^                               | `LevelThree` + `Lock`           | 3     | `bar`        | `Lock` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Shift` + `Lock` | 4     | `exclamdown` | `Lock` filtered out |
    | `AD01` | [`us`][us-layout] | [`ALPHABETIC`][ALPHABETIC] | (none)                    | 1     | `q`          | |
    | ^      | ^      | ^                               | `Shift`                         | 2     | `Q`          | |
    | ^      | ^      | ^                               | `Lock`                          | 2     | `Q`          | |
    | ^      | ^      | ^                               | `Shift` + `Lock`                | 1     | `q`          | `Lock` cancelled by `Shift` |
    | ^      | ^      | ^                               | `LevelThree`                    | 1     | `q`          | `LevelThree` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Shift`          | 1     | `q`          | `LevelThree` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Lock`           | 2     | `Q`          | `LevelThree` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Shift` + `Lock` | 1     | `q`          | `LevelThree` filtered out, `Lock` cancelled by `Shift` |
    | ^      | [`es`][es-layout] | [`FOUR_LEVEL_SEMIALPHABETIC`][FOUR_LEVEL_SEMIALPHABETIC] | (none) | 1 | `q`   | |
    | ^      | ^      | ^                               | `Shift`                         | 2     | `Q`          | |
    | ^      | ^      | ^                               | `Lock`                          | 2     | `Q`          | |
    | ^      | ^      | ^                               | `Shift` + `Lock`                | 1     | `q`          | `Lock` cancelled by `Shift` |
    | ^      | ^      | ^                               | `LevelThree`                    | 3     | `at`         |  |
    | ^      | ^      | ^                               | `LevelThree` + `Shift`          | 4     | `Greek_OMEGA`|  |
    | ^      | ^      | ^                               | `LevelThree` + `Lock`           | 3     | `at`         | `Lock` does not affect `LevelThree` combos |
    | ^      | ^      | ^                               | `LevelThree` + `Shift` + `Lock` | 4     | `Greek_OMEGA`| `Lock` does not affect `LevelThree` combos |
    | `AD05` | [`us`][us-layout] | [`ALPHABETIC`][ALPHABETIC] | (none)                    | 1     | `t`          | |
    | ^      | ^      | ^                               | `Shift`                         | 2     | `T`          | |
    | ^      | ^      | ^                               | `Lock`                          | 2     | `T`          | |
    | ^      | ^      | ^                               | `Shift` + `Lock`                | 1     | `t`          | `Lock` cancelled by `Shift` |
    | ^      | ^      | ^                               | `LevelThree`                    | 1     | `t`          | `LevelThree` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Shift`          | 1     | `t`          | `LevelThree` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Lock`           | 2     | `T`          | `LevelThree` filtered out |
    | ^      | ^      | ^                               | `LevelThree` + `Shift` + `Lock` | 1     | `t`          | `LevelThree` filtered out, `Lock` cancelled by `Shift` |
    | ^      | [`es`][es-layout] | [`FOUR_LEVEL_ALPHABETIC`][FOUR_LEVEL_ALPHABETIC] | (none) | 1  | `t`          | |
    | ^      | ^      | ^                               | `Shift`                         | 2     | `T`          | |
    | ^      | ^      | ^                               | `Lock`                          | 2     | `T`          | |
    | ^      | ^      | ^                               | `Shift` + `Lock`                | 1     | `t`          | `Lock` cancelled by `Shift` |
    | ^      | ^      | ^                               | `LevelThree`                    | 3     | `tslash`     | |
    | ^      | ^      | ^                               | `LevelThree` + `Shift`          | 4     | `Tslash`     | |
    | ^      | ^      | ^                               | `LevelThree` + `Lock`           | 4     | `Tslash`     | |
    | ^      | ^      | ^                               | `LevelThree` + `Shift` + `Lock` | 3     | `tslash`     | `Lock` cancelled by `Shift` |
    </details>
    
    
    ## The “xkb_compat” section {#the-xkb_compat-section}
    
    This [section] is the third to be processed, after `xkb_keycodes` and
    `xkb_types`.
    
    ### Interpret statements {#interpret-statements}
    
    Statements of the form:
    
        interpret Num_Lock+Any { ... }
        interpret Shift_Lock+AnyOf(Shift+Lock) { ... }
    
    The <code>[xkb_symbols]</code> section (see below)
    allows the keymap author to perform, among other things, the following
    things for each key:
    
    - Bind a sequence of [actions], like `SetMods` or `LockGroup`, to the key.
      Actions, like symbols, are specified for each level of each group
      in the key separately.
    
    - Add a [virtual modifier] to the key’s virtual modifier mapping
      (`vmodmap`).
    
    - Specify whether the key should repeat or not.
    
    However, doing this for each key (or level) is tedious and inflexible.
    Interpret’s are a mechanism to apply these settings to a bunch of
    keys/levels at once.
    
    @anchor interpret-mechanism
    Each interpret specifies a condition by which it attaches to certain
    levels. The condition consists of two parts:
    
    - A <strong>[keysym]</strong>. If the level has a different (or more than one)
      keysym, the match fails. Leaving out the keysym is equivalent to using the
      special value `Any` or the `NoSymbol` keysym, which always matches
      successfully.
    
    - A <strong>[modifier] predicate</strong>. The predicate consists of:
      - A __mask__ of _real_ modifiers: a `+`-separated list of modifiers or
        the special value `all`, which denotes all the modifiers.
    
        The modifiers are matched against the key’s modifier map (`modmap`).
      - A __matching operation__, that is one of the following:
    
        * `AnyOfOrNone` – The modmap must either be empty or include at
            least one of the specified modifiers.
        * `AnyOf` – The modmap must include at least one of the specified
            modifiers.
        * `Any` – Alias for `AnyOf(all)`.
        * `NoneOf` – The modmap must not include any of the specified
            modifiers.
        * `AllOf` – The modmap must include all of the specified modifiers
            (but may include others as well).
        * `Exactly` – The modmap must be exactly the same as the specified
            modifiers.
    
      Leaving out the predicate is equivalent to using `AnyOfOrNone(all)`.
      Leaving out just the matching condition is equivalent to using
      `Exactly`.
    
    An interpret may also include `useModMapMods = level1;` – see below.
    
    If a [level] fulfils the conditions of several interprets, only the
    most specific one is used:
    
    - A specific keysym will always match before a generic `NoSymbol`
      condition.
    
    - If the keysyms are the same, the interpret with the more specific
      matching operation is used. The above list is sorted from least to
      most specific.
    
    - If both the keysyms and the matching operations are the same (but the
      modifiers are different), the first interpret is used.
    
    As described above, once an interpret “attaches” to a level, it can bind
    an action to that level, add one virtual modifier to the key’s vmodmap,
    or set the key’s repeat setting. You should note the following:
    
    - The key repeat is a property of the entire key; it is not
      level-specific. In order to avoid confusion, it is only inspected
      for the first level of the first group; the interpret’s repeat
      setting is ignored when applied to other levels.
    
    - If one of the above fields was set directly for a key in
      `xkb_symbols`, the explicit setting takes precedence over the
      interpret.
    
    The body of the statement may include statements of the following
    forms (all of which are optional):
    
    #### “useModMapMods” statement
    
        useModMapMods = level1;
    
    When set to `level1`, the interpret will only match keysyms which are
    on the first level of the first group of the keys. This can be useful
    in conjunction with e.g. a [`virtualModifier`](@ref interpret-virtualModifier)
    statement, because `virtualModifier` is an attribute of the key rather than a
    specific level.
    
    Note: the other possible value is `any` and is the default value.
    
    See [virtual modifier map] for further information.
    
    #### “virtualModifier” statement {#interpret-virtualModifier}
    
        virtualModifier = NumLock;
    
    Add this virtual modifier to the key’s `vmodmap`. The given virtual
    modifier must be declared at the top level of the file with a
    `virtual_modifiers` statement, e.g.:
    
        virtual_modifiers NumLock;
    
    See [virtual modifier map] for further information.
    
    #### “repeat” statement {#interpret-repeat}
    
        repeat = True;
    
    Set whether the key should repeat or not. Must be a boolean value.
    
    #### “action” statement {#interpret-action}
    
        action = LockMods(modifiers=NumLock);
    
    Bind this action to the matching levels. See [key actions][actions]
    for the list of available key actions.
    
    Since 1.9.0, it is also possible to assign a sequence of actions, mirroring
    the feature used in the [key statement](@ref key-multiple-symbols-per-level).
    
        action = {SetMods(modifiers=NumLock),SetGroup(group=2)};
    
    ### LED map statements {#indicator-effect}
    
    [indicator effect]: @ref indicator-effect
    
    Statements of the form:
    
        indicator "Shift Lock" { ... }
    
    This statement specifies the behavior and binding of the LED (AKA
    [indicator]) with the given name (“Shift Lock” above). The name should
    have been declared previously in the `xkb_keycodes` section (see
    [LED name][indicator name] statement), and given an index there.
    If it wasn’t, it is created with the next free index.
    
    The body of the statement describes the conditions of the keyboard
    state which will cause the LED to be lit. It may include the following
    statements:
    
    #### “modifiers” statement
    
        modifiers = ScrollLock;
    
    If the given [modifiers] are in the required state (see below), the
    LED is lit.
    
    #### “whichModState” statement
    
        whichModState = Latched+Locked;
    
    Can be any combination of:
    
    * `base`, `latched`, `locked`, `effective`
    * `any` (i.e. all of the above)
    * `none` (i.e. none of the above)
    * `compat` (legacy value, treated as effective)
    
    This will cause the respective portion of the modifier state (see
    `struct xkb_state`) to be matched against the modifiers given in the
    `modifiers` statement.
    
    Here’s a simple example:
    
        indicator "Num Lock" {
            modifiers = NumLock;
            whichModState = Locked;
        };
    
    Whenever the NumLock modifier is locked, the Num Lock LED will light
    up.
    
    #### “groups” statement
    
        groups = All - group1;
    
    If the given groups are in the required state (see below), the LED is
    lit.
    
    #### “whichGroupState” statement
    
        whichGroupState = Effective;
    
    Can be any combination of:
    
    * `base`, `latched`, `locked`, `effective`
    * `any` (i.e. all of the above)
    * `none` (i.e. none of the above)
    
    This will cause the respective portion of the group state (see
    `struct xkb_state`) to be matched against the groups given in the
    `groups` statement.
    
    Note: the above conditions are disjunctive, i.e. if any of them are
    satisfied the LED is lit.
    
    ### Set default values
    
    One may change the default values of the following statements:
    
    - `interpret`: use `interpret.FIELD = VALUE;`
    - `indicator`: use `indicator.FIELD = VALUE;`
    - actions: use `ACTION_NAME.FIELD = VALUE;`.
      E.g. `setMods.clearLocks= True;`.
    
    
    ## The “xkb_symbols” section {#the-xkb_symbols-section}
    
    <!--
    Ivan Pascal’s doc:
    https://web.archive.org/web/20190723233834/http://pascal.tsu.ru/en/xkb/gram-symbols.html
    -->
    
    <!-- TODO complete this section -->
    
    This [section] is the fourth to be processed, after `xkb_keycodes`,
    `xkb_types` and `xkb_compat`.
    
    Statements of the form:
    
        xkb_symbols "basic" {
            ...
        }
    
    Declare a symbols map named `basic`. Statements inside the curly braces only
    affect the symbols map.
    
    ### Name statements
    
    Statements of the form:
    
        name[Group1] = "US/ASCII";
        groupName[1] = "US/ASCII";
    
    Gives the name “US/ASCII” to the first group of symbols. Other groups can be
    named using a different group index (ex: `Group2`), and with a different name.
    A group must be named.
    
    `group` and `groupName` mean the same thing, and the `Group` in `Group1` is
    optional.
    
    ### Key statement {#key-statement}
    
    Statements of the form:
    
        key <AD01> { ... };
    
    defines the *key description* of the [keycode] `<AD01>` and is the main type
    of record of the `xkb_symbols` section. The possible keycodes are defined in the
    [`xkb_keycodes`](@ref the-xkb_keycodes-section) section.
    
    A key description consists of:
    
    <dl>
        <dt>Groups</dt>
        <dd>
            Each key may have one or more associated [groups]. Each group can be
            configured with the following parameters:
    
            - @ref key-type-setting "Type"</dt>
            - @ref key-symbols-table "Symbols"</dt>
            - @ref key-actions-table "Actions"</dt>
        </dd>
        <dt>Additional attributes</dt>
        <dd>
            These attributes are usually set via the <code>[xkb_compat]</code>
            section, but may be also set directly:
    
            - @ref key-virtual-modifiers "Virtual modifiers"
            - @ref key-repeat "Repeat"
        </dd>
    </dl>
    
    @warning Using multiple groups in *symbols* files is not recommended, because
    some tools rely on the assumption that an `xkb_symbols` section only affect a
    single group. It is fine with a *keymap* file though.
    
    @note In what follows we assume the common use case with a *single* group, which
    benefits from a special syntax. See the section @ref key-groups "Multiple groups"
    for the general syntax.
    
    [groups]: @ref layout-def
    
    #### Symbols {#key-symbols-table}
    
    The main part of the key description is the *symbols table*. It maps shift levels
    to keysyms, e.g.:
    
    ```c
    key <AD01> { [ q, Q ] }; // Level 1 → `q`, Level 2 → `Q`
    ```
    
    Symbols are named using the symbolic names from the
    `xkbcommon/xkbcommon-keysyms.h` file. See the @ref keysym-syntax "keysym syntax"
    for further information. A group of symbols is enclosed in brackets
    and separated by commas. Each element of the symbol arrays corresponds to a
    different [shift level]. In this example, the symbol (keysym) `XKB_KEY_q` for
    level 1 and `XKB_KEY_Q` for level 2. These levels are configured by the
    @ref key-type-setting "key type", presented in the next section.
    
    @remark Remember that @ref keysym-transformations may affect the resulting
    keysym when some modifiers are not [consumed](@ref consumed-modifiers).
    
    @remark Trailing `NoSymbol` are dropped.
    
    @anchor key-multiple-symbols-per-level As an extension to the XKB legacy format,
    libxkbcommon supports multiple key symbols and actions per level (the latter
    since version 1.8.0):
    
    ```c
    key <AD08> { [ {i, j}        , U0132         ] }; // IJ Dutch digraph
    key <AC05> { [ {g, U0303}    , {G, U0303}    ] }; // G̃ Guarani letter
    key <AB05> { [ {U0644, U0627}, {U0644, U0622}] }; // ⁧لا⁩ ⁧لآ⁩ Arabic Lam-Alef ligatures decomposed
    key <AD01> { [ {c, U2019, h} , {C, U2019, h} ] }; // C’H Breton trigraph
    ```
    
    In this example, the keycode `<AD08>` produces two symbols on level 1
    (`XKB_KEY_i` and `XKB_KEY_j`) and one symbol (Unicode keysym `U0132` for “IJ”)
    on level 2. `<AD08>` and `<AD01>` produce letters that have no *precomposed*
    code point in Unicode. Key `<AB05>` avoids the need of using Compose.
    
    @anchor keysyms-string Since 1.9.0, UTF-8-encoded *strings* may be used to
    denote a list of keysyms corresponding to the encoded Unicode code points.
    E.g. the previous example can be also written more intuitively as:
    
    ```c
    key <AD08> { [ "ij" , "IJ"   ] }; // IJ Dutch digraph
    key <AC05> { [ "g̃"  , "G̃"   ] }; // G̃ Guarani letter
    // NOTE: We use U+200E LEFT-TO-RIGHT MARK in order to display the strings in
    //       in the proper order.
    key <AB05> { [ "لا"‎  , "لآ"‎   ] }; // ⁧لا⁩ ⁧لآ⁩ Arabic Lam-Alef ligatures decomposed
    key <AD01> { [ "c’h", "C’h" ] }; // C’H Breton trigraph
    ```
    
    When no actions are explicitly given, they are automatically filled
    thanks to [interpretations] from the [compat section][xkb_compat].
    In the following example,
    
        key <LCTL> { [ { Control_L, ISO_Group_Shift } ] };
    
    is equivalent to (given standard definitions from `xkeyboard-config`):
    
        key <LCTL> {
            symbols[1] = [ { Control_L,                  ISO_Group_Shift    } ],
            actions[1] = [ { SetMods(modifiers=Control), SetGroup(group=+1) } ]
        };
    
    When using this example with e.g. two layouts `fr,us` (respectively Azerty and
    Qwerty layouts), typing `Control + A` in the first layout `fr` will in fact
    result in `Control + Q`, because the actions are run sequentially: first set the
    base modifiers to Control, then switch to the second layout while `Control` is
    pressed.
    
    @remark
    Given a level, keysyms and actions may have a *different count*. For instance,
    the following would achieve the same effect than the former example with only
    1 keysym, but it requires to use 2 explicit actions:
    ```c
    key <LCTL> {
        symbols[1] = [ Control_L                                          ],
        actions[1] = [ { SetMods(modifiers=Control), SetGroup(group=+1) } ]
    };
    ```
    
    @note
    There are some *limitations* with this extension:
    - For now, *at most one* action of each following categories is allowed per
      level:
      - [modifier actions][]: `SetMods`, `LatchMods`, `LockMods`;
      - [group actions][]: `SetGroup`, `LatchGroup`, `LockGroup`.
    
      Some examples of actions combination:
      - `SetMods` + `SetGroup`: ok
      - `SetMods` + `SetMods`: *error*
      - `SetMods` + `LockMods`: *error*
      - `SetMods` + `LockGroup`: ok
    - Multiple actions are only supported from version 1.8.0.
    
    <div>
    
    @since 1.8.0: When using multiple keysyms or actions per level, `NoSymbol` and
    `NoAction()` are dropped in order to normalize the levels:
    ```c
    // Before normalization
    key <> { [{NoSymbol}, {a, NoSymbol}, {NoSymbol,b}, {a, NoSymbol, b}] };
    // After normalization
    key <> { [NoSymbol, a, b, {a, b}] };
    ```
    
    </div>
    <div>
    
    @since 1.9.0: Trailing `NoSymbol` and `NoAction()` are dropped in groups:
    ```c
    // Before normalization
    key <> { [a, NoSymbol] };
    // After normalization
    key <> { [a] };
    ```
    This affects the automatic key type detection.
    
    </div>
    <div>
    
    @since 1.9.0: Added support for keysyms and actions lists of length 0 and 1,
    respectively `{}` and `{a}`. `{}` is equivalent to the corresponding `NoSymbol`
    or `NoAction()`.
    
    </div>
    
    @warning Keymaps containing multiple key symbols per level are not supported
    by the various X11-related tools (`setxkbmap`, `xkbcomp`, etc.).
    
    [symbols table]: @ref key-symbols-table
    
    #### Type {#key-type-setting}
    
    Each key has a [key type] set per group. This key type is defined in the
    <code>[xkb_types]</code> section. Its associated [shift levels] are used to
    index the [symbols table] presented in the previous section.
    
    A key type is set using the following syntax:
    
    <!-- TODO: it also works without the group index -->
    
    ```c
    key <AD01> {
        type[Group1] = "TWO_LEVEL", // Type
        [q, Q]                      // Symbols
    };
    ```
    
    The name of the key type is enclosed between double quotes.
    
    The key type may be omitted and will default to:
    
    - `key.type` global defaults, if set.
    - a standard type using the following **heuristic**:
      <!-- See: xkbcomp/symbols.c (FindAutomaticType) -->
      - **1** keysym: `ONE_LEVEL`
      - **2** keysyms:
        - if the two keysyms are letter and the first is lower case and the other
          upper case, then [`ALPHABETIC`][ALPHABETIC];
        - if one of the keysyms is numpad, then `KEYPAD` else [`TWO_LEVEL`][TWO_LEVEL].
      - **3 or 4** keysyms (a missing 4th keysym is set to `NoSymbol`):
        - if the first two keysyms are letters and the first is lower case and the
          other upper case:
          - if the last two keysyms are letters and the first is lower case and the
            other upper case then [`FOUR_LEVEL_ALPHABETIC`][FOUR_LEVEL_ALPHABETIC];
          - else [`FOUR_LEVEL_SEMIALPHABETIC`][FOUR_LEVEL_SEMIALPHABETIC].
        - if one of the first two keysyms is numpad, then `FOUR_LEVEL_KEYPAD`;
        - else [`FOUR_LEVEL`][FOUR_LEVEL].
    
    @figure@figcaption
    Commented examples for inferred types:
    @endfigcaption
    
    ```c
    // 1 to 2 keysyms
    key <LFSH> { [Shift_L] };                    // Type: ONE_LEVEL
    key <AE01> { [1, exclam] };                  // Type: TWO_LEVEL
    key <AD01> { [q, Q] };                       // Type: ALPHABETIC
    key <KP1>  { [KP_End, KP_1] };               // Type: KEYPAD
    // Edge case: this is consider alphabetic, although
    // the lower case does not correspond to the upper case.
    key <AD01> { [q, N] };                       // Type: ALPHABETIC
    
    // 3 to 4 keysyms
    key <AE01> { [1, exclam, bar] };             // Type: FOUR_LEVEL
    key <AE01> { [1, exclam, bar, exclamdown] }; // Type: FOUR_LEVEL
    key <AD01> { [q, Q, at] };                   // Type: FOUR_LEVEL_SEMIALPHABETIC
    key <AD01> { [q, Q, at, Greek_OMEGA] };      // Type: FOUR_LEVEL_SEMIALPHABETIC
    key <AD05> { [t, T, tslash, Tslash] };       // Type: FOUR_LEVEL_ALPHABETIC
    
    // The inferred type is `FOUR_LEVEL`, but using `LevelThree+Lock`
    // will produce `Q`, because of the keysyms transformations and
    // the corresponding internal capitalization processing.
    key <AE01> { [1, exclam, q, Q] };            // Type: FOUR_LEVEL
    
    // Won’t work, because there is no heuristic for more than 4 keysyms
    // It will trigger the warnings XKB-183 and XKB-516 and default to ONE_LEVEL,
    // ignoring all the keysyms but the first one.
    key <AD01> {[q, Q, at, any, masculine, U2642]};
    // Will work as expected
    key <AD01> {
        type[Group1] = "EIGHT_LEVEL_SEMIALPHABETIC",
        [q, Q, at, any, masculine, U2642]
    };
    ```
    @endfigure
    
    #### Actions {#key-actions-table}
    
    @note This is usually not set explicitly but via the
    <em>[interpret mechanism]</em> by using the
    [`action`](@ref interpret-action) statement in the
    <code>[xkb_compat]</code> section.
    
    
    @figure@figcaption
    Example: Set the modifier action of the key `<LALT>` manually.
    @endfigcaption
    
    ```c
    key <LALT> {
        symbols[Group1]=[Alt_L],
        actions[Group1]=[SetMods(modifiers=modMapMods)]
    };
    ```
    @endfigure
    
    For further details see [key actions][actions].
    
    @remark Trailing `NoAction()` are dropped.
    
    #### Multiple groups {#key-groups}
    
    Each group represents a list of symbols mapped to a keycode:
    
        name[Group1]= "US/ASCII";
        name[Group2]= "Russian";
        ...
        key <AD01> { [ q, Q ],
                     [ Cyrillic_shorti, Cyrillic_SHORTI ] };
    
    A long-form syntax can also be used:
    
        key <AD01> {
            symbols[Group1]= [ q, Q ],
            symbols[Group2]= [ Cyrillic_shorti, Cyrillic_SHORTI ]
        };
    
    Groups can also be omitted, but the brackets must be present. The following
    statement only defines the Group3 of a mapping:
    
        key <AD01> { [], [], [ q, Q ] };
    
    @warning Using multiple groups in *symbols* files is not recommended, because
    some tools rely on the assumption that an `xkb_symbols` section only affect a
    single group. It is fine with a *keymap* file though.
    
    #### Virtual modifiers {#key-virtual-modifiers}
    
    @note This is usually not set explicitly but via the
    <em>[interpret mechanism]</em> by using the
    [`virtualModifier`](@ref interpret-virtualModifier) statement from the
    <code>[xkb_compat]</code> section.
    
    @remarks When setting a [modifier action](@ref modifiers-actions), it is required
    to declare the corresponding virtual modifier using a
    [`virtual_modifiers`](@ref virtual-modifier-statements) statement.
    
    @figure@figcaption
    Example: Set the virtual modifier of the key `<LALT>` to `Alt`.
    @endfigcaption
    
    ```c
    // Declare the virtual modifier that will be used
    virtual_modifiers Alt;
    
    key  <LALT> {
        virtualModifiers = Alt,
        [ Alt_L ]
    };
    ```
    @endfigure
    
    See [virtual modifier map]  for further information.
    
    [interpret mechanism]: @ref interpret-mechanism
    
    #### Repeat {#key-repeat}
    
    @note This is usually not set explicitly but via the
    <em>[interpret mechanism]</em> by using the
    [`repeat`](@ref interpret-repeat) statement in the
    <code>[xkb_compat]</code> section.
    
    @figure@figcaption
    Example: make the `<LALT>` key not repeating.
    @endfigcaption
    
    ```c
    key  <LALT> {
        repeat = False,
        [ Alt_L ]
    };
    ```
    @endfigure
    
    ### Real Modifier map {#modmap-statement}
    
    Bind a [*real* modifier](@ref real-modifier) to a key, e.g.:
    
    ```c
    // Bind the real modifier `Control` to the key `<LCTL>` and/or the first key with
    // the keysym `Control_L`.
    modifier_map Control { <LCTL>, Control_L };
    ```
    
    See [real modifier map] for further information.
    
    ### Set default values
    
    One may change the default values of the following statements:
    
    - `key`: use `key.FIELD = VALUE;`. E.g. `key.type = "ALPHABETIC";`.
    - `action`: use `ACTION_NAME.FIELD = VALUE;`.
      E.g. `setMods.clearLocks= True;`.
    
    
    ## Modifiers declaration and binding {#modifiers-declaration-and-binding}
    
    [modifiers declaration and binding]: @ref modifiers-declaration-and-binding
    
    ### Real and virtual modifiers
    
    [Modifiers] are a particularly tricky part of XKB and deserve their own section.
    For historical reasons they are divided in two categories:
    
    <dl>
    <dt><a name="real-modifier">Real modifier</a></dt>
    <dd>
    
    They are the **8** *predefined* (AKA *core*, *X11*) modifiers:
    
    | Name      | Index/Bit | Mask   | Description                |
    | --------- | --------- | ------ | -------------------------- |
    | `Shift`   | 0         | `0x01` | Used to type upper case letters of [bicameral scripts]; keyboard shortcuts |
    | `Lock`    | 1         | `0x02` | Used to type upper case letters of [bicameral scripts]: “Caps Lock” |
    | `Control` | 2         | `0x04` | Used in keyboard shortcuts |
    | `Mod1`    | 3         | `0x08` | Generic modifier 1         |
    | `Mod2`    | 4         | `0x10` | Generic modifier 2         |
    | `Mod3`    | 5         | `0x20` | Generic modifier 3         |
    | `Mod4`    | 6         | `0x40` | Generic modifier 4         |
    | `Mod5`    | 7         | `0x80` | Generic modifier 5         |
    
    [bicameral scripts]: https://en.wikipedia.org/wiki/Letter_case#Bicameral_script
    
    They are the modifiers defined in the [*core* X11 protocol][X11 Core Protocol].
    They are qualified as “real”, because in the XKB protocol they denote the *bits*
    that *encode* the modifiers state. See @ref modifiers-encoding "" for further
    information.
    
    Since they are predefined, they require no [explicit declaration](@ref virtual-modifier-statements)
    and have a *fixed* [encoding](@ref modifiers-encoding).
    </dd>
    <dt><a name="virtual-modifier">Virtual modifier</a></dt>
    <dd>
    
    They are the modifiers that are *not* predefined. They require an
    [*explicit* declaration](@ref virtual-modifier-statements) and their
    [encoding](@ref modifiers-encoding) is *user-defined*.
    
    Note that in X11, the maximum of virtual modifiers is **16** (see
    `XkbNumVirtualMods`), whereas up to **24** virtual modifiers can be defined in
    libxkbcommon, for a total of **32** modifiers (real + virtual).
    </dd>
    </dl>
    
    ### Modifiers declarations {#virtual-modifier-statements}
    
    *Virtual* modifiers must be declared before their first use with the
    `virtual_modifiers` statement:
    
    - Declare a *single* modifier:
      ```c
      virtual_modifiers MyModifier;
      ```
    - Declare *multiple* modifiers using a comma-separated list:
      ```c
      virtual_modifiers M1, M2, M3.
      ```
    
    Furthermore, it is possible to set the [explicit modifier encoding] with the
    following syntax:
    
    - Use a *real* modifier mask:
      ```c
      // Single modifier: real modifier
      virtual_modifiers M1 = Mod3;
      // Single modifier: using mask as a plus-separated list
      virtual_modifiers M2 = Mod4+Mod5;
      // Multiple modifiers
      virtual_modifiers M1 = Mod3, M2 = Mod4+Mod5;
      ```
    - Use a *numeric* mask:
      ```c
      virtual_modifiers M1 = 0x20;
      virtual_modifiers M2 = 0xC0;
      virtual_modifiers M1 = 0x20, M2 = 0xC0;
      ```
    - Use `none`, an alias for `0`:
      ```c
      virtual_modifiers M1 = none;
      // Equivalent to: M1 = 0;
      ```
    
    This can be done in the [`xkb_types`][xkb_types], [`xkb_compat`][xkb_compat] and
    [`xkb_symbols`][xkb_symbols] sections.
    
    ### Modifiers key bindings {#modifiers-bindings}
    
    [modifiers bindings]: @ref modifiers-bindings
    
    Each key has two **modifiers maps**:
    
    <dl>
    <dt><a name="real-modifier-map">*Real* modifier map</a></dt>
    <dd>
    
    List the [*real* modifiers](@ref real-modifier) associated to the key.
    
    It is used as a compatibility layer for the X11 core protocol and to apply
    [interpretations].
    
    See @ref set-real-mod-map "" for further information.
    </dd>
    <dt><a name="virtual-modifier-map">*Real* modifier map</a></dt>
    <dd>
    
    List the [*virtual* modifiers](@ref virtual-modifier) associated to the key.
    
    It is used to set the [implicit encoding](@ref implicit-modifier-encoding)
    of virtual modifiers.
    
    See @ref set-virtual-mod-map "" for further information.
    </dd>
    </dl>
    
    [real modifier map]: @ref real-modifier-map
    [real modifier maps]: @ref real-modifier-map
    [virtual modifier map]: @ref virtual-modifier-map
    
    #### Setting the real modifier map {#set-real-mod-map}
    
    The [real modifier map] is set in the [`xkb_symbols`][xkb_symbols] section
    using the `modifier_map` statement:
    
    - Bind *directly* to a **keycode**, e.g.:
      ```c
      // Bind `Mod1` to the keycode <LALT>.
      modifier_map Mod1 { <LALT> };
      ```
    - Bind *indirectly* via a **keysym**, e.g.:
      ```c
      // Bind `Mod1` looking up for the keysym `Alt_L`
      modifier_map Mod1 { Alt_L };
      ```
    
      Indirect bindings require to be resolved to a *single direct* bindings.
      Given a keysym, there can be multiple keys that generate it, so the
      corresponding key is chosen following this order:
      1. by lowest group in which the keysym appears,
      2. by lowest level,
      3. by lowest key code.
    - Bind using a comma-separated **list** of keycodes and keysyms:
      ```c
      // Bind `Mod1` diretly to keycode <LALT> and indirectly via the keysym `Alt_L`
      modifier_map Mod1 { <LALT>, Alt_L };
      ```
    
    @note A key can be associated to _at most **one**_ real modifier.
    
    There is also a special entry, `None`, that enable *deleting* a previous entry:
    
    ```c
    modifier_map None { <LALT> };
    ```
    
    @note `None` must use the *exact* same target (keycode or keysym) in order to
    delete the corresponding previous entry:
    ```c
    xkb_symbols {
        key <LALT> { [Alt_L] };
        modifier_map Mod1 { <LALT> };
        // Does *not* delete previous entry (expected keycode, got keysym)
        modifier_map None { Alt_L };
        // *Does* delete previous entry (correct expected keycode)
        modifier_map None { <LALT> };
    };
    ```
    
    #### Setting the virtual modifier map {#set-virtual-mod-map}
    
    The [virtual modifier map] can be set in 2 ways:
    - *Directly* in the [`xkb_symbols`][xkb_symbols] section using the
      `virtualModifiers` key property:
      ```c
      xkb_symbols {
          // Virtual modifiers must be declared before use
          virtual_modifiers Alt;
    
          key <LALT> {
              // Explicit virtual modifier map
              virtualModifiers = Alt,
              ...
          };
      };
      ```
    - *Indirectly* using [interpretations] in [`xkb_compat`][xkb_compat] and the
      corresponding [`xkb_symbols`][xkb_symbols] keysyms:
      ```c
      xkb_compat {
          // Virtual modifiers must be declared before use
          virtual_modifiers Alt, Super;
    
          interpret Alt_L {
              // Bind the virtual modifier…
              virtualModifier = Alt;
              // … independently of the group and level (default)
              useModMap = AnyLevel;
          };
          interpret Super_L {
              // Bind the virtual modifier…
              virtualModifier = Super;
              // … only if the keysym is on the first level of the first group
              useModMap = Level1;
          };
      };
      xkb_symbols {
          // Successful bindings
          key <LALT> { [Alt_L] };
          key <LALT> { [No,Symbol, Alt_L] };    // independent of group and level
          key <LALT> { [], [NoSymbol, Alt_L] }; // independent of group and level
    
          key <LWIN> { [Super_L] };
    
          // Unsuccessful bindings
          key <LWIN> { [NoSymbol, Super_L] };   // requires first level
          key <LWIN> { [], [Super_L] };         // requires first group
      };
      ```
    
    ### Modifiers encoding {#modifiers-encoding}
    
    [modifier encoding]: @ref modifiers-encoding
    
    Each modifier has an associated **32 bit mask** used to *encode* it in the
    keyboard state. The keyboard state represents active modifiers with the bitwise
    OR of the encoding of each active modifiers.
    
    @note Display servers may use a different encoding in their protocols:
    - **Wayland protocol:** use the same *32-bit* encoding as libxkbcommon and
      support its full range of modifiers.
    - **X11 protocol:** use a *8-bit* encoding. It supports only using
      [real modifiers](@ref real-modifier) to encode
      [virtual modifiers](@ref virtual-modifier).
    
    @important
    - [Real modifiers](@ref real-modifier) have a *fixed predefined* encoding.
    - [Virtual modifiers](@ref virtual-modifier) have a *user-defined* encoding.
    
    Virtual modifiers require to be encoded by the user,
    *implicitly* (using the [auto mode](@ref auto-modifier-encoding) and/or the
    [legacy mode](@ref implicit-modifier-encoding)) and/or
    [*explicitly*](@ref explicit-modifier-encoding), the combination resulting in their
    [*effective*](@ref effective-modifier-encoding) encoding.
    
    <dl>
    <dt><a name="implicit-modifier-encoding">*Implicit* modifier encoding</a></dt>
    <dd>
    
    Virtual modifiers *always* compute their implicit encoding, which is defined for
    a given virtual modifier by the bitwise OR of all the [real modifier maps]
    where the virtual modifier is in the [virtual modifier map] of the corresponding
    key.
    
    Example:
    
    ```c
    xkb_symbols {
        virtual_modifiers Alt;
    
        // Virtual modifier map: Alt is bound to <LALT>
        // Note: alternatively one can use xkb_compat interpretations.
        key <LALT> { virtualModifier = Alt };
    
        // Real modifier map: Mod1 is bound to <LALT>
        modifier_map Mod1 { <LALT> };
    
        // Implicit encoding: Alt = Mod1
    };
    ```
    </dd>
    <dt><a name="explicit-modifier-encoding">*Explicit* modifier encoding</a></dt>
    <dd>
    
    Virtual modifiers can optionally define an initial mapping using the
    [`virtual_modifiers`](@ref virtual-modifier-statements) statements:
    
    ```c
    virtual_modifiers M1 = Mod1;     // Single real modifier
    virtual_modifiers M2 = Mod4+Mod5;// Real modifier mask
    virtual_modifiers M3 = 0x400;    // Numeric mask
    ```
    
    See @ref virtual-modifier-statements "" for further information.
    
    @warning Although it is explicit, this may not be the
    [effective encoding][effective modifier encoding], detailed hereinafter.
    </dd>
    <dt><a name="effective-modifier-encoding">*Effective* modifier encoding</a></dt>
    <dd>
    The effective encoding is the bitwise OR of the [explicit modifier encoding]
    and the [implicit modifier encoding].
    
    @note @anchor auto-modifier-encoding If using `::XKB_KEYMAP_FORMAT_TEXT_V2`,
    virtual modifiers that were not mapped either *implicitly* using the
    `virtualModifier`/`modifier_map` feature hereinabove or
    [*explicitly*](@ref explicit-modifier-encoding), then they are mapped to their
    [*canonical* mapping](@ref canonical-modifier-def).
    
    Example:
    
    ```c
    xkb_symbols {
        virtual_modifiers Alt, Meta, Super = none, Hyper = 0x1000, Useless = none;
    
        // Virtual modifier maps
        // Note: alternatively one can use xkb_compat interpretations.
        key <LALT> { virtualModifier = Alt   }; // Alt is bound to <LALT>
        key <LWIN> { virtualModifier = Super }; // Super is bound to <LWIN>
        key <RWIN> { virtualModifier = Super }; // Super is bound to <RWIN>
        key <HYPR> { virtualModifier = Hyper }; // Hyper is bound to <HYPR>
    
        // Real modifier maps
        modifier_map Mod1 { <LALT> }; // Mod1 is bound to <LALT>
        modifier_map Mod4 { <LWIN> }; // Mod4 is bound to <LWIN>
        modifier_map Mod5 { <RWIN> }; // Mod5 is bound to <RWIN>
        modifier_map Mod3 { <HYPR> }; // Mod3 is bound to <HYPR>
    
    };
    ```
    
    <table>
    <caption>Modifiers encoding of the previous example</caption>
    <thead>
    <tr>
    <th>Modifier</th>
    <th>Index</th>
    <th colspan="5">Encoding</th>
    </tr>
    <tr>
    <th></th>
    <th></th>
    <th>Canonical</th>
    <th>Explicit</th>
    <th>Implicit</th>
    <th colspan="2">Effective</th>
    </tr>
    <tr>
    <th></th>
    <th colspan="2">(xkbcommon)</th>
    <th colspan="2"></th>
    <th>`::XKB_KEYMAP_FORMAT_TEXT_V1`</th>
    <th>`::XKB_KEYMAP_FORMAT_TEXT_V2`</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>Alt</th>
    <td>8</td>
    <td>`0x100`</td>
    <td></td>
    <td>`Mod1`</td>
    <td>`Mod1`</td>
    <td>`Mod1`</td>
    </tr>
    <tr>
    <th>Meta</th>
    <td>9</td>
    <td>`0x200`</td>
    <td></td>
    <td></td>
    <td>0 (unmapped)</td>
    <td>`0x200` (canonical, xkbcommon value)</td>
    </tr>
    <tr>
    <th>Super</th>
    <td>10</td>
    <td>`0x400`</td>
    <td>0</td>
    <td>`Mod4 + Mod5`</td>
    <td>`Mod4 + Mod5`</td>
    <td>`Mod4 + Mod5`</td>
    </tr>
    <tr>
    <th>Hyper</th>
    <td>11</td>
    <td>`0x800`</td>
    <td>`0x1000`</td>
    <td></td>
    <td>`0x1000`</td>
    <td>`0x1000`</td>
    </tr>
    <tr>
    <th>Useless</th>
    <td>12</td>
    <td>`0x1000`</td>
    <td>0</td>
    <td></td>
    <td>0 (unmapped)</td>
    <td>0 (explicit mapping)</td>
    </tr>
    </tbody>
    </table>
    </dd>
    </dl>
    
    [explicit modifier encoding]: @ref explicit-modifier-encoding
    [implicit modifier encoding]: @ref implicit-modifier-encoding
    [effective modifier encoding]: @ref effective-modifier-encoding
    
    ### Canonical and non-canonical modifiers
    
    @anchor canonical-modifier-def A **canonical modifier** have an encoding defined
    by: `1 << mod_index`, where `mod_index` is:
    - Fixed for the *real* modifiers, in order to match the X11 values.
      See [real modifiers mapping](@ref real-modifier).
    - Implementation-dependent for the the *virtual* modifiers.
      See @ref xkbcommon-vmod-encoding "" for further details.
    
    [canonical modifier]: @ref canonical-modifier-def
    
    ### Usual modifiers and associated keysyms {#usual-modifiers-keysyms}
    
    The following table summarizes the modifiers defined in
    [`xkeyboard-config` 2.44][xkeyboard-config]:
    
    | Modifier     | Type    | Compat files     | Associated keysyms                                        |
    |--------------|---------|------------------|-----------------------------------------------------------|
    | `Shift`      | Real    | `compat/basic`   | `Shift_L`, `Shift_R`                                      |
    | ^            | ^       | `compat/iso9995` | `Shift_L`, `Shift_R`, `ISO_Level2_Latch`                  |
    | `Lock`       | Real    | `compat/basic`,  | `Caps_Lock`                                               |
    | ^            | ^       | `compat/caps`    | ^                                                         |
    | `Control`    | Real    | `compat/basic`   | `Control_L`, `Control_R`                                  |
    | `Alt`        | Virtual | `compat/misc`,   | `Alt_L`, `Alt_R`                                          |
    | ^            | ^       | `compat/pc`      | ^                                                         |
    | `Meta`       | Virtual | `compat/misc`    | `Meta_L`, `Meta_R`                                        |
    | `Super`      | Virtual | `compat/misc`    | `Super_L`, `Super_R`                                      |
    | `Hyper`      | Virtual | `compat/misc`    | `Hyper_L`, `Hyper_R`                                      |
    | `ScrollLock` | Virtual | `compat/misc`    | `Scroll_Lock`                                             |
    | `NumLock`    | Virtual | `compat/basic`,  | `Num_Lock`,                                               |
    | ^            | ^       | `compat/level5`  | (`ISO_Level5_Lock`)                                       |
    | `LevelThree` | Virtual | `compat/iso9995` | `ISO_Level3_Shift`, `ISO_Level3_Latch`, `ISO_Level3_Lock` |
    | `LevelFive`  | Virtual | `compat/level5`  | `ISO_Level5_Shift`, `ISO_Level5_Latch`, `ISO_Level5_Lock` |
    | `Kana_Lock`  | Virtual | `compat/japan`   | `Kana_Lock`                                               |
    | `Square`     | Virtual | `compat/olpc`    | `KP_Home`                                                 |
    | `Cross`      | Virtual | `compat/olpc`    | `KP_Next`                                                 |
    | `Circle`     | Virtual | `compat/olpc`    | `KP_End`                                                  |
    | `Triangle`   | Virtual | `compat/olpc`    | `KP_Prior`                                                |
    
    ### Modifiers portability {#modifiers-portability}
    
    #### Avoid using numeric modifier masks
    
    @note Any field that accept virtual modifier *names* is a virtual modifier
    *mask*, denoting virtual modifiers *indices*. These indices are
    implementation-specific and should not be leaked. Therefore any *numeric* value
    used for these fields should be interpreted equally as a virtual modifier mask,
    and is thus implementation-specific.
    
    @important In order to preserve [modifier encoding] *portability*, XKB
    implementations are recommended to **avoid *numeric* modifier masks** and to
    **use virtual modifiers *names* whenever possible** when serializing the keymap.
    This avoids *leaking* the indices of the modifiers.
    
    #### xkbcomp and libxkbcommon implementations {#xkbcommon-vmod-encoding}
    
    @attention This section is not part of the keymap text format specification and
    presents libxkbcommon’s *implementation details* that may change, solely for the
    purpose of informing other XKB implementation.
    **Users should not rely on this!**
    
    Both X11 xkbcomp and libxkbcommon currently implement modifiers indices as follow:
    
    1. Real modifiers have the following indices: @anchor real-modifier-indices
       | Name      | Index |
       | --------- | ----- |
       | `Shift`   | 0     |
       | `Lock`    | 1     |
       | `Control` | 2     |
       | `Mod1`    | 3     |
       | `Mod2`    | 4     |
       | `Mod3`    | 5     |
       | `Mod4`    | 6     |
       | `Mod5`    | 7     |
    2. Virtual modifiers names are assigned to virtual modifier indices following
       their order of appearance in a keymap component, if that name was not
       previously assigned.
    3. Indices are assigned in *ascending order*, from 0.
    4. If an index is already assigned to a different name, then the next free index
       is used.
    5. The order of the relevant keymap components used for virtual mods assignment is:
       1. [xkb_types]
       2. [xkb_compat]
       3. [xkb_symbols]
    6. A virtual modifier *mask* always denotes virtual modifiers *indices*.
    
    @note It suffices to declare all virtual modifiers in [xkb_types] \(or if empty,
    whatever non-empty section afterwards, in the order specified above) in their
    ascending indices order to use virtual modifiers indices
    **compatible with libxkbcommon**.
    
    ### Example: define and use a modifier, step by step
    
    We will use the example of the _real_ modifier `Shift` and the virtual
    modifier `LevelThree` in `xkeyboard-config`.
    
    In order to define and use a modifier, one must:
    
    1. Define its behavior and [keysym] binding in the
        <code>[xkb_compat]</code> section:
    
        ```c
        // Declare virtual modifiers. Shift being real modifier,
        // we do not need to add it here.
        virtual_modifiers LevelThree;
    
        // Set defaults. They are overridden if set directly in the xkb_symbols.
        interpret.repeat= False; // only applied on first level
        setMods.clearLocks= True;
        latchMods.clearLocks= True;
        latchMods.latchToLock= True;
    
        // Default statement for real modifiers: any key bound to a real
        // modifier via modifier_map will set this modifier at all its
        // levels.
        // Here only to illustrate: do not add it!
        interpret Any + Any {
    	    action= SetMods(modifiers=modMapMods);
        };
    
        // Shift being real modifier, we do not need a corresponding
        // interpret statement because the previous one suffices.
    
        // Let’s associate LevelThree to the keysym ISO_Level3_Shift
    
        // First, match the keys and their levels with the
        // ISO_Level3_Shift keysym and with any real modifier
        // (Any = AnyOf(all)) in its modmap.
        interpret ISO_Level3_Shift+Any {
            // Only match the first level of the first group
            useModMapMods= level1;
            // Add the virtual modifier to the key’s vmodmap
            virtualModifier= LevelThree;
            // Activate the LevelThree modifier (depressed mode)
            action= SetMods(modifiers=LevelThree);
        };
    
        // Then for keys and their levels with the
        // ISO_Level3_Shift keysym but with either no real modifier
        // in its modmap or a level higher than 1.
        // Indeed:
        // • In case the level is higher than 1 there is no match
        //   in the previous statement.
        // • The condition is equivalent to
        //   ISO_Level3_Shift+AnyOfOrNone(all), but since
        //   the previous statement ISO_Level3_Shift+Any is more
        //   specific, it will be matched before this one.
        interpret ISO_Level3_Shift {
            // Activate the LevelThree modifier (depressed mode)
            action= SetMods(modifiers=LevelThree);
        };
        ```
    
    2. Define [key types] that use it in the
        <code>[xkb_types]</code> section:
    
        ```c
        // Declare virtual modifiers. Shift being real modifier,
        // we do not need to add it here.
        virtual_modifiers LevelThree;
    
        type "FOUR_LEVEL" {
            // Key type modifier mask: all the modifiers used in the key type
            modifiers = Shift + LevelThree;
            map[None] = Level1;
            map[Shift] = Level2;
            map[LevelThree] = Level3;
            map[Shift+LevelThree] = Level4;
            level_name[Level1] = "Base";
            level_name[Level2] = "Shift";
            level_name[Level3] = "AltGr";
            level_name[Level4] = "Shift AltGr";
        };
        ```
    
    3. Bind it to a [keycode] in the
        <code>[xkb_symbols]</code> section:
    
        1. Map [keysyms] used in the `xkb_compat` section hereinabove.
        2. Bind [real modifiers] to keys using these keysyms with
           `modifier_map`.
    
        _Note:_ Only one key binding to real modifier is required.
        The corresponding keysym must then be on the first level of
        the first Group.
    
        _Note:_ One can optionally bind directly a virtual modifier to a
        key using `virtualmodifiers` instead of doing it in the
        `xkb_compat` section. But the recommended way is to use the
        `xkb_compat` section.
    
        ```c
        // Shift: defined in pc symbols
        key <LFSH> {[  Shift_L    ]};
        key <RTSH> {[  Shift_R    ]};
        modifier_map Shift { Shift_L, Shift_R };
        // The previous will resolve to:
        // modifier_map Shift { <LFSH>, <RTSH> };
        // Thus the real modifier Shift is added to the modmap of
        // <LFSH> and <RTSH>.
        // The “Any + Any” interpret statement matches <LFSH> and <RTSH>,
        // therefore these keys set the Shift modifier.
    
        // LevelThree: defined in pc symbols
        // With the following 2 lines:
        // 1. The modifier keysym is on the first level of the first group.
        // 2. The real modifier Mod5 is bound to <LVL3>,
        //    i.e. Mod5 is added to its modmap.
        // 3. It matches the interpret statement “ISO_Level3_Shift+Any”,
        //    which adds the LevelThree modifier to the vmodmap of <LVL3>.
        // 4. The mapping of LevelThree to real modifiers is the union
        //    of modmaps with corresponding vmodmaps containing
        //    LevelThree. In our case there is only one: therefore
        //    LevelThree maps to Mod5.
        key <LVL3> {[  ISO_Level3_Shift  ]};
        modifier_map Mod5  { <LVL3> };
    
        // LevelThree: defined in level3 symbols
        // Not bound to a real modifier, so interpret statement
        // “ISO_Level3_Shift” applies.
        key <RALT> {[ISO_Level3_Shift], type[group1]="ONE_LEVEL" };
    
        // Note: we could have the following line, but it is not necessary
        // because we have the mappings of <LVL3>.
        // modifier_map Mod5  { <RALT> };
    
        // Warning: if we had the for example the following line, the
        // mapping of LevelThree to real modifiers would be “Mod1+Mod5”.
        // modifier_map Mod1  { <RALT> };
    
        // Alternative definitions, without using interpret statements
        virtual_modifiers LevelThree;
        key <LVL3> { virtualmodifiers=LevelThree
                   , repeats=False
                   , symbols[Group1] = [ISO_Level3_Shift]
                   , actions[Group1] = [SetMods(modifiers=LevelThree)] };
        modifier_map Mod5  { <LVL3> };
        key <RALT> { repeat=False
                   , symbols[Group1] = [ISO_Level3_Shift]
                   , actions[Group1] = [SetMods(modifiers=LevelThree)]
                   , type[group1]="ONE_LEVEL" };
    
        // FOUR_LEVEL key type example from latin symbols
        key <AB05> {[b, B, leftdoublequotemark, leftsinglequotemark]};
        ```
    
    ## Key actions {#key-actions}
    
    The following table provide an overview of the available actions:
    
    | Category | Action name         | Alias            | Description                        |
    |----------|---------------------|------------------|------------------------------------|
    | [Ineffectual action] | [`NoAction`][NoAction] |   | **Default action**: *implicitly* do nothing |
    | ^        | [`VoidAction`][VoidAction] |           | *Explicitly* do nothing            |
    | [Modifier action] | [`SetMods`][SetMods] |        | Modifies the <em>[depressed]</em> modifiers |
    | ^        | [`LatchMods`][Latchmods] |             | Modifies the <em>[latched]</em> modifiers   |
    | ^        | [`LockMods`][LockMods] |               | Modifies the <em>[locked]</em> modifiers    |
    | [Group action] | [`SetGroup`][SetGroup] |         | Modifies the _base_ group          |
    | ^        | [`LatchGroup`][LatchGroup] |           | Modifies the _latched_ group       |
    | ^        | [`LockGroup`][LockGroup] |             | Modifies the _locked_ group        |
    | [Legacy action] | `MovePointer`| `MovePtr`        | Move the mouse pointer             |
    | ^        | `PointerButton`     | `PtrBtn`         | Simulate a mouse button press      |
    | ^        | `LockPointerButton` | `LockPtrBtn`     | Simulate a mouse button press, locked until the action’s key is pressed again. |
    | ^        | `SetPointerDefault` | `SetPtrDflt`     | Set the default select button (???)|
    | ^        | [`SetControls`][SetControls] |         | Set the standard XKB controls      |
    | ^        | [`LockControls`][LockControls] |       | Lock the standard XKB controls     |
    | ^        | [`TerminateServer`][TerminateServer] | `Terminate` | Shut down the X server |
    | ^        | `SwitchScreen`      |                  | Switch virtual X screen            |
    | ^        | [`Private`][Private]|                  | Raw encoding of an action          |
    | [Unsupported legacy action]| [`RedirectKey`][redirectkey] | `Redirect` | Emulate pressing a key with a different key code |
    | ^        | `ISOLock`           |                  | Convert ordinary modifier key actions into lock actions while this action is active |
    | ^        | `DeviceButton`      | `DevBtn`         | Emulate an event from an arbitrary input device such as a joystick |
    | ^        | `LockDeviceButton`  | `LockDevBtn`     | Emulate an event from an arbitrary input device such as a joystick |
    | ^        | `DeviceValuator`    | `DevVal`         | <span class="todo">TODO</span> |
    | ^        | `MessageAction`     | `Message`        | Generate an arbitrary special-purpose XKB event |
    
    Common syntax:
    - Boolean values:
      - `true`, `yes`, `on`
      - `false`, `no`, `off`
    
    ### Ineffectual actions {#ineffectual-actions}
    
    [ineffectual action]: @ref ineffectual-actions
    [NoAction]:   @ref no-action
    [VoidAction]: @ref void-action
    
    <dl>
    <dt>`NoAction` @anchor no-action</dt>
    <dd>
    **Default action**: *implicitly* do nothing.
    Does *not* override previous actions and is dropped.
    
    No parameters.
    </dd>
    <dt>`VoidAction` @anchor void-action</dt>
    <dd>
    *Explicitly* do nothing.
    *Does* override previous actions and is not dropped.
    
    No parameters.
    
    @note This is a libxkbcommon *extension*. In order to maintain backward-compatibility,
    it serializes to `LockControls(controls=none,affect=neither)`.
    
    @since 1.10.0
    </dd>
    </dl>
    
    ### Modifiers actions {#modifiers-actions}
    
    [modifier action]: @ref modifiers-actions
    [modifier actions]: @ref modifiers-actions
    [SetMods]:   @ref set-mods-action
    [LatchMods]: @ref latch-mods-action
    [LockMods]:  @ref lock-mods-action
    
    There are 3 modifiers actions:
    
    <dl>
    <dt>`SetMods` @anchor set-mods-action</dt>
    <dd>
    Modifies the <em>[depressed]</em> modifiers.
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Aliases</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`modifiers`</th>
    <td>`mods`</td>
    <td>Modifier mask</td>
    <td>`none` (0)</td>
    <td>
    The list of modifiers to modify, separated by `+`, or the special value
    `modMapMods`. The latter means the parameter value has to be read from the
    `vmodmap` attribute of the key.
    </td>
    <tr>
    <th>`clearLocks`</th>
    <td></td>
    <td>boolean</td>
    <td>`false`</td>
    <td>See its use [hereinafter](@ref set-modifier-action-effects)</td>
    </tr>
    <tr>
    <th>`unlockOnPress`</th>
    <td></td>
    <td>boolean</td>
    <td>`false`</td>
    <td>
    Control whether [locked] modifiers are unlocked on key press or release (default).
    See [hereinafter](@ref set-modifier-action-effects) for further details.
    
    @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
    </td>
    </tr>
    </tbody>
    </table>
    </dd>
    
    <dt>`LatchMods` @anchor latch-mods-action</dt>
    <dd>
    Modifies the <em>[latched]</em> modifiers
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Aliases</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`modifiers`</th>
    <td>`mods`</td>
    <td>Modifier mask</td>
    <td>`none` (0)</td>
    <td>see [`SetMods`][SetMods].</td>
    <tr>
    <th>`clearLocks`</th>
    <td></td>
    <td>boolean</td>
    <td>`false`</td>
    <td>See its use [hereinafter](@ref latch-modifier-action-effects)</td>
    </tr>
    <tr>
    <th>`latchToLock`</th>
    <td></td>
    <td>boolean</td>
    <td>`false`</td>
    <td>See its use [hereinafter](@ref latch-modifier-action-effects)</td>
    </tr>
    <tr>
    <th>`latchOnPress`</th>
    <td></td>
    <td>boolean</td>
    <td>`false`</td>
    <td>
    Control whether [latched] modifiers are latched on key press or release (default).
    See [hereinafter](@ref latch-modifier-action-effects) for further details.
    
    @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
    </tr>
    <tr>
    <th>`unlockOnPress`</th>
    <td></td>
    <td>boolean</td>
    <td>`false`</td>
    <td>
    Control whether [locked] modifiers are unlocked on key press or release (default).
    See [hereinafter](@ref latch-modifier-action-effects) for further details.
    
    @note It is *implied* if both `latchOnPress=true` and `clearLocks=true`.
    
    @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
    </td>
    </tr>
    </tbody>
    </table>
    
    </dd>
    
    <dt>`LockMods` @anchor lock-mods-action</dt>
    <dd>
    Modifies the <em>[locked]</em> modifiers.
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Aliases</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`modifiers`</th>
    <td>`mods`</td>
    <td>Modifier mask</td>
    <td>`none` (0)</td>
    <td>see [`SetMods`][SetMods]</td>
    <tr>
    <th>`affect`</th>
    <td></td>
    <td>
    enumeration:
    - `lock`
    - `unlock`
    - `both`
    - `neither`
    </td>
    <td>`both`</td>
    <td>
    - `lock`: the action only locks the modifier, but cannot unlock it.
    - `unlock`: the action only unlocks modifier, but cannot lock it.
    - `both`: the first key press locks the modifier and the second key
      press releases the modifier..
    - `neither`: do not lock nor unlock, i.e. do nothing.
    </td>
    </tr>
    <tr>
    <th>`unlockOnPress`</th>
    <td></td>
    <td>boolean</td>
    <td>`false`</td>
    <td>
    Control whether [locked] modifiers are unlocked on key press or release.
    See [hereinafter](@ref lock-modifier-action-effects) for further details.
    
    @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
    </td>
    </tr>
    </tbody>
    </table>
    
    </dd>
    
    </dl>
    
    @todo highlight that there is reference counting for
    the modifiers, e.g. to manage multiple physical keys for the same modifier.
    
    These actions perform different tasks on key press and on key release:
    
    <table>
      <caption>
        Effects of modifiers actions @anchor modifier-actions-effects
      </caption>
      <thead>
        <tr>
          <th>Action</th>
          <th>On key press</th>
          <th>On key release</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th>`SetMods` @anchor latch-modifier-action-effects</th>
          <td>
          - If `clearLocks` and `unlockOnPress` are true, unlock the target
            modifiers.
          - Adds modifiers to <em>[depressed]</em> modifiers that were not unlocked.
          </td>
          <td>
          - Removes modifiers added on press from <em>[depressed]</em> modifiers,
            provided that no other key which affects the same modifiers is logically
            down.
          - If `clearLocks` is true, `unlockOnPress` is false and no other key were
            operated simultaneously with this key, then the modifiers will be
            removed as well from the <em>[locked]</em> modifiers.
          </td>
        </tr>
        <tr>
            <th>`LatchMods` @anchor set-modifier-action-effects</th>
            <td>
            - If `unLockOnPress` and `clearLocks` are true and target modifiers were
              locked, then unlocks them and clear the action.
            - Otherwise if `latchOnPress` is true, then adds modifiers to the
              <em>[latched]</em> modifiers.
            - Otherwise adds modifiers to <em>[depressed]</em> modifiers.
            </td>
            <td>
            - If `latchOnPress` is false, then:
              - Removes modifiers from <em>[depressed]</em> modifiers.
            - If no keys were operated simultaneously with the latching modifier key:
              - If `clearLocks` is true and `unLockOnPress` is false and target
                modifiers were locked, then unlock then stop here and clear the
                action.
              <!-- TODO: pending latch? -->
              - Otherwise add modifiers to <em>[latched]</em> modifiers.
              - If `latchToLock` is true and if the target modifiers are latched,
                then unlatch them and <em>[lock][locked]</em> them.
              - Latch target modifiers that were not used by `clearLocks` and
                `latchToLock`.
            - Otherwise unlatch the target modifiers and clear the action.
            </td>
        </tr>
        <tr>
            <th>`LockMods` @anchor lock-modifier-action-effects</th>
            <td>
            - If `unlockOnPress` is true and some of the target modifiers were
              <em>[locked]</em> before the key press, then unlock them if `noUnlock`
              false.
            - Otherwise:
              - add target modifiers to <em>[depressed]</em> modifiers;
              - if `noLock` is false, add target modifiers to the <em>[locked]</em>
                modifiers.
            </td>
            <td>
            - If `unlockOnPress` is true and triggered unlocking on key press, do
              nothing.
            - Otherwise:
              - remove modifiers from the <em>[depressed]</em> modifiers, if no
                other key that affect the same modifiers is down;
              - if `noUnlock` is false and if any target modifiers was locked before
                the key press, *[unlock][locked]* them.
            </td>
        </tr>
      </tbody>
    </table>
    
    ### Group actions {#group-actions}
    
    [group action]: @ref group-actions
    [group actions]: @ref group-actions
    [SetGroup]:   @ref set-group-action
    [LatchGroup]: @ref latch-group-action
    [LockGroup]:  @ref lock-group-action
    
    There are 3 group actions:
    
    <dl>
    <dt>`SetGroup` @anchor set-group-action</dt>
    <dd>
    Modifies the *base* group.
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`group`</th>
    <td>
    Group index:
    - 1-based numbering
    - either absolute (no sign) or relative (`+`/`-` sign)
    </td>
    <td>0</td>
    <td>Target group or group delta</td>
    <tr>
    <th>`clearLocks`</th>
    <td>boolean</td>
    <td>`false`</td>
    <td>See its use [hereinafter](@ref set-group-action-effects)</td>
    </tr>
    </tbody>
    </table>
    
    </dd>
    
    <dt>`LatchGroup` @anchor latch-group-action</dt>
    <dd>
    Modifies the *latched* group.
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`group`</th>
    <td>Group index (see [`SetGroup`][SetGroup])</td>
    <td>0</td>
    <td>Target group or group delta</td>
    <tr>
    <th>`clearLocks`</th>
    <td>boolean</td>
    <td>`false`</td>
    <td>See its use [hereinafter](@ref latch-group-action-effects)</td>
    </tr>
    <tr>
    <th>`latchToLock`</th>
    <td>boolean</td>
    <td>`false`</td>
    <td>See its use [hereinafter](@ref latch-group-action-effects)</td>
    </tr>
    </tbody>
    </table>
    
    </dd>
    
    <dt>`LockGroup` @anchor lock-group-action</dt>
    <dd>
    Modifies the *locked* group.
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`group`</th>
    <td>Group index (see [`SetGroup`][SetGroup])</td>
    <td>0</td>
    <td>Target group or group delta</td>
    </tr>
    <tr>
    <th>`lockOnRelease`</th>
    <td>boolean</td>
    <td>false</td>
    <td>
    Control whether to trigger the group change on key press (default) or release.
    See further details [hereinafter](@ref lock-group-action-effects)
    
    @note Available since 1.11, only with `::XKB_KEYMAP_FORMAT_TEXT_V2`.
    </td>
    </tr>
    </tbody>
    </table>
    
    </dd>
    
    </dl>
    
    <table>
    <caption>Effects of group actions</caption>
    <thead>
    <tr>
    <th>Action</th>
    <th>On key press</th>
    <th>On key release</th>
    </tr>
    </thead>
    <tbody>
    
    <tr>
    <th>`SetGroup` @anchor set-group-action-effects</th>
    <td>
    
    - If the `group` parameter is *absolute*, key press events sets the *base*
      keyboard group to `group`.
    - Otherwise, it adds `group` to the *base* keyboard group.
    
    In either case, the resulting *effective* keyboard group is brought back into
    range depending on the value of the `GroupsWrap` control for the keyboard.
    </td>
    <td>
    If *no* keys were operated simultaneously with this key and the `clearLocks`
    parameter is set, key release also sets the *locked* keyboard group to `Group1`.
    </td>
    </tr>
    
    <tr>
    <th>`LatchGroup` @anchor latch-group-action-effects</th>
    <td>
    Same as `SetGroup`.
    </td>
    <td>
    Same as `SetGroup`.
    
    If no keys were operated simultaneously with the latching group key and the
    `clearLocks` parameter was not set or had no effect, key release has the following
    additional effects:
    
    - If `latchToLock` parameter is set and the *latched* keyboard group is not the
      first group, the key release adds the *delta* applied by the corresponding key
      press to the locked keyboard group and subtracts it from the latched keyboard
      group. The *locked* and *effective* keyboard group are brought back into range
      according to the value of the global `GroupsWrap` control for the keyboard.
    - Otherwise, key release adds the key press *delta* to the latched keyboard
      group.
    </td>
    </tr>
    
    <tr>
    <th>`LockGroup` @anchor lock-group-action-effects</th>
    <td>
    
    - If `lockOnRelease` is set, then key press has no effect.
    - Otherwise:
      - if the `group` is absolute, key press sets the *locked* keyboard group to
        `group`;
      - otherwise, key press adds `group` to the *locked* keyboard group.
    
      In either case, the resulting *locked* and *effective* group is brought back
      into range depending on the value of the `GroupsWrap` control for the keyboard.
    </td>
    <td>
    
    - If `lockOnRelease` is not set, then key release has no effect.
    - Otherwise, if any other key was *pressed* after the locking key, then
      key release has no effect.
    
      <details>
      <summary>This enables e.g. using `Alt+Shift` combination in any order.</summary>
    
      - `Shift` down, `Alt` down, `Alt` up, `Shift` up
      - `Shift` down, `Alt` down, `Shift` up, `Alt` up
      - `Alt` down, `Shift` down, `Shift` up, `Alt` up
      - `Alt` down, `Shift` down, `Alt` up, `Shift` up
    
      This would not be possible if locking was cancelled by key *release* too.
      </details>
    
    - Otherwise, it has the same effect than a key press *without* `lockOnRelease`
      set.
    </td>
    </tr>
    
    </tbody>
    </table>
    
    
    ### Legacy X11 actions {#legacy-x11-actions}
    
    [legacy action]: @ref legacy-x11-actions
    
    @attention The following legacy actions are kept for compatibility only: they are parsed
    and validated but have no effect. This allows to use keymaps defined in
    <code>[xkeyboard-config]</code> for both X11 and Wayland.
    
    #### Pointer actions
    
    <dl>
    <dt>`MovePointer`<dt>
    <dt>`MovePtr`</dt>
    <dd>
    Move the mouse pointer
    
    @todo MovePointer parameters
    <!-- blank required by Doxgen -->
    
    </dd>
    
    <dt>`PointerButton`</dt>
    <dt>`PtrBtn`</dt>
    <dd>
    Simulate a mouse button press
    
    @todo PointerButton parameters
    <!-- blank required by Doxgen -->
    
    </dd>
    
    <dt>`LockPointerButton`</dt>
    <dt>`LockPointerBtn`</dt>
    <dt>`LockPtrButton`</dt>
    <dt>`LockPtrBtn`</dt>
    <dd>
    Simulate a mouse button press, locked until this actiion’s key is pressed again
    
    @todo LockPointerButton parameters
    <!-- blank required by Doxgen -->
    
    </dd>
    
    <dt>`SetPointerDefault`</dt>
    <dt>`SetPtrDflt`</dt>
    <dd>
    Set the default select button (???)
    
    @todo SetPointerDefault parameters
    <!-- blank required by Doxgen -->
    
    <dd>
    </dl>
    
    
    #### Control flags actions
    
    [SetControls]:  @ref set-controls-action
    [LockControls]: @ref lock-controls-action
    
    <dl>
    <dt>`SetControls` @anchor set-controls-action</dt>
    <dd>
    
    Set the standard XKB controls
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Alias</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`controls`</th>
    <td>`ctrls`</td>
    <td>
    Mask of the following enumeration:
    
    - `RepeatKeys`
    - `Repeat`
    - `AutoRepeat`
    - `SlowKeys`
    - `BounceKeys`
    - `StickyKeys`
    - `MouseKeys`
    - `MouseKeysAccel`
    - `AccessXKeys`
    - `AccessXTimeout`
    - `AccessXFeedback`
    - `AudibleBell`
    - `IgnoreGroupLock`
    - `Overlay1`
    - `Overlay2`
    
    Plus 2 special values:
    - `all`
    - `none`
    </td>
    <td>0</td>
    <td>Standard XKB controls</td>
    </tbody>
    </table>
    
    </dd>
    <dt>`LockControls` @anchor lock-controls-action</dt>
    <dd>
    Lock the standard XKB controls
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Alias</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`controls`</th>
    <td>`ctrls`</td>
    <td>Mask (see [`SetControls`][SetControls])</td>
    <td>0</td>
    <td>Standard XKB controls</td>
    <tr>
    <th>`affect`</th>
    <td></td>
    <td>
    enumeration:
    - `lock`
    - `unlock`
    - `both`
    - `neither`
    </td>
    <td>`both`</td>
    <td><span class="todo">TODO</span></td>
    </tr>
    </tbody>
    </table>
    
    </dd>
    </dl>
    
    #### Server actions
    
    [TerminateServer]: @ref terminate-server-action
    
    <dl>
    <dt>`TerminateServer` @anchor terminate-server-action</dt>
    <dd>
    Shut down the X server
    
    No parameters.
    </dd>
    <dt>`SwitchScreen`</dt>
    <dd>
    
    @todo SwitchScreen
    <!-- blank for Doxygen -->
    
    </dd>
    </dl>
    
    #### Private action {#private-action}
    
    [Private]: @ref private-action
    
    Raw encoding of an action. Aimed to support arbitrary action unknown to the XKB
    compiler.
    
    @warning This assumes that the corresponding action’s C `struct` is laid out in
    memory exactly as described in the XKB specification and libraries. However,
    libxkbcommon have changed these `struct`s in various ways, so this assumption is
    no longer true and the actions defined in the XKB protocol are unsupported.
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`type`</th>
    <td>integer</td>
    <td>0</td>
    <td>
    Action type, as encoded in the XKB protocol
    </td>
    <tr>
    <th>`data`</th>
    <td>byte array or a string of *exactly 7 bytes*</td>
    <td>"0000000"</td>
    <td>Raw byte encoding of the action following the XKB protocol</td>
    </tr>
    </tbody>
    </table>
    
    Examples:
    - `Private(type=123, data="abcdefg");`
    - `Private(type=123, data[1]=0, data[2]=100, data[3]=12);`
    
    ### Unsupported legacy X11 actions {#unsupported-legacy-x11-actions}
    
    [unsupported legacy action]: @ref unsupported-legacy-x11-actions
    
    @attention The following legacy actions are **unsupported**: they are parsed
    and but *not validated* and are then completely *ignored*.
    
    #### Redirect key {#redirect-key-action}
    
    [redirectkey]: @ref redirect-key-action
    
    `RedirectKey` emulates pressing a key with a different key code.
    
    `RedirectKey` normally redirects to another key on the *same device* as the key
    or button which caused the event, else on the *core* keyboard device.
    
    <table>
    <caption>Parameters</caption>
    <thead>
    <tr>
    <th>Name</th>
    <th>Aliases</th>
    <th>Data type</th>
    <th>Default value</th>
    <th>Description</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <th>`key`</th>
    <td>`keycode`, `kc`</td>
    <td>keycode</td>
    <td>0</td>
    <td>Target keycode to emulate</td>
    <tr>
    <th>`clearmodifiers`</th>
    <td>`clearmods`</td>
    <td>modifier mask</td>
    <td>`none` (0)</td>
    <td>Modifiers to clear</td>
    </tr>
    <tr>
    <th>`modifiers`</th>
    <td>`mods`</td>
    <td>modifier mask</td>
    <td>`none` (0)</td>
    <td>Modifiers to add</td>
    </tr>
    </tbody>
    </table>
    
    <table>
    <caption>Effects</caption>
    <thead>
    <tr>
    <th>On key *press*</th>
    <th>On key *release*</th>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>
    
    Key press causes a key press event for the key specified by the `key` parameter
    instead of for the actual key. The state reported in this event reports of the
    current *effective* modifiers changed as follow:
    - Modifiers in the `clearmodifiers` parameter are cleared.
    - Modifiers in the `modifiers` parameter are set.
    </td>
    <td>
    
    Key release causes a key release event for the key specified by the `key`
    parameter; the state field for this event consists of the *effective*
    modifiers at the time of the release, changed as described on the key press.
    </td>
    </tbody>
    </table>
    
    #### ISO lock
    
    @todo `ISOLock`
    
    #### Device actions
    
    <dl>
    <dt>`DeviceButton`</dt>
    <dd>
    
    @todo DeviceButton
    <!-- blank for Doxygen -->
    
    </dd>
    <dt>`LockDeviceButton`</dt>
    <dd>
    
    @todo LockDeviceButton
    <!-- blank for Doxygen -->
    
    </dd>
    <dt>`DeviceValuator`</dt>
    <dd>
    
    @todo DeviceValuator
    <!-- blank for Doxygen -->
    
    </dd>
    </dl>
    
    #### Message
    
    @todo `ActionMessage`
    
    ## The “xkb_geometry” section {#the-xkb_geometry-section}
    
    This section aims to describe the *physical* layout of a keyboard and its main
    use case is to produce a picture of the keyboard via e.g. the `xkbprint` program.
    
    @warning libxkbcommon does not support this section: while it can parse the
    syntax, it does not interpret it; the section is simply dropped so there is no
    API to query it and the keymap serialization does not contain it.
    
    @sa @ref geometry-support "Compatibility with X11".
    

Download