xref: /aosp_15_r20/external/libxkbcommon/doc/rules-format.md (revision 2b949d0487e80d67f1fda82db69e101e761f8064)
1*2b949d04SAndroid Build Coastguard WorkerThe rules file
2*2b949d04SAndroid Build Coastguard Worker==============
3*2b949d04SAndroid Build Coastguard Worker
4*2b949d04SAndroid Build Coastguard WorkerThe purpose of the rules file is to map between configuration values
5*2b949d04SAndroid Build Coastguard Workerthat are easy for a user to specify and understand, and the
6*2b949d04SAndroid Build Coastguard Workerconfiguration values xkbcomp uses and understands.
7*2b949d04SAndroid Build Coastguard Worker
8*2b949d04SAndroid Build Coastguard Workerxkbcomp uses the xkb_component_names struct, which maps directly to
9*2b949d04SAndroid Build Coastguard Workerinclude statements of the appropriate sections, called for short
10*2b949d04SAndroid Build Coastguard WorkerKcCGST (see doc/keymap-format-text-v1.txt; 'G' stands for "geometry",
11*2b949d04SAndroid Build Coastguard Workerwhich is not supported). These are not really intuitive or straight-
12*2b949d04SAndroid Build Coastguard Workerforward for the uninitiated.
13*2b949d04SAndroid Build Coastguard Worker
14*2b949d04SAndroid Build Coastguard WorkerInstead, the user passes in a xkb_rule_names struct, which consists
15*2b949d04SAndroid Build Coastguard Workerof the name of a rules file (in Linux this is usually "evdev"), a
16*2b949d04SAndroid Build Coastguard Workerkeyboard model (e.g. "pc105"), a set of layouts (which will end up
17*2b949d04SAndroid Build Coastguard Workerin different groups, e.g. "us,fr"), variants (used to alter/augment
18*2b949d04SAndroid Build Coastguard Workerthe respective layout, e.g. "intl,dvorak"), and a set of options
19*2b949d04SAndroid Build Coastguard Worker(used to tweak some general behavior of the keyboard, e.g.
20*2b949d04SAndroid Build Coastguard Worker"ctrl:nocaps,compose:menu" to make the Caps Lock key act like Ctrl
21*2b949d04SAndroid Build Coastguard Workerand the Menu key like Compose). We call these RMLVO.
22*2b949d04SAndroid Build Coastguard Worker
23*2b949d04SAndroid Build Coastguard WorkerFormat of the file
24*2b949d04SAndroid Build Coastguard Worker------------------
25*2b949d04SAndroid Build Coastguard WorkerThe file consists of rule sets, each consisting of rules (one per
26*2b949d04SAndroid Build Coastguard Workerline), which match the MLVO values on the left hand side, and, if
27*2b949d04SAndroid Build Coastguard Workerthe values match to the values the user passed in, results in the
28*2b949d04SAndroid Build Coastguard Workervalues on the right hand side being added to the resulting KcCGST.
29*2b949d04SAndroid Build Coastguard WorkerSince some values are related and repeated often, it is possible
30*2b949d04SAndroid Build Coastguard Workerto group them together and refer to them by a group name in the
31*2b949d04SAndroid Build Coastguard Workerrules.
32*2b949d04SAndroid Build Coastguard Worker
33*2b949d04SAndroid Build Coastguard WorkerAlong with matching values by simple string equality, and for
34*2b949d04SAndroid Build Coastguard Workermembership in a group defined previously, rules may also contain
35*2b949d04SAndroid Build Coastguard Worker"wildcard" values - "*" - which always match. These usually appear
36*2b949d04SAndroid Build Coastguard Workernear the end.
37*2b949d04SAndroid Build Coastguard Worker
38*2b949d04SAndroid Build Coastguard WorkerGrammar
39*2b949d04SAndroid Build Coastguard Worker-------
40*2b949d04SAndroid Build Coastguard Worker(It might be helpful to look at a file like rules/evdev along with
41*2b949d04SAndroid Build Coastguard Workerthis grammar. Comments, whitespace, etc. are not shown.)
42*2b949d04SAndroid Build Coastguard Worker
43*2b949d04SAndroid Build Coastguard Worker```
44*2b949d04SAndroid Build Coastguard WorkerFile         ::= { "!" (Include | Group | RuleSet) }
45*2b949d04SAndroid Build Coastguard Worker
46*2b949d04SAndroid Build Coastguard WorkerInclude      ::= "include" <ident>
47*2b949d04SAndroid Build Coastguard Worker
48*2b949d04SAndroid Build Coastguard WorkerGroup        ::= GroupName "=" { GroupElement } "\n"
49*2b949d04SAndroid Build Coastguard WorkerGroupName    ::= "$"<ident>
50*2b949d04SAndroid Build Coastguard WorkerGroupElement ::= <ident>
51*2b949d04SAndroid Build Coastguard Worker
52*2b949d04SAndroid Build Coastguard WorkerRuleSet      ::= Mapping { Rule }
53*2b949d04SAndroid Build Coastguard Worker
54*2b949d04SAndroid Build Coastguard WorkerMapping      ::= { Mlvo } "=" { Kccgst } "\n"
55*2b949d04SAndroid Build Coastguard WorkerMlvo         ::= "model" | "option" | ("layout" | "variant") [ Index ]
56*2b949d04SAndroid Build Coastguard WorkerIndex        ::= "[" 1..XKB_NUM_GROUPS "]"
57*2b949d04SAndroid Build Coastguard WorkerKccgst       ::= "keycodes" | "symbols" | "types" | "compat" | "geometry"
58*2b949d04SAndroid Build Coastguard Worker
59*2b949d04SAndroid Build Coastguard WorkerRule         ::= { MlvoValue } "=" { KccgstValue } "\n"
60*2b949d04SAndroid Build Coastguard WorkerMlvoValue    ::= "*" | GroupName | <ident>
61*2b949d04SAndroid Build Coastguard WorkerKccgstValue  ::= <ident>
62*2b949d04SAndroid Build Coastguard Worker```
63*2b949d04SAndroid Build Coastguard Worker
64*2b949d04SAndroid Build Coastguard WorkerNotes:
65*2b949d04SAndroid Build Coastguard Worker
66*2b949d04SAndroid Build Coastguard Worker- Include processes the rules in the file path specified in the ident,
67*2b949d04SAndroid Build Coastguard Worker  in order. %-expansion is performed, as follows:
68*2b949d04SAndroid Build Coastguard Worker
69*2b949d04SAndroid Build Coastguard Worker```
70*2b949d04SAndroid Build Coastguard Worker  %%:
71*2b949d04SAndroid Build Coastguard Worker    A literal %.
72*2b949d04SAndroid Build Coastguard Worker
73*2b949d04SAndroid Build Coastguard Worker  %H:
74*2b949d04SAndroid Build Coastguard Worker    The value of the HOME environment variable.
75*2b949d04SAndroid Build Coastguard Worker
76*2b949d04SAndroid Build Coastguard Worker  %E:
77*2b949d04SAndroid Build Coastguard Worker    The extra lookup path for system-wide XKB data (usually /etc/xkb/rules).
78*2b949d04SAndroid Build Coastguard Worker
79*2b949d04SAndroid Build Coastguard Worker  %S:
80*2b949d04SAndroid Build Coastguard Worker    The system-installed rules directory (usually /usr/share/X11/xkb/rules).
81*2b949d04SAndroid Build Coastguard Worker```
82*2b949d04SAndroid Build Coastguard Worker
83*2b949d04SAndroid Build Coastguard Worker- The order of values in a Rule must be the same as the Mapping it
84*2b949d04SAndroid Build Coastguard Worker  follows. The mapping line determines the meaning of the values in
85*2b949d04SAndroid Build Coastguard Worker  the rules which follow in the RuleSet.
86*2b949d04SAndroid Build Coastguard Worker
87*2b949d04SAndroid Build Coastguard Worker- If a Rule is matched, %-expansion is performed on the KccgstValue,
88*2b949d04SAndroid Build Coastguard Worker  as follows:
89*2b949d04SAndroid Build Coastguard Worker
90*2b949d04SAndroid Build Coastguard Worker```
91*2b949d04SAndroid Build Coastguard Worker  %m, %l, %v:
92*2b949d04SAndroid Build Coastguard Worker     The model, layout or variant, if only one was given (e.g.
93*2b949d04SAndroid Build Coastguard Worker     %l for "us,il" is invalid).
94*2b949d04SAndroid Build Coastguard Worker
95*2b949d04SAndroid Build Coastguard Worker  %l[1], %v[1]:
96*2b949d04SAndroid Build Coastguard Worker     Layout or variant for the specified group Index, if more than
97*2b949d04SAndroid Build Coastguard Worker     one was given (e.g. %l[1] for "us" is invalid).
98*2b949d04SAndroid Build Coastguard Worker
99*2b949d04SAndroid Build Coastguard Worker  %+m, %+l, %+v, %+l[1], %+v[1]
100*2b949d04SAndroid Build Coastguard Worker     As above, but prefixed with '+'. Similarly, '|', '-', '_' may be
101*2b949d04SAndroid Build Coastguard Worker     used instead of '+'.
102*2b949d04SAndroid Build Coastguard Worker
103*2b949d04SAndroid Build Coastguard Worker  %(m), %(l), %(l[1]), %(v), %(v[1]):
104*2b949d04SAndroid Build Coastguard Worker     As above, but prefixed by '(' and suffixed by ')'.
105*2b949d04SAndroid Build Coastguard Worker```
106*2b949d04SAndroid Build Coastguard Worker
107*2b949d04SAndroid Build Coastguard Worker  In case the expansion is invalid, as described above, it is
108*2b949d04SAndroid Build Coastguard Worker  skipped (the rest of the string is still processed); this includes
109*2b949d04SAndroid Build Coastguard Worker  the prefix and suffix (that's why you shouldn't use e.g. "(%v[1])").
110