To do this with xkb, I prefer to do the following:
- Create a directory to store my custom keymap, so changes can be reapplied if a reinstall is needed. I chose to create the directory
~/.settings/keyboard/
, then create a file (I chose to call mine uc
, us
with a c
for custom) with the following content:
default partial alphanumeric_keys
xkb_symbols "uc" {
name[Group1]="uc";
include "us(basic)"
key <ESC> { [Caps_Lock] };
key <CAPS> { [Escape] };
};
You can then create a symlink to this file like so:
cd /usr/share/X11/xkb/symbols/
sudo ln -s ~/.settings/keyboard/uc uc
Make sure that the link is to the right file using the command
ls -l /usr/share/X11/xkb/symbols/uc
Doing this is enough to then use the command setxkbmap uc
(Which I recommend doing, to ensure that everything goes as expected) which will then switch those keys as long as the X server is running. (Note: in wayland, for me this did not actually set the keymap, but I had to do the next step, and then go to the keyboard menu and set English (Custom) as the top keyboard layout, and rebooting. If multiple layouts are selected in the keyboard menu, I have also had to click on the en
appearing in the top right corner, selecting English (Custom), and then select Show Keyboard Layout, then the layout is loaded).
- To make this change permanent, (also to make this new keyboard layout available in the keyboard menu, this works in cinnamon anyway), also copy the file
sudo cp /usr/share/X11/xkb/rules/evdev.xml ~/.settings/keyboard/
Then edit the file to contain your layout, this will look like the following, in the <layoutList>
section, insert the following:
...
<layoutList>
<layout>
<configItem>
<name>uc</name>
<shortDesciption>uc</shortDescription>
<description>English (Custom)</description>
</configItem>
</layout>
...
...
</layoutList>
(Note the <layoutList>
and </layoutList>
already exist in the file, we are just adding a new layout)
Then, the following commands will enable you to select this keyboard layout from the keyboard menu:
cd /usr/share/X11/xkb/rules
sudo mv evdev.xml evdev.xml.original
sudo ln -s ~/.settings/keyboard/evdev.xml evdev.xml
Then, opening up your keyboard settings menu, you will be able to see a layout named English (Custom) that contains the desired keyboard layout. If you set this to be your keyboard layout from this menu, the changes will be persistent every time you log in.
Hopefully this helps!
echo $XDG_SESSION_TYPE
and indeed I am on Wayland. Could give me hints about what I shall do? – ecjb Jun 25 '22 at 17:07