Joachim Wuttke:

How to modify keybindings under X.Org?

Task: Adapt an out-of-the-box keymap to your personal needs. To be specific, let us add European special characters (German umlauts, accent dead keys, euro sign) to the standard ASCII keyboard us. The modified keymap shall be called us_de.

Solution: (1) Create a difference file us_de_diff. (2) Create an overarching file us_de that calls in both us and us_de_diff. (3) Test with setxkbmap. (4) Make us_de permanently known to the operating system.

Step 1: Create a difference file us_de_diff

The following example extends the US ASCII keyboard by the following ALT keys: Save the following as /usr/share/X11/xkb/symbols/us_de_diff:
default partial 
xkb_symbols "basic" {
    key <AE01> {  [  1,   exclam      , dead_grave             ] };
    key <AE02> {  [  2,   at          , dead_circumflex        ] };
    key <AE03> {  [  3,   numbersign  , dead_acute             ] };
    key <AE04> {  [  4,   dollar      , dead_diaeresis         ] };
    key <AE05> {  [  5,   percent     , dead_cedilla           ] };
    key <AE06> {  [  6,   asciicircum , dead_caron             ] };
    key <AE07> {  [  7,   ampersand   , section                ] };
    key <AD03> {  [  e,   E           , EuroSign               ] };
    key <AD07> {  [  u,   U           , udiaeresis, Udiaeresis ] };
    key <AD09> {  [  o,   O           , odiaeresis, Odiaeresis ] };
    key <AC01> {  [  a,   A           , adiaeresis, Adiaeresis ] };
    key <AC02> {  [  s,   S           , ssharp                 ] };
    key <AB03> {  [  c,   C           , ccedilla               ] };
    key <AB01> {  [  z,   Z           , guillemotleft          ] };
    key <AB02> {  [  x,   X           , guillemotright         ] };
};

Step 2: Create a master file us_de

Save the following as /usr/share/X11/xkb/symbols/us_de:
partial default alphanumeric_keys
xkb_symbols "basic" {
    include "us"
    include "us_de_diff"
    name[Group1]="en_US";
    key <RALT>  { type[Group1]="TWO_LEVEL",
                  [ ISO_Level3_Shift, Multi_key ]   };
    modifier_map Mod5   { <RALT> };
};
xkb_symbols "nodeadkeys" {
    include "pc/en_US(basic)"
    include "pc/latin(nodeadkeys)"
    include "us_de_diff"
};

Step 3: Testing

Use the command setxkbmap -layout us_de to test the new key binding.

Step 4: Permanent reconfiguration of the X.Org server

Old style: modify xorg.conf

Prior to about 2010, the configuration of the X server was kept in a file /etc/X11/xorg.conf. To change the keymap, the following section had to be modified:
Section "InputDevice"
        [...]
        Option      "XkbLayout" "us_de"
EndSection

Current style: modify /etc/default/keyboard

In current Linux distributions, the configuration file /etc/X11/xorg.conf is no longer needed. Under Debian 6.0 `squeeze', the keyboard map is defined in /etc/default/keyboard. Just modify the XKBLAYOUT entry.

Please inform me if other distribution need to be configured in different ways.

Changelog

First published in the German Linux-Magazin 10/2003, under the title "Deutsch-Amerikanische Freundschaft".
Revised version for X11R7 published online 2006.
Revised version for X.Org versions without xorg.conf, 3 March 2012.