Home | History | Annotate | Line # | Download | only in docs
      1  1.1.1.6  mrg 
      2  1.1.1.6  mrg                       How to enhance XKB configuration
      3      1.1  mrg 
      4      1.1  mrg                          Kamil Toman, Ivan U. Pascal
      5      1.1  mrg 
      6      1.1  mrg                               25 November 2002
      7      1.1  mrg 
      8      1.1  mrg                                   Abstract
      9      1.1  mrg 
     10  1.1.1.6  mrg      This guide is aimed at alleviating one's labour when creating a
     11  1.1.1.6  mrg      new (internationalized) keyboard layout. Unlike other documents,
     12  1.1.1.6  mrg      this guide emphasizes the keymap developer's point of view.
     13  1.1.1.6  mrg 
     14      1.1  mrg 
     15      1.1  mrg 1.  Overview
     16      1.1  mrg 
     17  1.1.1.6  mrg The developer of a new layout should read the XKB protocol specification
     18  1.1.1.6  mrg (The X Keyboard Extension: Protocol Specification [1]) at least to clarify
     19  1.1.1.6  mrg for themselves some XKB-specific terms used in this document and elsewhere
     20  1.1.1.6  mrg in XKB configuration. It is also wise to understand how the X server and
     21  1.1.1.6  mrg a client digest their keyboard inputs (with and without XKB).
     22  1.1.1.6  mrg 
     23  1.1.1.6  mrg Another useful source is Ivan Pascal's text about XKB configuration [2].
     24  1.1.1.6  mrg 
     25  1.1.1.6  mrg    [1] https://www.x.org/docs/XKB/XKBproto.pdf
     26  1.1.1.6  mrg    [2] http://pascal.tsu.ru/en/xkb/
     27      1.1  mrg 
     28      1.1  mrg Note that this document covers only enhancements which are to be made to
     29  1.1.1.6  mrg XFree86 versions 4.3.x and newer.
     30  1.1.1.6  mrg 
     31      1.1  mrg 
     32      1.1  mrg 2.  The Basics
     33      1.1  mrg 
     34  1.1.1.6  mrg At boottime (or later at the user's command) the X server starts its xkb
     35  1.1.1.6  mrg keyboard extension module and reads data from a compiled configuration file.
     36      1.1  mrg 
     37      1.1  mrg This compiled configuration file is prepared by the program xkbcomp which
     38  1.1.1.6  mrg behaves altogether as an ordinary compiler (see man xkbcomp). Its input are
     39  1.1.1.6  mrg human-readable xkb configuration files which are verified and then composed
     40      1.1  mrg into a useful xkb configuration. Users don't need to mess with xkbcomp them-
     41  1.1.1.6  mrg selves, for them it is invisible. Usually, it is run upon X server startup.
     42      1.1  mrg 
     43  1.1.1.6  mrg As you probably already know, XKB configuration consists of five main
     44      1.1  mrg modules:
     45      1.1  mrg 
     46      1.1  mrg       Keycodes
     47  1.1.1.6  mrg             Tables that define the translation from keyboard scan codes into
     48  1.1.1.6  mrg             reasonably symbolic names, maximum and minimum valid keycodes,
     49  1.1.1.6  mrg             symbolic aliases, and a description of physically present LED-indica-
     50  1.1.1.6  mrg             tors. The primary sense of this component is to allow definitions
     51      1.1  mrg             of maps of symbols (see below) to be independent of physical key-
     52  1.1.1.6  mrg             board scancodes. There are two main conventions for symbolic
     53  1.1.1.6  mrg             names (always four bytes long):
     54      1.1  mrg 
     55  1.1.1.6  mrg                o  names which express some traditional meaning, like <SPCE>
     56  1.1.1.6  mrg                   (which stands for space bar)
     57      1.1  mrg 
     58  1.1.1.6  mrg                o  names which express a relative position on the keyboard,
     59  1.1.1.6  mrg                   for example <AE01> (the exclamation mark on US keyboards),
     60  1.1.1.6  mrg                   with on its right the keys <AE02>, <AE03>, etc.
     61      1.1  mrg 
     62      1.1  mrg       Types
     63  1.1.1.6  mrg             Types describe how the pressed key is affected by active modifiers
     64  1.1.1.6  mrg             (like Shift, Control, Alt, ...). There are several predefined
     65  1.1.1.6  mrg             types which cover most of the usual combinations.
     66      1.1  mrg 
     67      1.1  mrg       Compat
     68  1.1.1.6  mrg             The compatibility component defines the internal behaviour of
     69  1.1.1.6  mrg             modifiers. Using the compat component you can assign various
     70  1.1.1.6  mrg             actions (elaborately described in the XKB specification) to key
     71  1.1.1.6  mrg             events. This is also the place where LED-indicators behaviour
     72  1.1.1.6  mrg             is defined.
     73      1.1  mrg 
     74      1.1  mrg       Symbols
     75      1.1  mrg             For i18n purposes, this is the most important table. It defines
     76      1.1  mrg             what values (=symbols) are assigned to what keycodes (represented
     77  1.1.1.6  mrg             by their symbolic name, see above). More than one value may be
     78  1.1.1.6  mrg             defined for each key and then it depends on the key type and on
     79  1.1.1.6  mrg             the modifiers state (respective compat component) which value
     80  1.1.1.6  mrg             will be the resulting one when the key is pressed.
     81      1.1  mrg 
     82      1.1  mrg       Geometry
     83      1.1  mrg             Geometry files aren't used by xkb itself but they may be used by
     84      1.1  mrg             some external programs to depict a keyboard image.
     85      1.1  mrg 
     86  1.1.1.6  mrg All these components have their files located in the xkb configuration tree,
     87  1.1.1.6  mrg in subdirectories with the same name (usually in /usr/share/X11/xkb).
     88  1.1.1.6  mrg 
     89      1.1  mrg 
     90  1.1.1.6  mrg 3.  Enhancing the XKB Configuration
     91      1.1  mrg 
     92  1.1.1.6  mrg Most of XKB enhancements are about a need to define new output symbols for
     93      1.1  mrg some input key events. In other words, a need to define a new symbol map (for
     94  1.1.1.6  mrg a new language, or standard, or just to feel more comfortable when typing text).
     95      1.1  mrg 
     96  1.1.1.6  mrg What do you need to do? Generally, you have to define the following things:
     97      1.1  mrg 
     98      1.1  mrg    o  the map of symbols itself
     99      1.1  mrg 
    100      1.1  mrg    o  the rules to allow users to select the new mapping
    101      1.1  mrg 
    102      1.1  mrg    o  the description of the new layout
    103      1.1  mrg 
    104      1.1  mrg First of all, it is good to go through existing layouts and to examine them
    105  1.1.1.6  mrg to see if there is something you could easily adjust to fit your needs. Even
    106  1.1.1.6  mrg if there is nothing similar, you may get some ideas about the basic concepts
    107  1.1.1.6  mrg and used tricks.
    108  1.1.1.6  mrg 
    109  1.1.1.6  mrg 3.1  Levels and Groups
    110  1.1.1.6  mrg 
    111  1.1.1.6  mrg Since XFree86 4.3.0, you can use multiple layouts in the xkb configuration.
    112  1.1.1.6  mrg Though still within the boundaries of the xkb protocol and its general ideas,
    113  1.1.1.6  mrg the keymap designer must obey new rules when creating new maps. In exchange
    114  1.1.1.6  mrg we get a more powerful and cleaner configuration system.
    115      1.1  mrg 
    116      1.1  mrg Remember that it is the application which must decide which symbol matches
    117  1.1.1.6  mrg which keycode according to the effective modifier state. The X server itself
    118  1.1.1.6  mrg sends only an input event message. Of course, usually the interpretation is
    119  1.1.1.6  mrg done by Xlib, Xaw, Motif, Qt, Gtk, or similar libraries. The X server only
    120  1.1.1.6  mrg supplies its mapping table (usually upon application startup).
    121      1.1  mrg 
    122  1.1.1.6  mrg You can think of the X server's symbol table as of an irregular table where
    123      1.1  mrg each keycode has its row and where each combination of modifiers determines
    124      1.1  mrg exactly one column. The resulting cell then gives the proper symbolic value.
    125  1.1.1.6  mrg Not all keycodes need to bind different values for different combinations of
    126  1.1.1.6  mrg modifiers. The <ENTER> key, for instance, usually doesn't depend on any modi-
    127  1.1.1.6  mrg fiers so it has in its row only one column defined.
    128      1.1  mrg 
    129      1.1  mrg Note that in XKB there is no prior assumption that certain modifiers are
    130  1.1.1.6  mrg bound to certain columns. By editing the proper files (see Key Types, below)
    131  1.1.1.6  mrg this mapping can be changed as well.
    132      1.1  mrg 
    133  1.1.1.6  mrg Unlike the original X protocol, the XKB approach is far more flexible.
    134  1.1.1.6  mrg XKB introduces one additional term: the group. You can think of a group
    135  1.1.1.6  mrg as of a vector of columns per keycode (naturally the dimension of this
    136      1.1  mrg vector may differ for different keycodes). What is it good for? The group is
    137      1.1  mrg not very useful unless you intend to use more than one logically different
    138      1.1  mrg set of symbols (like more than one alphabet) defined in a single mapping ta-
    139  1.1.1.6  mrg ble. But then the group has a natural meaning: each symbol set has its own
    140  1.1.1.6  mrg group and changing it means selecting a different one. The XKB approach allows
    141      1.1  mrg up to four different groups. The columns inside each group are called (shift)
    142  1.1.1.6  mrg levels. The X server knows what the current group is and reports it together
    143  1.1.1.6  mrg with the modifier state and the keycode in key events.
    144      1.1  mrg 
    145      1.1  mrg To sum it up:
    146      1.1  mrg 
    147  1.1.1.6  mrg    o  for each keycode the XKB keyboard map contains up to four one-dimensional
    148  1.1.1.6  mrg       tables - groups (logically different symbol sets)
    149      1.1  mrg 
    150  1.1.1.6  mrg    o  for each group of a keycode the XKB keyboard map contains some columns -
    151  1.1.1.6  mrg       shift levels (values reached by combinations of Shift, Ctrl, Alt, ...
    152  1.1.1.6  mrg       modifiers)
    153      1.1  mrg 
    154      1.1  mrg    o  different keycodes can have different number of groups
    155      1.1  mrg 
    156  1.1.1.6  mrg    o  different groups of one keycode can have different number of shift levels
    157      1.1  mrg 
    158  1.1.1.6  mrg    o  the current group number is tracked by the X server
    159      1.1  mrg 
    160  1.1.1.6  mrg It is clear that if you sanely define levels and groups, and sanely bind modi-
    161  1.1.1.6  mrg fiers and associated actions, you can have loaded simultaneously up to four
    162      1.1  mrg different symbol sets where each of them would reside in its own group.
    163      1.1  mrg 
    164      1.1  mrg The multi-layout concept provides a facility to manipulate xkb groups and
    165  1.1.1.6  mrg symbol definitions in a way that allows almost arbitrary composition of
    166  1.1.1.6  mrg predefined symbol tables. To keep it fully functional you have to:
    167      1.1  mrg 
    168      1.1  mrg    o  define all symbols only in the first group
    169      1.1  mrg 
    170      1.1  mrg    o  (re)define any modifiers with extra care to avoid strange (anisometric)
    171  1.1.1.6  mrg       behaviour
    172  1.1.1.6  mrg 
    173      1.1  mrg 
    174      1.1  mrg 4.  Defining New Layouts
    175      1.1  mrg 
    176  1.1.1.6  mrg See "Some Words About XKB internals" [3] for an explanation of used XKB
    177  1.1.1.6  mrg terms and problems addressed by the XKB extension.
    178  1.1.1.6  mrg 
    179  1.1.1.6  mrg See "Common notes about XKB configuration files language" [4] for a more
    180  1.1.1.6  mrg precise explanation of the syntax of XKB configuration files.
    181  1.1.1.6  mrg 
    182  1.1.1.6  mrg    [3] http://pascal.tsu.ru/en/xkb/internals.html
    183  1.1.1.6  mrg    [4] http://pascal.tsu.ru/en/xkb/gram-common.html
    184      1.1  mrg 
    185      1.1  mrg 4.1  Predefined XKB Symbol Sets
    186      1.1  mrg 
    187      1.1  mrg If you are about to define some European symbol map extension, you might want
    188  1.1.1.6  mrg to use one of four predefined Latin alphabet layouts.
    189      1.1  mrg 
    190  1.1.1.6  mrg Okay, let's assume you want to extend an existing keymap and you want to over-
    191      1.1  mrg ride a few keys. Let's take a simple U.K. keyboard as an example (defined in
    192      1.1  mrg pc/gb):
    193      1.1  mrg 
    194  1.1.1.5  mrg      default partial alphanumeric_keys
    195      1.1  mrg      xkb_symbols "basic" {
    196  1.1.1.6  mrg 
    197      1.1  mrg        include "pc/latin"
    198      1.1  mrg 
    199      1.1  mrg        name[Group1]="Great Britain";
    200      1.1  mrg 
    201      1.1  mrg        key <AE02>  { [         2,   quotedbl,  twosuperior,    oneeighth ] };
    202      1.1  mrg        key <AE03>  { [         3,   sterling, threesuperior,    sterling ] };
    203      1.1  mrg        key <AC11>  { [apostrophe,         at, dead_circumflex, dead_caron] };
    204      1.1  mrg        key <TLDE>  { [     grave,    notsign,          bar,          bar ] };
    205      1.1  mrg        key <BKSL>  { [numbersign, asciitilde,   dead_grave,   dead_breve ] };
    206  1.1.1.6  mrg 
    207      1.1  mrg        key <RALT>  { type[Group1]="TWO_LEVEL",
    208  1.1.1.6  mrg                      [ ISO_Level3_Shift, Multi_key ] };
    209      1.1  mrg 
    210      1.1  mrg        modifier_map Mod5   { <RALT> };
    211      1.1  mrg      };
    212      1.1  mrg 
    213  1.1.1.6  mrg It defines a new layout in the basic variant as an extension of a common latin
    214      1.1  mrg alphabet layout. The layout (symbol set) name is set to "Great Britain".
    215  1.1.1.6  mrg Then there are redefinitions of a few keycodes and a modifier binding. As
    216  1.1.1.6  mrg you can see, the number of shift levels is the same for the <AE02>, <AE03>,
    217  1.1.1.6  mrg <AC11>, <TLDE> and <BKSL> keys but it differs from the number of shift
    218  1.1.1.6  mrg levels of <RALT>.
    219      1.1  mrg 
    220      1.1  mrg Note that the <RALT> key itself is a binding key for Mod5 and that it serves
    221  1.1.1.6  mrg like a shift modifier for LevelThree, and together with Shift as a Compose key.
    222  1.1.1.6  mrg It is a good habit to respect this rule in a new similar layout.
    223      1.1  mrg 
    224      1.1  mrg Okay, you could now define more variants of your new layout besides basic
    225      1.1  mrg simply by including (augmenting/overriding/...) the basic definition and
    226      1.1  mrg altering what may be needed.
    227      1.1  mrg 
    228      1.1  mrg 4.2  Key Types
    229      1.1  mrg 
    230  1.1.1.6  mrg The differences in the number of columns (shift levels) are caused by the
    231  1.1.1.6  mrg different types of the keys (see the Types definition in section The Basics).
    232  1.1.1.6  mrg Most keycodes have implicitly set the keytype in the included "pc/latin" file
    233  1.1.1.6  mrg to "FOUR_LEVEL_ALPHABETIC". The only exception is the <RALT> keycode which is
    234      1.1  mrg explicitly set "TWO_LEVEL" keytype.
    235      1.1  mrg 
    236      1.1  mrg All those names refer to pre-defined shift level schemes. Usually you can
    237  1.1.1.6  mrg choose a suitable shift level scheme from the default types scheme list in
    238  1.1.1.6  mrg the proper xkb component's subdirectory.
    239      1.1  mrg 
    240      1.1  mrg The most used schemes are:
    241      1.1  mrg 
    242      1.1  mrg       ONE_LEVEL
    243  1.1.1.6  mrg             The key does not depend on any modifiers. The symbol from the
    244  1.1.1.6  mrg             first level is always chosen.
    245      1.1  mrg 
    246      1.1  mrg       TWO_LEVEL
    247  1.1.1.6  mrg             The key uses the modifier Shift and may have two possible values.
    248  1.1.1.6  mrg             The second level is chosen by the Shift modifier. If the Lock
    249  1.1.1.6  mrg             modifier (usually Caps-lock) applies, the symbol is further
    250  1.1.1.6  mrg             processed using system-specific capitalization rules. If both
    251  1.1.1.6  mrg             the Shift and Lock modifiers apply, the symbol from the second
    252  1.1.1.6  mrg             level is taken and capitalization rules are applied (but usually
    253  1.1.1.6  mrg             have no effect).
    254      1.1  mrg 
    255      1.1  mrg       ALPHABETIC
    256  1.1.1.6  mrg             The key uses the modifiers Shift and Lock. It may have two
    257  1.1.1.6  mrg             possible values. The second level is chosen by Shift. When the
    258      1.1  mrg             Lock modifier applies, the symbol from the first level is taken
    259      1.1  mrg             and further processed using system-specific capitalization rules.
    260  1.1.1.6  mrg             If both the Shift and Lock modifiers apply, the symbol from the
    261  1.1.1.6  mrg             first level is taken and no capitalization rules are applied.
    262  1.1.1.6  mrg             This is often called shift-cancels-caps behaviour.
    263      1.1  mrg 
    264      1.1  mrg       THREE_LEVEL
    265  1.1.1.6  mrg             Is the same as TWO_LEVEL but it considers an extra modifier:
    266  1.1.1.6  mrg             LevelThree, which can be used to gain the symbol value from the
    267  1.1.1.6  mrg             third level. If both the Shift and LevelThree modifiers apply,
    268  1.1.1.6  mrg             the value from the third level is taken. As in TWO_LEVEL, the
    269  1.1.1.6  mrg             Lock modifier doesn't influence the resulting level - only Shift
    270  1.1.1.6  mrg             and LevelThree are taken into consideration. If the Lock modifier
    271  1.1.1.6  mrg             is active, capitalization rules are applied to the resulting
    272      1.1  mrg             symbol.
    273      1.1  mrg 
    274      1.1  mrg       FOUR_LEVEL
    275  1.1.1.6  mrg             Is the same as THREE_LEVEL but, unlike THREE_LEVEL, if both the
    276  1.1.1.6  mrg             Shift and LevelThree modifiers apply, the symbol is taken from
    277  1.1.1.6  mrg             the fourth level.
    278      1.1  mrg 
    279      1.1  mrg       FOUR_LEVEL_ALPHABETIC
    280      1.1  mrg             Is similar to FOUR_LEVEL but also defines shift-cancels-caps
    281  1.1.1.6  mrg             behaviour as in ALPHABETIC. If both Lock and LevelThree apply,
    282  1.1.1.6  mrg             the symbol from the third level is taken and the capitalization
    283  1.1.1.6  mrg             rules are applied. If all three modifiers (Lock and Shift and
    284  1.1.1.6  mrg             LevelThree) apply, the symbol from the third level is taken and
    285  1.1.1.6  mrg             no capitalization rules are applied
    286      1.1  mrg 
    287      1.1  mrg       KEYPAD
    288  1.1.1.6  mrg             As the name suggest, this scheme is primarily used for numeric
    289  1.1.1.6  mrg             keypads. The scheme considers two modifiers: Shift and NumLock.
    290  1.1.1.6  mrg             If none of the modifiers applies, the symbol from the first level
    291  1.1.1.6  mrg             is taken. If either the Shift or the NumLock modifier apply, the
    292  1.1.1.6  mrg             symbol from the second level is taken. If both the Shift and the
    293  1.1.1.6  mrg             NumLock modifier apply, the symbol from the first level is taken.
    294  1.1.1.6  mrg             Again, a shift-cancels-caps variant.
    295      1.1  mrg 
    296      1.1  mrg       FOUR_LEVEL_KEYPAD
    297  1.1.1.6  mrg             Is similar to the KEYPAD scheme but considers also the LevelThree
    298  1.1.1.6  mrg             modifier. If the LevelThree modifier applies, the symbol from the
    299  1.1.1.6  mrg             third level is taken. If both Shift and LevelThree or NumLock and
    300  1.1.1.6  mrg             LevelThree apply, the symbol from the fourth level is taken. If
    301  1.1.1.6  mrg             all three (Shift+NumLock+LevelThree) apply, the symbol from the
    302  1.1.1.6  mrg             third level is taken. This also is a shift-cancels-caps variant.
    303      1.1  mrg 
    304      1.1  mrg       FOUR_LEVEL_MIXED_KEYPAD
    305  1.1.1.6  mrg             A four-level keypad scheme where the first two levels behave like
    306  1.1.1.6  mrg             the KEYPAD scheme (with Shift and NumLock). The LevelThree modifier
    307  1.1.1.6  mrg             acts as an override, providing access to two normally Shift-ed
    308  1.1.1.6  mrg             levels: when LevelThree is active we ignore the NumLock state.
    309  1.1.1.6  mrg             Intended for the digit area of the keypad.
    310      1.1  mrg 
    311      1.1  mrg       FOUR_LEVEL_X
    312      1.1  mrg             A four-level scheme where the base level accepts no modifier,
    313  1.1.1.6  mrg             LevelThree provides two more Shift-ed levels (levels 2 and 3),
    314  1.1.1.6  mrg             and Ctrl plus Alt command the fourth level. Intended for the
    315  1.1.1.6  mrg             operator part of a keypad, though since NumLock plays no part,
    316  1.1.1.6  mrg             it is not keypad-specific.
    317      1.1  mrg 
    318  1.1.1.6  mrg Besides that, there are some schemes for special purposes:
    319      1.1  mrg 
    320      1.1  mrg       PC_CONTROL_LEVEL2
    321  1.1.1.6  mrg             Similar to the TWO_LEVEL scheme but it considers the Control
    322  1.1.1.6  mrg             modifier rather than Shift. That means, the symbol from the
    323  1.1.1.6  mrg             second level is chosen by Control rather than by Shift.
    324      1.1  mrg 
    325      1.1  mrg       PC_ALT_LEVEL2
    326  1.1.1.6  mrg             Similar to the TWO_LEVEL scheme but it considers the Alt
    327  1.1.1.6  mrg             modifier rather than Shift. That means, the symbol from
    328  1.1.1.6  mrg             the second level is chosen by Alt rather than by Shift.
    329      1.1  mrg 
    330      1.1  mrg       CTRL+ALT
    331  1.1.1.6  mrg             The key uses the modifiers Alt and Control. It may have two
    332  1.1.1.6  mrg             possible values. If just one modifier (Alt or Control) applies,
    333  1.1.1.6  mrg             the symbol from the first level is chosen. Only if both the Alt
    334  1.1.1.6  mrg             and Control modifiers apply, the symbol from the second level
    335  1.1.1.6  mrg             is chosen.
    336      1.1  mrg 
    337      1.1  mrg       SHIFT+ALT
    338  1.1.1.6  mrg             The key uses the modifiers Shift and Alt. It may have two
    339  1.1.1.6  mrg             possible values. If just one modifier (Alt or Shift) applies,
    340  1.1.1.6  mrg             the symbol from the first level is chosen. Only if both the
    341  1.1.1.6  mrg             Alt and Shift modifiers apply, the symbol from the second
    342  1.1.1.6  mrg             level is chosen.
    343      1.1  mrg 
    344      1.1  mrg If needed, special caps schemes may be used. They redefine the standard
    345      1.1  mrg behaviour of all *ALPHABETIC types. The layouts (maps of symbols) with keys
    346      1.1  mrg defined in respective types then automatically change their behaviour accord-
    347      1.1  mrg ingly. Possible redefinitions are:
    348      1.1  mrg 
    349      1.1  mrg    o internal
    350      1.1  mrg 
    351      1.1  mrg    o internal_nocancel
    352      1.1  mrg 
    353      1.1  mrg    o shift
    354      1.1  mrg 
    355      1.1  mrg    o shift_nocancel
    356      1.1  mrg 
    357      1.1  mrg None of these schemes should be used directly. They are defined merely for
    358  1.1.1.6  mrg the 'caps:' xkb option (used to globally change the layouts behaviour).
    359      1.1  mrg 
    360  1.1.1.6  mrg Don't alter any of the existing key types. If you need a different behaviour,
    361  1.1.1.6  mrg create a new type.
    362      1.1  mrg 
    363  1.1.1.6  mrg 4.2.1  More on Definitions of Types
    364      1.1  mrg 
    365  1.1.1.6  mrg When the XKB software deals with a separate type description, it gets a com-
    366      1.1  mrg plete list of modifiers that should be taken into account from the 'modi-
    367  1.1.1.6  mrg fiers=<list of modifiers>' list and expects a set of 'map[<combination of
    368  1.1.1.6  mrg modifiers>]=<level indication>' instructions that contain the mapping for
    369      1.1  mrg each combination of modifiers mentioned in that list. Modifiers that are not
    370      1.1  mrg explicitly listed are NOT taken into account when the resulting shift level
    371  1.1.1.6  mrg is computed. If some combination is omitted, the program (subroutine) should
    372      1.1  mrg choose the first level for this combination (a quite reasonable behavior).
    373      1.1  mrg 
    374  1.1.1.6  mrg Let's consider an example with two modifiers, ModOne and ModTwo:
    375      1.1  mrg 
    376      1.1  mrg      type "..." {
    377      1.1  mrg          modifiers = ModOne+ModTwo;
    378      1.1  mrg          map[None] = Level1;
    379      1.1  mrg          map[ModOne] = Level2;
    380      1.1  mrg      };
    381      1.1  mrg 
    382  1.1.1.6  mrg In this case the map has a statement for ModOne only and ModOne+ModTwo is
    383  1.1.1.6  mrg omitted. This means that if ModTwo is active, the subroutine can't find an
    384  1.1.1.6  mrg explicit mapping for this combination and will use the default level, i.e.
    385      1.1  mrg Level1.
    386      1.1  mrg 
    387  1.1.1.6  mrg But in the case that the type is described as:
    388      1.1  mrg 
    389      1.1  mrg      type "..." {
    390      1.1  mrg          modifiers = ModOne;
    391      1.1  mrg          map[None] = Level1;
    392      1.1  mrg          map[ModOne] = Level2;
    393      1.1  mrg      };
    394      1.1  mrg 
    395      1.1  mrg the ModTwo will not be taken into account and the resulting level depends on
    396      1.1  mrg the ModOne state only. That means, ModTwo alone produces the Level1 but the
    397  1.1.1.6  mrg combination ModOne+ModTwo (as well as ModOne alone) produces the Level2.
    398      1.1  mrg 
    399  1.1.1.6  mrg What does it mean if the second modifier is not ModTwo but Lock? It means that
    400  1.1.1.6  mrg in the first case (Lock itself is included in the list of modifiers but combina-
    401      1.1  mrg tions with this modifier aren't mentioned in the map statements) the internal
    402      1.1  mrg capitalization rules will be applied to the symbol from the first level. But
    403      1.1  mrg in the second case the capitalization will be applied to the symbol chosen
    404  1.1.1.6  mrg accordingly to the first modifier - and this can be the symbol from the first
    405      1.1  mrg as well as from the second level.
    406      1.1  mrg 
    407      1.1  mrg Usually, all modifiers introduced in 'modifiers=<list of modifiers>' list are
    408      1.1  mrg used for shift level calculation and then discarded. Sometimes this is not
    409      1.1  mrg desirable. If you want to use a modifier for shift level calculation but you
    410  1.1.1.6  mrg don't want to discard it, you may list it in 'preserve[<combination of modi-
    411      1.1  mrg fiers>]=<list of modifiers>'. That means, for a given combination all listed
    412      1.1  mrg modifiers will be preserved. If the Lock modifier is preserved then the
    413  1.1.1.6  mrg resulting symbol is passed to the internal capitalization routine regardless
    414      1.1  mrg whether it has been used for a shift level calculation or not.
    415      1.1  mrg 
    416      1.1  mrg Any key type description can use both real and virtual modifiers. Since real
    417      1.1  mrg modifiers always have standard names it is not necessary to explicitly
    418  1.1.1.6  mrg declare them. Virtual modifiers can have arbitrary names and must be declared
    419  1.1.1.6  mrg (prior to using them) directly in the key type definition:
    420      1.1  mrg 
    421  1.1.1.6  mrg      virtual_modifiers <comma-separated list of modifiers> ;
    422      1.1  mrg 
    423  1.1.1.6  mrg as seen in for example the basic, pc, or mousekeys key type definitions.
    424      1.1  mrg 
    425      1.1  mrg 4.3  Rules
    426      1.1  mrg 
    427  1.1.1.6  mrg Once you are finished with your symbol map you need to add it to the rules file.
    428  1.1.1.6  mrg The rules file describes how all the five basic components (keycodes, types,
    429  1.1.1.6  mrg compat, symbols, and geometry) should be composed to give a sensible resulting
    430      1.1  mrg xkb configuration.
    431      1.1  mrg 
    432  1.1.1.6  mrg The main advantage of rules over formerly used keymaps is the possibility to
    433      1.1  mrg simply parameterize (once) fixed patterns of configurations and thus to ele-
    434      1.1  mrg gantly allow substitutions of various local configurations into predefined
    435      1.1  mrg templates.
    436      1.1  mrg 
    437  1.1.1.6  mrg A pattern in a rules file (often located in /usr/share/X11/xkb/rules) can be
    438  1.1.1.6  mrg parameterized with four other arguments: Model, Layout, Variant, and Options.
    439  1.1.1.6  mrg For most cases the parameters Model and Layout should be sufficient for choosing
    440      1.1  mrg a functional keyboard mapping.
    441      1.1  mrg 
    442  1.1.1.6  mrg The rules file itself is composed of pattern lines and lines with rules. Each
    443  1.1.1.6  mrg pattern line starts with an exclamation mark ('!') and describes how XKB will
    444  1.1.1.6  mrg interpret the subsequent lines (rules). A sample rules file looks like this:
    445      1.1  mrg 
    446      1.1  mrg      ! model                   =   keycodes
    447  1.1.1.6  mrg        macintosh_old           =   macintosh
    448      1.1  mrg        ...
    449      1.1  mrg        *                       =   xfree86
    450      1.1  mrg 
    451  1.1.1.6  mrg      ! model                   =   symbols
    452      1.1  mrg        hp                      =   +inet(%m)
    453  1.1.1.6  mrg        microsoftpro            =   +inet(%m)
    454  1.1.1.6  mrg        geniuscomfy             =   +inet(%m)
    455      1.1  mrg 
    456  1.1.1.6  mrg      ! model       layout[1]   =   symbols
    457  1.1.1.6  mrg        macintosh   us          =   macintosh/us%(v[1])
    458  1.1.1.6  mrg        *           *           =   pc/pc(%m)+pc/%l[1]%(v[1])
    459  1.1.1.6  mrg 
    460  1.1.1.6  mrg      ! model       layout[2]   =   symbols
    461  1.1.1.6  mrg        macintosh   us          =   +macintosh/us[2]%(v[2]):2
    462  1.1.1.6  mrg        *           *           =   +pc/%l[2]%(v[2]):2
    463  1.1.1.6  mrg 
    464  1.1.1.6  mrg      ! option                  =   types
    465  1.1.1.6  mrg        caps:internal           =   +caps(internal)
    466  1.1.1.6  mrg        caps:internal_nocancel  =   +caps(internal_nocancel)
    467      1.1  mrg 
    468  1.1.1.6  mrg Each rule defines what a certain combination of values on the left side of the
    469  1.1.1.6  mrg equals sign ('=') results in. For example, a (keyboard) model macintosh_old
    470      1.1  mrg instructs xkb to take definitions of keycodes from file keycodes/macintosh
    471  1.1.1.6  mrg while the rest of the models (represented by a wildcard '*') instructs it to
    472  1.1.1.6  mrg take them from file keycodes/xfree86. The wildcard represents all possible
    473      1.1  mrg values on the left side which were not found in any of the previous rules.
    474      1.1  mrg The more specialized (more complete) rules have higher precedence than gen-
    475      1.1  mrg eral ones, i.e. the more general rules supply reasonable default values.
    476      1.1  mrg 
    477      1.1  mrg As you can see some lines contain substitution parameters - the parameters
    478      1.1  mrg preceded by the percent sign ('%'). The first alphabetical character after
    479      1.1  mrg the percent sign expands to the value which has been found on the left side.
    480      1.1  mrg For example +%l%(v) expands into +cz(bksl) if the respective values on the
    481      1.1  mrg left side were cz layout in its bksl variant. More, if the layout resp. vari-
    482      1.1  mrg ant  parameter is followed by a pair of brackets ('[', ']') it means that xkb
    483  1.1.1.6  mrg should place the layout resp. variant into the specified xkb group. If the
    484  1.1.1.6  mrg brackets are omitted, the first group is the default value.
    485      1.1  mrg 
    486      1.1  mrg So the second block of rules enhances symbol definitions for some particular
    487      1.1  mrg keyboard models with extra keys (for internet, multimedia, ...) . Other mod-
    488      1.1  mrg els are left intact. Similarly, the last block overrides some key type defi-
    489      1.1  mrg nitions, so the common global behaviour ''shift cancels caps'' or ''shift
    490  1.1.1.6  mrg doesn't cancel caps'' can be selected. The rest of the rules produce special
    491  1.1.1.6  mrg symbols for each US variant of the macintosh keyboard, and standard pc symbols
    492  1.1.1.6  mrg in appropriate variants as a default.
    493      1.1  mrg 
    494      1.1  mrg 4.4  Descriptive Files of Rules
    495      1.1  mrg 
    496  1.1.1.6  mrg Now you just need to add a detailed description to the <rules>.xml description
    497  1.1.1.6  mrg file so that other users (and external programs which often parse this file)
    498  1.1.1.6  mrg know what your work is about.
    499      1.1  mrg 
    500      1.1  mrg 4.4.1  Old Descriptive Files
    501      1.1  mrg 
    502  1.1.1.6  mrg The formerly used descriptive files were named <rules>.lst. Its structure is
    503      1.1  mrg very simple and quite self descriptive but such simplicity had also some cav-
    504      1.1  mrg ities, for example there was no way how to describe local variants of layouts
    505      1.1  mrg and there were problems with the localization of descriptions. To preserve
    506      1.1  mrg compatibility with some older programs, new XML descriptive files can be con-
    507  1.1.1.6  mrg verted to the old '.lst' format.
    508      1.1  mrg 
    509  1.1.1.6  mrg The meaning of each possible parameter of the rules file should be described.
    510  1.1.1.6  mrg For the sample rules file given above, the .lst file could look like this:
    511      1.1  mrg 
    512      1.1  mrg      ! model
    513      1.1  mrg        pc104        Generic 104-key PC
    514      1.1  mrg        microsoft    Microsoft Natural
    515      1.1  mrg        pc98         PC-98xx Series
    516  1.1.1.6  mrg        macintosh    Original Macintosh
    517      1.1  mrg        ...
    518      1.1  mrg 
    519      1.1  mrg      ! layout
    520      1.1  mrg        us      U.S. English
    521      1.1  mrg        cz      Czech
    522      1.1  mrg        de      German
    523      1.1  mrg        ...
    524      1.1  mrg 
    525      1.1  mrg      ! option
    526  1.1.1.6  mrg        caps:internal           uses internal capitalization, Shift cancels Caps
    527  1.1.1.6  mrg        caps:internal_nocancel  uses internal capitalization, Shift doesn't cancel Caps
    528      1.1  mrg 
    529      1.1  mrg And that should be it. Enjoy creating your own xkb mapping.
    530