There is a updated version on how to make keyboard layouts available and especially safe against xkeyboard-config
package upgrades.
Please have a look at Custom Keyboard Layouts with xkb.
As a developer I prefer to use the us intl. keyboard layout as many symboles are positioned better than on the german keyboard layout. But on the other side I also have to write texts in german and I need to have access to all german umlauts and symboles. Unfortunately there is no layout that suited in all details to my daily needs. Here comes the ability to define a custom keyboard layout in account.
layout over variant
There are two ways of defining your keyboard arrangement.
- The first one is to define a variant of an existing layout.
- The second one is to define a custom layout with a custom variant.
I personally prefer the second way as I don’t need to modify an existing layout file. Which is in my opinion the better way to prevent unwanted switchbacks while updating the layout definition.
defining a variant
In my case I started to use the variant alt-intl
for the us intl. keyboard layout. This variant already defines the german umlauts. But it does not define a key combo for e.g. the umlaut ß and also a key combo for the paragraph sign and cent sign was missing.
Let’s define a custom layout for the us intl. keyboard layout. Layouts are saved in the /usr/share/X11/xkb/symbols
directory. Here we create a new file in our case we named it usde
.
1
2
3
4
5
6
7
8
9
10
11
12
partial alphanumeric_keys
xkb_symbols "usde" {
include "us(alt-intl)"
key <TLDE> { [ grave, asciitilde, section, plusminus ] };
key <AC02> { [ s, S, ssharp, U1E9E ] };
key <AB03> { [ c, C, cent, copyright ] };
include "level3(ralt_switch)"
};
- We define our layout within the
xkb_symbols
section. - First of all we include the layout
us(alt-intl)
which works well for us so far and we don’t want to define all the keys again. - We define the tilde key to work as
backtick
andtilde
(/w shift). In combination withralt
we define thesection
key and theplusminus
key (/w shift). - We define the s key to work as
sS
andß
and upper umlaut ß (/w shift). - We define the c key to work as
cC
and in combination withralt
the cent sign and the copyright sign (/w shift). - Last we also include the
level3(ralt_switch)
section which defines theralt
key to switch between thealtgr
layer of defined keys.
Note: You can define the variant also in the symboles file for an existing layout e.g. us
. But we think that it is better to define the variant in a separate file to be upgrade safe.
make your variant a layout
To make the recently defined variant a layout we have to define a new layout for xkb. Layouts and variants are defined in the /usr/share/X11/xkb/rules/evdev.xml
file. You need to add a <layout></layout>
section within the <layoutList></layoutList>
block.
1
2
3
4
5
6
7
8
9
10
<layout>
<configItem>
<name>usde</name>
<shortDescription>usde</shortDescription>
<description>English (US, with german symbols)</description>
<languageList>
<iso639Id>eng</iso639Id>
</languageList>
</configItem>
</layout>
- We define a new layout with the name
usde
. The description will be shown in the configuration dialog. - We also define a variant with the name
usde
. The description will also be shown in the configuration dialog. - Bound the our
usde
layout to all languages with ideng
. E.g.English (United Kindom)
orEnglich (United States)
.
Note: If you decided to define your variant within an existing file you need to create a new variant in the corresponding <layout></layout>
block, e.g. us
.
setup your keyboard
Now you can select your newly defined layout in the configuration dialog.
Note: It can be necessary to logout and relogin to make the layout available.
From now on you can use all the defined key combos as you would normally do.