Monday, October 22, 2018

Adventures in ratpoison keymaps - Caps Lock, Windows Key and Retraining My Brain

I can't imagine there are ton of ratpoison users out there, but for the benefit of anyone who does discover the greatest all of Linux Window Managers, here's some thoughts on my latest config.

For years, I operated ratpoison with the Caps Lock key set to the Hyper-L key, and Hyper-L set as the primary Escape key:

;; ~/.xmodmap
;; Turn Caps Lock into the Hyper_L key
keycode      66 = Hyper_L

# .ratpoisonrc
escape Hyper_L

This put the easy-to-hit Caps Lock key to good use.

Lately, however, I've been on a mission to turn Caps Lock into a clone of the Escape key. I have this setup on Windows, Mac and my Android device. When I'd fire up Linux, I found myself hitting Caps Lock when I wanted Escape. Except, Caps Lock was already allocated. This past week, I re-arranged things so that ratpoison no longer uses the Caps Lock key as the primary Escape directive. Here's my current config.

First off, I'm using .xmodmap to turn Caps Lock into the Escape key, not the Hyper_L key:

!! Turn Caps Lock into Hyper
clear      lock 
clear   control
clear      mod1
clear      mod2
clear      mod3
clear      mod4
clear      mod5
keycode      66 = Escape  ;; CHANGED
add     control = Control_L Control_R
add        mod1 = Alt_L Alt_R Meta_L
add        mod2 = Num_Lock
add        mod3 = Hyper_L
add        mod4 = Super_L Super_R
add        mod5 = Mode_switch ISO_Level3_Shift

Next, I've setup ratpoison to use Hyper_L, which is the Windows key, as the primary Escape command:

## Thanks to xmodmap, this is my windows key
escape Super_L

##  ___ - bindings
definekey root Up exec chvolume 2%+
definekey root Down exec chvolume 2%-
definekey root Left exec chbrightness dim
definekey root Right exec chbrightness bright
definekey root e exec rpwin goto emacs
definekey root g exec snipit
definekey root z exec xtext ts

I then defined a new keymap, something I'd yet to do previously in ratpoison:

## Make   execute
## what's on the 'custom' keymap
newkmap custom
definekey root Escape readkey custom

To use that keymap, I setup Escape on the root keymap to invoke the readkey command using the custom keymap. In other words, ratpoison listens for a key and when it hears Escape it invokes readkey, which in turn, listens for a new key stroke. This allows you to have arbitrarily nested keystrokes, and is a brilliant way to handle key definitions.

To avoid clashing with existing ratpoison commands, I setup the majority of my custom keys to hang off of this new keymap:

##   ___ - Bindings
definekey custom j exec rpwin restore J
definekey custom k exec rpwin restore K
definekey custom l exec rpwin restore L
definekey custom h  exec rpwin restore H
definekey custom J exec rpwin capture J
definekey custom K exec rpwin capture K
definekey custom L exec rpwin capture L
definekey custom H exec rpwin capture H
definekey custom p exec mkpass | xclip -selection clipboard
definekey custom o exec rpwin goto Gimp

unbind K
bind j nextscreen
bind k prevscreen

Using this config, I now have to press Windows Key - Caps Lock - j to return to the 'j' window configuration. And training my brain to hit the extra key stroke has taken a bit of practice. But in another week or two, this should be second nature.

I've now turned Caps Lock into Escape on all my computers and learned a clever protocol for handling nested key strokes. I'm telling you, ratpoison is the ultimate Linux Window Manager. Try, you'll see.

No comments:

Post a Comment