Ugly Xmodmap Caps Lock Workaround

So, I decide to do a system upgrade (including all xorg packages) the other day and suddenly xmodmap isn’t working any more. Specifically, these lines in my .xinitrc no longer do the job (of making Caps lock my mod3 key (for use in Xmonad)):

xmodmap -e "remove Lock = Caps_Lock"
xmodmap -e "add mod3 = Caps_Lock"

So after tons of googling, I found this page: http://forums.gentoo.org/viewtopic-t-857625.html.

Basically, to get the same behavior back, I have to have

remove Lock = Caps_Lock
remove mod3 = Super_L
keysym Caps_Lock = Super_L
add mod3 = Super_L

in my (new) ~/.xmodmap file, and then do this in my ~/.xinitrc:

xmodmap -e "remove Lock = Caps_Lock"
xmodmap -e "add mod3 = Caps_Lock"
xmodmap ~/.xmodmap

This is a very, very ugly hack, but even after spending a solid hour trying manual xmodmap commands and this and that and all sorts of combinations, this is the only method that works.

I have no idea which package exactly broke xmodmap’s former 2-liner functionality, but it was sometime in the past couple months, probably. If the old 2-liner starts working again, I’ll let you all know…

Advertisements

6 thoughts on “Ugly Xmodmap Caps Lock Workaround

  1. Huh, that’s really weird. I don’t have the exact same setup (I switch Escape and Caps Lock, for Vim), but just running xmodmap on a file containing this works for me:

    remove Lock = Caps_Lock
    keysym Escape = Caps_Lock
    keysym Caps_Lock = Escape
    add Lock = Caps_Lock

    Have you tried ‘adding’ Lock to another key?

  2. @Hagu-chan (Honey & Clover! haha): I’ve tried all sorts of combinations, but they don’t work and I’m too tired to try out another. Not sure what you mean by “adding”. One key difference to note, though: your setup is to simply swap 2 existing keys. My setup kills the Caps Lock key and changes it into the “mod3” key. So the end result is that my xmodmap says:


    xmodmap: up to 4 keys per modifier, (keycodes in parentheses):

    shift Shift_L (0x32), Shift_R (0x3e)
    lock <----- this is where the Caps Lock key used to be
    control Control_L (0x25), Control_R (0x69)
    mod1 Alt_L (0x40), Alt_R (0x6c), Meta_L (0xcd)
    mod2 Num_Lock (0x4d)
    mod3 Super_L (0x42) <------------- this "Super_L" 0x42 key is my former Caps Lock key
    mod4 Super_L (0x85), Super_R (0x86), Super_L (0xce), Hyper_L (0xcf)
    mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)

    I can do this safely because the mod3 key is already unmapped by default, so I don’t have to worry about changing whatever was already there. Thanks for your input though, it will help others who land on this page.

  3. > Not sure what you mean by “adding”. One key difference to note, though: your setup is to simply swap 2 existing keys. My setup kills the Caps Lock key and changes it into the “mod3″ key.

    I was referring to this command:

    add Lock = Caps_Lock

    Instead of just killing the Caps Lock key, is it possible to bind Lock to a dummy key? Maybe the problem is that it’s remaining unbound. For example, I don’t see mod2 used anywhere in my xmonad.hs.

    I really like the extra mod key idea though. By using the context menu key as mod3, I’ll now be able to go from 20 to 40 workspaces in xmonad ;/

  4. > Instead of just killing the Caps Lock key, is it possible to bind Lock to a dummy key? Maybe the problem is that it’s remaining unbound.

    Er, I think I didn’t express myself clearly; the xmodmap output I commented is my current, working setup’s output. So there’s no problem with the Lock key being unbound.

    > For example, I don’t see mod2 used anywhere in my xmonad.hs.

    Well for me it says

    myNumlockMask = mod2Mask

    which is in turn passed into defaultConfig for the numlockMask field, so it definitely is being used… but this is getting off-topic.

    > I really like the extra mod key idea though. By using the context menu key as mod3, I’ll now be able to go from 20 to 40 workspaces in xmonad ;/

    Isn’t 40 a bit much? I personally have 22 (0-9, F1-F12)…

  5. I just ran into this after installing Gentoo on a new system; the .xmodmap I’ve been using for ages doesn’t work anymore. I’m not sure what’s different, but your workaround fixed it for now, so many thanks

Comments are closed.