1 # Introduction to XKB {#xkb-intro}
3 __XKB__ stands for “X Keyboard Extension”. It may refer to either:
5 - a [protocol](@ref xkb-the-protocol)
6 - a [keyboard layout configuration](@ref xkb-the-config)
7 - a [text format](@ref xkb-the-text-format)
9 ## XKB the protocol {#xkb-the-protocol}
11 A __protocol__ for the [X Windows System], that extends the core protocol.
13 _xkbcommon’s_ API is somehow derived from this API, but has been
14 substantially reworked to function as a library instead of a protocol,
15 and exposes fewer internal details to clients.
17 _xkbcommon_ does not depend on a particular windows system; for instance
18 it is used by the [Wayland] protocol.
20 _xkbcommon_ provides the <code>[xkbcommon-x11]</code> module to interface
21 a client with an X server using the XKB protocol. Relevant links:
23 - [The X Window System Protocol][X Protocol]
24 - [The X Keyboard Extension: Protocol Specification][XKB Protocol]
28 ## XKB the keyboard keymap configuration {#xkb-the-config}
30 In order to use [the protocol](@ref xkb-the-protocol), one must first load a
31 [complete keymap]. The keymap usually comes from the OS _layout database_,
32 which is commonly [xkeyboard-config]. Since keymaps may have definitions in
33 common, the database actually stores their basic components separately to allow
34 maximum composability and coherence. A recipe to compose a keymap from its
35 components is called a _keymap configuration_.
37 In XKB, there are several ways to define a keymap configuration. They all aim to
38 produce a [complete keymap]. The following diagram presents an overview.
39 Then they are presented hereinafter, ordered from end user to low-level
42 @dotfile xkb-configuration "XKB keymap configurations"
45 RMLVO: <u>R</u>ules, <u>M</u>odel, <u>L</u>ayout, <u>V</u>ariant,
46 <u>O</u>ptions @anchor RMLVO-intro
49 This is the configuration the end user usually faces in the UI.
50 The idea is to expose high level concepts such as [keyboard model] and
51 [keyboard layout] to the user, then to _map_ them to the corresponding set
52 of low-level configuration files (see [KcCGST]).
54 @note The RMLVO configurations actually available to the end user is managed
55 by the `xkbregistry`. It uses an XML file, the _registry_, which exposes and
56 documents the set of RMLVO settings in the layout database.
58 The RMLVO configuration consists of the following components:
63 The rules define the _mapping_ from high to low level components.
64 The rules _component_ is the file containing the set of rules to use.
65 It is usually implicit and set by the system.
67 See the [rules file format](@ref rule-file-format) for further details.
71 The name of the model of the keyboard hardware in use.
74 - The _location_ and _language_ of the user, because languages may
75 require [specific keys][language input keys] for their input methods,
76 such as the _muhenkan_ key on Japanese keyboard and the _Hanja_ key
77 for Korean keyboards. The keyboard are usually classified by the
78 [standard][keyboard standard] it is based on, e.g. ANSI, ISO, JIS,
80 - The keyboard _vendor:_ keyboard may have a set of keys that are not
81 standard, or may be specific to an OS.
85 The identifier of the general layout to use. It usually refers to a
86 country or a language.
90 Any minor variants on the general layout. It may be national variants
94 Set of extra options to customize the standard layouts.
96 Examples: switch modifiers keys, location of the compose key, etc.
101 KcCGST: <u>K</u>ey<u>c</u>odes, <u>C</u>ompat, <u>G</u>eometry,
102 <u>S</u>ymbols, <u>T</u>ypes @anchor KcCGST-intro
105 This is the low-level configuration of XKB and how the files are actually
106 organized in the _layout database_.
107 It is not really intuitive or straight-forward for the uninitiated.
109 @note _xkbcommon_ [does not offer an API for KcCGST](@ref KcCGST-support):
110 it is considered an implementation detail.
111 Instead, [RMLVO] is the preferred way for the user to configure XKB.
113 The KcCGST configuration consists of the following components:
118 A translation of the raw [key codes] from the keyboard into
121 <dt>Compatibility</dt>
123 A specification of what internal actions modifiers and various
124 special-purpose keys produce.
128 A description of the physical layout of a keyboard.
130 @attention This legacy feature is [not supported](@ref geometry-support)
135 A translation of symbolic key codes into actual [key symbols] (keysyms).
139 Types describe how a pressed key is affected by active [modifiers]
140 such as Shift, Control, Alt, etc.
144 <dt>Complete Keymap @anchor keymap-intro</dt>
146 A complete keymap is a _self-contained_ text file with all the [KcCGST]
147 components needed to configure a keyboard. This is the result of the
148 _resolution_ of the [RMLVO] and [KcCGST] configurations. This is also the
149 format used by X11 and Wayland when prompted to _serialize_ the keymap in use.
151 @note This is a low-level configuration. [RMLVO] is the preferred way for the
152 end user to configure XKB, but some _power users_ may need it for _avanced_
155 See the [XKB text format] for further details.
159 @note Layout making use of dead keys require a [Compose](@ref compose) file. The
160 same applies when if using a [Compose key].
162 [key codes]: @ref keycode-def
163 [key symbols]: @ref keysym-def
164 [levels]: @ref level-def
165 [modifiers]: @ref modifier-def
166 [RMLVO]: @ref RMLVO-intro
167 [KcCGST]: @ref KcCGST-intro
168 [complete keymap]: @ref keymap-intro
169 [Compose key]: https://en.wikipedia.org/wiki/Compose_key
170 [XKB text format]: @ref xkb-the-text-format
173 ## XKB the text format {#xkb-the-text-format}
175 A __text format__ to define keyboard keymaps. XKB 1.0 is the specification
176 implemented in current X servers. The format supported by _xkbcommon_
177 is very close to XKB 1.0, with some removals and additions. See the
178 [compatibility] page for further details.
180 The format supported by _xkbcommon_ is documented at the page
181 “[The XKB keymap text format, V1][keymap-text-format-v1]”.
183 The documentation of the _original_ XKB 1.0 format is much more scarce than
184 for the protocol. Some priceless resources are:
186 - [Ivan Pascal's XKB documentation][ivan-pascal]
187 - [An Unreliable Guide to XKB Configuration][unreliable-guide]
188 - [ArchWiki XKB page][arch-wiki]
190 [X Windows System]: https://en.wikipedia.org/wiki/X_Window_System
191 [X Protocol]: https://www.x.org/releases/current/doc/xproto/x11protocol.html#Keyboards
192 [XKB Protocol]: https://www.x.org/releases/current/doc/kbproto/xkbproto.html
193 [xkbcommon-x11]: @ref x11-overview
194 [Wayland]: https://wayland.freedesktop.org/docs/html/apa.html#protocol-spec-wl_keyboard
195 [compatibility]: @ref xkb-v1-compatibility
196 [keymap-text-format-v1]: @ref keymap-text-format-v1
197 [ivan-pascal]: https://web.archive.org/web/20190724015820/http://pascal.tsu.ru/en/xkb/
198 [unreliable-guide]: https://www.charvolant.org/doug/xkb/html/index.html
199 [arch-wiki]: https://wiki.archlinux.org/index.php/X_keyboard_extension
200 [keyboard model]: https://en.wikipedia.org/wiki/Computer_keyboard
201 [keymap]: https://en.wikipedia.org/wiki/Keyboard_layout
202 [keyboard layout]: https://en.wikipedia.org/wiki/Keyboard_layout
203 [xkeyboard-config]: https://gitlab.freedesktop.org/xkeyboard-config/xkeyboard-config
204 [keyboard standard]: https://en.wikipedia.org/wiki/Computer_keyboard#Types_and_standards
205 [language input keys]: https://en.wikipedia.org/wiki/Language_input_keys
207 @todo Explain how to configure XKB, with examples