6.5 Cursors

The cursor is different from other types of output to the screen since it is transient, passing over the screen without permanently changing it. The cursor is drawn where the pointer is pointing and removed as soon as the pointer moves.

Each window can have a different cursor defined in its window attributes (using XDefineCursor()). Whenever the pointer is in a visible window, the cursor is set to the cursor defined for that window. If no cursor was defined for that window, the cursor will be the one that was defined for the parent window unless otherwise specified in the attributes.

From X’s perspective, a cursor consists of a cursor shape, mask, foreground and background colors, and hotspot (defined in a moment):

  • The cursor bitmap determines the shape of the cursor.

  • The mask bitmap determines the pixels on the screen that will be modified by the cursor.

  • The pixel values determine the foreground color (the 1 bits in the cursor bitmap) and the background color (the 0 bits in the cursor bitmap).

  • The hotspot defines the point on the cursor that will be reported when a pointer event occurs. The hotspot is the actual tracking position—for example, the center for a crosshair cursor or the point of an arrow.

There usually are limitations imposed by the hardware on cursors as to size, shape, and whether a mask is implemented. XQueryBestCursor() is used to find out what sizes are possible.

You need to create a Cursor resource to call XDefineCursor(). Read on for a description of the ...

Get XLIB Programming Manual, Rel. 5, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.