How I learned to stop worrying and love the 'book

A guide for emigrants from X11-based unices

by Azundris 2011/09/25

First, let's sort out at least some of the keyboard: if you're on something reasonably close to a US layout, things won't be perfect, but they won't be a perfect mess either. 1

  1. Install KeyRemap4MacBook°
  2. Open its pane in the System Preferences
  3. go to the Change Key tab
  4. in Change Command_L key enable Command_L to Option_L
  5. in Change Option_L Key, select Option_L to Command_L

thereby completing the swap to a more sane, id est standards-conformant layout, namely:
Control, Cmd/Super, Option/Alt, Space, …
(This has the added benefit of moving the Mac's app-switcher to Super-Tab, leaving Alt-Tab free for X11's window-switcher.)

In fact while you're at it, you might feel that the key in the bottom left corner should bloody well be Control, and you'd be right: fortunately, there is Fn to Control_L to address that. You will probably want to preserve Fn as it's useful for scrolling (MacBooks lack PgUp/PgDn) — Option_R to Fn is an obvious choice here as it utilizes a mostly unused key and moves Fn close to the cursor keys it's usually used in conjunction with.


As far as Apple is concerned, the trackpad maps a one finger click to leftClick, and a two finger click to rightClick. This is very counter intuitive to most X11 users who expect three buttons — left, middle, right —, which would more naturally map to one, two, and three finger clicks, respectively.

Let's enforce X11-like behaviour system-wide: we'll emulate three buttons on the trackpad. A three finger click is button3 in XQuartz, but also "right button" (the one that opens the context menu) in Mac Aqua applications. Thus, we need the following:

First, we'll have the three finger click generate a right click (so it'll open context-menus, etc.).

  1. Install BetterTouchTool° if you haven't already.
  2. Open its configuration.
  3. Select the Global context.
  4. Add the gesture three finger click, assign the action rightclick. (In fact you may pick either or both of the three finger click and three finger tap gestures here.)

(Make sure that your three finger gesture of choice actually brings up a context menu in an application that has one before you proceed.)

Then, we'll have the two finger click generate a middle click instead of a right click. BetterTouchTool cannot do this, so we'll fix it in KeyRemap4MacBook:

System PreferencesKeyRemap4MacBook pane ➞ Change key tab ➞ Samples for KeyRemap4MacBook DeveloperPointingButtonToPointingButton ➞ Activate RightClick to MiddleClick.

Mouse-buttons, II

Now, you might decide that that whole three finger clicking is kinda hard on the wrist, and that Apple was, whole and large, onto something with putting the context menu on the two finger click, especially since while you could map the middle click to Paste (Cmd-V), you don't need it as often anyway, and let's keep the Apple apps the Apple way, and our sentences, whole and large, shorter than this.

One way to accomplish this is to have the "two finger click is middle click, not right click" setting only apply to a given program (namely, X11):

System Preferences, KeyRemap4MacBook, Misc, Open private.xml

<?xml version="1.0"?>
      <name>RightClick to MiddleClick (selective)</name>
      <only>EMACS, TERMINAL, X11</only>
      <autogen>—PointingButtonToPointingButton— PointingButton::RIGHT, PointingButton::MIDDLE</autogen>

If you then go to the Change Key tab and Reload XML, you should see a new option (RightClick to MiddleClick (selective)). This will set you up in the "UNIXoid" applications XQuartz, iTerm2, and emacs-for-Aqua, but will leave the "Aqua-y" programs well alone.

Mouse-buttons, III

Finally, if for some reason KeyRemap4MacBook is not an option (because you don't have root/Administrator on your machine (seriously?), or because your machine is not compatible, or prudence or company policy forbid you to load third party kernel modules), you can at least set up X11 correctly like so:

In BetterTouchTool's preferences, add X11 to the application-list on the left (it's /Applications/Utilities/ Then, add three finger click as a gesture, with middleclick (as opposed to rightclick above!) as the action. This will make the three finger click visible to X, albeit as button 2 ("middle click"). Fortunately, this sort of configuration is immensely less painful on X than it is on Mac:

xmodmap -e "pointer = 1 3 2"

changes the button order as far as X11 is concerned. (Mind that entering this in a shell won't make it stick, so you'll probably want to put the statement in your X11 setup files (~/.xinitrc or ~/.xinitrc.d/), or preferably just the pointer = 1 3 2 part in your ~/.Xmodmap).

This won't fix iTerm2 or emacs-on-Aqua (emacs in XQuartz will be fine!), but as long as you do your UNIXy work on X, you should still be OK.

Window operations / window management

Many X11 window managers are set so that pressing Alt/Option and dragging with the left button moves a window (anywhere in the window will do, not just on the title bar), whereas Alt and the middle button ("two finger click") let you resize a window.

Afloat° lets you do just that (and a few other fun things) on OS X. True, it's not Alt, it's Control-Command, but you might find that easy to adapt to (or, you could just fix it in the source and roll your own, like yours truly (unmodified source°), which also gives you a chance to make it accept "middle or right button for resize", which would make it a little more co-operative while we're swapping mouse-buttons like crazy). The only downside is that as a SIMBL, it only works with cocoa applications, not with legacy carbon ones (Thunderbird, Firefox, etc.).

As an aside, Deskovery offers wobbly windows to the compizly homesick as well as, more importantly, window shading (double-clicking the title-bar reduces the window to the title-bar; double-clicking again restores it). It does however interfere with my X11 window manager's Alt-Tab window switcher (even when the option in Deskovery is disabled), so I haven't bought a license yet. To its credit, it wobblifies anything — cocoa, carbon, X11+e16, it just doesn't care.


For a computer that is the artists' choice and asks you to think different, Macs are insanely unthemeable. It's only recently that themes for Snow Leopard and later have emerged, snolo having introduced a new format, thereby breaking existing themes. Even so what existed before and what exists now is very samey-samey by X11 standards (think enlightenment DR16 themes with shaped borders, etc. — not all of them were pretty, it's true, but those that weren't were usually at least daring). Long story short, those of us who work nights would at least like to change the colors to something less offensive: paint it black.

CrystalBlack° does the trick, but costs $6 after a free evaluation period. (That's another thing you're probably not used to — most everything costs money. At $6, CrystalBlack is a steal, but if you're on a budget or philosophically opposed to paying for software, Black-Mac° will at least blacken your window borders, whereas CrystalBlack also addresses a window's contents.) Again we're talking SIMBL city here; so in practice, everything but the three apps I spent most my tube time in (X11 with enlightenment, Firefox, ThunderbirdquartzWM is a carbon application, by the way, and closed source to boot) are supported. Those three of course at least have their own theming features; it's wireframe for me on e16, dark carbonite on Firefox, and BlackWhite on Thunderbird. (You'd think it'd work best to have the same theme on FF and TB, but that's not how it worked out in practice. I forced the Personas (1.6.2) extension on Thunderbird 6 by the way, thus making the theme-handling more weird than annoying.)


Nu, but what about those weird menus, you say. Why are they not in their window where they belong? Why do even apps that have little need of a menu waste an entire line of my MacBook's none to plentiful screen estate? Good questions all around, and it's certainly tempting to set the menu-bar to auto-hide. Which you can. As long as you do it for each application separately. Oh, and since that setting is saved within the application bundle, you'll break the app's signature/checksum°, so caveat emptor. I have e.g. XQuartz's menu on auto-hide (even in rootless mode), but I'd think twice before blindly changing all the applications.

But then even outside of screen estate, having the menu separate from the application is not just weird, but plainly inconvenient with a multi-screen setup. DejaMenu° puts an application's menu in a context menu that you can call up with the pressing of a key or the clicking of a button.

Reloaded I: Use Control rather than Command in Mac apps, like on Windows

We remap the left control key to generate command, so then e.g. Control-W closes a tab in Chrome, same as on Windows.

We specifically exclude unixoid applications (X11, terminal, and Firefox which presumably has Firemacs installed) as those already use Control.

As Firefox and iTerm still expect Command-LeftClick to open links, we add another toggle to map that to Control-LeftClick.

Optionally, we make Control-T and Control-L (new tab and edit URL, respectively) work in Firefox even though they're not part of Firemacs out of the box.

Since we no longer need the left Command-key, we remap left Command to left Command plus right Shift (so we can tell it from naturally occurring Command + Shift combinations — if nothing else, it helps us to avoid further processing).

This doesn't just mean that Mac apps and unixoid apps now both use Control rather than Command (which also means that Firefox, Chrome, etc. handle the same way as on Windows); it also means that Command / WinKey / Super is now free for us to do with as we please.

The suggested course of action is to install the free version of FastScripts (or the for-pay version, if you need more functionality and/or wish to support, in which case, yay you), and bind Command-Shift-C (in other words, just Alt-C going by Apple's keycaps) to some AppleScript that raises Chrome: tell application "Google Chrome" to activate
C raises Chrome, F raises Firefox, T raises Thunderbird, etc. — direct access to whatever your most important apps are. Fastest setup in the west!
You can even work without multiple desktops that way if you must.

Extended private.xml for KeyRemap4Macbook including all the original extensions, plus those from this new chapter ("Reloaded I").
Note that if you use any of the new Azundris->Command & Control options, you may have to disable any selections in the Change Command_L key and Change Control_L key sections further down!

Well, this was fun.

Or at least it's better than working with the Mac defaults (If Macs were cars, you wouldn't be able to adjust the seat in an Apple — Steve Jobs knows best how tall you should be!). Now that iTerm2 and emacs on the Aqua side of things look and behave a little more sane, I might not even need X11 that much anymore (and of course, the urxvt in X11 will connect to the same screen session as the iTerm2 on Aqua, anyway, so switching back and forth is easy).

I'm a little happier now; the machine is less painful to use, and feels more my own now. On the downside where linux invites you in to configure anything and everything, with the Mac it at times felt like I had to break into my own property. "Just works" it ain't. And of course if I ever upgrade to Lion, it'll all just break again.

By that token, this is what works for me. This account comes with no warranty or endorsement; these programs or the combination thereof may be dangerous; this travelogue if misconstrued as instructions may be dangerous, incomplete, or misleading; you are on your own; any error yours. Good luck!

1   If you're on a non-English keyboard, the whole Alt vs AltGr thing is a complete pig's breakfast on Aqua — at least it halfway works in VirtualBox and X11. But even so the program we'll be looking at next might offer some relief, e.g. by fixing the issue where a German touch typist will quit the program when they try to type an at sign.

2011/09/25 1.0 init
2011/10/30 1.1 HTML
2012/06/15 1.2 "Reloaded I"