An X cursor hack

April 05, 2009

Much like how fonts work, X has two systems (one succeeding the other) for how (mouse) pointer cursors work. The newer system came along after Xrender as a rework of the cursor API in general and allows for theming, an alpha channel, animated cursors, etc.

Gtk's cursor API wrapped* only the old API. If you use it to load a standard cursor (like the text entry I-beam) the server translates this request to the new themed cursors. Unfortunately, the "mouse pointer + hourglass" cursor (which looks like a pointer with a spinning circle on my Ubuntu system) is only available via the new API. What to do?

This post nicely explains it: when the new API was introduced, Mozilla already had a custom cursor it used for this state (its primary use is "the page is still loading but you can interact with it right now"). It was important for the theming system to be able to cover this cursor, which lead to a hack: they use the hash of the custom cursor pixmap as an index into the cursor theme.

So now, after r12683, when we (and Eclipse, and surely others) want this interactible-but-loading cursor we send up the Mozilla pixmap as a custom cursor, knowing that the X server will ignore it and theme over it. Yikes.

* In researching for this post I discovered gdk_cursor_new_from_name, which maybe means this hack is obsolete since GTK 2.8. So maybe we should simplify our change? I don't yet quite get how all the pieces fit — like how this API interacts with other X servers that potentially lack the extension, and whether we care about those anyway. (E.g. our first Chromium+Linux demo given at Google was done via remote X on a Mac, which may not support this, though I can't say with confidence whether that's client-side Xcursor library support or server-side cursor theming or PEBCAK. Again, not sure I care too much.)