Create xkb configuration from xmodmap

Make your own xkb configuration file

The idea is to "read" the current keyboard config (do not call xmodmap), and write your own symbols file based on it. First:

xkbcomp -xkb $DISPLAY

This creates server-0_0.xkb. In this file, take the following block:

xkb_symbols "pc+inet(evdev)+compose(menu)+whatever(option)" {
    key <ESC> { [ Escape ] };
    ...
};

change the first line into:

default xkb_symbols "my_symbols" {
    include "pc+inet(evdev)"
    include "compose(menu)+whatever(option)"

(I think you can break options into as many "include" lines as you like). Change the keys you want to modify and prepend them with override:

override key <AE10>  { [ 0, parenright, degree ]};

Remove all unchanged keys.

System-wide installation

Put all this into /usr/share/X11/xkb/symbols/my_terrific_kb. Now users may load it with setxkbmap my_terrific_kb (in .xinitrc or .xsessionrc). Probably you can put Option "XkbLayout" "my_terrific_kb" in xorg.conf for a system-wide change.

Single-user installation

Put all this into ~/anywhere/my_terrific_kb. Find the XInput id of your keyboard with xinput list. Then run xkbcomp -i <XInput_id> ~/anywhere/my_terrific_kb $DISPLAY.


The map file produced by xkbcomp :0 custom-xkb-keymap consists of many components that you can load by simply swapping the arguments xkbcomp custom-xkb-keymap :0. It shows a few warnings here, but seems to work, when I change the layout in the file.

The xkb layout is stored in the symbols directory, e.g. /usr/local/share/X11/xkb/symbols. The path may vary depending on the system. When you need the layout, you need to cut out the part looking like:

xkb_symbols "id+id+id(pc104)" {
    name[group1]="..."
    .
    .
    .
};

and store it in the symbols directory. Please make sure, you don't overwrite any file there! Once it is stored there (for example as mylayout) you can load it by typing setxkbmap mylayout. And this corresponds with the xorg.conf setting Option "XkbLayout" "mylayout" in the section InputDevice (see man page for kbd for further details).

It seems that the other parts in the xkcomp output correspond to the files in the other directories, so if something does not work, you will probably have to split up the custom-xkb-keymap into its components and copy it to the proper directories under /usr/local/share/X11/xkb. But this is something I have never done, yet.

Better layouts

Instead of using raw dumps that look like decompiled code, you can also make your own symbols file, which is more readable. I have got my own custom layout, which will probably not be usable for most of you, but you can still take a look at this short file that I use for programming on German keyboards (just to get an idea how this can look like and what you can do with a symbols file).

Tags:

Xmodmap

Xkb