README.enhancing revision 154daed1
1154daed1Smrg How to further enhance XKB configuration 2154daed1Smrg 3154daed1Smrg Kamil Toman, Ivan U. Pascal 4154daed1Smrg 5154daed1Smrg 25 November 2002 6154daed1Smrg 7154daed1Smrg Abstract 8154daed1Smrg 9154daed1Smrg This guide is aimed to relieve one's labour to create a new (inter- 10154daed1Smrg nationalized) keyboard layout. Unlike other documents this guide 11154daed1Smrg accents the keymap developer's point of view. 12154daed1Smrg 13154daed1Smrg1. Overview 14154daed1Smrg 15154daed1SmrgThe developer of a new layout should read the xkb protocol specification (The 16154daed1SmrgX Keyboard Extension: Protocol Specification <URL:http://www.x- 17154daed1Smrgdocs.org/XKB/XKBproto.pdf>) at least to clarify for himself some xkb-specific 18154daed1Smrgterms used in this document and elsewhere in xkb configuration. Also it shows 19154daed1Smrgwise to understand how the X server and a client digest their keyboard inputs 20154daed1Smrg(with and without xkb). 21154daed1Smrg 22154daed1SmrgA useful source is also Ivan Pascal's text about xkb configuration 23154daed1Smrg<URL:http://www.tsu.ru/~pascal/en/xkb> often referenced throughout this docu- 24154daed1Smrgment. 25154daed1Smrg 26154daed1SmrgNote that this document covers only enhancements which are to be made to 27154daed1SmrgXFree86 version 4.3.x and above. 28154daed1Smrg 29154daed1Smrg2. The Basics 30154daed1Smrg 31154daed1SmrgAt the startup (or at later at user's command) X server starts its xkb key- 32154daed1Smrgboard module extension and reads data from a compiled configuration file. 33154daed1Smrg 34154daed1SmrgThis compiled configuration file is prepared by the program xkbcomp which 35154daed1Smrgbehaves altogether as an ordinary compiler (see man xkbcomp). Its input are 36154daed1Smrghuman readable xkb configuration files which are verified and then composed 37154daed1Smrginto a useful xkb configuration. Users don't need to mess with xkbcomp them- 38154daed1Smrgselves, for them it is invisible. Usually, it is started upon X server 39154daed1Smrgstartup. 40154daed1Smrg 41154daed1SmrgAs you probably already know, the xkb configuration consists of five main 42154daed1Smrgmodules: 43154daed1Smrg 44154daed1Smrg Keycodes 45154daed1Smrg Tables that defines translation from keyboard scan codes into 46154daed1Smrg reasonable symbolic names, maximum, minimum legal keycodes, sym- 47154daed1Smrg bolic aliases and description of physically present LED-indica- 48154daed1Smrg tors. The primary sence of this component is to allow definitions 49154daed1Smrg of maps of symbols (see below) to be independent of physical key- 50154daed1Smrg board scancodes. There are two main naming conventions for sym- 51154daed1Smrg bolic names (always four bytes long): 52154daed1Smrg 53154daed1Smrg o names which express some traditional meaning like <SPCE> 54154daed1Smrg (stands for space bar) or 55154daed1Smrg 56154daed1Smrg o names which express some relative positioning on a key- 57154daed1Smrg board, for example <AE01> (an exclamation mark on US key- 58154daed1Smrg boards), on the right there are keys <AE02>, <AE03> etc. 59154daed1Smrg 60154daed1Smrg Types 61154daed1Smrg Types describe how the produced key is changed by active modi- 62154daed1Smrg fiers (like Shift, Control, Alt, ...). There are several prede- 63154daed1Smrg fined types which cover most of used combinations. 64154daed1Smrg 65154daed1Smrg Compat 66154daed1Smrg Compatibility component defines internal behaviour of modifiers. 67154daed1Smrg Using compat component you can assign various actions (elabo- 68154daed1Smrg rately described in xkb specification) to key events. This is 69154daed1Smrg also the place where LED-indicators behaviour is defined. 70154daed1Smrg 71154daed1Smrg Symbols 72154daed1Smrg For i18n purposes, this is the most important table. It defines 73154daed1Smrg what values (=symbols) are assigned to what keycodes (represented 74154daed1Smrg by their symbolic name, see above). There may be defined more 75154daed1Smrg than one value for each key and then it depends on a key type and 76154daed1Smrg on modifiers state (respective compat component) which value will 77154daed1Smrg be the resulting one. 78154daed1Smrg 79154daed1Smrg Geometry 80154daed1Smrg Geometry files aren't used by xkb itself but they may be used by 81154daed1Smrg some external programs to depict a keyboard image. 82154daed1Smrg 83154daed1SmrgAll these components have the files located in xkb configuration tree in sub- 84154daed1Smrgdirectories with the same names (usually in /usr/lib/X11/xkb). 85154daed1Smrg 86154daed1Smrg3. Enhancing XKB Configuration 87154daed1Smrg 88154daed1SmrgMost of xkb enhancements concerns a need to define new output symbols for the 89154daed1Smrgsome input key events. In other words, a need to define a new symbol map (for 90154daed1Smrga new language, standard or just to feel more comfortable when typing text). 91154daed1Smrg 92154daed1SmrgWhat do you need to do? Generally, you have to define following things: 93154daed1Smrg 94154daed1Smrg o the map of symbols itself 95154daed1Smrg 96154daed1Smrg o the rules to allow users to select the new mapping 97154daed1Smrg 98154daed1Smrg o the description of the new layout 99154daed1Smrg 100154daed1SmrgFirst of all, it is good to go through existing layouts and to examine them 101154daed1Smrgif there is something you could easily adjust to fit your needs. Even if 102154daed1Smrgthere is nothing similar you may get some ideas about basic concepts and used 103154daed1Smrgtricks. 104154daed1Smrg 105154daed1Smrg3.1 Levels And Groups 106154daed1Smrg 107154daed1SmrgSince XFree86 4.3.0 you can use multi-layout concept of xkb configuration. 108154daed1SmrgThough it is still in boundaries of xkb protocol and general ideas, the 109154daed1Smrgkeymap designer must obey new rules when creating new maps. In exchange we 110154daed1Smrgget a more powerful and cleaner configuration system. 111154daed1Smrg 112154daed1SmrgRemember that it is the application which must decide which symbol matches 113154daed1Smrgwhich keycode according to effective modifier state. The X server itself 114154daed1Smrgsends only an input event message to. Of course, usually the general inter- 115154daed1Smrgpretation is processed by Xlib, Xaw, Motif, Qt, Gtk and similar libraries. 116154daed1SmrgThe X server only supplies its mapping table (usually upon an application 117154daed1Smrgstartup). 118154daed1Smrg 119154daed1SmrgYou can think of the X server's symbol table as of a irregular table where 120154daed1Smrgeach keycode has its row and where each combination of modifiers determines 121154daed1Smrgexactly one column. The resulting cell then gives the proper symbolic value. 122154daed1SmrgNot all keycodes need to bind different values for different combination of 123154daed1Smrgmodifiers. <ENTER> key, for instance, usually doesn't depend on any modi- 124154daed1Smrgfiers so it its row has only one column defined. 125154daed1Smrg 126154daed1SmrgNote that in XKB there is no prior assumption that certain modifiers are 127154daed1Smrgbound to certain columns. By editing proper files (see keytypes (section 4.2, 128154daed1Smrgpage 1)) this mapping can be changed as well. 129154daed1Smrg 130154daed1SmrgUnlike the original X protocol the XKB approach is far more flexible. It is 131154daed1Smrgcomfortable to add one additional XKB term - group. You can think of a group 132154daed1Smrgas of a vector of columns per each keycode (naturally the dimension of this 133154daed1Smrgvector may differ for different keycodes). What is it good for? The group is 134154daed1Smrgnot very useful unless you intend to use more than one logically different 135154daed1Smrgset of symbols (like more than one alphabet) defined in a single mapping ta- 136154daed1Smrgble. But then, the group has a natural meaning - each symbol set has its own 137154daed1Smrggroup and changing it means selecting a different one. XKB approach allows 138154daed1Smrgup to four different groups. The columns inside each group are called (shift) 139154daed1Smrglevels. The X server knows the current group and reports it together with 140154daed1Smrgmodifier set and with a keycode in key events. 141154daed1Smrg 142154daed1SmrgTo sum it up: 143154daed1Smrg 144154daed1Smrg o for each keycode XKB keyboard map contains up to four one-dimensional 145154daed1Smrg tables - groups (logically different symbol sets) 146154daed1Smrg 147154daed1Smrg o for each group of a keycode XKB keyboard map contains some columns - 148154daed1Smrg shift levels (values reached by combinations of Shift, Ctrl, Alt, ... 149154daed1Smrg modifiers) 150154daed1Smrg 151154daed1Smrg o different keycodes can have different number of groups 152154daed1Smrg 153154daed1Smrg o different groups of one keycode can have different number of shift lev- 154154daed1Smrg els 155154daed1Smrg 156154daed1Smrg o the current group number is tracked by X server 157154daed1Smrg 158154daed1SmrgIt is clear that if you sanely define levels, groups and sanely bind modi- 159154daed1Smrgfiers and associated actions you can have simultaneously loaded up to four 160154daed1Smrgdifferent symbol sets where each of them would reside in its own group. 161154daed1Smrg 162154daed1SmrgThe multi-layout concept provides a facility to manipulate xkb groups and 163154daed1Smrgsymbol definitions in a way that allows almost arbitrary composition of pre- 164154daed1Smrgdefined symbol tables. To keep it fully functional you have to: 165154daed1Smrg 166154daed1Smrg o define all symbols only in the first group 167154daed1Smrg 168154daed1Smrg o (re)define any modifiers with extra care to avoid strange (anisometric) 169154daed1Smrg behaviour 170154daed1Smrg 171154daed1Smrg4. Defining New Layouts 172154daed1Smrg 173154daed1SmrgSee Some Words About XKB internals <URL:http://www.tsu.ru/~pas- 174154daed1Smrgcal/en/xkb/internals.html> for explanation of used xkb terms and problems 175154daed1Smrgaddressed by XKB extension. 176154daed1Smrg 177154daed1SmrgSee Common notes about XKB configuration files language 178154daed1Smrg<URL:http://www.tsu.ru/~pascal/en/xkb/gram-common.html> for more precise 179154daed1Smrgexplanation of syntax of xkb configuration files. 180154daed1Smrg 181154daed1Smrg4.1 Predefined XKB Symbol Sets 182154daed1Smrg 183154daed1SmrgIf you are about to define some European symbol map extension, you might want 184154daed1Smrgto use on of four predefined latin alphabet layouts. 185154daed1Smrg 186154daed1SmrgOkay, let's assume you want extend an existing keymap and you want to over- 187154daed1Smrgride a few keys. Let's take a simple U.K. keyboard as an example (defined in 188154daed1Smrgpc/gb): 189154daed1Smrg 190154daed1Smrg partial default alphanumeric_keys 191154daed1Smrg xkb_symbols "basic" { 192154daed1Smrg include "pc/latin" 193154daed1Smrg 194154daed1Smrg name[Group1]="Great Britain"; 195154daed1Smrg 196154daed1Smrg key <AE02> { [ 2, quotedbl, twosuperior, oneeighth ] }; 197154daed1Smrg key <AE03> { [ 3, sterling, threesuperior, sterling ] }; 198154daed1Smrg key <AC11> { [apostrophe, at, dead_circumflex, dead_caron] }; 199154daed1Smrg key <TLDE> { [ grave, notsign, bar, bar ] }; 200154daed1Smrg key <BKSL> { [numbersign, asciitilde, dead_grave, dead_breve ] }; 201154daed1Smrg key <RALT> { type[Group1]="TWO_LEVEL", 202154daed1Smrg [ ISO_Level3_Shift, Multi_key ] }; 203154daed1Smrg 204154daed1Smrg modifier_map Mod5 { <RALT> }; 205154daed1Smrg }; 206154daed1Smrg 207154daed1SmrgIt defines a new layout in basic variant as an extension of common latin 208154daed1Smrgalphabet layout. The layout (symbol set) name is set to "Great Britain". 209154daed1SmrgThen there are redefinitions of a few keycodes and a modifiers binding. As 210154daed1Smrgyou can see the number of shift levels is the same for <AE02>, <AE03>, 211154daed1Smrg<AC11>, <TLDE> and <BKSL> keys but it differs from number of shift levels of 212154daed1Smrg<RALT>. 213154daed1Smrg 214154daed1SmrgNote that the <RALT> key itself is a binding key for Mod5 and that it serves 215154daed1Smrglike a shift modifier for LevelThree, together with Shift as a multi-key. It 216154daed1Smrgis a good habit to respect this rule in a new similar layout. 217154daed1Smrg 218154daed1SmrgOkay, you could now define more variants of your new layout besides basic 219154daed1Smrgsimply by including (augmenting/overriding/...) the basic definition and 220154daed1Smrgaltering what may be needed. 221154daed1Smrg 222154daed1Smrg4.2 Key Types 223154daed1Smrg 224154daed1SmrgThe differences in the number of columns (shift levels) are caused by a dif- 225154daed1Smrgferent types of keys (see the types definition in section basics). Most key- 226154daed1Smrgcodes have implicitly set the keytype in the included "pc/latin" file to 227154daed1Smrg"FOUR_LEVEL_ALPHABETIC". The only exception is <RALT> keycode which is 228154daed1Smrgexplicitly set "TWO_LEVEL" keytype. 229154daed1Smrg 230154daed1SmrgAll those names refer to pre-defined shift level schemes. Usually you can 231154daed1Smrgchoose a suitable shift level scheme from default types scheme list in proper 232154daed1Smrgxkb component's subdirectory. 233154daed1Smrg 234154daed1SmrgThe most used schemes are: 235154daed1Smrg 236154daed1Smrg ONE_LEVEL 237154daed1Smrg The key does not depend on any modifiers. The symbol from first 238154daed1Smrg level is always chosen. 239154daed1Smrg 240154daed1Smrg TWO_LEVEL 241154daed1Smrg The key uses a modifier Shift and may have two possible values. 242154daed1Smrg The second level may be chosen by Shift modifier. If Lock modi- 243154daed1Smrg fier (usually Caps-lock) applies the symbol is further processed 244154daed1Smrg using system-specific capitalization rules. If both Shift+Lock 245154daed1Smrg modifier apply the symbol from the second level is taken and cap- 246154daed1Smrg italization rules are applied (and usually have no effect). 247154daed1Smrg 248154daed1Smrg ALPHABETIC 249154daed1Smrg The key uses modifiers Shift and Lock. It may have two possible 250154daed1Smrg values. The second level may be chosen by Shift modifier. When 251154daed1Smrg Lock modifier applies, the symbol from the first level is taken 252154daed1Smrg and further processed using system-specific capitalization rules. 253154daed1Smrg If both Shift+Lock modifier apply the symbol from the first level 254154daed1Smrg is taken and no capitalization rules applied. This is often 255154daed1Smrg called shift-cancels-caps behaviour. 256154daed1Smrg 257154daed1Smrg THREE_LEVEL 258154daed1Smrg Is the same as TWO_LEVEL but it considers an extra modifier - 259154daed1Smrg LevelThree which can be used to gain the symbol value from the 260154daed1Smrg third level. If both Shift+LevelThree modifiers apply the value 261154daed1Smrg from the third level is also taken. As in TWO_LEVEL, the Lock 262154daed1Smrg modifier doesn't influence the resulting level. Only Shift and 263154daed1Smrg LevelThree are taken into that consideration. If the Lock modi- 264154daed1Smrg fier is active capitalization rules are applied on the resulting 265154daed1Smrg symbol. 266154daed1Smrg 267154daed1Smrg FOUR_LEVEL 268154daed1Smrg Is the same as THREE_LEVEL but unlike LEVEL_THREE if both 269154daed1Smrg Shift+LevelThree modifiers apply the symbol is taken from the 270154daed1Smrg fourth level. 271154daed1Smrg 272154daed1Smrg FOUR_LEVEL_ALPHABETIC 273154daed1Smrg Is similar to FOUR_LEVEL but also defines shift-cancels-caps 274154daed1Smrg behaviour as in ALPHABETIC. If Lock+LevelThree apply the symbol 275154daed1Smrg from the third level is taken and the capitalization rules are 276154daed1Smrg applied. If Lock+Shift+LevelThree apply the symbol from the 277154daed1Smrg third level is taken and no capitalization rules are applied. 278154daed1Smrg 279154daed1Smrg KEYPAD 280154daed1Smrg As the name suggest this scheme is primarily used for numeric 281154daed1Smrg keypads. The scheme considers two modifiers - Shift and NumLock. 282154daed1Smrg If none of modifiers applies the symbol from the first level is 283154daed1Smrg taken. If either Shift or NumLock modifiers apply the symbol from 284154daed1Smrg the second level is taken. If both Shift+NumLock modifiers apply 285154daed1Smrg the symbol from the first level is taken. Again, shift-cancels- 286154daed1Smrg caps variant. 287154daed1Smrg 288154daed1Smrg FOUR_LEVEL_KEYPAD 289154daed1Smrg Is similar to KEYPAD scheme but considers also LevelThree modi- 290154daed1Smrg fier. If LevelThree modifier applies the symbol from the third 291154daed1Smrg level is taken. If Shift+LevelThree or NumLock+LevelThree apply 292154daed1Smrg the symbol from the fourth level is taken. If all Shift+Num- 293154daed1Smrg Lock+LevelThree modifiers apply the symbol from the third level 294154daed1Smrg is taken. This also, shift-cancels-caps variant. 295154daed1Smrg 296154daed1Smrg FOUR_LEVEL_MIXED_KEYPAD 297154daed1Smrg A four-level keypad scheme where the first two levels are similar 298154daed1Smrg to the KEYPAD scheme (NumLock+Shift) 299154daed1Smrg LevelThree acts as an override providing access to two Shift-ed 300154daed1Smrg levels. When LevelThree is active we totally ignore NumLock state 301154daed1Smrg Intended for the digit area of the keypad 302154daed1Smrg 303154daed1Smrg FOUR_LEVEL_X 304154daed1Smrg A four-level scheme where the base level accepts no modifier, 305154daed1Smrg LevelThree provides two more Shift-ed levels like in the previous 306154daed1Smrg scheme, and Ctrl+Alt controls the fourth level 307154daed1Smrg Intended for the operator part of a keypad, though since NumLock 308154daed1Smrg plays no part, it is not keypad-specific 309154daed1Smrg 310154daed1SmrgBesides that, there are several schemes for special purposes: 311154daed1Smrg 312154daed1Smrg PC_CONTROL_LEVEL2 313154daed1Smrg It is similar to TWO_LEVEL scheme but it considers the Control 314154daed1Smrg modifier rather than Shift. That means, the symbol from the sec- 315154daed1Smrg ond level is chosen by Control rather than by Shift. 316154daed1Smrg 317154daed1Smrg PC_ALT_LEVEL2 318154daed1Smrg It is similar to TWO_LEVEL scheme but it considers the Alt modi- 319154daed1Smrg fier rather than Shift. That means, the symbol from the second 320154daed1Smrg level is chosen by Alt rather than by Shift. 321154daed1Smrg 322154daed1Smrg CTRL+ALT 323154daed1Smrg The key uses modifiers Alt and Control. It may have two possible 324154daed1Smrg values. If only one modifier (Alt or Control) applies the symbol 325154daed1Smrg from the first level is chosen. Only if both Alt+Control modi- 326154daed1Smrg fiers apply the symbol from the second level is chosen. 327154daed1Smrg 328154daed1Smrg SHIFT+ALT 329154daed1Smrg The key uses modifiers Shift and Alt. It may have two possible 330154daed1Smrg values. If only one modifier (Alt or Shift) applies the symbol 331154daed1Smrg from the first level is chosen. Only if both Alt+Shift modifiers 332154daed1Smrg apply the symbol from the second level is chosen. 333154daed1Smrg 334154daed1SmrgIf needed, special caps schemes may be used. They redefine the standard 335154daed1Smrgbehaviour of all *ALPHABETIC types. The layouts (maps of symbols) with keys 336154daed1Smrgdefined in respective types then automatically change their behaviour accord- 337154daed1Smrgingly. Possible redefinitions are: 338154daed1Smrg 339154daed1Smrg o internal 340154daed1Smrg 341154daed1Smrg o internal_nocancel 342154daed1Smrg 343154daed1Smrg o shift 344154daed1Smrg 345154daed1Smrg o shift_nocancel 346154daed1Smrg 347154daed1SmrgNone of these schemes should be used directly. They are defined merely for 348154daed1Smrg'caps:' xkb options (used to globally change the layouts behaviour). 349154daed1Smrg 350154daed1SmrgDon't alter any of existing key types. If you need a different behaviour cre- 351154daed1Smrgate a new one. 352154daed1Smrg 353154daed1Smrg4.2.1 More On Definitions Of Types 354154daed1Smrg 355154daed1SmrgWhen the XKB software deals with a separate type description it gets a com- 356154daed1Smrgplete list of modifiers that should be taken into account from the 'modi- 357154daed1Smrgfiers=<list of modifiers>' list and expects that a set of 'map[<combination 358154daed1Smrgof modifiers>]=<list of modifiers>' instructions that contain the mapping for 359154daed1Smrgeach combination of modifiers mentioned in that list. Modifiers that are not 360154daed1Smrgexplicitly listed are NOT taken into account when the resulting shift level 361154daed1Smrgis computed. If some combination is omitted the program (subroutine) should 362154daed1Smrgchoose the first level for this combination (a quite reasonable behavior). 363154daed1Smrg 364154daed1SmrgLets consider an example with two modifiers ModOne and ModTwo: 365154daed1Smrg 366154daed1Smrg type "..." { 367154daed1Smrg modifiers = ModOne+ModTwo; 368154daed1Smrg map[None] = Level1; 369154daed1Smrg map[ModOne] = Level2; 370154daed1Smrg }; 371154daed1Smrg 372154daed1SmrgIn this case the map statements for ModTwo only and ModOne+ModTwo are omit- 373154daed1Smrgted. It means that if the ModTwo is active the subroutine can't found 374154daed1Smrgexplicit mapping for such combination an will use the default level i.e. 375154daed1SmrgLevel1. 376154daed1Smrg 377154daed1SmrgBut in the case the type described as: 378154daed1Smrg 379154daed1Smrg type "..." { 380154daed1Smrg modifiers = ModOne; 381154daed1Smrg map[None] = Level1; 382154daed1Smrg map[ModOne] = Level2; 383154daed1Smrg }; 384154daed1Smrg 385154daed1Smrgthe ModTwo will not be taken into account and the resulting level depends on 386154daed1Smrgthe ModOne state only. That means, ModTwo alone produces the Level1 but the 387154daed1Smrgcombination ModOne+ModTwo produces the Level2 as well as ModOne alone. 388154daed1Smrg 389154daed1SmrgWhat does it mean if the second modifier is the Lock? It means that in the 390154daed1Smrgfirst case (the Lock itself is included in the list of modifiers but combina- 391154daed1Smrgtions with this modifier aren't mentioned in the map statements) the internal 392154daed1Smrgcapitalization rules will be applied to the symbol from the first level. But 393154daed1Smrgin the second case the capitalization will be applied to the symbol chosen 394154daed1Smrgaccordingly to he first modifier - and this can be the symbol from the first 395154daed1Smrgas well as from the second level. 396154daed1Smrg 397154daed1SmrgUsually, all modifiers introduced in 'modifiers=<list of modifiers>' list are 398154daed1Smrgused for shift level calculation and then discarded. Sometimes this is not 399154daed1Smrgdesirable. If you want to use a modifier for shift level calculation but you 400154daed1Smrgdon't want to discard it, you may list in 'preserve[<combination of modi- 401154daed1Smrgfiers>]=<list of modifiers>'. That means, for a given combination all listed 402154daed1Smrgmodifiers will be preserved. If the Lock modifier is preserved then the 403154daed1Smrgresulting symbol is passed to internal capitalization routine regardless 404154daed1Smrgwhether it has been used for a shift level calculation or not. 405154daed1Smrg 406154daed1SmrgAny key type description can use both real and virtual modifiers. Since real 407154daed1Smrgmodifiers always have standard names it is not necessary to explicitly 408154daed1Smrgdeclare them. Virtual modifiers can have arbitrary names and can be declared 409154daed1Smrg(prior using them) directly in key type definition: 410154daed1Smrg 411154daed1Smrg virtual_modifiers <comma-separated list of modifiers> ; 412154daed1Smrg 413154daed1Smrgas seen in for example basic, pc or mousekeys key type definitions. 414154daed1Smrg 415154daed1Smrg4.3 Rules 416154daed1Smrg 417154daed1SmrgOnce you are finished with your symbol map you need to add it to rules file. 418154daed1SmrgThe rules file describes how all the five basic keycodes, types, compat, sym- 419154daed1Smrgbols and geometry components should be composed to give a sensible resulting 420154daed1Smrgxkb configuration. 421154daed1Smrg 422154daed1SmrgThe main advantage of rules over formerly used keymaps is a possibility to 423154daed1Smrgsimply parameterize (once) fixed patterns of configurations and thus to ele- 424154daed1Smrggantly allow substitutions of various local configurations into predefined 425154daed1Smrgtemplates. 426154daed1Smrg 427154daed1SmrgA pattern in a rules file (often located in /usr/lib/X11/xkb/rules) can be 428154daed1Smrgparameterized with four other arguments: Model, Layout, Variant and Options. 429154daed1SmrgFor most cases parameters model and layout should be sufficient for choosing 430154daed1Smrga functional keyboard mapping. 431154daed1Smrg 432154daed1SmrgThe rules file itself is composed of pattern lines and lines with rules. The 433154daed1Smrgpattern line starts with an exclamation mark ('!') and describes how will the 434154daed1Smrgxkb interpret the following lines (rules). A sample rules file looks like 435154daed1Smrgthis: 436154daed1Smrg 437154daed1Smrg ! model = keycodes 438154daed1Smrg macintosh_old = macintosh 439154daed1Smrg ... 440154daed1Smrg * = xfree86 441154daed1Smrg 442154daed1Smrg ! model = symbols 443154daed1Smrg hp = +inet(%m) 444154daed1Smrg microsoftpro = +inet(%m) 445154daed1Smrg geniuscomfy = +inet(%m) 446154daed1Smrg 447154daed1Smrg ! model layout[1] = symbols 448154daed1Smrg macintosh us = macintosh/us%(v[1]) 449154daed1Smrg * * = pc/pc(%m)+pc/%l[1]%(v[1]) 450154daed1Smrg 451154daed1Smrg ! model layout[2] = symbols 452154daed1Smrg macintosh us = +macintosh/us[2]%(v[2]):2 453154daed1Smrg * * = +pc/%l[2]%(v[2]):2 454154daed1Smrg 455154daed1Smrg ! option = types 456154daed1Smrg caps:internal = +caps(internal) 457154daed1Smrg caps:internal_nocancel = +caps(internal_nocancel) 458154daed1Smrg 459154daed1SmrgEach rule defines what certain combination of values on the left side of 460154daed1Smrgequal sign ('=') results in. For example a (keyboard) model macintosh_old 461154daed1Smrginstructs xkb to take definitions of keycodes from file keycodes/macintosh 462154daed1Smrgwhile the rest of models (represented by a wild card '*') instructs it to 463154daed1Smrgtake them from file keycodes/xfree86. The wild card represents all possible 464154daed1Smrgvalues on the left side which were not found in any of the previous rules. 465154daed1SmrgThe more specialized (more complete) rules have higher precedence than gen- 466154daed1Smrgeral ones, i.e. the more general rules supply reasonable default values. 467154daed1Smrg 468154daed1SmrgAs you can see some lines contain substitution parameters - the parameters 469154daed1Smrgpreceded by the percent sign ('%'). The first alphabetical character after 470154daed1Smrgthe percent sign expands to the value which has been found on the left side. 471154daed1SmrgFor example +%l%(v) expands into +cz(bksl) if the respective values on the 472154daed1Smrgleft side were cz layout in its bksl variant. More, if the layout resp. vari- 473154daed1Smrgant parameter is followed by a pair of brackets ('[', ']') it means that xkb 474154daed1Smrgshould place the layout resp. variant into specified xkb group. If the brack- 475154daed1Smrgets are omitted the first group is the default value. 476154daed1Smrg 477154daed1SmrgSo the second block of rules enhances symbol definitions for some particular 478154daed1Smrgkeyboard models with extra keys (for internet, multimedia, ...) . Other mod- 479154daed1Smrgels are left intact. Similarly, the last block overrides some key type defi- 480154daed1Smrgnitions, so the common global behaviour ''shift cancels caps'' or ''shift 481154daed1Smrgdoesn't cancel caps'' can be selected. The rest of rules produces special 482154daed1Smrgsymbols for each variant us layout of macintosh keyboard and standard pc sym- 483154daed1Smrgbols in appropriate variants as a default. 484154daed1Smrg 485154daed1Smrg4.4 Descriptive Files of Rules 486154daed1Smrg 487154daed1SmrgNow you just need to add a detailed description to <rules>.xml description 488154daed1Smrgfile so the other users (and external programs which often parse this file) 489154daed1Smrgknow what is your work about. 490154daed1Smrg 491154daed1Smrg4.4.1 Old Descriptive Files 492154daed1Smrg 493154daed1SmrgThe formerly used descriptive files were named <rules>.lst Its structure is 494154daed1Smrgvery simple and quite self descriptive but such simplicity had also some cav- 495154daed1Smrgities, for example there was no way how to describe local variants of layouts 496154daed1Smrgand there were problems with the localization of descriptions. To preserve 497154daed1Smrgcompatibility with some older programs, new XML descriptive files can be con- 498154daed1Smrgverted to old format '.lst'. 499154daed1Smrg 500154daed1SmrgFor each parameter of rules file should be described its meaning. For the 501154daed1Smrgrules file described above the .lst file could look like: 502154daed1Smrg 503154daed1Smrg ! model 504154daed1Smrg pc104 Generic 104-key PC 505154daed1Smrg microsoft Microsoft Natural 506154daed1Smrg pc98 PC-98xx Series 507154daed1Smrg macintosh Original Macintosh 508154daed1Smrg ... 509154daed1Smrg 510154daed1Smrg ! layout 511154daed1Smrg us U.S. English 512154daed1Smrg cz Czech 513154daed1Smrg de German 514154daed1Smrg ... 515154daed1Smrg 516154daed1Smrg ! option 517154daed1Smrg caps:internal uses internal capitalization. Shift cancels Caps 518154daed1Smrg caps:internal_nocancel uses internal capitalization. Shift doesn't cancel Caps 519154daed1Smrg 520154daed1SmrgAnd that should be it. Enjoy creating your own xkb mapping. 521154daed1Smrg 522154daed1Smrg Generated from XFree86: xc/programs/Xserver/hw/xfree86/doc/sgml/XKB-Enhancing.sgml,v 1.2 dawes Exp $ 523154daed1Smrg 524154daed1Smrg 525154daed1Smrg$XFree86: xc/programs/xkbcomp/README.enhancing,v 1.5 2003/10/19 19:57:44 dawes Exp $ 526