This guide will assist you in configuring keyboard layout variants, such as the popular cz_sk_de variant of the us layout. These variants are specified in the file /usr/share/X11/xkb/rules/base.extras.xml and all have a property popularity="exotic", which renders them invisible to most common programs, including systemd and GNOME. Fortunately, there is a workaround for this.
Use xkb-list-layouts-variants.sh, a POSIX shell function and CLI utility, to print/list all XKB layouts and their variants, including the exotic ones, and also print their descriptions. This is a significant improvement over localectl's list-x11-keymap-layouts and list-x11-keymap-variants commands.
You can download it immediately like this:
wget "https://gist.github.com/rindeal/1891455c258b22f3e31e1da8f9821c28/raw/8bdcaa09a3f559bdb32354229fd05f73ae6c8f11/xkb-list-layouts-variants.sh"
chmod +x "xkb-list-layouts-variants.sh"If you prefer not to use the GUI to change GNOME settings, you can configure them directly using its configuration database, GSettings. The values are stored as a GVariant array, which is prone to errors if edited manually. I've created a Python-based tool called gsettings-array.py to simplify this process.
You can download it immediately like this:
wget "https://gist.github.com/rindeal/c5786254410028f760ee2351d884a744/raw/49e10b113d1bc8d7dd3ab576228746f572a74360/gsettings-array.py"
chmod +x "gsettings-array.py"Once you have selected a layout and variant to your liking using xkb-list-layouts-variants.sh, proceed further.
For X11/Xorg and the virtual console, you can use systemd's command:
sudo localectl set-x11-keymap "us" "pc102" "cz_sk_de"This generates the following files:
/etc/vconsole.conf:
KEYMAP=us
FONT=eurlatgr
XKBLAYOUT=us
XKBMODEL=pc102
XKBVARIANT=cz_sk_de/etc/X11/xorg.conf.d/01-keyboard.conf:
Section "InputClass"
Identifier "system-keyboard"
Driver "evdev"
MatchIsKeyboard "true"
Option "XkbModel" "pc102"
Option "XkbLayout" "us"
Option "XkbVariant" "cz_sk_de"
EndSectionGNOME uses its own preferences and on Wayland, it ignores all xorg configs. This means that the systemd's command doesn't have much effect on GNOME, especially on Wayland.
To set the keyboard layout in GUI settings, visit the menu: Settings > Keyboard > Input sources > +
If GNOME doesn't show all variants as mentioned above, use this command to always show all variants, including exotic ones.
gsettings set "org.gnome.desktop.input-sources" "show-all-sources" "true"You can use the gsettings-array.py tool to set various settings like this:
To set the keyboard layout:
./gsettings-array.py insert --dedup "org.gnome.desktop.input-sources" "sources" 0 "('xkb', 'us+cz_sk_de')"To change the Caps Lock behavior so that the CapsLock key itself is disabled and toggling its state is possible only with the simultaneous pressing of both Shift keys:
./gsettings-array.py insert --dedup "org.gnome.desktop.input-sources" "xkb-options" 0 "caps:none" "shift:both_capslock"To enable AltGr as a third keyboard row shifter, e.g., for AltGr+V as @:
./gsettings-array.py insert --dedup "org.gnome.desktop.input-sources" "xkb-options" 0 "lv3:ralt_switch"