I remapped a few keys for my comfort via Xmodmap.
Every time I attach a USB device or wake the laptop from sleep, the mappings are forgotten.
If I re-run the mappings manually, everything works ok.
Why is that, and how can I fix it?
I am using Ubuntu 20.04.4 LTS on a Lenovo P50, and my map is this:
clear control
clear mod1
clear mod4
clear mod5
! comments follow key assignment
keycode 133 = Alt_L Meta_L
! this makes left win into alt
keycode 64 = Control_L
! this makes left alt into control
keycode 37 = Super_L Super_L
! this makes left control into windows
! keycode 37 = Alt_L Meta_L
! this makes left control into alt
add control = Control_L Control_R
add mod1 = Alt_L Meta_L
add mod4 = Super_L Super_R
!clear control
!clear mod1
!clear mod4
...because
xmodmap
is not anymore up to date. It is an old tool. While it still works to change keybindings, it became unreliable in the way you see, i.e., it does not persist when you change an USB keyboard, after sleep, and even after you changed from one language to another and back.Workaround: define a quick shortcut key to load the mappings again.
Fundamental method: create a customized keyboard layout, but that is very complicated unfortunately.
Note also that
xmodmap
won't work anymore on Wayland.