Monday, 12 October 2009

Hints for X11 on Mac OS X

One of the lovely features of Mac OS X, being based on Unix technology, is that it's possible to run X11 based applications with an almost native look and feel. Unfortunately this doesn't translate completely due to the way the X11 server is implemented. It is a single app, and all X11 windows are considered children of it, so the OS X window manager treats all X11 windows as a large group. This does mean, however, that those of us used to working with X11 apps in a different way to OS X native apps can do so, as long as you don't mind the slight mismatch of behaviour.

One of the first things folk notice about the OS X window manager for X11, quartzwm, is that the mouse focus model is completely unintuitive. Focussing a window requires clicking within it, but then activating controls requires another click. You can't just move the mouse over to a window and click, and expect anything to happen. This is usually resolved in one of two ways; turning on "focus follows mouse", or enabling "click through" to allow the window to respond to the focussing click as if it were already focussed.

When I'm using a linux window manager, I am happy working in either of these modes. For Gnome, I like to have click-to-focus, and for more lightweight WMs like Fluxbox, I prefer focus-follows-mouse. Fortunately, enabling either of these options for quartzwm (for Snow Leopard, anyway) is as simple as opening the preferences pane and clicking a checkbox. For OS X, I find that click-to-focus matches the rest of the OS best, so I enable click-throughs.

When using X11 on OS X, it is usually to use the Gimp. This is bundled as a self-contained application, and will launch the X11 server on demand. Of course, all the Gimp's windows are still considered a part of the X11 app, but the Gimp dock icon responds to drag-and-drop and other OS X features. It's a bit weird, but easy to get used to.

Enabling click-through makes working with the Gimp a lot more fluid. The multi-window interface is a pain to work with otherwise, because even something as simple as changing which tool you're using requires clicking the toolbox window, then clicking again to select the tool. It is very frustrating to click a tool and then try to use it, only to realise that a) the tool never got selected, because the WM swallowed the click before the Gimp could respond, and b) the tool window is now focussed, so trying to use the tool on the image will not work until you refocus it with yet another click.

For those of you who don't like using nasty, icky GUIs for something like changing WM preferences (why are you using OS X again?) there is a command line way to do it. In a terminal (or Xterm if you're so inclined), type one of the following to enable focus-follows-mouse (ffm) or click-throughs:
defaults write org.x.X11 wm_ffm -bool true
defaults write org.x.X11 wm_click_through -bool true
Another useful feature built into quartzwm is the ability to shut down the X server automatically when no windows are left. For those of use who only use the occassional X11 program, and are somewhat obsessive about not leaving programs running in the Dock that aren't actually in use, this is very useful indeed. To enable it, enter the following command into a terminal:
defaults write org.x.X11 wm_auto_quit -bool true
A secondary option allows you to specify a short timeout, in which the WM will wait for a few seconds to see if you start any more windows. If you do, quartzwm doesn't shut down and continues until all windows really have gone. It is very important to use this option if you use the Gimp. With a 0 second timeout, the X11 server will close as soon as the Gimp splash screen disappears, because it takes a moment for the main image window to appear. This fraction of a second delay is enough to make the X11 server disappear and take the Gimp with it, making it impossible to start up. I would recommend a 5 second timeout to make sure that all windows really are closed, and more importantly, no more are on the way before shutting down the X11 server.

To enable this feature, enter this command in the terminal:
defaults write org.x.X11 wm_auto_quit_timeout -int 5

Note that all this options are available in earlier versions of Mac OS X than Snow Leopard. For Leopard users, they are identical. For Tiger users, replace all references to org.x.x11 with com.apple.x11. This is because versions of OS X prior to Leopard used the now mostly defunct XFree86, while Leopard and Snow Leopard have moved to the much sexier X.org.

No comments:

Post a Comment