Custom (X11/xkb) keyboard layout without being root
Published:
Updated:
Short tutorial about creating a custom keyboard layout without being root.
Configuration
In a directory, create a symbols/
subdirectory. In this subdirectory, create a custom
file:
mkdir -p keyboard/symbols
sensible-editor keyboard/symbols/custom
In this file, create a new layout inheriting from the base layout of your choice:
partial alphanumeric_keys
xkb_symbols "fr" {
// This is the base layout you are inheriting:
include "fr(oss)"
// Overridden/new bindings goes here
}
Choose the behaviour of the Control/Shift/Alt/Lego/Menu keys:
Some versions of oss
map right-control to access another group of symbols. This can be overriden with:
key <LCTL> { [ Control_L ] };
key <RCTL> { [ Control_R ] };
Use LWIN to serve another AltGr:
key <LWIN> {
type[Group1]="ONE_LEVEL",
symbols[Group1] = [ ISO_Level3_Shift ]
};
key <RALT> {
type[Group1]="ONE_LEVEL",
symbols[Group1] = [ ISO_Level3_Shift ]
};
Use RWIN as another Alt:
key <RWIN> { [ Alt_R, Meta_R ] };
key <LALT> { [ Alt_L, Meta_L ] };
Another group of keys:
Use the MENU and CAPS keys to access another group of symbols:
key <MENU> {
symbols[Group1]= [ Mode_switch ],
virtualMods= AltGr
};
key <CAPS> {
symbols[Group1]= [ Mode_switch ],
virtualMods= AltGr
};
It is now possible to assign 4 new symbols to each key:
// This is the D key:
key <AC03> { symbols[Group2] = [ Greek_delta, Greek_DELTA, U2202, U2207 ] }; // δ Δ ∂ ∇
Using it
setxkbmap
will only use the system config files. In order to use your custom configuration files without installing it in the system directory, you have to use xkbcmp
:
cd keyboard/
setxkbmap custom fr -option -print | xkbcomp -I. - $DISPLAY
Notes:
- If the
-option
argument it not used, the options will be inherited from the configuration stored in the root window (read withXkbRF_SetNamesProp
). - The
-I
flag is used to add an include directory for the files. - When going through
xkbcomp
, the new configuration is not stored in the root window which might break the expectations of some programs (XkbRF_SetNamesProp
).
Shell script
You can move this configuration in ~/.xkb
and use this shell script:
#!/bin/sh
setxkbmap -option "" custom fr -print | xkbcomp -I"$HOME"/.xkb - $DISPLAY
or more generally:
#!/bin/sh
setxkbmap -option "" "$@" -print | xkbcomp -I"$HOME"/.xkb - $DISPLAY