Remapped! | Ben Cunningham

Remapped!

Written by Ben Cunningham · on July 23, 2017

I like my ThinkPad. I bought a X220 a little under a year ago to replace my hulking T530 and it’s been great. I’ve especially enjoyed ditching Lenovo’s new chiclet console for a “regular” keyboard. But there are a few things about the old layout that I miss.

First up: the ThinkVantage button. I still don’t really understand what you’re expected to do with this one, so I’ve always ended up remapping mine. In the past, I’ve used it to call my email client, but this time around I decided launching a terminal was more useful.

To understand what keycode I’d need to remap, I ran xev in a terminal, pushed the ThinkVantage button, and saw something like this:

KeyRelease event, serial 37, synthetic NO, window 0x2c00001,
    root 0xcc, subw0x0, time 5447693, (267,-181), root:(950,273),
    state 0x0, keycode 156 (keysym 0x1008ff41, XF86Launch1), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

The important bit here is state 0x0, keycode 156. A bit of experimentation revealed that xbindkeys was probably going to be the most reliable way to remap this key, so after installing the package, I copied the following into ~/.xbindkeysrc:

"gnome-terminal"
m:0x0 + c:156

Pretty simple. The first line is just a command. The second is the state (0x0) and keycode (156) the I found with xev. On keydown, ThinkVantage now opens a GNOME terminal.

The last thing to do is make sure xbindkeys is always running by adding xbindkeys_autostart as an Ubuntu startup program.

Next up: paging up and down. On my T530, the up arrow key is flanked by Page Up and Page Down (formally, I’ve learned, Prior and Next). But on my X220, forward (XF86Forward) and backward (XF86Back) occupy those places. Because of this, I often accidentally navigate back and forth through my browser history, rather than skipping up and down pages.

Figuring out a permanent fix took me a while. I tried xmodmap (the key simulations worked, but the mapping itself would often come undone on login). I tried xbindkeys, as I did above (getting the mapping to work on key down rather than release was near impossible).

Finally, I found that configuring XKB was the way to go. After looking up the keys with xev, I replaced the following block in /usr/share/X11/xkb/symbols/inet with the two lines listed below:

key <I166> { [ XF86Back     ] };
key <I167> { [ XF86Forward  ] };
key <I166> { [ Prior        ] };
key <I167> { [ Next         ] };

Because XKB configuration files are setup when an X session starts, there’s no need to hack together any other scripts to run the mapping ad hoc.