XKB and xsessionrc

So, for a while now I've been using xmodmap to remap my caps lock key off to mod4 to make using awesome just that little easier... although my laptop has got a 'Windows' key, it's in an awkward place for general use, whereas caps lock is in a somewhat more convenient place. Also, not wanting to make it system wide (you never know, someone else might want to use the laptop at some point, at which point it'd be a different user), I wanted to keep with something close to the xmodmap method of just replacing bits as we needed 'em.

As I upgraded the laptop yesterday, various things broke (not least of all, my awesome config, as the theme format had changed to lua, and my theme, erm, broked it), I changed from it using my ~/.xsession for starting the things that I want to using the default Xsession foo, fortunately this sources a .xsessionrc file, which is handy.

So, using hints from madduck's post about extending xkb, I setup a very simple mapping that just adds in the Caps Lock -> Mod4 override, which is nice and handy.

I then just use:

[ -r $HOME/.xkb/keymaps/default ] && xkbcomp -I$HOME/.xkb $HOME/.xkb/keymaps/default $DISPLAY

in my .xsessionrc to setup the keyboard with the right settings, the default keymap in $HOME/.xkb/keymaps is simply the output of setxkbmap -print, edited to add +brettp(caps_mod4) to the symbols, the +brettp(caps_mod4) is a copy of madducks partial for that, i.e. there is a file $HOME/.xkb/symbols/brettp that contains:

// caps_mod4: make capslock generate the mod4 modifier
partial modifier_keys
xkb_symbols "caps_mod4" {
  replace key <CAPS> {
    [ VoidSymbol, VoidSymbol ]
  modifier_map Mod4 { <CAPS> };

Looks a little cleaner than using xmodmap, and might mean that firing off Xnest sessions might stop breaking things!

Posted: 2009-08-16 14:13 in Tech | permalink