| 1 |
/* |
| 2 |
* Copyright © 2024 Thomas E. Dickey |
| 3 |
* Copyright © 2002 Keith Packard |
| 4 |
* |
| 5 |
* Permission to use, copy, modify, distribute, and sell this software and its |
| 6 |
* documentation for any purpose is hereby granted without fee, provided that |
| 7 |
* the above copyright notice appear in all copies and that both that |
| 8 |
* copyright notice and this permission notice appear in supporting |
| 9 |
* documentation, and that the name of Keith Packard not be used in |
| 10 |
* advertising or publicity pertaining to distribution of the software without |
| 11 |
* specific, written prior permission. Keith Packard makes no |
| 12 |
* representations about the suitability of this software for any purpose. It |
| 13 |
* is provided "as is" without express or implied warranty. |
| 14 |
* |
| 15 |
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 16 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 17 |
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 18 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 19 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 20 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 21 |
* PERFORMANCE OF THIS SOFTWARE. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifndef _XCURSOR_H_ |
| 25 |
#define _XCURSOR_H_ |
| 26 |
#include <stdio.h> |
| 27 |
#include <stdint.h> |
| 28 |
#include <X11/Xfuncproto.h> |
| 29 |
#include <X11/Xlib.h> |
| 30 |
|
| 31 |
typedef int XcursorBool; |
| 32 |
typedef uint32_t XcursorUInt; |
| 33 |
|
| 34 |
typedef XcursorUInt XcursorDim; |
| 35 |
typedef XcursorUInt XcursorPixel; |
| 36 |
|
| 37 |
#define XcursorTrue 1 |
| 38 |
#define XcursorFalse 0 |
| 39 |
|
| 40 |
/* |
| 41 |
* Cursor files start with a header. The header |
| 42 |
* contains a magic number, a version number and a |
| 43 |
* table of contents which has type and offset information |
| 44 |
* for the remaining tables in the file. |
| 45 |
* |
| 46 |
* File minor versions increment for compatible changes |
| 47 |
* File major versions increment for incompatible changes (never, we hope) |
| 48 |
* |
| 49 |
* Chunks of the same type are always upward compatible. Incompatible |
| 50 |
* changes are made with new chunk types; the old data can remain under |
| 51 |
* the old type. Upward compatible changes can add header data as the |
| 52 |
* header lengths are specified in the file. |
| 53 |
* |
| 54 |
* File: |
| 55 |
* FileHeader |
| 56 |
* LISTofChunk |
| 57 |
* |
| 58 |
* FileHeader: |
| 59 |
* CARD32 magic magic number |
| 60 |
* CARD32 header bytes in file header |
| 61 |
* CARD32 version file version |
| 62 |
* CARD32 ntoc number of toc entries |
| 63 |
* LISTofFileToc toc table of contents |
| 64 |
* |
| 65 |
* FileToc: |
| 66 |
* CARD32 type entry type |
| 67 |
* CARD32 subtype entry subtype (size for images) |
| 68 |
* CARD32 position absolute file position |
| 69 |
*/ |
| 70 |
|
| 71 |
#define XCURSOR_MAGIC 0x72756358 /* "Xcur" LSBFirst */ |
| 72 |
|
| 73 |
/* |
| 74 |
* Current Xcursor version number. Will be substituted by configure |
| 75 |
* from the version in the libXcursor configure.ac file. |
| 76 |
*/ |
| 77 |
|
| 78 |
#undef XCURSOR_LIB_MAJOR |
| 79 |
#undef XCURSOR_LIB_MINOR |
| 80 |
#undef XCURSOR_LIB_REVISION |
| 81 |
#define XCURSOR_LIB_VERSION ((XCURSOR_LIB_MAJOR * 10000) + \ |
| 82 |
(XCURSOR_LIB_MINOR * 100) + \ |
| 83 |
(XCURSOR_LIB_REVISION)) |
| 84 |
|
| 85 |
/* |
| 86 |
* This version number is stored in cursor files; changes to the |
| 87 |
* file format require updating this version number |
| 88 |
*/ |
| 89 |
#define XCURSOR_FILE_MAJOR 1 |
| 90 |
#define XCURSOR_FILE_MINOR 0 |
| 91 |
#define XCURSOR_FILE_VERSION ((XCURSOR_FILE_MAJOR << 16) | (XCURSOR_FILE_MINOR)) |
| 92 |
#define XCURSOR_FILE_HEADER_LEN (4 * 4) |
| 93 |
#define XCURSOR_FILE_TOC_LEN (3 * 4) |
| 94 |
|
| 95 |
typedef struct _XcursorFileToc { |
| 96 |
XcursorUInt type; /* chunk type */ |
| 97 |
XcursorUInt subtype; /* subtype (size for images) */ |
| 98 |
XcursorUInt position; /* absolute position in file */ |
| 99 |
} XcursorFileToc; |
| 100 |
|
| 101 |
typedef struct _XcursorFileHeader { |
| 102 |
XcursorUInt magic; /* magic number */ |
| 103 |
XcursorUInt header; /* byte length of header */ |
| 104 |
XcursorUInt version; /* file version number */ |
| 105 |
XcursorUInt ntoc; /* number of toc entries */ |
| 106 |
XcursorFileToc *tocs; /* table of contents */ |
| 107 |
} XcursorFileHeader; |
| 108 |
|
| 109 |
/* |
| 110 |
* The rest of the file is a list of chunks, each tagged by type |
| 111 |
* and version. |
| 112 |
* |
| 113 |
* Chunk: |
| 114 |
* ChunkHeader |
| 115 |
* <extra type-specific header fields> |
| 116 |
* <type-specific data> |
| 117 |
* |
| 118 |
* ChunkHeader: |
| 119 |
* CARD32 header bytes in chunk header + type header |
| 120 |
* CARD32 type chunk type |
| 121 |
* CARD32 subtype chunk subtype |
| 122 |
* CARD32 version chunk type version |
| 123 |
*/ |
| 124 |
|
| 125 |
#define XCURSOR_CHUNK_HEADER_LEN (4 * 4) |
| 126 |
|
| 127 |
typedef struct _XcursorChunkHeader { |
| 128 |
XcursorUInt header; /* bytes in chunk header */ |
| 129 |
XcursorUInt type; /* chunk type */ |
| 130 |
XcursorUInt subtype; /* chunk subtype (size for images) */ |
| 131 |
XcursorUInt version; /* version of this type */ |
| 132 |
} XcursorChunkHeader; |
| 133 |
|
| 134 |
/* |
| 135 |
* Here's a list of the known chunk types |
| 136 |
*/ |
| 137 |
|
| 138 |
/* |
| 139 |
* Comments consist of a 4-byte length field followed by |
| 140 |
* UTF-8 encoded text |
| 141 |
* |
| 142 |
* Comment: |
| 143 |
* ChunkHeader header chunk header |
| 144 |
* CARD32 length bytes in text |
| 145 |
* LISTofCARD8 text UTF-8 encoded text |
| 146 |
*/ |
| 147 |
|
| 148 |
#define XCURSOR_COMMENT_TYPE 0xfffe0001 |
| 149 |
#define XCURSOR_COMMENT_VERSION 1 |
| 150 |
#define XCURSOR_COMMENT_HEADER_LEN (XCURSOR_CHUNK_HEADER_LEN + (1 *4)) |
| 151 |
#define XCURSOR_COMMENT_COPYRIGHT 1 |
| 152 |
#define XCURSOR_COMMENT_LICENSE 2 |
| 153 |
#define XCURSOR_COMMENT_OTHER 3 |
| 154 |
#define XCURSOR_COMMENT_MAX_LEN 0x100000 |
| 155 |
|
| 156 |
typedef struct _XcursorComment { |
| 157 |
XcursorUInt version; |
| 158 |
XcursorUInt comment_type; |
| 159 |
char *comment; |
| 160 |
} XcursorComment; |
| 161 |
|
| 162 |
/* |
| 163 |
* Each cursor image occupies a separate image chunk. |
| 164 |
* The length of the image header follows the chunk header |
| 165 |
* so that future versions can extend the header without |
| 166 |
* breaking older applications |
| 167 |
* |
| 168 |
* Image: |
| 169 |
* ChunkHeader header chunk header |
| 170 |
* CARD32 width actual width |
| 171 |
* CARD32 height actual height |
| 172 |
* CARD32 xhot hot spot x |
| 173 |
* CARD32 yhot hot spot y |
| 174 |
* CARD32 delay animation delay |
| 175 |
* LISTofCARD32 pixels ARGB pixels |
| 176 |
*/ |
| 177 |
|
| 178 |
#define XCURSOR_IMAGE_TYPE 0xfffd0002 |
| 179 |
#define XCURSOR_IMAGE_VERSION 1 |
| 180 |
#define XCURSOR_IMAGE_HEADER_LEN (XCURSOR_CHUNK_HEADER_LEN + (5*4)) |
| 181 |
#define XCURSOR_IMAGE_MAX_SIZE 0x7fff /* 32767x32767 max cursor size */ |
| 182 |
|
| 183 |
typedef struct _XcursorImage { |
| 184 |
XcursorUInt version; /* version of the image data */ |
| 185 |
XcursorDim size; /* nominal size for matching */ |
| 186 |
XcursorDim width; /* actual width */ |
| 187 |
XcursorDim height; /* actual height */ |
| 188 |
XcursorDim xhot; /* hot spot x (must be inside image) */ |
| 189 |
XcursorDim yhot; /* hot spot y (must be inside image) */ |
| 190 |
XcursorUInt delay; /* animation delay to next frame (ms) */ |
| 191 |
XcursorPixel *pixels; /* pointer to pixels */ |
| 192 |
} XcursorImage; |
| 193 |
|
| 194 |
/* |
| 195 |
* Other data structures exposed by the library API |
| 196 |
*/ |
| 197 |
typedef struct _XcursorImages { |
| 198 |
int nimage; /* number of images */ |
| 199 |
XcursorImage **images; /* array of XcursorImage pointers */ |
| 200 |
char *name; /* name used to load images */ |
| 201 |
} XcursorImages; |
| 202 |
|
| 203 |
typedef struct _XcursorCursors { |
| 204 |
Display *dpy; /* Display holding cursors */ |
| 205 |
int ref; /* reference count */ |
| 206 |
int ncursor; /* number of cursors */ |
| 207 |
Cursor *cursors; /* array of cursors */ |
| 208 |
} XcursorCursors; |
| 209 |
|
| 210 |
typedef struct _XcursorAnimate { |
| 211 |
XcursorCursors *cursors; /* list of cursors to use */ |
| 212 |
int sequence; /* which cursor is next */ |
| 213 |
} XcursorAnimate; |
| 214 |
|
| 215 |
typedef struct _XcursorFile XcursorFile; |
| 216 |
|
| 217 |
struct _XcursorFile { |
| 218 |
void *closure; |
| 219 |
int (*read) (XcursorFile *file, unsigned char *buf, int len); |
| 220 |
int (*write) (XcursorFile *file, unsigned char *buf, int len); |
| 221 |
int (*seek) (XcursorFile *file, long offset, int whence); |
| 222 |
}; |
| 223 |
|
| 224 |
typedef struct _XcursorComments { |
| 225 |
int ncomment; /* number of comments */ |
| 226 |
XcursorComment **comments; /* array of XcursorComment pointers */ |
| 227 |
} XcursorComments; |
| 228 |
|
| 229 |
#define XCURSOR_CORE_THEME "core" |
| 230 |
|
| 231 |
_XFUNCPROTOBEGIN |
| 232 |
|
| 233 |
/* |
| 234 |
* Manage Image objects |
| 235 |
*/ |
| 236 |
XcursorImage * |
| 237 |
XcursorImageCreate (int width, int height); |
| 238 |
|
| 239 |
void |
| 240 |
XcursorImageDestroy (XcursorImage *image); |
| 241 |
|
| 242 |
/* |
| 243 |
* Manage Images objects |
| 244 |
*/ |
| 245 |
XcursorImages * |
| 246 |
XcursorImagesCreate (int size); |
| 247 |
|
| 248 |
void |
| 249 |
XcursorImagesDestroy (XcursorImages *images); |
| 250 |
|
| 251 |
void |
| 252 |
XcursorImagesSetName (XcursorImages *images, const char *name); |
| 253 |
|
| 254 |
/* |
| 255 |
* Manage Cursor objects |
| 256 |
*/ |
| 257 |
XcursorCursors * |
| 258 |
XcursorCursorsCreate (Display *dpy, int size); |
| 259 |
|
| 260 |
void |
| 261 |
XcursorCursorsDestroy (XcursorCursors *cursors); |
| 262 |
|
| 263 |
/* |
| 264 |
* Manage Animate objects |
| 265 |
*/ |
| 266 |
XcursorAnimate * |
| 267 |
XcursorAnimateCreate (XcursorCursors *cursors); |
| 268 |
|
| 269 |
void |
| 270 |
XcursorAnimateDestroy (XcursorAnimate *animate); |
| 271 |
|
| 272 |
Cursor |
| 273 |
XcursorAnimateNext (XcursorAnimate *animate); |
| 274 |
|
| 275 |
/* |
| 276 |
* Manage Comment objects |
| 277 |
*/ |
| 278 |
XcursorComment * |
| 279 |
XcursorCommentCreate (XcursorUInt comment_type, int length); |
| 280 |
|
| 281 |
void |
| 282 |
XcursorCommentDestroy (XcursorComment *comment); |
| 283 |
|
| 284 |
XcursorComments * |
| 285 |
XcursorCommentsCreate (int size); |
| 286 |
|
| 287 |
void |
| 288 |
XcursorCommentsDestroy (XcursorComments *comments); |
| 289 |
|
| 290 |
/* |
| 291 |
* XcursorFile/Image APIs |
| 292 |
*/ |
| 293 |
XcursorImage * |
| 294 |
XcursorXcFileLoadImage (XcursorFile *file, int size); |
| 295 |
|
| 296 |
XcursorImages * |
| 297 |
XcursorXcFileLoadImages (XcursorFile *file, int size); |
| 298 |
|
| 299 |
XcursorImages * |
| 300 |
XcursorXcFileLoadAllImages (XcursorFile *file); |
| 301 |
|
| 302 |
XcursorBool |
| 303 |
XcursorXcFileLoad (XcursorFile *file, |
| 304 |
XcursorComments **commentsp, |
| 305 |
XcursorImages **imagesp); |
| 306 |
|
| 307 |
XcursorBool |
| 308 |
XcursorXcFileSave (XcursorFile *file, |
| 309 |
const XcursorComments *comments, |
| 310 |
const XcursorImages *images); |
| 311 |
|
| 312 |
/* |
| 313 |
* FILE/Image APIs |
| 314 |
*/ |
| 315 |
XcursorImage * |
| 316 |
XcursorFileLoadImage (FILE *file, int size); |
| 317 |
|
| 318 |
XcursorImages * |
| 319 |
XcursorFileLoadImages (FILE *file, int size); |
| 320 |
|
| 321 |
XcursorImages * |
| 322 |
XcursorFileLoadAllImages (FILE *file); |
| 323 |
|
| 324 |
XcursorBool |
| 325 |
XcursorFileLoad (FILE *file, |
| 326 |
XcursorComments **commentsp, |
| 327 |
XcursorImages **imagesp); |
| 328 |
|
| 329 |
XcursorBool |
| 330 |
XcursorFileSaveImages (FILE *file, const XcursorImages *images); |
| 331 |
|
| 332 |
XcursorBool |
| 333 |
XcursorFileSave (FILE * file, |
| 334 |
const XcursorComments *comments, |
| 335 |
const XcursorImages *images); |
| 336 |
|
| 337 |
/* |
| 338 |
* Filename/Image APIs |
| 339 |
*/ |
| 340 |
XcursorImage * |
| 341 |
XcursorFilenameLoadImage (const char *filename, int size); |
| 342 |
|
| 343 |
XcursorImages * |
| 344 |
XcursorFilenameLoadImages (const char *filename, int size); |
| 345 |
|
| 346 |
XcursorImages * |
| 347 |
XcursorFilenameLoadAllImages (const char *filename); |
| 348 |
|
| 349 |
XcursorBool |
| 350 |
XcursorFilenameLoad (const char *file, |
| 351 |
XcursorComments **commentsp, |
| 352 |
XcursorImages **imagesp); |
| 353 |
|
| 354 |
XcursorBool |
| 355 |
XcursorFilenameSaveImages (const char *filename, const XcursorImages *images); |
| 356 |
|
| 357 |
XcursorBool |
| 358 |
XcursorFilenameSave (const char *file, |
| 359 |
const XcursorComments *comments, |
| 360 |
const XcursorImages *images); |
| 361 |
|
| 362 |
/* |
| 363 |
* Library/Image APIs |
| 364 |
*/ |
| 365 |
XcursorImage * |
| 366 |
XcursorLibraryLoadImage (const char *library, const char *theme, int size); |
| 367 |
|
| 368 |
XcursorImages * |
| 369 |
XcursorLibraryLoadImages (const char *library, const char *theme, int size); |
| 370 |
|
| 371 |
/* |
| 372 |
* Library/shape API |
| 373 |
*/ |
| 374 |
|
| 375 |
const char * |
| 376 |
XcursorLibraryPath (void); |
| 377 |
|
| 378 |
int |
| 379 |
XcursorLibraryShape (const char *library); |
| 380 |
|
| 381 |
/* |
| 382 |
* Image/Cursor APIs |
| 383 |
*/ |
| 384 |
|
| 385 |
Cursor |
| 386 |
XcursorImageLoadCursor (Display *dpy, const XcursorImage *image); |
| 387 |
|
| 388 |
XcursorCursors * |
| 389 |
XcursorImagesLoadCursors (Display *dpy, const XcursorImages *images); |
| 390 |
|
| 391 |
Cursor |
| 392 |
XcursorImagesLoadCursor (Display *dpy, const XcursorImages *images); |
| 393 |
|
| 394 |
/* |
| 395 |
* Filename/Cursor APIs |
| 396 |
*/ |
| 397 |
Cursor |
| 398 |
XcursorFilenameLoadCursor (Display *dpy, const char *file); |
| 399 |
|
| 400 |
XcursorCursors * |
| 401 |
XcursorFilenameLoadCursors (Display *dpy, const char *file); |
| 402 |
|
| 403 |
/* |
| 404 |
* Library/Cursor APIs |
| 405 |
*/ |
| 406 |
Cursor |
| 407 |
XcursorLibraryLoadCursor (Display *dpy, const char *file); |
| 408 |
|
| 409 |
XcursorCursors * |
| 410 |
XcursorLibraryLoadCursors (Display *dpy, const char *file); |
| 411 |
|
| 412 |
/* |
| 413 |
* Shape/Image APIs |
| 414 |
*/ |
| 415 |
|
| 416 |
XcursorImage * |
| 417 |
XcursorShapeLoadImage (unsigned int shape, const char *theme, int size); |
| 418 |
|
| 419 |
XcursorImages * |
| 420 |
XcursorShapeLoadImages (unsigned int shape, const char *theme, int size); |
| 421 |
|
| 422 |
/* |
| 423 |
* Shape/Cursor APIs |
| 424 |
*/ |
| 425 |
Cursor |
| 426 |
XcursorShapeLoadCursor (Display *dpy, unsigned int shape); |
| 427 |
|
| 428 |
XcursorCursors * |
| 429 |
XcursorShapeLoadCursors (Display *dpy, unsigned int shape); |
| 430 |
|
| 431 |
/* |
| 432 |
* This is the function called by Xlib when attempting to |
| 433 |
* load cursors from XCreateGlyphCursor. The interface must |
| 434 |
* not change as Xlib loads 'libXcursor.so' instead of |
| 435 |
* a specific major version |
| 436 |
*/ |
| 437 |
Cursor |
| 438 |
XcursorTryShapeCursor (Display *dpy, |
| 439 |
Font source_font, |
| 440 |
Font mask_font, |
| 441 |
unsigned int source_char, |
| 442 |
unsigned int mask_char, |
| 443 |
XColor _Xconst *foreground, |
| 444 |
XColor _Xconst *background); |
| 445 |
|
| 446 |
void |
| 447 |
XcursorNoticeCreateBitmap (Display *dpy, |
| 448 |
Pixmap pid, |
| 449 |
unsigned int width, |
| 450 |
unsigned int height); |
| 451 |
|
| 452 |
void |
| 453 |
XcursorNoticePutBitmap (Display *dpy, |
| 454 |
Drawable draw, |
| 455 |
XImage *image); |
| 456 |
|
| 457 |
Cursor |
| 458 |
XcursorTryShapeBitmapCursor (Display *dpy, |
| 459 |
Pixmap source, |
| 460 |
Pixmap mask, |
| 461 |
XColor *foreground, |
| 462 |
XColor *background, |
| 463 |
unsigned int x, |
| 464 |
unsigned int y); |
| 465 |
|
| 466 |
#define XCURSOR_BITMAP_HASH_SIZE 16 |
| 467 |
|
| 468 |
void |
| 469 |
XcursorImageHash (XImage *image, |
| 470 |
unsigned char hash[XCURSOR_BITMAP_HASH_SIZE]); |
| 471 |
|
| 472 |
/* |
| 473 |
* Display information APIs |
| 474 |
*/ |
| 475 |
XcursorBool |
| 476 |
XcursorSupportsARGB (Display *dpy); |
| 477 |
|
| 478 |
XcursorBool |
| 479 |
XcursorSupportsAnim (Display *dpy); |
| 480 |
|
| 481 |
XcursorBool |
| 482 |
XcursorSetDefaultSize (Display *dpy, int size); |
| 483 |
|
| 484 |
int |
| 485 |
XcursorGetDefaultSize (Display *dpy); |
| 486 |
|
| 487 |
XcursorBool |
| 488 |
XcursorSetResizable (Display *dpy, XcursorBool flag); |
| 489 |
|
| 490 |
XcursorBool |
| 491 |
XcursorGetResizable (Display *dpy); |
| 492 |
|
| 493 |
XcursorBool |
| 494 |
XcursorSetTheme (Display *dpy, const char *theme); |
| 495 |
|
| 496 |
char * |
| 497 |
XcursorGetTheme (Display *dpy); |
| 498 |
|
| 499 |
XcursorBool |
| 500 |
XcursorGetThemeCore (Display *dpy); |
| 501 |
|
| 502 |
XcursorBool |
| 503 |
XcursorSetThemeCore (Display *dpy, XcursorBool theme_core); |
| 504 |
|
| 505 |
_XFUNCPROTOEND |
| 506 |
|
| 507 |
#endif |