5.2 Creating, Recoloring, and Freeing Cursors

Each window can have a different cursor defined for it. Whenever the pointer is in a visible window, it is set to the cursor defined for that window. If no cursor was defined for that window, the cursor is the one defined for the parent window.

From X's perspective, a cursor consists of a cursor source, mask, colors, and a hotspot. The mask pixmap determines the shape of the cursor and must be a depth of one. The source pixmap must have a depth of one, and the colors determine the colors of the source. The hotspot defines the point on the cursor that is reported when a pointer event occurs. There may be limitations imposed by the hardware on cursors as to size and whether a mask is implemented. XQueryBestCursor() can be used to find out what sizes are possible. There is a standard font for creating cursors, but Xlib provides functions that you can use to create cursors from an arbitrary font or from bitmaps.

To create a cursor from the standard cursor font, use XCreateFontCursor().

To create a cursor from font glyphs, use XCreateGlyphCursor().

To create a cursor from two bitmaps, use XCreatePixmapCursor().

To determine useful cursor sizes, use XQueryBestCursor().

To change the color of a given cursor, use XRecolorCursor().

To free (destroy) a given cursor, use XFreeCursor().

Next Chapter: Color Management Functions

Christophe Tronche, [email protected]