17

I created the following ~/.Xmodmap file as per this answer.

keysym Delete = Menu
keysym Menu = Delete

clear Lock
keycode 0x42 = Escape

In other words, swap Delete and Menu, and make Caps Lock an additional Escape.

The next time I logged in, Ubuntu asked me if I wanted to load ~/.Xmodmap as expected. I loaded it, but nothing happened (either then or on subsequent logins). If I manually run xmodmap ~/.Xmodmap, it works as expected.

I know that this worked early in the 10.10 beta, but it's failing on my fresh 10.10 install. I haven't tried in on anything earlier than 10.10. Any ideas?

Edit: I put some debugging statements in /etc/gdm/Xsession to make sure ~/.Xmodmap was loading, and everything magically started working. I didn't change anything except adding some echos, and it's still working now that I reverted my changes and restarted again. Strangest thing I ever saw.

One thing I realized is that the "remap Caps Lock to Escape" part of the Xmodmap was always working. It was just the Delete/Menu swap that failed. I'll leave this question open for now in case anyone else has the same problem, since I don't actually know why the problem stopped.

  • I'm experiencing this same problem myself, been driving me nuts. If I figure out the cause I'll be sure to post an answer. – Jorge Israel Peña Feb 16 '13 at 23:30
11

I know it's silly but as a workaround you could just autostart xmodmap ~/.Xmodmap.

Also you could check /etc/gdm/Xsession for the line usermodmap="$HOME/.Xmodmap" and if it isn't there just append it at the end of the file. If you're the only user of the system just put your changes into /etc/X11/Xmodmap.

| improve this answer | |
  • 2
    How do you "autostart" commands? – miguel.martin Jul 21 '14 at 14:50
  • See Autostarting. The easiest is probably to just add an entry to Settings->Session and Startup, or something along those lines. – Mateen Ulhaq Jun 7 '17 at 2:54
  • Or for example, add it to your shell, so if you open shells often then it will run it. First thing I do when I enter Gnome is open a shell most of the time, so that is one way that works. – trusktr Jun 17 '17 at 0:40
4

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
  • ~/.gnomerc
  • ~/.xprofile
  • ~/.xinitrc
  • /etc/X11/Xsession.d/myscript
  • /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"

Basically create ~/.config/autostart/my-xmodmap.desktop file, and put in it:

[Desktop Entry]
Name=MyXmodmap
Exec=/usr/bin/xmodmap /home/me/.Xmodmap
Terminal=false
Type=Application
X-GNOME-Autostart-enabled=true

replace me with your username (note that I didn't bother to try ~/ or $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 xkb!

Edit (again)

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

Exec=$HOME/bin/mystart &

(note the &) mystart is a script in a new directory bin I created that contains

#!/bin/bash    
sleep 5
/usr/bin/xmodmap /home/me/.Xmodmap &
date >> /tmp/xmodmap-has-run

and

chmod u+x ~/bin/mystart

The script sleeps 5 seconds before to run xmodmap, and tracks when it did run (in the file /tmp/xmodmap-has-run).

Hopefully that will be all!

| improve this answer | |
3

Here is, perhaps a better answer then: http://cweiske.de/howto/xmodmap/ar01s06.html

You may have to tweak it a little bit to work for you but the instructions are all there.

| improve this answer | |
  • 1
    This instructions are for KDE, but if I look at the Gnome equivalent (/etc/gdm/Xsession), the lines that link says to add are already in it. – Matthew Oct 15 '10 at 14:16
3

Perhaps you have a syntax error in your ~/.Xmodmap file?

Try running:

$ xmodmap ~/.Xmodmap

That should fire an error if there are any.

| improve this answer | |
2

Unfortunately, this looks like a (very) long standing issue, and it is just because after Gnome 3.6, xmodmap support was dropped.

This is discussed in Remap keys on GNOME3.8 using xmodmap? and Bug 873656 - .Xmodmap file not loaded by Gnome 3.x .

The solution is to move to xkb. There is a bit of help from comment 29 in the second link.

| improve this answer | |
1

I had the same weird problem, trying to start up my xmodmap while logging in my session (Ubuntu 13.04). I finally made it work with a .xinitrc file in my Home folder where I put my command, but with absolute paths to it, that is:

/usr/bin/xmodmap /home/MYNAME/.Xmodmap

Then I had to reboot (not just relog) so that it would be executed.

| improve this answer | |
  • 2
    This does not work under Ubuntu 14.04, for me. – miguel.martin Jul 21 '14 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.