head	1.1;
branch	1.1.1;
access;
symbols
	netbsd-11-0-RC4:1.1.1.6
	netbsd-11-0-RC3:1.1.1.6
	netbsd-11-0-RC2:1.1.1.6
	netbsd-11-0-RC1:1.1.1.6
	netbsd-11:1.1.1.6.0.4
	netbsd-11-base:1.1.1.6
	netbsd-10-1-RELEASE:1.1.1.6
	netbsd-8-3-RELEASE:1.1.1.4
	netbsd-9-4-RELEASE:1.1.1.4
	netbsd-10-0-RELEASE:1.1.1.6
	netbsd-10-0-RC6:1.1.1.6
	netbsd-10-0-RC5:1.1.1.6
	netbsd-10-0-RC4:1.1.1.6
	netbsd-10-0-RC3:1.1.1.6
	netbsd-10-0-RC2:1.1.1.6
	netbsd-10-0-RC1:1.1.1.6
	xkeyboard-config-2-38:1.1.1.6
	netbsd-10:1.1.1.6.0.2
	netbsd-10-base:1.1.1.6
	xkeyboard-config-2-37:1.1.1.6
	netbsd-9-3-RELEASE:1.1.1.4
	xkeyboard-config-2-34:1.1.1.5
	xkeyboard-config-2-33:1.1.1.5
	netbsd-9-2-RELEASE:1.1.1.4
	xkeyboard-config-2-32:1.1.1.5
	xkeyboard-config-2-31:1.1.1.5
	netbsd-9-1-RELEASE:1.1.1.4
	netbsd-8-2-RELEASE:1.1.1.4
	xkeyboard-config-2-29:1.1.1.4
	netbsd-9-0-RELEASE:1.1.1.4
	netbsd-9-0-RC2:1.1.1.4
	netbsd-9-0-RC1:1.1.1.4
	netbsd-9:1.1.1.4.0.10
	netbsd-9-base:1.1.1.4
	xkeyboard-config-2-27:1.1.1.4
	netbsd-8-1-RELEASE:1.1.1.4
	netbsd-8-1-RC1:1.1.1.4
	xkeyboard-config-2-26:1.1.1.4
	xkeyboard-config-2-25:1.1.1.4
	netbsd-7-2-RELEASE:1.1.1.4
	netbsd-8-0-RELEASE:1.1.1.4
	netbsd-8-0-RC2:1.1.1.4
	netbsd-8-0-RC1:1.1.1.4
	netbsd-7-1-2-RELEASE:1.1.1.4
	xkeyboard-config-2-23-1:1.1.1.4
	netbsd-7-1-1-RELEASE:1.1.1.4
	xkeyboard-config-2-21:1.1.1.4
	netbsd-8:1.1.1.4.0.8
	netbsd-8-base:1.1.1.4
	netbsd-7-1:1.1.1.4.0.6
	netbsd-7-1-RELEASE:1.1.1.4
	netbsd-7-1-RC2:1.1.1.4
	xkeyboard-config-2-20:1.1.1.4
	netbsd-7-1-RC1:1.1.1.4
	xkeyboard-config-2-19:1.1.1.4
	netbsd-7-0-2-RELEASE:1.1.1.4
	netbsd-7-0-1-RELEASE:1.1.1.4
	netbsd-7-0:1.1.1.4.0.4
	netbsd-7-0-RELEASE:1.1.1.4
	netbsd-7-0-RC3:1.1.1.4
	netbsd-7-0-RC2:1.1.1.4
	xkeyboard-config-2-15:1.1.1.4
	netbsd-7-0-RC1:1.1.1.4
	netbsd-5-2-3-RELEASE:1.1.1.1
	netbsd-5-1-5-RELEASE:1.1.1.1
	netbsd-6-0-6-RELEASE:1.1.1.3
	netbsd-6-1-5-RELEASE:1.1.1.3
	netbsd-7:1.1.1.4.0.2
	netbsd-7-base:1.1.1.4
	xkeyboard-config-2-12:1.1.1.4
	netbsd-6-1-4-RELEASE:1.1.1.3
	netbsd-6-0-5-RELEASE:1.1.1.3
	riastradh-xf86-video-intel-2-7-1-pre-2-21-15:1.1.1.3
	xkeyboard-config-2-11:1.1.1.3
	riastradh-drm2:1.1.1.3.0.8
	riastradh-drm2-base:1.1.1.3
	netbsd-6-1-3-RELEASE:1.1.1.3
	netbsd-6-0-4-RELEASE:1.1.1.3
	netbsd-5-2-2-RELEASE:1.1.1.1
	netbsd-5-1-4-RELEASE:1.1.1.1
	netbsd-6-1-2-RELEASE:1.1.1.3
	netbsd-6-0-3-RELEASE:1.1.1.3
	netbsd-5-2-1-RELEASE:1.1.1.1
	netbsd-5-1-3-RELEASE:1.1.1.1
	netbsd-6-1-1-RELEASE:1.1.1.3
	xkeyboard-config-2-9:1.1.1.3
	netbsd-6-1:1.1.1.3.0.6
	netbsd-6-0-2-RELEASE:1.1.1.3
	netbsd-6-1-RELEASE:1.1.1.3
	netbsd-6-1-RC4:1.1.1.3
	netbsd-6-1-RC3:1.1.1.3
	netbsd-6-1-RC2:1.1.1.3
	netbsd-6-1-RC1:1.1.1.3
	netbsd-5-2:1.1.1.1.0.8
	netbsd-6-0-1-RELEASE:1.1.1.3
	netbsd-5-2-RELEASE:1.1.1.1
	netbsd-5-2-RC1:1.1.1.1
	netbsd-6-0:1.1.1.3.0.4
	netbsd-6-0-RELEASE:1.1.1.3
	netbsd-6-0-RC2:1.1.1.3
	netbsd-6-0-RC1:1.1.1.3
	netbsd-6:1.1.1.3.0.2
	netbsd-6-base:1.1.1.3
	netbsd-5-1-2-RELEASE:1.1.1.1
	netbsd-5-1-1-RELEASE:1.1.1.1
	xkeyboard-config-2-3:1.1.1.3
	xkeyboard-config-2-1:1.1.1.2
	xkeyboard-config-2-0:1.1.1.2
	netbsd-5-1:1.1.1.1.0.6
	netbsd-5-1-RELEASE:1.1.1.1
	netbsd-5-1-RC4:1.1.1.1
	netbsd-5-1-RC3:1.1.1.1
	xkeyboard-config-1-9:1.1.1.2
	netbsd-5-1-RC2:1.1.1.1
	netbsd-5-1-RC1:1.1.1.1
	netbsd-5-0-2-RELEASE:1.1.1.1
	netbsd-5-0-1-RELEASE:1.1.1.1
	xkeyboard-config-1-4:1.1.1.1
	netbsd-5-0:1.1.1.1.0.4
	netbsd-5-0-RELEASE:1.1.1.1
	netbsd-5-0-RC4:1.1.1.1
	netbsd-5-0-RC3:1.1.1.1
	netbsd-5-0-RC2:1.1.1.1
	netbsd-5-0-RC1:1.1.1.1
	netbsd-5:1.1.1.1.0.2
	netbsd-5-base:1.1.1.1
	xkeyboard-config-1-3:1.1.1.1
	xorg:1.1.1;
locks; strict;
comment	@# @;


1.1
date	2008.08.30.09.12.23;	author mrg;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2008.08.30.09.12.23;	author mrg;	state Exp;
branches;
next	1.1.1.2;

1.1.1.2
date	2010.05.28.09.54.51;	author ghen;	state Exp;
branches;
next	1.1.1.3;

1.1.1.3
date	2011.07.23.11.20.08;	author mrg;	state Exp;
branches;
next	1.1.1.4;

1.1.1.4
date	2014.07.11.19.08.50;	author mrg;	state Exp;
branches;
next	1.1.1.5;
commitid	sTMk7xRU971ADZHx;

1.1.1.5
date	2020.11.01.12.00.13;	author mrg;	state Exp;
branches;
next	1.1.1.6;
commitid	75Iv0Ep30piUabuC;

1.1.1.6
date	2022.10.17.07.37.06;	author mrg;	state Exp;
branches;
next	;
commitid	WK5G7TzJGmFIJ2YD;


desc
@@


1.1
log
@Initial revision
@
text
@                  How to further enhance XKB configuration

                         Kamil Toman, Ivan U. Pascal

                              25 November 2002

                                  Abstract

     This guide is aimed to relieve one's labour to create a new (inter-
     nationalized) keyboard layout. Unlike other documents this guide
     accents the keymap developer's point of view.

1.  Overview

The developer of a new layout should read the xkb protocol specification (The
X Keyboard Extension: Protocol Specification <URL:http://www.x-
docs.org/XKB/XKBproto.pdf>) at least to clarify for himself some xkb-specific
terms used in this document and elsewhere in xkb configuration. Also it shows
wise to understand how the X server and a client digest their keyboard inputs
(with and without xkb).

A useful source is also Ivan  Pascal's text about xkb configuration
<URL:http://www.tsu.ru/~pascal/en/xkb> often referenced throughout this docu-
ment.

Note that this document covers only enhancements which are to be made to
XFree86 version 4.3.x and above.

2.  The Basics

At the startup (or at later at user's command) X server starts its xkb key-
board module extension and reads data from a compiled configuration file.

This compiled configuration file is prepared by the program xkbcomp which
behaves altogether as an ordinary compiler (see man xkbcomp).  Its input are
human readable xkb configuration files which are verified and then composed
into a useful xkb configuration. Users don't need to mess with xkbcomp them-
selves, for them it is invisible. Usually, it is started upon X server
startup.

As you probably already know, the xkb configuration consists of five main
modules:

      Keycodes
            Tables that defines translation from keyboard scan codes into
            reasonable symbolic names, maximum, minimum legal keycodes, sym-
            bolic aliases and description of physically present LED-indica-
            tors. The primary sence of this component is to allow definitions
            of maps of symbols (see below) to be independent of physical key-
            board scancodes. There are two main naming conventions for sym-
            bolic names (always four bytes long):

               o  names which express some traditional meaning like <SPCE>
                 (stands for space bar) or

               o  names which express some relative positioning on a key-
                 board, for example <AE01> (an exclamation mark on US key-
                 boards), on the right there are keys <AE02>, <AE03> etc.

      Types
            Types describe how the produced key is changed by active modi-
            fiers (like Shift, Control, Alt, ...). There are several prede-
            fined types which cover most of used combinations.

      Compat
            Compatibility component defines internal behaviour of modifiers.
            Using compat component you can assign various actions (elabo-
            rately described in xkb specification) to key events. This is
            also the place where LED-indicators behaviour is defined.

      Symbols
            For i18n purposes, this is the most important table. It defines
            what values (=symbols) are assigned to what keycodes (represented
            by their symbolic name, see above). There may be defined more
            than one value for each key and then it depends on a key type and
            on modifiers state (respective compat component) which value will
            be the resulting one.

      Geometry
            Geometry files aren't used by xkb itself but they may be used by
            some external programs to depict a keyboard image.

All these components have the files located in xkb configuration tree in sub-
directories with the same names (usually in /usr/lib/X11/xkb).

3.  Enhancing XKB Configuration

Most of xkb enhancements concerns a need to define new output symbols for the
some input key events. In other words, a need to define a new symbol map (for
a new language, standard or just to feel more comfortable when typing text).

What do you need to do? Generally, you have to define following things:

   o  the map of symbols itself

   o  the rules to allow users to select the new mapping

   o  the description of the new layout

First of all, it is good to go through existing layouts and to examine them
if there is something you could easily adjust to fit your needs.  Even if
there is nothing similar you may get some ideas about basic concepts and used
tricks.

3.1  Levels And Groups

Since XFree86 4.3.0 you can use multi-layout concept of xkb configuration.
Though it is still in boundaries of xkb protocol and general ideas, the
keymap designer must obey new rules when creating new maps. In exchange we
get a more powerful and cleaner configuration system.

Remember that it is the application which must decide which symbol matches
which keycode according to effective modifier state. The X server itself
sends only an input event message to. Of course, usually the general inter-
pretation is processed by Xlib, Xaw, Motif, Qt, Gtk and similar libraries.
The X server only supplies its mapping table (usually upon an application
startup).

You can think of the X server's symbol table as of a irregular table where
each keycode has its row and where each combination of modifiers determines
exactly one column. The resulting cell then gives the proper symbolic value.
Not all keycodes need to bind different values for different combination of
modifiers.  <ENTER> key, for instance, usually doesn't depend on any modi-
fiers so it its row has only one column defined.

Note that in XKB there is no prior assumption that certain modifiers are
bound to certain columns. By editing proper files (see keytypes (section 4.2,
page 1)) this mapping can be changed as well.

Unlike the original X protocol the XKB approach is far more flexible. It is
comfortable to add one additional XKB term - group. You can think of a group
as of a vector of columns per each keycode (naturally the dimension of this
vector may differ for different keycodes). What is it good for? The group is
not very useful unless you intend to use more than one logically different
set of symbols (like more than one alphabet) defined in a single mapping ta-
ble. But then, the group has a natural meaning - each symbol set has its own
group and changing it means selecting a different one.  XKB approach allows
up to four different groups. The columns inside each group are called (shift)
levels. The X server knows the current group and reports it together with
modifier set and with a keycode in key events.

To sum it up:

   o  for each keycode XKB keyboard map contains up to four one-dimensional
     tables - groups (logically different symbol sets)

   o  for each group of a keycode XKB keyboard map contains some columns -
     shift levels (values reached by combinations of Shift, Ctrl, Alt, ...
     modifiers)

   o  different keycodes can have different number of groups

   o  different groups of one keycode can have different number of shift lev-
     els

   o  the current group number is tracked by X server

It is clear that if you sanely define levels, groups and sanely bind modi-
fiers and associated actions you can have simultaneously loaded up to four
different symbol sets where each of them would reside in its own group.

The multi-layout concept provides a facility to manipulate xkb groups and
symbol definitions in a way that allows almost arbitrary composition of pre-
defined symbol tables. To keep it fully functional you have to:

   o  define all symbols only in the first group

   o  (re)define any modifiers with extra care to avoid strange (anisometric)
     behaviour

4.  Defining New Layouts

See Some Words  About XKB internals <URL:http://www.tsu.ru/~pas-
cal/en/xkb/internals.html> for explanation of used xkb terms and problems
addressed by XKB extension.

See Common  notes about XKB configuration files language
<URL:http://www.tsu.ru/~pascal/en/xkb/gram-common.html> for more precise
explanation of syntax of xkb configuration files.

4.1  Predefined XKB Symbol Sets

If you are about to define some European symbol map extension, you might want
to use on of four predefined latin alphabet layouts.

Okay, let's assume you want extend an existing keymap and you want to over-
ride a few keys. Let's take a simple U.K. keyboard as an example (defined in
pc/gb):

     partial default alphanumeric_keys
     xkb_symbols "basic" {
       include "pc/latin"

       name[Group1]="Great Britain";

       key <AE02>  { [         2,   quotedbl,  twosuperior,    oneeighth ] };
       key <AE03>  { [         3,   sterling, threesuperior,    sterling ] };
       key <AC11>  { [apostrophe,         at, dead_circumflex, dead_caron] };
       key <TLDE>  { [     grave,    notsign,          bar,          bar ] };
       key <BKSL>  { [numbersign, asciitilde,   dead_grave,   dead_breve ] };
       key <RALT>  { type[Group1]="TWO_LEVEL",
                     [ ISO_Level3_Shift, Multi_key ]   };

       modifier_map Mod5   { <RALT> };
     };

It defines a new layout in basic variant as an extension of common latin
alphabet layout. The layout (symbol set) name is set to "Great Britain".
Then there are redefinitions of a few keycodes and a modifiers binding. As
you can see the number of shift levels is the same for <AE02>, <AE03>,
<AC11>, <TLDE> and <BKSL> keys but it differs from number of shift levels of
<RALT>.

Note that the <RALT> key itself is a binding key for Mod5 and that it serves
like a shift modifier for LevelThree, together with Shift as a multi-key. It
is a good habit to respect this rule in a new similar layout.

Okay, you could now define more variants of your new layout besides basic
simply by including (augmenting/overriding/...) the basic definition and
altering what may be needed.

4.2  Key Types

The differences in the number of columns (shift levels) are caused by a dif-
ferent types of keys (see the types definition in section basics).  Most key-
codes have implicitly set the keytype in the included "pc/latin" file to
"FOUR_LEVEL_ALPHABETIC". The only exception is <RALT> keycode which is
explicitly set "TWO_LEVEL" keytype.

All those names refer to pre-defined shift level schemes. Usually you can
choose a suitable shift level scheme from default types scheme list in proper
xkb component's subdirectory.

The most used schemes are:

      ONE_LEVEL
            The key does not depend on any modifiers. The symbol from first
            level is always chosen.

      TWO_LEVEL
            The key uses a modifier Shift and may have two possible values.
            The second level may be chosen by Shift modifier. If Lock modi-
            fier (usually Caps-lock) applies the symbol is further processed
            using system-specific capitalization rules. If both Shift+Lock
            modifier apply the symbol from the second level is taken and cap-
            italization rules are applied (and usually have no effect).

      ALPHABETIC
            The key uses modifiers Shift and Lock. It may have two possible
            values. The second level may be chosen by Shift modifier. When
            Lock modifier applies, the symbol from the first level is taken
            and further processed using system-specific capitalization rules.
            If both Shift+Lock modifier apply the symbol from the first level
            is taken and no capitalization rules applied. This is often
            called shift-cancels-caps behaviour.

      THREE_LEVEL
            Is the same as TWO_LEVEL but it considers an extra modifier -
            LevelThree which can be used to gain the symbol value from the
            third level. If both Shift+LevelThree modifiers apply the value
            from the third level is also taken. As in TWO_LEVEL, the Lock
            modifier doesn't influence the resulting level. Only Shift and
            LevelThree are taken into that consideration. If the Lock modi-
            fier is active capitalization rules are applied on the resulting
            symbol.

      FOUR_LEVEL
            Is the same as THREE_LEVEL but unlike LEVEL_THREE if both
            Shift+LevelThree modifiers apply the symbol is taken from the
            fourth level.

      FOUR_LEVEL_ALPHABETIC
            Is similar to FOUR_LEVEL but also defines shift-cancels-caps
            behaviour as in ALPHABETIC. If Lock+LevelThree apply the symbol
            from the third level is taken and the capitalization rules are
            applied.  If Lock+Shift+LevelThree apply the symbol from the
            third level is taken and no capitalization rules are applied.

      KEYPAD
            As the name suggest this scheme is primarily used for numeric
            keypads.  The scheme considers two modifiers - Shift and NumLock.
            If none of modifiers applies the symbol from the first level is
            taken. If either Shift or NumLock modifiers apply the symbol from
            the second level is taken.  If both Shift+NumLock modifiers apply
            the symbol from the first level is taken. Again, shift-cancels-
            caps variant.

      FOUR_LEVEL_KEYPAD
            Is similar to KEYPAD scheme but considers also LevelThree modi-
            fier.  If LevelThree modifier applies the symbol from the third
            level is taken.  If Shift+LevelThree or NumLock+LevelThree apply
            the symbol from the fourth level is taken. If all Shift+Num-
            Lock+LevelThree modifiers apply the symbol from the third level
            is taken. This also, shift-cancels-caps variant.

      FOUR_LEVEL_MIXED_KEYPAD
	    A four-level keypad scheme where the first two levels are similar
            to the KEYPAD scheme (NumLock+Shift)
            LevelThree acts as an override providing access to two Shift-ed
            levels. When LevelThree is active we totally ignore NumLock state
            Intended for the digit area of the keypad

      FOUR_LEVEL_X
            A four-level scheme where the base level accepts no modifier,
            LevelThree provides two more Shift-ed levels like in the previous
            scheme, and Ctrl+Alt controls the fourth level
            Intended for the operator part of a keypad, though since NumLock
            plays no part, it is not keypad-specific

Besides that, there are several schemes for special purposes:

      PC_CONTROL_LEVEL2
            It is similar to TWO_LEVEL scheme but it considers the Control
            modifier rather than Shift. That means, the symbol from the sec-
            ond level is chosen by Control rather than by Shift.

      PC_ALT_LEVEL2
            It is similar to TWO_LEVEL scheme but it considers the Alt modi-
            fier rather than Shift. That means, the symbol from the second
            level is chosen by Alt rather than by Shift.

      CTRL+ALT
            The key uses modifiers Alt and Control. It may have two possible
            values. If only one modifier (Alt or Control) applies the symbol
            from the first level is chosen. Only if both Alt+Control modi-
            fiers apply the symbol from the second level is chosen.

      SHIFT+ALT
            The key uses modifiers Shift and Alt. It may have two possible
            values.  If only one modifier (Alt or Shift) applies the symbol
            from the first level is chosen. Only if both Alt+Shift modifiers
            apply the symbol from the second level is chosen.

If needed, special caps schemes may be used. They redefine the standard
behaviour of all *ALPHABETIC types. The layouts (maps of symbols) with keys
defined in respective types then automatically change their behaviour accord-
ingly. Possible redefinitions are:

   o internal

   o internal_nocancel

   o shift

   o shift_nocancel

None of these schemes should be used directly. They are defined merely for
'caps:' xkb options (used to globally change the layouts behaviour).

Don't alter any of existing key types. If you need a different behaviour cre-
ate a new one.

4.2.1  More On Definitions Of Types

When the XKB software deals with a separate type description it gets a com-
plete list of modifiers that should be taken into account from the 'modi-
fiers=<list of modifiers>' list and expects that a set of 'map[<combination
of modifiers>]=<list of modifiers>' instructions that contain the mapping for
each combination of modifiers mentioned in that list. Modifiers that are not
explicitly listed are NOT taken into account when the resulting shift level
is computed.  If some combination is omitted the program (subroutine) should
choose the first level for this combination (a quite reasonable behavior).

Lets consider an example with two modifiers ModOne and ModTwo:

     type "..." {
         modifiers = ModOne+ModTwo;
         map[None] = Level1;
         map[ModOne] = Level2;
     };

In this case the map statements for ModTwo only and ModOne+ModTwo are omit-
ted.  It means that if the ModTwo is active the subroutine can't found
explicit mapping for such combination an will use the default level i.e.
Level1.

But in the case the type described as:

     type "..." {
         modifiers = ModOne;
         map[None] = Level1;
         map[ModOne] = Level2;
     };

the ModTwo will not be taken into account and the resulting level depends on
the ModOne state only. That means, ModTwo alone produces the Level1 but the
combination ModOne+ModTwo produces the Level2 as well as ModOne alone.

What does it mean if the second modifier is the Lock? It means that in the
first case (the Lock itself is included in the list of modifiers but combina-
tions with this modifier aren't mentioned in the map statements) the internal
capitalization rules will be applied to the symbol from the first level. But
in the second case the capitalization will be applied to the symbol chosen
accordingly to he first modifier - and this can be the symbol from the first
as well as from the second level.

Usually, all modifiers introduced in 'modifiers=<list of modifiers>' list are
used for shift level calculation and then discarded. Sometimes this is not
desirable. If you want to use a modifier for shift level calculation but you
don't want to discard it, you may list in 'preserve[<combination of modi-
fiers>]=<list of modifiers>'. That means, for a given combination all listed
modifiers will be preserved. If the Lock modifier is preserved then the
resulting symbol is passed to internal capitalization routine regardless
whether it has been used for a shift level calculation or not.

Any key type description can use both real and virtual modifiers. Since real
modifiers always have standard names it is not necessary to explicitly
declare them. Virtual modifiers can have arbitrary names and can be declared
(prior using them) directly in key type definition:

     virtual_modifiers <comma-separated list of modifiers>  ;

as seen in for example basic, pc or mousekeys key type definitions.

4.3  Rules

Once you are finished with your symbol map you need to add it to rules file.
The rules file describes how all the five basic keycodes, types, compat, sym-
bols and geometry components should be composed to give a sensible resulting
xkb configuration.

The main advantage of rules over formerly used keymaps is a possibility to
simply parameterize (once) fixed patterns of configurations and thus to ele-
gantly allow substitutions of various local configurations into predefined
templates.

A pattern in a rules file (often located in /usr/lib/X11/xkb/rules) can be
parameterized with four other arguments: Model, Layout, Variant and Options.
For most cases parameters model and layout should be sufficient for choosing
a functional keyboard mapping.

The rules file itself is composed of pattern lines and lines with rules. The
pattern line starts with an exclamation mark ('!') and describes how will the
xkb interpret the following lines (rules). A sample rules file looks like
this:

     ! model                   =   keycodes
       macintosh_old                     =   macintosh
       ...
       *                       =   xfree86

     ! model                        =   symbols
       hp                      =   +inet(%m)
       microsoftpro                 =   +inet(%m)
       geniuscomfy                  =   +inet(%m)

     ! model       layout[1]          = symbols
       macintosh    us           = macintosh/us%(v[1])
       *             *               =       pc/pc(%m)+pc/%l[1]%(v[1])

     ! model     layout[2]            = symbols
       macintosh     us              =  +macintosh/us[2]%(v[2]):2
       *       *               =   +pc/%l[2]%(v[2]):2

     ! option            =    types
       caps:internal               =    +caps(internal)
       caps:internal_nocancel =    +caps(internal_nocancel)

Each rule defines what certain combination of values on the left side of
equal sign ('=') results in. For example a (keyboard) model macintosh_old
instructs xkb to take definitions of keycodes from file keycodes/macintosh
while the rest of models (represented by a wild card '*') instructs it to
take them from file keycodes/xfree86. The wild card represents all possible
values on the left side which were not found in any of the previous rules.
The more specialized (more complete) rules have higher precedence than gen-
eral ones, i.e. the more general rules supply reasonable default values.

As you can see some lines contain substitution parameters - the parameters
preceded by the percent sign ('%'). The first alphabetical character after
the percent sign expands to the value which has been found on the left side.
For example +%l%(v) expands into +cz(bksl) if the respective values on the
left side were cz layout in its bksl variant. More, if the layout resp. vari-
ant  parameter is followed by a pair of brackets ('[', ']') it means that xkb
should place the layout resp. variant into specified xkb group. If the brack-
ets are omitted the first group is the default value.

So the second block of rules enhances symbol definitions for some particular
keyboard models with extra keys (for internet, multimedia, ...) . Other mod-
els are left intact. Similarly, the last block overrides some key type defi-
nitions, so the common global behaviour ''shift cancels caps'' or ''shift
doesn't cancel caps'' can be selected. The rest of rules produces special
symbols for each variant us layout of macintosh keyboard and standard pc sym-
bols in appropriate variants as a default.

4.4  Descriptive Files of Rules

Now you just need to add a detailed description to <rules>.xml description
file so the other users (and external programs which often parse this file)
know what is your work about.

4.4.1  Old Descriptive Files

The formerly used descriptive files were named <rules>.lst Its structure is
very simple and quite self descriptive but such simplicity had also some cav-
ities, for example there was no way how to describe local variants of layouts
and there were problems with the localization of descriptions. To preserve
compatibility with some older programs, new XML descriptive files can be con-
verted to old format '.lst'.

For each parameter of rules file should be described its meaning. For the
rules file described above the .lst file could look like:

     ! model
       pc104        Generic 104-key PC
       microsoft    Microsoft Natural
       pc98         PC-98xx Series
       macintosh     Original Macintosh
       ...

     ! layout
       us      U.S. English
       cz      Czech
       de      German
       ...

     ! option
       caps:internal           uses internal capitalization. Shift cancels Caps
       caps:internal_nocancel uses internal capitalization. Shift doesn't cancel Caps

And that should be it. Enjoy creating your own xkb mapping.

     Generated from XFree86: xc/programs/Xserver/hw/xfree86/doc/sgml/XKB-Enhancing.sgml,v 1.2 dawes Exp $


$XFree86: xc/programs/xkbcomp/README.enhancing,v 1.5 2003/10/19 19:57:44 dawes Exp $
@


1.1.1.1
log
@initial import of xkeyboard-config-1.3
@
text
@@


1.1.1.2
log
@Initial import of xkeyboard-config-1.9
@
text
@d16 5
a20 5
X Keyboard Extension: Protocol Specification 
<URL:http://xfree86.org/current/XKBproto.pdf>) at least to clarify for
himself some xkb-specific terms used in this document and elsewhere in xkb
configuration. Also it shows wise to understand how the X server and a client
digest their keyboard inputs (with and without xkb).
@


1.1.1.3
log
@initial import of xkeyboard-config 2.3.  important changes include:
	added symbols/apl, symbols/cm, symbols/tw
	removed all symbols/extras/*
@
text
@d521 5
@


1.1.1.4
log
@initial import of xkeyboard-config-2.12
@
text
@d23 1
a23 1
<URL:http://pascal.tsu.ru/en/xkb/> often referenced throughout this docu-
d173 3
a175 3
See Some Words  About XKB internals
<URL:http://pascal.tsu.ru/en/xkb/internals.html> for explanation of used xkb 
terms and problems addressed by XKB extension.
d178 1
a178 1
<URL:http://pascal.tsu.ru/en/xkb/gram-common.html> for more precise
@


1.1.1.5
log
@initial import of xkeyboard-config-2.31
@
text
@d190 1
a190 1
     default partial alphanumeric_keys
@


1.1.1.6
log
@initial import of xkeyboard-config-2.37
@
text
@d1 1
a1 2

                      How to enhance XKB configuration
d9 3
a11 4
     This guide is aimed at alleviating one's labour when creating a
     new (internationalized) keyboard layout. Unlike other documents,
     this guide emphasizes the keymap developer's point of view.

d15 10
a24 10
The developer of a new layout should read the XKB protocol specification
(The X Keyboard Extension: Protocol Specification [1]) at least to clarify
for themselves some XKB-specific terms used in this document and elsewhere
in XKB configuration. It is also wise to understand how the X server and
a client digest their keyboard inputs (with and without XKB).

Another useful source is Ivan Pascal's text about XKB configuration [2].

   [1] https://www.x.org/docs/XKB/XKBproto.pdf
   [2] http://pascal.tsu.ru/en/xkb/
d27 1
a27 2
XFree86 versions 4.3.x and newer.

d31 2
a32 2
At boottime (or later at the user's command) the X server starts its xkb
keyboard extension module and reads data from a compiled configuration file.
d35 2
a36 2
behaves altogether as an ordinary compiler (see man xkbcomp). Its input are
human-readable xkb configuration files which are verified and then composed
d38 2
a39 1
selves, for them it is invisible. Usually, it is run upon X server startup.
d41 1
a41 1
As you probably already know, XKB configuration consists of five main
d45 4
a48 4
            Tables that define the translation from keyboard scan codes into
            reasonably symbolic names, maximum and minimum valid keycodes,
            symbolic aliases, and a description of physically present LED-indica-
            tors. The primary sense of this component is to allow definitions
d50 2
a51 2
            board scancodes. There are two main conventions for symbolic
            names (always four bytes long):
d53 2
a54 2
               o  names which express some traditional meaning, like <SPCE>
                  (which stands for space bar)
d56 3
a58 3
               o  names which express a relative position on the keyboard,
                  for example <AE01> (the exclamation mark on US keyboards),
                  with on its right the keys <AE02>, <AE03>, etc.
d61 3
a63 3
            Types describe how the pressed key is affected by active modifiers
            (like Shift, Control, Alt, ...). There are several predefined
            types which cover most of the usual combinations.
d66 4
a69 5
            The compatibility component defines the internal behaviour of
            modifiers. Using the compat component you can assign various
            actions (elaborately described in the XKB specification) to key
            events. This is also the place where LED-indicators behaviour
            is defined.
d74 4
a77 4
            by their symbolic name, see above). More than one value may be
            defined for each key and then it depends on the key type and on
            the modifiers state (respective compat component) which value
            will be the resulting one when the key is pressed.
d83 2
a84 3
All these components have their files located in the xkb configuration tree,
in subdirectories with the same name (usually in /usr/share/X11/xkb).

d86 1
a86 1
3.  Enhancing the XKB Configuration
d88 1
a88 1
Most of XKB enhancements are about a need to define new output symbols for
d90 1
a90 1
a new language, or standard, or just to feel more comfortable when typing text).
d92 1
a92 1
What do you need to do? Generally, you have to define the following things:
d101 10
a110 10
to see if there is something you could easily adjust to fit your needs. Even
if there is nothing similar, you may get some ideas about the basic concepts
and used tricks.

3.1  Levels and Groups

Since XFree86 4.3.0, you can use multiple layouts in the xkb configuration.
Though still within the boundaries of the xkb protocol and its general ideas,
the keymap designer must obey new rules when creating new maps. In exchange
we get a more powerful and cleaner configuration system.
d113 5
a117 4
which keycode according to the effective modifier state. The X server itself
sends only an input event message. Of course, usually the interpretation is
done by Xlib, Xaw, Motif, Qt, Gtk, or similar libraries. The X server only
supplies its mapping table (usually upon application startup).
d119 1
a119 1
You can think of the X server's symbol table as of an irregular table where
d122 3
a124 3
Not all keycodes need to bind different values for different combinations of
modifiers. The <ENTER> key, for instance, usually doesn't depend on any modi-
fiers so it has in its row only one column defined.
d127 2
a128 2
bound to certain columns. By editing the proper files (see Key Types, below)
this mapping can be changed as well.
d130 3
a132 3
Unlike the original X protocol, the XKB approach is far more flexible.
XKB introduces one additional term: the group. You can think of a group
as of a vector of columns per keycode (naturally the dimension of this
d136 2
a137 2
ble. But then the group has a natural meaning: each symbol set has its own
group and changing it means selecting a different one. The XKB approach allows
d139 2
a140 2
levels. The X server knows what the current group is and reports it together
with the modifier state and the keycode in key events.
d144 2
a145 2
   o  for each keycode the XKB keyboard map contains up to four one-dimensional
      tables - groups (logically different symbol sets)
d147 3
a149 3
   o  for each group of a keycode the XKB keyboard map contains some columns -
      shift levels (values reached by combinations of Shift, Ctrl, Alt, ...
      modifiers)
d153 2
a154 1
   o  different groups of one keycode can have different number of shift levels
d156 1
a156 1
   o  the current group number is tracked by the X server
d158 2
a159 2
It is clear that if you sanely define levels and groups, and sanely bind modi-
fiers and associated actions, you can have loaded simultaneously up to four
d163 2
a164 2
symbol definitions in a way that allows almost arbitrary composition of
predefined symbol tables. To keep it fully functional you have to:
d169 1
a169 2
      behaviour

d173 7
a179 8
See "Some Words About XKB internals" [3] for an explanation of used XKB
terms and problems addressed by the XKB extension.

See "Common notes about XKB configuration files language" [4] for a more
precise explanation of the syntax of XKB configuration files.

   [3] http://pascal.tsu.ru/en/xkb/internals.html
   [4] http://pascal.tsu.ru/en/xkb/gram-common.html
d184 1
a184 1
to use one of four predefined Latin alphabet layouts.
d186 1
a186 1
Okay, let's assume you want to extend an existing keymap and you want to over-
a191 1

a200 1

d202 1
a202 1
                     [ ISO_Level3_Shift, Multi_key ] };
d207 1
a207 1
It defines a new layout in the basic variant as an extension of a common latin
d209 4
a212 4
Then there are redefinitions of a few keycodes and a modifier binding. As
you can see, the number of shift levels is the same for the <AE02>, <AE03>,
<AC11>, <TLDE> and <BKSL> keys but it differs from the number of shift
levels of <RALT>.
d215 2
a216 2
like a shift modifier for LevelThree, and together with Shift as a Compose key.
It is a good habit to respect this rule in a new similar layout.
d224 4
a227 4
The differences in the number of columns (shift levels) are caused by the
different types of the keys (see the Types definition in section The Basics).
Most keycodes have implicitly set the keytype in the included "pc/latin" file
to "FOUR_LEVEL_ALPHABETIC". The only exception is the <RALT> keycode which is
d231 2
a232 2
choose a suitable shift level scheme from the default types scheme list in
the proper xkb component's subdirectory.
d237 2
a238 2
            The key does not depend on any modifiers. The symbol from the
            first level is always chosen.
d241 6
a246 7
            The key uses the modifier Shift and may have two possible values.
            The second level is chosen by the Shift modifier. If the Lock
            modifier (usually Caps-lock) applies, the symbol is further
            processed using system-specific capitalization rules. If both
            the Shift and Lock modifiers apply, the symbol from the second
            level is taken and capitalization rules are applied (but usually
            have no effect).
d249 2
a250 2
            The key uses the modifiers Shift and Lock. It may have two
            possible values. The second level is chosen by Shift. When the
d253 3
a255 3
            If both the Shift and Lock modifiers apply, the symbol from the
            first level is taken and no capitalization rules are applied.
            This is often called shift-cancels-caps behaviour.
d258 7
a264 7
            Is the same as TWO_LEVEL but it considers an extra modifier:
            LevelThree, which can be used to gain the symbol value from the
            third level. If both the Shift and LevelThree modifiers apply,
            the value from the third level is taken. As in TWO_LEVEL, the
            Lock modifier doesn't influence the resulting level - only Shift
            and LevelThree are taken into consideration. If the Lock modifier
            is active, capitalization rules are applied to the resulting
d268 3
a270 3
            Is the same as THREE_LEVEL but, unlike THREE_LEVEL, if both the
            Shift and LevelThree modifiers apply, the symbol is taken from
            the fourth level.
d274 4
a277 5
            behaviour as in ALPHABETIC. If both Lock and LevelThree apply,
            the symbol from the third level is taken and the capitalization
            rules are applied. If all three modifiers (Lock and Shift and
            LevelThree) apply, the symbol from the third level is taken and
            no capitalization rules are applied
d280 7
a286 7
            As the name suggest, this scheme is primarily used for numeric
            keypads. The scheme considers two modifiers: Shift and NumLock.
            If none of the modifiers applies, the symbol from the first level
            is taken. If either the Shift or the NumLock modifier apply, the
            symbol from the second level is taken. If both the Shift and the
            NumLock modifier apply, the symbol from the first level is taken.
            Again, a shift-cancels-caps variant.
d289 6
a294 6
            Is similar to the KEYPAD scheme but considers also the LevelThree
            modifier. If the LevelThree modifier applies, the symbol from the
            third level is taken. If both Shift and LevelThree or NumLock and
            LevelThree apply, the symbol from the fourth level is taken. If
            all three (Shift+NumLock+LevelThree) apply, the symbol from the
            third level is taken. This also is a shift-cancels-caps variant.
d297 5
a301 5
            A four-level keypad scheme where the first two levels behave like
            the KEYPAD scheme (with Shift and NumLock). The LevelThree modifier
            acts as an override, providing access to two normally Shift-ed
            levels: when LevelThree is active we ignore the NumLock state.
            Intended for the digit area of the keypad.
d305 4
a308 4
            LevelThree provides two more Shift-ed levels (levels 2 and 3),
            and Ctrl plus Alt command the fourth level. Intended for the
            operator part of a keypad, though since NumLock plays no part,
            it is not keypad-specific.
d310 1
a310 1
Besides that, there are some schemes for special purposes:
d313 3
a315 3
            Similar to the TWO_LEVEL scheme but it considers the Control
            modifier rather than Shift. That means, the symbol from the
            second level is chosen by Control rather than by Shift.
d318 3
a320 3
            Similar to the TWO_LEVEL scheme but it considers the Alt
            modifier rather than Shift. That means, the symbol from
            the second level is chosen by Alt rather than by Shift.
d323 4
a326 5
            The key uses the modifiers Alt and Control. It may have two
            possible values. If just one modifier (Alt or Control) applies,
            the symbol from the first level is chosen. Only if both the Alt
            and Control modifiers apply, the symbol from the second level
            is chosen.
d329 4
a332 5
            The key uses the modifiers Shift and Alt. It may have two
            possible values. If just one modifier (Alt or Shift) applies,
            the symbol from the first level is chosen. Only if both the
            Alt and Shift modifiers apply, the symbol from the second
            level is chosen.
d348 1
a348 1
the 'caps:' xkb option (used to globally change the layouts behaviour).
d350 2
a351 2
Don't alter any of the existing key types. If you need a different behaviour,
create a new type.
d353 1
a353 1
4.2.1  More on Definitions of Types
d355 1
a355 1
When the XKB software deals with a separate type description, it gets a com-
d357 2
a358 2
fiers=<list of modifiers>' list and expects a set of 'map[<combination of
modifiers>]=<level indication>' instructions that contain the mapping for
d361 1
a361 1
is computed. If some combination is omitted, the program (subroutine) should
d364 1
a364 1
Let's consider an example with two modifiers, ModOne and ModTwo:
d372 3
a374 3
In this case the map has a statement for ModOne only and ModOne+ModTwo is
omitted. This means that if ModTwo is active, the subroutine can't find an
explicit mapping for this combination and will use the default level, i.e.
d377 1
a377 1
But in the case that the type is described as:
d387 1
a387 1
combination ModOne+ModTwo (as well as ModOne alone) produces the Level2.
d389 2
a390 2
What does it mean if the second modifier is not ModTwo but Lock? It means that
in the first case (Lock itself is included in the list of modifiers but combina-
d394 1
a394 1
accordingly to the first modifier - and this can be the symbol from the first
d400 1
a400 1
don't want to discard it, you may list it in 'preserve[<combination of modi-
d403 1
a403 1
resulting symbol is passed to the internal capitalization routine regardless
d408 2
a409 2
declare them. Virtual modifiers can have arbitrary names and must be declared
(prior to using them) directly in the key type definition:
d411 1
a411 1
     virtual_modifiers <comma-separated list of modifiers> ;
d413 1
a413 1
as seen in for example the basic, pc, or mousekeys key type definitions.
d417 3
a419 3
Once you are finished with your symbol map you need to add it to the rules file.
The rules file describes how all the five basic components (keycodes, types,
compat, symbols, and geometry) should be composed to give a sensible resulting
d422 1
a422 1
The main advantage of rules over formerly used keymaps is the possibility to
d427 3
a429 3
A pattern in a rules file (often located in /usr/share/X11/xkb/rules) can be
parameterized with four other arguments: Model, Layout, Variant, and Options.
For most cases the parameters Model and Layout should be sufficient for choosing
d432 4
a435 3
The rules file itself is composed of pattern lines and lines with rules. Each
pattern line starts with an exclamation mark ('!') and describes how XKB will
interpret the subsequent lines (rules). A sample rules file looks like this:
d438 1
a438 1
       macintosh_old           =   macintosh
d442 1
a442 1
     ! model                   =   symbols
d444 2
a445 2
       microsoftpro            =   +inet(%m)
       geniuscomfy             =   +inet(%m)
d447 11
a457 11
     ! model       layout[1]   =   symbols
       macintosh   us          =   macintosh/us%(v[1])
       *           *           =   pc/pc(%m)+pc/%l[1]%(v[1])

     ! model       layout[2]   =   symbols
       macintosh   us          =   +macintosh/us[2]%(v[2]):2
       *           *           =   +pc/%l[2]%(v[2]):2

     ! option                  =   types
       caps:internal           =   +caps(internal)
       caps:internal_nocancel  =   +caps(internal_nocancel)
d459 2
a460 2
Each rule defines what a certain combination of values on the left side of the
equals sign ('=') results in. For example, a (keyboard) model macintosh_old
d462 2
a463 2
while the rest of the models (represented by a wildcard '*') instructs it to
take them from file keycodes/xfree86. The wildcard represents all possible
d474 2
a475 2
should place the layout resp. variant into the specified xkb group. If the
brackets are omitted, the first group is the default value.
d481 3
a483 3
doesn't cancel caps'' can be selected. The rest of the rules produce special
symbols for each US variant of the macintosh keyboard, and standard pc symbols
in appropriate variants as a default.
d487 3
a489 3
Now you just need to add a detailed description to the <rules>.xml description
file so that other users (and external programs which often parse this file)
know what your work is about.
d493 1
a493 1
The formerly used descriptive files were named <rules>.lst. Its structure is
d498 1
a498 1
verted to the old '.lst' format.
d500 2
a501 2
The meaning of each possible parameter of the rules file should be described.
For the sample rules file given above, the .lst file could look like this:
d507 1
a507 1
       macintosh    Original Macintosh
d517 2
a518 2
       caps:internal           uses internal capitalization, Shift cancels Caps
       caps:internal_nocancel  uses internal capitalization, Shift doesn't cancel Caps
@


