GNOME supports fast input source (keyboard layout) However, if you are using xmodmap to create custom keymaps, it may not work correctly when you switch between multiple input sources. For example, you have two input sources, English and German. Your xmodmap commands work fine in the first input source you select, but when you switch to the second input source the same xmodmap commands produce incorrect output. xmodmap is an older protocol and does not have full view of the keyboard layout, so in more complex situations it causes errors.
An alternative method is to use xcompose to assign special symbols to sequences of key presses. This should work with any input source. Install xcompose by installing the libX11-devel package.
Next, assign a compose key with the Tweaks tool in Activities. You will press this key in sequence with one or two additional keys to print a special character. The keys must be pressed in the correct sequence, starting with the compose key.
Navigate to Keyboard & Mouse › Compose Key and select your command key
Figure 3.2: Enabling the Compose Key in Tweaks
Next, create a ~/.XCompose file. This is the default per-user configuration file. Enter your keymappings in this file, like this example:
include "%L"
<Multi_key> <a> : "α"
<Multi_key> <b> : "β"
<Multi_key> <exclam> : "¡"
include "%L" includes the default compose file for your locale, for example /usr/share/X11/locale/en_US.UTF-8.
The remaining lines specify the compose key, the other keypresses, and the symbols they are intended to print. After you make changes to your compose file, you must log out of your session and log back in to activate the changes.
Your key assignments are case-sensitive. ~/.XCompose overrides the system files. Use the compose file for your locale to see what is already configured, and to copy symbols from it into your personal compose file. (These files may have a lot of whitespace at the beginning; they're not empty so keep scrolling.) As always, watch out for conflicts with the other keymaps on your system.
For additional information see man xcompose.