1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" 3 "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" 4[ 5<!ENTITY % defs SYSTEM "defs.ent"> %defs; 6]> 7 8<article id='XKB-Enhancing'> 9 10 <articleinfo> 11 12 <title>How to further enhance XKB configuration</title> 13 <releaseinfo>X Version 11, Release &fullrelvers;</releaseinfo> 14 <authorgroup> 15 <author> 16 <firstname>Kamil</firstname><surname>Toman</surname> 17 </author> 18 <author> 19 <firstname>Ivan</firstname><othername>U.</othername> 20 <surname>Pascal</surname> 21 </author> 22 </authorgroup> 23 <pubdate>25 November 2002</pubdate> 24 <abstract> 25 26 <para> 27This guide is aimed to relieve one's labour to create a new (internationalized) 28keyboard layout. Unlike other documents this guide accents the keymap developer's point of view. 29 </para> 30 31 </abstract> 32 33 </articleinfo> 34 35 <sect1 id='Overview'> 36 <title>Overview</title> 37 38 <para> 39The developer of a new layout should read the xkb 40protocol specification (<ulink 41url="https://www.x.org/docs/XKB/XKBproto.pdf" 42>The X Keyboard Extension: Protocol Specification</ulink 43>) at least 44to clarify for himself some xkb-specific terms used in this document 45and elsewhere in xkb configuration. Also it shows wise to understand 46how the X server and a client digest their keyboard inputs 47(with and without xkb). 48 </para> 49 50 <para> 51A useful source is also <ulink 52url="http://www.tsu.ru/~pascal/en/xkb" 53>Ivan Pascal's text about xkb configuration</ulink 54> often referenced throughout this 55document. 56 </para> 57 58 <para> 59Note that this document covers only enhancements which 60are to be made to XFree86 version 4.3 and X11R6.7.0 and above. 61 </para> 62 63 </sect1> 64 65 <sect1 id='The_Basics'> 66 <title>The Basics</title> 67 68 <para> 69At the startup (or at later at user's command) X server starts its xkb 70keyboard module extension and reads data from a compiled configuration 71file. 72 </para> 73 74 <para> 75This compiled configuration file is prepared by the 76program <command>xkbcomp</command> which behaves altogether as an 77ordinary compiler (see <userinput>man xkbcomp</userinput>). 78Its input are human readable xkb configuration files which are verified and 79then composed into a useful xkb configuration. Users don't need to mess with 80<command>xkbcomp</command> themselves, for them it is invisible. Usually, 81it is started upon X server startup. 82 </para> 83 84 <para> 85As you probably already know, the xkb configuration consists of five 86main modules: 87 <variablelist> 88 89 <varlistentry> 90 <term>Keycodes</term> 91 <listitem> 92 <para> 93Tables that defines translation from keyboard scan codes into reasonable 94symbolic names, maximum, minimum legal keycodes, symbolic aliases and 95description of physically present LED-indicators. The primary sense of 96this component is to allow definitions of maps of symbols (see below) 97to be independent of physical keyboard scancodes. There are two main 98naming conventions for symbolic names (always four bytes long): 99 100 <itemizedlist> 101 <listitem> 102 <para> 103 names which express some traditional meaning like 104<keycode><SPCE></keycode> (stands for space bar) or 105 </para> 106 </listitem> 107 108 <listitem> 109 <para> 110 names which express some relative positioning on a keyboard, for 111example <keycode><AE01></keycode> (an exclamation mark on US keyboards), on 112the right there are keys <keycode><AE02></keycode>, <keycode><AE03></keycode> 113etc. 114 </para> 115 </listitem> 116 </itemizedlist> 117 118 </para> 119 </listitem> 120 </varlistentry> 121 <varlistentry> 122 <term>Types</term> 123 <listitem> 124 <para> 125Types describe how the produced key is changed by active modifiers (like 126Shift, Control, Alt, ...). There are several predefined types which 127cover most of used combinations. 128 </para> 129 </listitem> 130 </varlistentry> 131 <varlistentry> 132 <term>Compat</term> 133 <listitem> 134 <para> 135Compatibility component defines internal behaviour of modifiers. Using 136compat component you can assign various actions (elaborately described 137in xkb specification) to key events. This is also the place where 138LED-indicators behaviour is defined. 139 </para> 140 </listitem> 141 </varlistentry> 142 <varlistentry> 143 <term>Symbols</term> 144 <listitem> 145 <para> 146For i18n purposes, this is the most important table. It defines what 147values (=symbols) are assigned to what keycodes (represented by their 148symbolic name, see above). There may be defined more than one value 149for each key and then it depends on a key type and on modifiers state 150(respective compat component) which value will be the resulting one. 151 </para> 152 </listitem> 153 </varlistentry> 154 <varlistentry> 155 <term>Geometry</term> 156 <listitem> 157 <para> 158Geometry files aren't used by xkb itself but they may be used by some 159external programs to depict a keyboard image. 160 </para> 161 </listitem> 162 </varlistentry> 163 </variablelist> 164All these components have the files located in xkb configuration tree 165in subdirectories with the same names (usually in 166<filename class="directory">/usr/lib/X11/xkb</filename>). 167 </para> 168 169 </sect1> 170 171 <sect1 id='Enhancing_XKB_Configuration'> 172 <title>Enhancing XKB Configuration</title> 173 174 <para> 175Most of xkb enhancements concerns a need to define new output symbols 176for the some input key events. In other words, a need to define a new 177symbol map (for a new language, standard or just to feel more comfortable 178when typing text). 179 </para> 180 181 <para> 182What do you need to do? Generally, you have to define following things: 183 184 <itemizedlist> 185 <listitem> 186 <para> 187 the map of symbols itself 188 </para> 189 </listitem> 190 <listitem> 191 <para> 192 the rules to allow users to select the new mapping 193 </para> 194 </listitem> 195 <listitem> 196 <para> 197 the description of the new layout 198 </para> 199 </listitem> 200 </itemizedlist> 201 202 </para> 203 204 <para> 205First of all, it is good to go through existing layouts and to examine 206them if there is something you could easily adjust to fit your needs. 207Even if there is nothing similar you may get some ideas about basic 208concepts and used tricks. 209 </para> 210 211 <sect2 id='Levels_And_Groups'> 212 <title>Levels And Groups</title> 213 214 <para> 215Since XFree86 4.3.0 and X11R6.7.0 you can use 216<firstterm>multi-layout</firstterm> concept of xkb 217configuration. 218Though it is still in boundaries of xkb protocol and general ideas, the 219keymap designer must obey new rules when creating new maps. In exchange 220we get a more powerful and cleaner configuration system. 221 </para> 222 223 <para> 224Remember that it is the application which must decide which symbol 225matches which keycode according to effective modifier state. The X server 226itself sends only an input event message to. Of course, usually 227the general interpretation is processed by Xlib, Xaw, Motif, Qt, Gtk 228and similar libraries. The X server only supplies its mapping table 229(usually upon an application startup). 230 </para> 231 232 <para> 233You can think of the X server's symbol table as of a irregular table where each 234keycode has its row and where each combination of modifiers determines exactly 235one column. The resulting cell then gives the proper symbolic value. Not all 236keycodes need to bind different values for different combination of modifiers. 237<keycode><ENTER></keycode> key, for instance, usually doesn't depend on any 238modifiers so it its row has only one column defined. 239 </para> 240 241 <para> 242Note that in XKB there is no prior assumption that certain modifiers are bound 243to certain columns. By editing proper files (see <xref linkend='Key_Types' xrefstyle='select: title'/>) 244this mapping can be changed as well. 245 </para> 246 247 <para> 248Unlike the original X protocol the XKB approach is far more 249flexible. It is comfortable to add one additional XKB term - group. You can 250think of a group as of a vector of columns per each keycode (naturally the 251dimension of this vector may differ for different keycodes). What is it good 252for? The group is not very useful unless you intend to use more than one 253logically different set of symbols (like more than one alphabet) defined in a 254single mapping table. But then, the group has a natural meaning - each symbol 255set has its own group and changing it means selecting a different one. 256XKB approach allows up to four different groups. The columns inside each group 257are called (shift) levels. The X server knows the current group and reports it 258together with modifier set and with a keycode in key events. 259 </para> 260 261 <para> 262To sum it up: 263 264 <itemizedlist> 265 <listitem> 266 <para> 267 for each keycode XKB keyboard map contains up to four one-dimensional 268tables - groups (logically different symbol sets) 269 </para> 270 </listitem> 271 <listitem> 272 <para> 273 for each group of a keycode XKB keyboard map contains some columns 274- shift levels (values reached by combinations of Shift, Ctrl, Alt, ... 275modifiers) 276 </para> 277 </listitem> 278 <listitem> 279 <para> 280 different keycodes can have different number of groups 281 </para> 282 </listitem> 283 <listitem> 284 <para> 285 different groups of one keycode can have different number of shift levels 286 </para> 287 </listitem> 288 <listitem> 289 <para> 290 the current group number is tracked by X server 291 </para> 292 </listitem> 293 </itemizedlist> 294 </para> 295 296 <para> 297It is clear that if you sanely define levels, groups and sanely bind 298modifiers and associated actions you can have simultaneously loaded up to 299four different symbol sets where each of them would reside in its own group. 300 </para> 301 302 <para> 303The multi-layout concept provides a facility to manipulate xkb groups 304and symbol definitions in a way that allows almost arbitrary composition of 305predefined symbol tables. To keep it fully functional you have to: 306 307 <itemizedlist> 308 <listitem> 309 <para> 310 define all symbols only in the first group 311 </para> 312 </listitem> 313 <listitem> 314 <para> 315 (re)define any modifiers with extra care to avoid strange (anisometric) 316behaviour 317 </para> 318 </listitem> 319 </itemizedlist> 320 321 </para> 322 323 </sect2> 324 325 </sect1> 326 327 <sect1 id='Defining_New_Layouts'> 328 <title>Defining New Layouts</title> 329 330<!-- 331 TODO: It may be better to merge IP01 docs and this guide. 332--> 333 334 <para> 335See <ulink url="http://www.tsu.ru/~pascal/en/xkb/internals.html" 336>Some Words About XKB internals</ulink 337> for explanation of used xkb terms and problems 338addressed by XKB extension. 339 </para> 340 341 <para> 342See <ulink url="http://www.tsu.ru/~pascal/en/xkb/gram-common.html" 343>Common notes about XKB configuration files language</ulink 344> for more precise explanation of 345syntax of xkb configuration files. 346 </para> 347 348 <sect2 id='Predefined_XKB_Symbol_Sets'> 349 <title>Predefined XKB Symbol Sets</title> 350 351 <para> 352If you are about to define some European symbol map extension, you might 353want to use on of four predefined latin alphabet layouts. 354 </para> 355 356<!-- 357 TODO: more details 358 TODO: something similar for phonetic layouts 359 TODO: what are pc/pc layouts good for??? 360--> 361 362 <para> 363Okay, let's assume you want extend an existing keymap and you want to override 364a few keys. Let's take a simple U.K. keyboard as an example (defined in 365<filename>pc/gb</filename>): 366 367 <screen> 368partial default alphanumeric_keys 369xkb_symbols "basic" { 370 include "pc/latin" 371 372 name[Group1]="Great Britain"; 373 374 key <AE02> { [ 2, quotedbl, twosuperior, oneeighth ] }; 375 key <AE03> { [ 3, sterling, threesuperior, sterling ] }; 376 key <AC11> { [apostrophe, at, dead_circumflex, dead_caron] }; 377 key <TLDE> { [ grave, notsign, bar, bar ] }; 378 key <BKSL> { [numbersign, asciitilde, dead_grave, dead_breve ] }; 379 key <RALT> { type[Group1]="TWO_LEVEL", 380 [ ISO_Level3_Shift, Multi_key ] }; 381 382 modifier_map Mod5 { <RALT> }; 383}; 384 </screen> 385 386 </para> 387 388<!-- 389 TODO: ref IP01 file syntax TODO: some words about symbolic names like 390 'sterling' and also about 391 TODO: unicode characters (for non-latin alphabets), 392 TODO: ref to compatibility symbolic names vs. unicode 393--> 394 395 <para> 396It defines a new layout in <literal remap="tt">basic</literal> variant as an extension of common 397latin alphabet layout. The layout (symbol set) name is set to "Great Britain". 398Then there are redefinitions of a few keycodes and a modifiers binding. As you 399can see the number of shift levels is the same for 400<keycode><AE02></keycode>, <keycode><AE03></keycode>, 401<keycode><AC11></keycode>, <keycode><TLDE></keycode> and 402<keycode><BKSL></keycode> keys but it differs from number of shift 403levels of <keycode><RALT></keycode>. 404 </para> 405 406 <para> 407Note that the <keycode><RALT></keycode> key itself is a binding key for Mod5 and 408that it 409serves like a shift modifier for LevelThree, together with Shift 410as a multi-key. It is a good habit to respect this rule in a new similar 411layout. 412 </para> 413 414 <para> 415Okay, you could now define more variants of your new layout besides 416<literal remap="tt">basic</literal> simply by including (augmenting/overriding/...) the basic 417definition and altering what may be needed. 418 </para> 419 420 </sect2> 421 422 <sect2 id='Key_Types'> 423<title>Key Types</title> 424 425 <para> 426The differences in the number of columns (shift levels) are caused by 427a different types of keys (see the types definition in section basics). Most 428keycodes have implicitly set the keytype in the included 429<quote><filename>pc/latin</filename></quote> file to 430<quote><literal remap="tt">FOUR_LEVEL_ALPHABETIC</literal></quote>. The only exception is 431<keycode><RALT></keycode> keycode which is explicitly set 432<quote><literal remap="tt">TWO_LEVEL</literal></quote> keytype. 433 </para> 434 435 <para> 436All those names refer to pre-defined shift level schemes. Usually you can 437choose a suitable shift level scheme from <literal remap="tt">default</literal> types scheme list 438in proper xkb component's subdirectory. 439 </para> 440 441 <para> 442The most used schemes are: 443 <variablelist> 444 <varlistentry> 445 <term>ONE_LEVEL</term> 446 <listitem> 447 <para> 448The key does not depend on any modifiers. The symbol from first level 449is always chosen. 450 </para> 451 </listitem> 452 </varlistentry> 453 <varlistentry> 454 <term>TWO_LEVEL</term> 455 <listitem> 456 <para> 457The key uses a modifier Shift and may have two possible values. 458The second level may be chosen by Shift modifier. If Lock modifier 459(usually Caps-lock) applies the symbol is further processed using 460system-specific capitalization rules. If both Shift+Lock modifier apply the 461symbol from the second level is taken and capitalization rules are applied 462(and usually have no effect). 463 </para> 464 </listitem> 465 </varlistentry> 466 <varlistentry> 467 <term>ALPHABETIC</term> 468 <listitem> 469 <para> 470The key uses modifiers Shift and Lock. It may have two possible 471values. The second level may be chosen by Shift modifier. When Lock 472modifier applies, the symbol from the first level is taken and further 473processed using system-specific capitalization rules. If both Shift+Lock 474modifier apply the symbol from the first level is taken and no 475capitalization rules applied. This is often called shift-cancels-caps 476behaviour. 477 </para> 478 </listitem> 479 </varlistentry> 480 <varlistentry> 481 <term>THREE_LEVEL</term> 482 <listitem> 483 <para> 484Is the same as TWO_LEVEL but it considers an extra modifier - 485LevelThree which can be used to gain the symbol value from the third 486level. If both Shift+LevelThree modifiers apply the value from the third 487level is also taken. As in TWO_LEVEL, the Lock modifier doesn't influence 488the resulting level. Only Shift and LevelThree are taken into that 489consideration. If the Lock modifier is active capitalization rules 490are applied on the resulting symbol. 491 </para> 492 </listitem> 493 </varlistentry> 494 <varlistentry> 495 <term>FOUR_LEVEL</term> 496 <listitem> 497 <para> 498Is the same as THREE_LEVEL but unlike LEVEL_THREE if both Shift+LevelThree 499modifiers apply the symbol is taken from the fourth level. 500 </para> 501 </listitem> 502 </varlistentry> 503 <varlistentry> 504 <term>FOUR_LEVEL_ALPHABETIC</term> 505 <listitem> 506 <para> 507Is similar to FOUR_LEVEL but also defines shift-cancels-caps behaviour 508as in ALPHABETIC. If Lock+LevelThree apply the symbol from the 509third level is taken and the capitalization rules are applied. 510If Lock+Shift+LevelThree apply the symbol from the third level is taken 511and no capitalization rules are applied. 512 </para> 513 </listitem> 514 </varlistentry> 515 <varlistentry> 516 <term>KEYPAD</term> 517 <listitem> 518 <para> 519As the name suggest this scheme is primarily used for numeric keypads. 520The scheme considers two modifiers - Shift and NumLock. If none 521of modifiers applies the symbol from the first level is taken. If either 522Shift or NumLock modifiers apply the symbol from the second level is taken. 523If both Shift+NumLock modifiers apply the symbol from the first level 524is taken. Again, shift-cancels-caps variant. 525 </para> 526 </listitem> 527 </varlistentry> 528 <varlistentry> 529 <term>FOUR_LEVEL_KEYPAD</term> 530 <listitem> 531 <para> 532Is similar to KEYPAD scheme but considers also LevelThree modifier. 533If LevelThree modifier applies the symbol from the third level is taken. 534If Shift+LevelThree or NumLock+LevelThree apply the symbol from the fourth 535level is taken. If all Shift+NumLock+LevelThree modifiers apply the symbol 536from the third level is taken. This also, shift-cancels-caps variant. 537 </para> 538 </listitem> 539 </varlistentry> 540 </variablelist> 541 </para> 542 543 <para> 544Besides that, there are several schemes for special purposes: 545 <variablelist> 546 547 <varlistentry> 548 <term>PC_BREAK</term> 549 <listitem> 550 <para> 551It is similar to TWO_LEVEL scheme but it considers the Control 552modifier rather than Shift. That means, the symbol from the second level 553is chosen by Control rather than by Shift. 554 </para> 555 </listitem> 556 </varlistentry> 557 <varlistentry> 558 <term>PC_SYSRQ</term> 559 <listitem> 560 <para> 561It is similar to TWO_LEVEL scheme but it considers the Alt modifier rather 562than Shift. That means, the symbol from the second level 563is chosen by Alt rather than by Shift. 564 </para> 565 </listitem> 566 </varlistentry> 567 <varlistentry> 568 <term>CTRL+ALT</term> 569 <listitem> 570 <para> 571The key uses modifiers Alt and Control. It may have two possible 572values. If only one modifier (Alt or Control) applies the symbol 573from the first level is chosen. Only if both Alt+Control modifiers apply 574the symbol from the second level is chosen. 575 </para> 576 </listitem> 577 </varlistentry> 578 <varlistentry> 579 <term>SHIFT+ALT</term> 580 <listitem> 581 <para> 582The key uses modifiers Shift and Alt. It may have two possible values. 583If only one modifier (Alt or Shift) applies the symbol 584from the first level is chosen. Only if both Alt+Shift modifiers apply 585the symbol from the second level is chosen. 586 </para> 587 </listitem> 588 </varlistentry> 589 </variablelist> 590 </para> 591 592 <para> 593If needed, special <literal remap="tt">caps</literal> schemes may be used. 594They redefine the standard behaviour of all 595<literal remap="tt">*ALPHABETIC</literal> types. The layouts (maps of 596symbols) with keys defined in respective types then automatically change 597their behaviour accordingly. Possible redefinitions are: 598 599 <itemizedlist> 600 <listitem><para>internal</para></listitem> 601 <listitem><para>internal_nocancel</para></listitem> 602 <listitem><para>shift</para></listitem> 603 <listitem><para>shift_nocancel</para></listitem> 604 </itemizedlist> 605 606None of these schemes should be used directly. They are defined merely 607for <literal remap="tt">'caps:'</literal> xkb options (used to globally 608change the layouts behaviour). 609 </para> 610 611 <para> 612Don't alter any of existing key types. If you need a different behaviour 613create a new one. 614 </para> 615 616 <sect3 id='More_On_Definitions_Of_Types'> 617 <title>More On Definitions Of Types</title> 618 619 <para> 620When the XKB software deals with a separate type description it gets 621a complete list of modifiers that should be taken into account from the 622<literal remap="tt">'modifiers=<list of modifiers>'</literal> list and expects that a set 623of <literal remap="tt">'map[<combination of modifiers>]=<list of modifiers>'</literal> 624instructions that contain the mapping for each combination of modifiers 625mentioned in that list. Modifiers that are not explicitly listed are NOT taken 626into account 627when the resulting shift level is computed. 628If some combination is omitted the program (subroutine) should choose the first 629level for this combination (a quite reasonable behavior). 630 </para> 631 632 <para> 633Lets consider an example with two modifiers <keysym>ModOne</keysym> and 634<keysym>ModTwo</keysym>: 635 636 <screen> 637type "..." { 638 modifiers = ModOne+ModTwo; 639 map[None] = Level1; 640 map[ModOne] = Level2; 641}; 642 </screen> 643 644In this case the map statements for <keysym>ModTwo</keysym> only and 645<keysym>ModOne+ModTwo</keysym> are omitted. It means that if 646the <keysym>ModTwo</keysym> is active the subroutine can't found 647explicit mapping for such combination an will use 648the <emphasis>default level</emphasis> i.e. Level1. 649 </para> 650 651 <para> 652But in the case the type described as: 653 654 <screen> 655type "..." { 656 modifiers = ModOne; 657 map[None] = Level1; 658 map[ModOne] = Level2; 659}; 660 </screen> 661 662the ModTwo will not be taken into account and the resulting level depends on 663the ModOne state only. That means, ModTwo alone produces the Level1 but the 664combination ModOne+ModTwo produces the Level2 as well as ModOne alone. 665 </para> 666 667 <para> 668What does it mean if the second modifier is the Lock? It means that in 669the first case (the Lock itself is included in the list of modifiers but 670combinations with this modifier aren't mentioned in the map statements) 671the internal capitalization rules will be applied to the symbol from the first 672level. But in the second case the capitalization will be applied to the symbol 673chosen accordingly to the first modifier - and this can be the symbol from the 674first as well as from the second level. 675 </para> 676 677 <para> 678Usually, all modifiers introduced in <literal remap="tt">'modifiers=<list of modifiers>'</literal> list are used for shift level calculation and then 679discarded. Sometimes this is not desirable. If you want to use a modifier 680for shift level calculation but you don't want to discard it, you may 681list in '<literal remap="tt">preserve[<combination of modifiers>]=<list of modifiers>'</literal>. That means, for a given combination all listed modifiers 682will be preserved. If the Lock modifier is preserved then the resulting 683symbol is passed to internal capitalization routine regardless whether 684it has been used for a shift level calculation or not. 685 </para> 686 687 <para> 688Any key type description can use both real and virtual modifiers. Since real 689modifiers always have standard names it is not necessary to explicitly declare 690them. Virtual modifiers can have arbitrary names and can be declared (prior 691using them) directly in key type definition: 692 693 <screen> 694virtual_modifiers <comma-separated list of modifiers> ; 695 </screen> 696 697as seen in for example <literal remap="tt">basic</literal>, <literal remap="tt">pc</literal> or <literal remap="tt">mousekeys</literal> key 698type definitions. 699 </para> 700 701 </sect3> 702 703 </sect2> 704 705 <sect2 id='Rules'> 706 <title>Rules</title> 707 708 <para> 709Once you are finished with your symbol map you need to add it 710to rules file. The rules file describes how all the 711five basic keycodes, types, compat, symbols and geometry components 712should be composed to give a sensible resulting xkb configuration. 713 </para> 714 715 <para> 716The main advantage of rules over formerly used keymaps is a possibility 717to simply parameterize (once) fixed patterns of configurations and thus 718to elegantly allow substitutions of various local configurations 719into predefined templates. 720 </para> 721 722 <para> 723A pattern in a rules file (often located in 724<filename>/usr/lib/X11/xkb/rules</filename>) 725 can be parameterized with four other arguments: 726<literal remap="tt">Model</literal>, <literal remap="tt">Layout</literal>, 727<literal remap="tt">Variant</literal> and <literal remap="tt">Options</literal>. 728For most cases parameters <literal remap="tt">model</literal> and 729<literal remap="tt">layout</literal> should 730be sufficient for choosing a functional keyboard mapping. 731 </para> 732 733 <para> 734The rules file itself is composed of pattern lines and lines with rules. The 735pattern line starts with an exclamation mark ('<literal remap="tt">!</literal>') 736and describes how will the xkb interpret the following lines (rules). A sample 737rules file looks like this: 738 739 <screen> 740! model = keycodes 741 macintosh_old = macintosh 742 ... 743 * = xorg 744 745! model = symbols 746 hp = +inet(%m) 747 microsoftpro = +inet(%m) 748 geniuscomfy = +inet(%m) 749 750! model layout[1] = symbols 751 macintosh us = macintosh/us%(v[1]) 752 * * = pc/pc(%m)+pc/%l[1]%(v[1]) 753 754! model layout[2] = symbols 755 macintosh us = +macintosh/us[2]%(v[2]):2 756 * * = +pc/%l[2]%(v[2]):2 757 758! option = types 759 caps:internal = +caps(internal) 760 caps:internal_nocancel = +caps(internal_nocancel) 761 </screen> 762 763 </para> 764 765 <para> 766Each rule defines what certain combination of values on the left side 767of equal sign ('<literal remap="tt">=</literal>') results in. For 768example a (keyboard) model <literal remap="tt">macintosh_old</literal> 769instructs xkb to take definitions of keycodes from 770file <filename>keycodes/macintosh</filename> while the rest 771of models (represented by a wild card '<literal remap="tt">*</literal>') 772instructs it to take them from file <filename>keycodes/xorg</filename>. 773The wild card represents all possible values on the left side which 774were not found in any of the previous rules. The more specialized 775(more complete) rules have higher precedence than general ones, 776i.e. the more general rules supply reasonable default values. 777 </para> 778 779 <para> 780As you can see some lines contain substitution parameters - the parameters 781preceded by the percent sign ('<literal remap="tt">%</literal>'). 782The first alphabetical character after the percent sign expands to the 783value which has been found on the left side. For 784example <literal remap="tt">+%l%(v)</literal> expands 785into <literal remap="tt">+cz(bksl)</literal> if the respective values 786on the left side were <literal remap="tt">cz</literal> layout in 787its <literal remap="tt">bksl</literal> variant. More, if the layout 788resp. variant parameter is followed by a pair of brackets 789('<literal remap="tt">[</literal>', '<literal remap="tt">]</literal>') 790it means that xkb should <emphasis>place the layout resp. variant into 791specified xkb group</emphasis>. If the brackets are omitted the first 792group is the default value. 793 </para> 794 795 <para> 796So the second block of rules enhances symbol definitions for some particular 797keyboard models with extra keys (for internet, multimedia, ...) . Other models 798are left intact. Similarly, the last block overrides some key type definitions, 799so the common global behaviour ''shift cancels caps'' or ''shift doesn't cancel 800caps'' can be selected. The rest of rules produces special symbols for each 801variant <literal remap="tt">us</literal> layout of 802<literal remap="tt">macintosh</literal> keyboard and standard pc 803symbols in appropriate variants as a default. 804 </para> 805 806 </sect2> 807 808<!-- 809 TODO: more words about group switching (XkbOptions grp:...)? 810--> 811 812<!-- 813 TODO: user & 3rd party xkb tree? 814 TODO: better and more complex explanation of rules 815--> 816 817 <sect2 id='Descriptive_Files_of_Rules'> 818 <title>Descriptive Files of Rules</title> 819 820 <para> 821Now you just need to add a detailed description to 822<filename><rules>.xml</filename> 823description file so the other users (and external programs which often parse 824this file) know what is your work about. 825 </para> 826 827<!-- 828 TODO: format and semantics 829--> 830 831 <sect3 id='Old_Descriptive_Files'> 832 <title>Old Descriptive Files</title> 833 834 <para> 835The formerly used descriptive files were named <filename><rules>.lst</filename> 836Its structure is very simple and quite self descriptive but such simplicity 837had also some cavities, for example there was no way how to describe local 838variants of layouts and there were problems with the localization of 839descriptions. To preserve compatibility with some older programs, 840new XML descriptive files can be converted to old format '.lst'. 841 </para> 842 843 <para> 844For each parameter of rules file should be described its meaning. For the rules 845file described above the <filename>.lst</filename> file could look like: 846 847 <screen> 848! model 849 pc104 Generic 104-key PC 850 microsoft Microsoft Natural 851 pc98 PC-98xx Series 852 macintosh Original Macintosh 853 ... 854 855! layout 856 us U.S. English 857 cz Czech 858 de German 859 ... 860 861! option 862 caps:internal uses internal capitalization. Shift cancels Caps 863 caps:internal_nocancel uses internal capitalization. Shift doesn't cancel Caps 864 865 </screen> 866 867 </para> 868 869 <para> 870And that should be it. Enjoy creating your own xkb mapping. 871 </para> 872 873 </sect3> 874 875 </sect2> 876 877 </sect1> 878 879</article> 880