libxkbcommon 1.8.0
Library implementing the XKB specification for parsing keyboard descriptions and handling keyboard state
|
The purpose of the rules file is to map between configuration values that are easy for a user to specify and understand, and the configuration values that the keymap compiler, xkbcomp
, uses and understands. The following diagram presents an overview of this process. See the XKB introduction for further details on the components.
libxkbcommon
’s keymap compiler xkbcomp
uses the xkb_component_names
struct internally, which maps directly to include statements of the appropriate sections (called KcCGST for short):
These are not really intuitive nor straightforward for the uninitiated. Instead, the user passes in a xkb_rule_names
struct, which consists of the following fields (called RMLVO for short):
The file consists of rule sets, each consisting of rules (one per line), which match the MLVO values on the left hand side, and, if the values match to the values the user passed in, results in the values on the right hand side being added to the resulting KcCGST. See RMLVO resolution process for further details.
Since some values are related and repeated often, it is possible to group them together and refer to them by a group name in the rules.
Along with matching values by simple string equality and for membership in a group defined previously, rules may also contain wildcard values “*” with the following behavior:
model
and options
: always match.layout
and variant
: match any non-empty value. These usually appear near the end of a rule set to set default values.It is advised to look at a file like rules/evdev
along with this grammar.
ident
, in order. %-expansion is performed, as follows: %%
%H
$HOME
environment variable. %E
/etc/xkb/rules
). %S
/usr/share/X11/xkb/rules
). (Since version 1.8.0
) The following special indexes can be used to avoid repetition and clarify the semantics:
single
layout[single]
is the same as without explicit index: layout
. first
layout
and layout[1]
. later
layout[2]
.. layout[4]
. layout
, layout[1]
.. layout[4]
. When using a layout index range (later
, any
), the %i expansion can be used in the KccgstValue
to refer to the index of the matched layout.
Rule
must be the same as the Mapping
it follows. The mapping line determines the meaning of the values in the rules which follow in the RuleSet
.If a Rule
is matched, %-expansion is performed on the KccgstValue
, as follows:
%m
, %l
, %v
%l
for “us,il” is invalid). %l[1]
, %l[2]
, …, %v[1]
, %v[2]
, … Index
, if more than one was given, e.g.: %l[1]
is invalid for “us” but expands to “us” for “us,de”. %+m
, %+l
, %+l[1]
, %+l[2]
, …, %+v
, %+v[1]
, %+v[2]
, … %(m)
, %(l)
, %(l[1])
, %(l[2])
, …, %(v)
, %(v[1])
, %(v[2])
, … :%i
, %l[%i]
, %(l[%i])
, etc. 1.8.0
) In case the mapping uses a special index, %i
corresponds to the index of the matched layout. In case the expansion is invalid, as described above, it is skipped (the rest of the string is still processed); this includes the prefix and suffix. This is why one should use e.g. %(v[1])
instead of (%v[1])
. See Example: layouts, variants and symbols for an illustration.
(Since version 1.8.0
) If a Rule
is matched, the :all
qualifier in the KccgstValue
applies the qualified value (and its optional merge mode) to all layouts. If there is no merge mode, it defaults to override +
.
KccgstValue | Layouts count | Final KccgstValue |
---|---|---|
x:all | 1 | x:1 |
2 | x:1+x:2 | |
+x:all | 1 | +x:1 |
3 | +x:1+x:2+x:3 | |
|x:all | 1 | |x:1 |
4 | |x:1|x:2|x:3|x:4 | |
x|y:all | 1 | x|y:1 |
3 | x|y:1|y:2|y:3 | |
x:all+y|z:all | 2 | x:1+x:2+y|z:1|z:2 |
First of all, the rules file is extracted from the provided RMLVO configuration (usually evdev
). Then its path is resolved and the file is parsed to get the rule sets.
Then each rule set is checked against the provided MLVO configuration, following their order in the rules file.
If a rule matches in a rule set, then:
The KcCGST value of the rule is used to update the KcCGST configuration, using the following instructions. Note that foo
and bar
are placeholders; ‘+’ specifies the override merge mode and can be replaced by ‘|’ to specify the augment merge mode instead.
Rule value | Old KcCGST value | New KcCGST value |
---|---|---|
bar | bar | |
bar | foo | foo (skip bar ) |
bar | +foo | bar+foo (prepend) |
+bar | +bar | |
+bar | foo | foo+bar |
+bar | +foo | +foo+bar |
Using the following example:
we would have the following resolutions of key codes:
Model | Layout | Keycodes |
---|---|---|
jollasbj | us | evdev+jolla(jolla)+aliases(qwerty) |
olpc | be | evdev+olpc(olpc)+aliases(azerty) |
pc | al | evdev+aliases(qwertz) |
Using the following example:
we would have the following resolutions of symbols:
Layout | Variant | Symbols | Rules sets used |
---|---|---|---|
us | pc+us | #1 | |
us | intl | pc+us(intl) | #1 |
us,es | pc+us+es:2 | #2, #3 | |
us,es,fr | intl,,bepo | pc+us(intl)+es:2+fr(bepo):3 | #2, #3, #4 |
Since version 1.8.0
, the previous code can be replaced with simply:
Using the following example:
we would have the following resolutions of symbols:
Layout | Option | Symbols |
---|---|---|
be | caps:digits_row | pc+be+capslock(digits_row) |
gb | caps:digits_row | pc+gb |
fr | misc:typo | pc+fr+typo(base) |
fr | misc:typo,caps:digits_row | pc+fr+capslock(digits_row)+typo(base) |
fr | lv3:ralt_alt,caps:digits_row,misc:typo | pc+fr+capslock(digits_row)+typo(base)+level3(ralt_alt) |
fr,gb | caps:digits_row,misc:typo | pc+fr+gb:2+capslock(digits_row)+typo(base):1+typo(base):2 |
Note that the configuration with gb
layout has no match for the option caps:digits_row
and that the order of the options in the RMLVO configuration has no influence on the resulting symbols, as it depends solely on their order in the rules.
Since version 1.8.0
, the previous code can be replaced with simply: