github linkedin
Custom Keyboard Layouts With Linux

I am from Germany and have an external english keyboard, the keys you need for programming are better positioned on the US layout than on the german. But sometimes I do other things beside programming (yes, really!), and then I need the german umlauts (ü, ö, ä, ß). My laptop has a german keyboard built in, so I additionally want to be able to switch the layout completely to german.

I’m using XFCE, and XFCE has a keyboard layout switching plugin. It displays a nice flag, and when you click on the symbol, you can change the keyboard layout. But I don’t want to switch the whole layout just because I want to type an umlaut. So, the first try was to use a Xmodmap file. That works, until you switch the keyboard layout to german. Then every a, u, o you type is an umlaut. No idea why.

Next try: create a complete new layout, base it on the US one and just add the umlauts to it. The X server stores the layouts in /usr/share/X11/xkb/symbols/. I created a new file called us_umlauts and put the following text in it:

xkb_symbols "umlauts" {
    include "us(basic)"

    name[Group1]= "English (US, with umlauts)";

    key <AC01> {        [         a,    A,      adiaeresis,     Adiaeresis      ]       };
    key <AD09> {        [         o,    O,      odiaeresis,     Odiaeresis      ]       };
    key <AD07> {        [         u,    U,      udiaeresis,     Udiaeresis      ]       };
    key <AC02> {        [         s,    S,      ssharp                          ]       };
    key <AD03> {        [         e,    E,      EuroSign                        ]       };

    include "level3(ralt_switch)"

This adds an umlaut to the a, o, u, and the s key with the corresponding uppercase letter. It also adds the Euro sign (€) to the e key. Now if I want to type an ö, i just press the right alt key and press o. Very nice.

To get this layout into the XFCE switcher, I edited the file ~/.config/xfce4/xfconf/xfce-perchannel-xml/keyboard-layout.xml and changed us to us_umlauts:

<?xml version="1.0" encoding="UTF-8"?>
<channel name="keyboard-layout" version="1.0">
  <property name="Default" type="empty">
	<property name="XkbDisable" type="bool" value="false"/>
	<property name="XkbLayout" type="string" value="us_umlauts,de"/>
	<property name="XkbVariant" type="string" value=","/>

Logout and login again (or restart X) to apply the changes.

Back to posts