Karol Stasiak's Blog

Coding from an elevator.

Creating custom keyboard layouts for Linux

| Comments

I think almost every one of you has some beef with your keyboard layout. There are characters you’re never going to use, there are characters you’d love to use but they’re missing (and you don’t like/can’t use the compose key for them), and so on.

For example, this is the default Polish layout in Linux:

My helpful screenshot

A keen eye can notice several things that could be improved:

  • many characters can be input in multiple ways: [ (as [ or as AltGr-9), ł (as AltGr-w or AltGr-l), & (as Shift-7 or AltGr-Shift-k), @ (as Shift-2 or AltGr-q),

  • the layout has some unassigned combinations (for example AltGr-Shift-4),

  • some important characters are missing: (the euro sign) and (Polish opening quote),

  • since I can use the compose key, I don’t need all those arbitrarily assigned dead keys on the right.

Of course your keyboard layout may have different problems.

Disclaimer: The following was done on Ubuntu 12.04 with Unity DE, I don’t guarantee it will work on other distros. In particular, the file paths can differ.

How to create a new one, you ask? That’s actually pretty simple.

  • layout definitions are in the /usr/share/X11/xkb/symbols directory,

  • layout metadata are in the /usr/share/X11/xkb/rules/evdev.xml file.

Let’s first define our layout. The /usr/share/X11/xkb/symbols contains files, each corresponding to a language. Some layouts can belong to several languages, but they’re defined in only one of the files. If your layout is supposed to be listed under one language in the keyboard setting anyway, you’ll have to add it to the correct file. Since my keyboard layout was to be mostly an improvement on top of the Polish language layout, I decided to add it to /usr/share/X11/xkb/symbols/pl.