Late to the party, but this drove me nuts as well ; and, stubborn as I am, giving up was not an option.
Basically this is what I tried, (as my user, or root if necessary)
- ~/.Xmodmap only
- ~/.xsession, ~/.xsessionrc
- /usr/share/X11/xorg.conf.d/ (config files, didn't touch it)
(Actually, adding the
xmodmap command to
~/.bashrc worked, but it requires to start a terminal each time after login)
A few years ago(?),
xkb was chosen to deal with keys mapping and configuration (interfacing with X), but
xmodmap might also request key related changes to X, after
xkb did its work during the X session initialization.
The problem is when should these xmodmap settings happen?
It seems those above files are processed too early in the process, and either X was not ready to accept xmodmap changes, or xkb would overwrite them.
Note: I added some "tracking" to these files to ensure they were actually running at some time!
A solution that seems to work
I was not keen to add a
.desktop file initially (a simple one line script had to be enough), but that works, so here it is.
The solution comes from How to remap or swap special keyboard keys in Linux? "solution 1"
~/.config/autostart/my-xmodmap.desktop file, and put in it:
me with your username (note that I didn't bother to try
$HOME that may work equally well in place of
/home/me, and the full path of xmodmap is likely not necessary...), and add the exec bit
chmod +x ~/.config/autostart/my-xmodmap.desktop
The xmodmap commands have to be in a
~/.Xmodmap file in this case (or use the
-e option, or choose another file name!). Log out and back in.
Note that you might create the starting program from "Startup Applications".
Another solution would be to forget xmodmap and learn how to configure
Sometimes, maybe 25% of the logons, the
xmodmap still seems not working - while the command is actually run (a tracker proves that). The only conclusion I might come to at this time is that the
xkb process does run late in the logon process, and may end after the
xmodmap has run. Looks like a race condition... So, finally, I changed the autostart desktop file
exec line to
mystart is a script in a new directory
bin I created that contains
/usr/bin/xmodmap /home/me/.Xmodmap &
date >> /tmp/xmodmap-has-run
chmod u+x ~/bin/mystart
The script sleeps 5 seconds before to run xmodmap, and tracks when it did run (in the file
Hopefully that will be all!