Note that here I’m talking about windows getting focus when they launch, rather than focus-follows-mouse or window click-through (I’ll leave that one to Gruber).

Recently, I’ve learnt something about how window focus works on OSX, and subsequently been fairly disappointed by how it works in X (and probably Windows, but correct me if I’m wrong).

While writing autonose, I had this issue where, even though I called window.makeKeyAndOrderFront:, my window would still appear below the terminal (which is where it was launched from). It turns out that “front” meant “the front of the current layer”. I won’t go into the gritty details of what constitutes a layer, because I didn’t really find out myself.

What it amounts to though, is that OSX apps have a much more controlled way of grabbing focus when they launch. When you call makeKeyAndOrderFront, your app only gets focus if nothing else had focus. And it just to happens that whenever the finder (or dock, or other apps) launch an application, they effectively resign focus. So when you get launched from the dock or finder, your application will become frontmost when you call makeKeyAndOrderFront.

However, (and this is the critical bit), let’s say your app takes a long time to load. In the meantime, I (the user) get impatient and switch to my browser. Then, when you eventually load, you’ll be put at the front of your layer - which will be just below my browser window. You won’t steal my focus, and I can complete whatever browsing I was doing while I waited for you to launch.

Compare this to X, where launching an application pretty much means you shouldn’t bother trying to type anywhere else. Pretty much every time I launch evolution it fights itself for focus, and launching an IDE (especially intelliJ) is guaranteed to steal my focus no less than 4 times before it has actually finished loading (and for no good reason, it’s not like it wants me to do something when it steals my focus).

I don’t know that much about how the focus model in X, and it’s possible that IDEs are suffering in particular because they generally use cross-platform toolkits. But it seems to me like there’s no good way for an app to steal focus only if the user isn’t busy doing something else. Any when you use a lot of apps that can take upwards of a minute to launch, sitting there waiting because you don’t trust them not to screw around with your input focus seems a little daft.