This worked and was tested in X11, and should work for Wayland as well as per this discussion about the Wayland protocol. This method will be portable to any operating system using Xorg. Here is what has worked for me:
Create a directory to save your custom keymap to, I like to create a .settings
folder in my home directory, and create a subfolder named keyboard
just to keep things organized.
Create a file that will contain your keymap, say uc
(a play on the 'us' keymap, but with a 'c' custom) with the following lines
default partial alphanumeric_keys
xkb_symbols "uc" {
name[Group1]="uc";
include "us(basic)"
include "level3(ralt_switch_multikey)"
};
Here we basically just copy the default us
keymap with the line include "us(basic)"
, and I chose to set the right alt to be my level 3 shift, which will be our custom symbols. This choice was somewhat arbitrary, and there are many other options you could choose that are all listed in the file
/usr/share/X11/xkb/symbols/level3
At this point run the following command to ensure that there are no typos or errors in our script setxkbmap ./uc
.
- Let's add the symbols we want to our keyboard layout. For example, I am going to add the symbol
U2200
(for all symbol) to the letter a. This is done by adding the following line beneath the second include
statement:
key <AC01> { [a, A, U2200 ] };
Saving this file and running setxkbmap ./uc
will now add that symbol to the keyboard, and by holding the right alt key down, pressing a produces a ∀ symbol. In this line, the <AC01>
means we are going to be defining the a key on the keyboard, in the xkb_symbols
section in this document, the rows of the keyboard are denoted AA
, AB
, AC
, AD
, and AE
from bottom to top, and individual keys are listed 01
to the end of the keyboard (I haven't experimented much with this, but modifier keys and Tab are not counted, so z, a, and q are all key number 01
in their row), so the key AC01
is the first non-modifier key on the third row up of the keyboard, or rather, the a key. We then tell xkb
to set the values of this key to a
, A
, and U2200
for levels one, two and three, respectively. Don't forget to list the actual letters for the key first, or you will not be able to type those characters after setting this as your keymap. Doing this for each of the keys you wish to edit will give you the symbols you wish to add to your keymap.
At this point, we have done enough to be able to set this as our keymap. To see how to make these changes permanent and be able to access our new keymap in keyboard menus in system settings, see my other answer here. This basically consists of linking this file to the right spot, and adding an entry for it in the evdev.xml
file so your system can access it.
Good luck!
setxkbmap ./uc
leads to the error:Error loading new keyboard description
. I am sure, that I just copied your lines of code and that I am in the right folder, with the right filename. I tried to debug it by myself and looked into some files in/usr/share/X11/xkb/symbols/
, but your syntax seems right. (I tried putting first theinclude
s and then thename
, but this hasn't helped.) Do you have any idea,where this error could come from,or how to debug it? – Sinthoras May 21 '23 at 16:53setxkbmap
the changes get applied, but the second part, making them permanent, did not work. I added my layout to theevdev.xml
, (and rebooted afterwards,) but the layout does not show up in input sources in the keyboard settings. (I use gnome.) I'll accept this answer anyway, since it is really helpful. Do you have any idea, why the layout would not show up? – Sinthoras May 30 '23 at 21:19