Wayland and Remapping Characters on the Keyboard

Yes, I know, I am a few years late with this but it is very likely that for the next desktop iteration of the notebooks in the family, Wayland is going to be the display compositor. The X-Server is on the way out. I don’t really mind as long as I have the features I require. One of those features which are a bit special is that one member of the household requires special French characters to be mapped on a German keyboard layout to Alt-Gr + one normal key. Particularly: ‘ç ï ë œ ÿ’. Yes, it’s the keyboard and not the display, but the X-Server and Wayland handle the keyboard, too. Unfortunately, the solution I have for X-Server environments doesn’t work with Wayland anymore. So I had to find a new way.

The Old Ways No Longer Work

On my notebooks that run with the X display server today, I use the xmodmap command. But that command no longer works with Wayland. So what’s the alternative? After chatting with an AI search tool and coming up with nothing, I gave a traditional web search a try but also came up empty handed. Basic key mapping works with some tools, but as soon as those special characters above come into play, every solution I found just didn’t work. So I decided to dig a bit deeper and found a nice, elegant and easy way to map these character to AltGr + one key for easy access.

The Mac Keyboard Layout Helps

I actually found the solution because while looking through some of the config files mentioned in some of the articles I read on the topic, I noticed that the German keyboard description had a sub-layout to emulate a Macintosh keyboard. And in this sub-layout, the ç character is mapped to AltGr+c. I loaded that sub-layout and indeed, I got ç to work with AltGr+c. Cool. So the only thing I had to do was to copy and paste that line and insert it into the main German keyboard layout description.

One Config File to Modify

OK, long story short, the configuration file we are talking about, in the case of a German keyboard (de) is /usr/share/X11/xkb/symbols/de. Yes, there is X11 and xkb in the path, but Wayland uses this as well. So much for cutting all cords. So to add all the characters I mentioned above, I first made a copy of the keyboard layout file and then copied the following lines to the top of the config file at the end of the ‘basic’ description part:

cp /usr/share/X11/xkb/symbols/de  ~/x-temp-del-de-keyboard-map.txt

sudo nano /usr/share/X11/xkb/symbols/de

# Keys to insert:
key <AB03>  {[ c,     C,      ccedilla,      Ccedilla            ]};
key <AD08>  {[ i,     I,      idiaeresis,    Idiaeresis          ]};
key <AD02>  {[ w,     W,      ediaeresis,    Ediaeresis          ]};
key <AD09>  {[ o,     O,      U0153,         U0152               ]};
key <AB01>  {[ y,     Y,      ydiaeresis,    Ydiaeresis          ]};

The ç and it’s upper case variant is represented by ccedilla and Ccedilla and I guess the others are self explaining. One little bonus: Any unicode character can be mapped, such as the œ, which is U0153 and U0152 in unicode.

Once saved, the configuration can be activated by switching to another keyboard layout and then back to the original, i.e. German in my case, either in the GUI or with the following two commands:

# Set the keyboard to English mapping
gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'en')]"
# And now back to the German mapping
gsettings set org.gnome.desktop.input-sources sources "[('xkb', 'de')]"

The Universal Solution

And a super bonus: This works for both X-Server and Wayland environments!

It took me half a day to figure this out, but it can be applied and activated in two minutes once you know how. Have fun!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.