Keyboard-only X, cwm hacks and Vimperator

July 09, 2007 at 08:26 PM | categories: Technical, Health | View Comments |

A few weeks ago, I wrote a short entry on some of the software I'd been looking at to reduce my reliance on the mouse. Specifically, I mentioned a window manager, cwm, and a FireFox extension, Conkeror.

Since I wrote that piece, I have refined my setup a little more. I found a Firefox extension called Vimperator which adds Vi-like keybindings. I prefer it to Conkeror mostly because it seems a little less buggy. Both Conkeror and Vimperator have a feature where you press a key and all links on a page get associated numbers (in the case of Conkeror) or letters (in the case of Vimperator). This feature enables you to very quickly visit links on a page. I found that Conkeror's implementation of this feature would not work with certain focus-manipulating JavaScript used on websites, and also it would sometimes insert the HTML and CSS for these numbered links into HTML you were editing! In fact, because of Conkeror, I ended up with it's numbered links embedded into an entry on this site - which was very odd and quite annoying. Conkeror also had a tendency to crash in some way which disabled all its keyboard shortcuts on windows, such that the only way to kill a window was via terminal - again, highly annoying. Vimperator is a little buggy still, but doesn't seem quite so bad. Furthermore, Vimperator makes it easier to open links in a new tab and copy links via the keyboard. Finally, I feel more at home with Vi-like keybindings than with Emacs-like keybindings, and I think they are a little easier on the hands in any case (less chording).

As for cwm, the window manager, I in fact went ahead and made some improvements to it of my own. The cwm code is quite clean and elegant C code, and was a pleasure to hack on. Already, it featured a window-switching dialog which had auto-complete (a.k.a. type ahead find). This feature is very nice and makes switching windows via the keyboard very easy. However, cwm also had an execution dialog which lacked this feature. I felt it would be relatively easy to populate the execution dialog with the executable files in the default path to add such auto-completion. It was a little more involved than I originally anticipated, owing to the fact that the existing cwm API for these auto-completing dialogs was designed for selecting one item from many, not for entering input. With a little hacking, though, I made a working patch. I find this feature very useful, as it allows me to launch common applications like Firefox and Pidgin with a minimal number of keystrokes. The next feature I added was based on something that I saw in the Ion3 window manager - namely, an auto-completing `ssh-to' dialog. Much like the window-switch dialog or the exec dialog, the `ssh-to' dialog is populated with entries from your ~/.ssh/known_hosts file. OpenSSH has support for hashing these entries - the `ssh-to' dialog simply skips hashed entries. For me at least, my work involves ssh'ing to a large number of different hosts, many of which have long names. The auto-completing dialog saves me considerable time. After committing these two hacks to the OpenBSD Xenocara tree, cwm was becoming very comfortable for me indeed. Only one major thing was bugging me - window movement. Cwm still required you to use the mouse to move windows around. Unlike a window manager such as Ion3, cwm does not (yet...) support tiling layout, and as such terminals and so on must be moved manually to maximise screen real estate. A simple solution to this is the ability to move windows around with the keyboard. After a productive conversation with OpenBSD developer Todd T. Fries I hacked up a simple patch which moved the active window with a Vi-style M-hjkl keybinding. Todd improved on this initial hack and committed it to the Xenocara tree. With these improvements, I find cwm quite comfortable and have little use for the mouse.

There are still a few niggling things in my setup. Mostly they revolve around X11's copy/paste buffer management. A thing I do very frequently is to copy a link or text selection from Firefox into an xterm, and vice versa. X11 has effectively two copy buffers - the "PRIMARY selection" and the "CLIPBOARD". If you select text with the mouse in an xterm, it goes into the "PRIMARY selection". You can paste the contents into an xterm using the keybinding shift-insert. Additionally, links yanked with Vimperator, or text selected in Firefox with the mouse - this all ends up in the "PRIMARY selection" also. However, typing shift-insert in the "open" dialog (`o') of Vimperator pastes the contents of the "CLIPBOARD"! Actually, not just the "open" dialog behaves like this, but every text input field in Firefox. Effectively this means I have to use the mouse to paste text into Firefox, which is quite irritating. I hope to find a utility which can keep the "CLIPBOARD" and "PRIMARY selection" synchronised. Personally, I do not find it helpful for these to be separate and it simply causes me annoyance. More information on X copy and paste can be found in this jwz article.

Niall O'Higgins is an author and software developer. He wrote the O'Reilly book MongoDB and Python. He also develops Strider Open Source Continuous Deployment and offers full-stack consulting services at FrozenRidge.co.

blog comments powered by Disqus