libxkbcommon 1.7.0
|
This page describes how to add a custom layout or option so that it will be parsed by libxkbcommon.
libxkbcommon searches the following paths for XKB configuration files:
$XDG_CONFIG_HOME/xkb/
, or $HOME/.config/xkb/
if the $XDG_CONFIG_HOME
environment variable is not defined$HOME/.xkb/
$XKB_CONFIG_EXTRA_PATH
if set, otherwise <sysconfdir>/xkb
(on most distributions this is /etc/xkb
)$XKB_CONFIG_ROOT
if set, otherwise <datadir>/X11/xkb/
(path defined by the xkeyboard-config
package, on most distributions this is /usr/share/X11/xkb
)A keymap created with xkb_keymap::xkb_keymap_new_from_names()
will look up those paths in order until the required data is found.
<datadir>
) path is available.Each directory should have one or more of the following subdirectories:
compat
geometry
(libxkbcommon ignores this directory)keycodes
rules
symbols
types
The majority of user-specific configurations involve modifying key symbols and this is what this document focuses on. For use-cases where a user may need to add new key types or compat entries the general approach remains the same. A detailed description for how to add those types or compat entries is out of scope for this document.
You should never need to add user-specific keycodes. Where a keycode is missing, the addition should be filed in the upstream xkeyboard-config project.
Due to how XKB is configured, there is no such thing as a "layout" in XKB itself, or, indeed, any of the rules, models, variant, options (RMLVO) described in struct xkb_rule_names
. RMLVO names are merely lookup keys in the rules file provided by xkeyboard-config to map to the correct keycode, compat, geometry (ignored by libxkbcommon), symbols and types (KcCGST). The KcCGST data is the one used by XKB and libxkbcommon to map keys to actual symbols.
For example, a common RMLVO configuration is layout "us", variant "dvorak" and option "terminate:ctrl_alt_bksp". Using the default rules file and model this maps into the following KcCGST components:
A detailed explanation of how rules files convert RMLVO to KcCGST is out of scope for this document. See the rules file page instead.
Adding a layout requires that the user adds symbols in the correct location.
The default rules files (usually evdev
) have a catch-all to map a layout, say "foo", and a variant, say "bar", into the "bar" section in the file $xkb_base_dir/symbols/foo
. This is sufficient to define a new keyboard layout. The example below defines the keyboard layout "banana" with an optional variant "orange":
The default
section is loaded when no variant is given. The first example sections uses include
to populate with a symbols list defined elsewhere (here: section basic
from the file symbols/us
, aka. the default US keyboard layout) and overrides parts of these symbols. The effect of this section is to swap the numbers and symbols in the top-most row (compared to the US layout) but otherwise use the US layout.
The "orange" variant uses the "banana" symbols and includes a different section to define the eurosign. It does not specificially override any symbols.
The exact details of how xkb_symbols
work is out of scope for this document.
For technical reasons, options do not have a catch-all to map option names to files and sections and must be specifically mapped by the user. This requires a custom rules file. As the evdev
ruleset is hardcoded in many clients, the custom rules file must usually be named evdev
.
This rules file maps the RMLVO option "custom:foo" to the "bar" section in the symbols/custom
file and the "custom:baz" option to the "baz" section in the symbols/other
file. Note how the RMLVO option name may be different to the file or section name.
The include
statement includes the system-provided evdev
ruleset. This allows users to only override those options they need.
The files themselves are similar to the layout examples in the previous section:
With these in place, a user may select any layout/variant together with the "custom:foo" and/or "custom:baz" options.
libxkbregistry
as XKB lookup tool and does not work where clients parse the XML file directly.The above sections apply only to the data files and require that the user knows about the existence of the new entries. To make custom entries discoverable by the configuration tools (e.g. the GNOME Control Center), the new entries must also be added to the XML file that is parsed by libxkbregistry
. In most cases, this is the evdev.xml
file in the rules directory. The example below shows the XML file that would add the custom layout and custom options as outlined above to the XKB registry:
The default behavior of libxkbregistry
ensures that the new layout and options are added to the system-provided layouts and options.
For details on the XML format, see the DTD in <datadir>/X11/xkb/rules/xkb.dtd
and the system-provided XML files <datadir>/X11/xkb/rules/*.xml
.