I use an alternative german keyboard layout on Ubuntu 18.04:
~$ setxkbmap de koy
Now I want to swap three keys (Mod3 → f → ß → Mod3) as shown in that picture:

This are the keycodes for these keys:
~$ xmodmap -pke | grep -E 'keycode (33|48|51)'
keycode 33 = ssharp U1E9E ssharp U1E9E ampersand Greek_finalsmallsigma KP_Add KP_Add jot NoSymbol ampersand Greek_finalsmallsigma KP_Add KP_Add jot
keycode 48 = f F f F at Greek_phi period KP_Decimal Greek_PHI NoSymbol at Greek_phi period KP_Decimal Greek_PHI
keycode 51 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift
Q1: Why are there 15 columns for the f key and the ß key? /usr/share/X11/xkb/symbols/de only defines 8 columns!
I can swap the keys by using these xmodmap commands:
~$ xmodmap -e "keycode 51 = ssharp U1E9E ssharp U1E9E ampersand Greek_finalsmallsigma KP_Add KP_Add jot NoSymbol ampersand Greek_finalsmallsigma KP_Add KP_Add jot"
~$ xmodmap -e "keycode 33 = f F f F at Greek_phi period KP_Decimal Greek_PHI NoSymbol at Greek_phi period KP_Decimal Greek_PHI"
~$ xmodmap -e "keycode 48 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift"
Now the keys are swapped but …
- the ß (ssharp) key returns
ßon all levels! Expected (as before swapping):ß ẞ & + ς ∘ - key 48 (former f key) works as Mod3 except when used together with other modifiers: Shift+Mod3+a should give an
αbut gives anAnow.
Just checking again:
~$ xmodmap -pke | grep -E 'keycode (33|48|51)'
keycode 33 = f F f F ampersand Greek_phi KP_Add KP_Add Greek_PHI NoSymbol ampersand Greek_phi KP_Add KP_Add Greek_PHI NoSymbol f F ampersand Greek_phi KP_Add KP_Add Greek_PHI NoSymbol f F ampersand Greek_phi KP_Add KP_Add Greek_PHI
keycode 48 = ISO_Level3_Shift NoSymbol ISO_Level3_Shift NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol ISO_Level3_Shift NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol NoSymbol ISO_Level3_Shift
keycode 51 = ssharp NoSymbol ssharp U1E9E at Greek_finalsmallsigma period KP_Decimal
keycodes 48 and 51 are not as I set them.
Q2: What did go wrong?
In some other questions on StackExchange people say that it's important to remove or clear modifiers before changing them. But this always fails:
~$ xmodmap -pm
xmodmap: up to 3 keys per modifier, (keycodes in parentheses):
shift Shift_L (0x32), Shift_R (0x3e)
lock Shift_L (0x32)
control Control_L (0x25), Control_R (0x69)
mod1 Alt_L (0x40), Meta_L (0xcd)
mod2 BadKey (0xcf)
mod3 ISO_Level5_Shift (0xcb)
mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce)
mod5 ISO_Level3_Shift (0x5c)
~$ xmodmap -e "remove mod5 = ISO_Level3_Shift"
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 118 (X_SetModifierMapping)
Value in failed request: 0x17
Serial number of failed request: 11
Current serial number in output stream: 11
~$ xmodmap -e "clear mod5"
X Error of failed request: BadValue (integer parameter out of range for operation)
Major opcode of failed request: 118 (X_SetModifierMapping)
Value in failed request: 0x17
Serial number of failed request: 8
Current serial number in output stream: 8
Q3: What do these errors mean?
Mod2 BadKeybit. Even when you're just changing one thing, thexmodmaputility callsXGetModifierMapping, makes that one change, then callsXSetModifierMapping. If you've somehow ended up with a bad configuration on the server, the Set step fails.clear mod2may help, although I'm not sure if that's enough.