Window Chord


Window Chord

Mon 13 Dec 2021

Software engineering is a game of concentration. If you want to stay "in flow," you need the right information in front of your eyes at the right time. You need to bring it into view quickly, using only muscle memory. If your editor, or debugger, or web browser isn't in sight right when you need it, or if a distracting program like your email reader is visible when you don't need it, you can lose focus.

I remember being amazed by Genera, the operating system of the Symbolics Lisp Machine. Genera made it easy to bring up exactly the program I wanted with a simple key combination of my choosing. On every OS I've used since, I've built up a set of keyboard shortcuts, or "chords," to do the same with programs I use regularly. I've posted this collection on Github as Window Chord.

Here are some example chords I use on Linux:

ctrl-alt-shift-aEvince (document viewer)
ctrl-alt-shift-eGNU Emacs
ctrl-alt-shift-wGoogle Chrome
ctrl-alt-shift-fMozilla Firefox
ctrl-alt-shift-nNautilus file browser
ctrl-alt-shift-tGnome Terminal

If my web browser isn't yet running, then ctrl-alt-shift-w starts it. If the browser is already running, but isn't the selected window, the same chord makes it visible and selects it. If the browser is already running and selected, that chord switches to another browser window. So my caveman brain can think "show me web page," and my fingers make the right thing happen instantly. No fiddling with the mouse, no traversing workspaces, no distractions.

I use the ctrl-alt-shift prefix because such chords don't interfere with Emacs. It's surprisingly easy to hit such a chord without looking, but you can choose simpler chords if you prefer.

Adding a chord for a new program is simple. Here's an example, launch-or-select-chrome:


launch-or-select \
  google-chrome \
  /opt/google/chrome/chrome \
    --enable-dom-distiller \

The launch-or-select program first looks for an X11 window with class google-chrome. If there isn't one, it starts Chrome using the remaining command-line arguments, starting with /opt/google/chrome/chrome.

In many Linux distributions, once you've written something like launch-or-select-chrome, it's a simple matter to add it as a custom shortcut. For example, in Pop! OS, which I use on my fantastic System76 Lemur Pro, Settings > Keyboard > Customize Shortcuts > Custom Shortcuts > Add Shortcut pops up a dialog box that asks for a name (e.g. Google Chrome), a command line (e.g. launch-or-select-chrome), and a key chord (e.g. ctrl-alt-shift-w).

In addition to chords for selecting programs, Window Chord includes a few for positioning windows. So that I don't get distracted worrying about exactly where each window should be, they're simple, leaving little room for fiddling. If you have a bigger monitor, you could easily expand the set. Here they are:

ctrl-alt-shift-1Fill the left half of the screen.
ctrl-alt-shift-2Fill the right half of the screen.
ctrl-alt-shift-xFill both sides of the screen.
ctrl-alt-shift-hHide the window.
ctrl-alt-shift-oHide other windows in the same program.

Even if you prefer a window manager that places windows for you, the launch-or-select programs above can be useful. I prefer to do placement myself. A simple left-half/right-half system requires almost no attention, but doesn't lead to distracting surprises, either.

To use Window Chord, put all of its programs somewhere on your $PATH, then install Chibi Scheme, an excellent implementation of Scheme written by Alex Shinn, as well as wmctrl and xdotool, which are low-level command-line programs for manipulating X11 windows.dependencies

I wish you all maximum productivity and minimum distractions.



Window Chord depends on:


The keyboard diagram at the top of this post is based on this image from Wikimedia, and is licensed in the same way, by CC BY-SA 3.0.

Symbolics Lisp machine keyboard photo

The keyboard photo in this post is from Wikipedia, and is also licensed under CC BY-SA 3.0.


This project is licensed under the MIT License except where otherwise noted.

See also

You might also like Ecky Putrady's Using xdotool as a Tiling Window Solution.