Note for other searchers landing on this page: this is apparently peculiar to the de-us
layout in the Unity environment, because for some reason it lacks an entry in a particular configuration file.
How keyboard data is stored in Ubuntu
In Ubuntu, there is a folder called /usr/share/X11/xkb/symbols
which contains a few subfolders as well as a number of text files, each representing a different layout. Most, if not all, of these layouts, have a number of variants. The one we're interested in is the us
variant of the de
keyboard, so we open the file de
and scroll down to the following entry (it was at line 686 for me, but I'm not on 15.10).
partial alphanumeric_keys
xkb_symbols "us" {
include "us"
name[Group1]="German (US keyboard with German letters)";
key <AC01> { [ a, A, adiaeresis, Adiaeresis ] };
key <AC02> { [ s, S, ssharp, ssharp ] };
key <AC10> { [ semicolon, colon, odiaeresis, Odiaeresis ] };
key <AC11> { [ apostrophe, quotedbl, adiaeresis, Adiaeresis ] };
key <AD03> { [ e, E, EuroSign, EuroSign ] };
key <AD07> { [ u, U, udiaeresis, Udiaeresis ] };
key <AD09> { [ o, O, odiaeresis, Odiaeresis ] };
key <AD11> { [ bracketleft, braceleft, udiaeresis, Udiaeresis ] };
key <AE03> { [ 3, numbersign, section, section ] };
key <AE11> { [ minus, underscore, ssharp, question ] };
include "level3(ralt_switch)"
};
This defines the keyboard to be identical to the standard QWERTY variety us
, with changes to
- keys 1 (A), 2 (S), 10 (;), and 11 (') on the home row
- keys 3 (E), 7 (U), 9 (O), and 11 ([) on the top row
- keys 3 (3) and 11 (-) on the numbers row
- the ALT key used to access the special characters
We check that it's properly formatted, not missing any brackets or anything, and it is. This is why setxkbmap de us
succeeds, if only temporarily. We'll copy the description from this entry later on.
How Ubuntu accesses that data
Ubuntu has a registry setting where it saves the name of the keyboard or keyboards the user wants. However, we have to fix an entry in another configuration file before Ubuntu will accept our preferred keyboard. The file that needs to be modified is /usr/share/X11/xkb/rules/evdev.xml
.
This file has three major sections:
- a list of known keyboard models (describing the physical arrangement of buttons)
- a list of known keyboard layouts (describing the logical assignment of characters to keys)
- a list of options (describing possible modifications to the layout)
We need to open this as root so we can save it later. Since we want to use the us
variant of the de
layout, the relevant portion of the file is going to be the second section- specifically, we modify the German layout (in my copy, this begins on line 3176).
<layout>
<configItem>
<name>de</name>
<shortDescription>de</shortDescription>
<description>German</description>
<languageList>
<iso639Id>ger</iso639Id>
</languageList>
</configItem>
<variantList>
<variant>
<configItem>
<name>us</name>
<description>German (US keyboard with German letters)</description>
</configItem>
</variant>
Notice the structure of this section. Each layout contains a configuration and multiple variants. I've added a new variant
entry (the last six lines), immediately after the tag opening variantList
, the content of which matches what I found in the keyboard data file above.
After saving, change the registry setting to select our newly added entry:
gsettings set org.gnome.desktop.input-sources sources [('xkb', 'de+us')]
I found it necessary to log out and back in for this change to take effect, but after that, the layout worked as one would hope, including surviving suspend/resume cycles.