XCURSOR(3) | Keith Packard | XCURSOR(3) |
XCURSOR - Cursor management library
#include <X11/Xcursor/Xcursor.h>
Xcursor is a simple library designed to help locate and load cursors. Cursors can be loaded from files or memory. A library of common cursors exists which map to the standard X cursor names. Cursors can exist in several sizes and the library automatically picks the best size.
Xcursor is built in a couple of layers; at the bottom layer is code which can load cursor images from files. Above that is a layer which locates cursor files based on the library path and theme. At the top is a layer which builds cursors either out of an image loaded from a file or one of the standard X cursors. When using images loaded from files, Xcursor prefers to use the Render extension CreateCursor request if supported by the X server. Where not supported, Xcursor maps the cursor image to a standard X cursor and uses the core CreateCursor request.
Xcursor defines a new format for cursors on disk. Each file holds one or more cursor images. Each cursor image is tagged with a nominal size so that the best size can be selected automatically. Multiple cursors of the same nominal size can be loaded together; applications are expected to use them as an animated sequence.
Cursor files are stored as a header containing a table of contents followed by a sequence of chunks. The table of contents indicates the type, subtype and position in the file of each chunk. The file header looks like:
magic: CARD32 'Xcur' (0x58, 0x63, 0x75, 0x72)
header: CARD32 bytes in this header
version: CARD32 file version number
ntoc: CARD32 number of toc entries
toc: LISTofTOC table of contents
Each table of contents entry looks like:
type: CARD32 entry type
subtype: CARD32 type-specific label - size for images
position: CARD32 absolute byte position of table in file
Each chunk in the file has set of common header fields followed by additional type-specific fields:
header: CARD32 bytes in chunk header (including type-specific fields)
type: CARD32 must match type in TOC for this chunk
subtype: CARD32 must match subtype in TOC for this chunk
version: CARD32 version number for this chunk type
There are currently two chunk types defined for cursor files; comments and images. Comments look like:
header: 20 Comment headers are 20 bytes
type: 0xfffe0001 Comment type is 0xfffe0001
subtype: { 1 (COPYRIGHT), 2 (LICENSE), 3 (OTHER) }
version: 1
length: CARD32 byte length of UTF-8 string
string: LISTofCARD8 UTF-8 string
Images look like:
header: 36 Image headers are 36 bytes
type: 0xfffd0002 Image type is 0xfffd0002
subtype: CARD32 Image subtype is the nominal size
version: 1
width: CARD32 Must be less than or equal to 0x7fff
height: CARD32 Must be less than or equal to 0x7fff
xhot: CARD32 Must be less than or equal to width
yhot: CARD32 Must be less than or equal to height
delay: CARD32 Delay between animation frames in milliseconds
pixels: LISTofCARD32 Packed ARGB format pixels
Xcursor (mostly) follows the freedesktop.org spec for theming icons. The default search path it uses is ~/.icons, /usr/share/icons, /usr/share/pixmaps. Within each of these directories, it searches for a directory using the theme name. Within the theme directory, it looks for cursor files in the 'cursors' subdirectory. It uses the first cursor file found along the path.
If necessary, Xcursor also looks for a "index.theme" file in each theme directory to find inherited themes and searches along the path for those themes as well.
If no theme is set, or if no cursor is found for the specified theme, Xcursor checks the "default" theme.
typedef struct _XcursorImage {
XcursorDim size; /∗ nominal size for matching */
XcursorDim width; /∗ actual width */
XcursorDim height; /∗ actual height */
XcursorDim xhot; /∗ hot spot x (must be inside image) */
XcursorDim yhot; /∗ hot spot y (must be inside image) */
XcursorPixel *pixels; /∗ pointer to pixels */
} XcursorImage;
typedef struct _XcursorImages {
int nimage; /∗ number of images */
XcursorImage **images; /∗ array of XcursorImage pointers */
} XcursorImages;
typedef struct _XcursorCursors {
Display *dpy; /∗ Display holding cursors */
int ref; /∗ reference count */
int ncursor; /∗ number of cursors */
Cursor *cursors; /∗ array of cursors */
} XcursorCursors;
typedef struct _XcursorAnimate {
XcursorCursors *cursors; /∗ list of cursors to use */
int sequence; /∗ which cursor is next */
} XcursorAnimate;
typedef struct _XcursorFile {
void *closure;
int (*read) (XcursorFile *file, unsigned char *buf, int len);
int (*write) (XcursorFile *file, unsigned char *buf, int len);
int (*seek) (XcursorFile *file, long offset, int whence);
};
Xcursor will probably change radically in the future; weak attempts will be made to retain some level of source-file compatibility.
Keith Packard
libXcursor 1.2.0 | X Version 11 |