17914d74bSmrg/* 26b7436aeSmrg * Copyright © 2024 Thomas E. Dickey 37914d74bSmrg * Copyright © 2002 Keith Packard 47914d74bSmrg * 57914d74bSmrg * Permission to use, copy, modify, distribute, and sell this software and its 67914d74bSmrg * documentation for any purpose is hereby granted without fee, provided that 77914d74bSmrg * the above copyright notice appear in all copies and that both that 87914d74bSmrg * copyright notice and this permission notice appear in supporting 97914d74bSmrg * documentation, and that the name of Keith Packard not be used in 107914d74bSmrg * advertising or publicity pertaining to distribution of the software without 117914d74bSmrg * specific, written prior permission. Keith Packard makes no 127914d74bSmrg * representations about the suitability of this software for any purpose. It 137914d74bSmrg * is provided "as is" without express or implied warranty. 147914d74bSmrg * 157914d74bSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 167914d74bSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 177914d74bSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 187914d74bSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 197914d74bSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 207914d74bSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 217914d74bSmrg * PERFORMANCE OF THIS SOFTWARE. 227914d74bSmrg */ 237914d74bSmrg 247914d74bSmrg#ifndef _XCURSORINT_H_ 257914d74bSmrg#define _XCURSORINT_H_ 267914d74bSmrg 277914d74bSmrg#ifdef HAVE_CONFIG_H 287914d74bSmrg#include "config.h" 297914d74bSmrg#endif 30e6d5e4e0Smrg 317914d74bSmrg#include <X11/Xlib.h> 327914d74bSmrg#include <X11/cursorfont.h> 337914d74bSmrg#include <X11/extensions/Xrender.h> 347914d74bSmrg 357914d74bSmrg#ifdef HAVE_XFIXES 367914d74bSmrg#include <X11/extensions/Xfixes.h> 377914d74bSmrg#endif 387914d74bSmrg 397914d74bSmrg#include "Xcursor.h" 400ea508b1Smrg 410ea508b1Smrg#include <fcntl.h> 420ea508b1Smrg#ifdef O_CLOEXEC 430ea508b1Smrg#define FOPEN_CLOEXEC "e" 440ea508b1Smrg#else 450ea508b1Smrg#define FOPEN_CLOEXEC "" 460ea508b1Smrg#endif 477914d74bSmrg 487914d74bSmrgtypedef struct _XcursorFontInfo { 497914d74bSmrg struct _XcursorFontInfo *next; 507914d74bSmrg Font font; 517914d74bSmrg XcursorBool is_cursor_font; 527914d74bSmrg} XcursorFontInfo; 537914d74bSmrg 547914d74bSmrg/* 557914d74bSmrg * Track a few recently created bitmaps to see 567914d74bSmrg * if they get used to create cursors. This 577914d74bSmrg * is done by hooking into Xlib and watching 587914d74bSmrg * for XCreatePixmap, XPutImage, XCreatePixmapCursor 597914d74bSmrg * with appropriate arguments. When this happens 607914d74bSmrg * Xcursor computes a hash value for the source image 617914d74bSmrg * and tries to load a library cursor of that name. 627914d74bSmrg */ 63e6d5e4e0Smrg 647914d74bSmrg/* large bitmaps are unlikely to be cursors */ 657914d74bSmrg#define MAX_BITMAP_CURSOR_SIZE 64 667914d74bSmrg/* don't need to remember very many; in fact, 2 is likely sufficient */ 677914d74bSmrg#define NUM_BITMAPS 8 687914d74bSmrg 697914d74bSmrgtypedef struct _XcursorBitmapInfo { 707914d74bSmrg Pixmap bitmap; 717914d74bSmrg unsigned long sequence; 727914d74bSmrg unsigned int width, height; 737914d74bSmrg Bool has_image; 747914d74bSmrg unsigned char hash[XCURSOR_BITMAP_HASH_SIZE]; 757914d74bSmrg} XcursorBitmapInfo; 767914d74bSmrg 777914d74bSmrgtypedef enum _XcursorDither { 787914d74bSmrg XcursorDitherThreshold, 797914d74bSmrg XcursorDitherMedian, 807914d74bSmrg XcursorDitherOrdered, 817914d74bSmrg XcursorDitherDiffuse 827914d74bSmrg} XcursorDither; 837914d74bSmrg 847914d74bSmrgtypedef struct _XcursorDisplayInfo { 857914d74bSmrg struct _XcursorDisplayInfo *next; 867914d74bSmrg Display *display; 877914d74bSmrg XExtCodes *codes; 887914d74bSmrg XcursorBool has_render_cursor; 897914d74bSmrg XcursorBool has_anim_cursor; 906b7436aeSmrg XcursorBool resized_cursors; 917914d74bSmrg XcursorBool theme_core; 927914d74bSmrg int size; 937914d74bSmrg XcursorFontInfo *fonts; 947914d74bSmrg char *theme; 957914d74bSmrg char *theme_from_config; 967914d74bSmrg XcursorDither dither; 977914d74bSmrg XcursorBitmapInfo bitmaps[NUM_BITMAPS]; 987914d74bSmrg} XcursorDisplayInfo; 997914d74bSmrg 1007914d74bSmrgXcursorDisplayInfo * 1017914d74bSmrg_XcursorGetDisplayInfo (Display *dpy); 1027914d74bSmrg 1037914d74bSmrgCursor 1047914d74bSmrg_XcursorCreateGlyphCursor(Display *dpy, 1057914d74bSmrg Font source_font, 1067914d74bSmrg Font mask_font, 1077914d74bSmrg unsigned int source_char, 1087914d74bSmrg unsigned int mask_char, 1097914d74bSmrg XColor _Xconst *foreground, 1107914d74bSmrg XColor _Xconst *background); 1117914d74bSmrg 1127914d74bSmrgCursor 1137914d74bSmrg_XcursorCreateFontCursor (Display *dpy, unsigned int shape); 114e6d5e4e0Smrg 1156b7436aeSmrg/* provide for XCURSOR_RESIZED */ 1166b7436aeSmrgXcursorImage * 1176b7436aeSmrg_XcursorFileLoadImage (FILE *file, int size, XcursorBool resize); 1186b7436aeSmrg 1196b7436aeSmrgXcursorImages * 1206b7436aeSmrg_XcursorXcFileLoadImages (XcursorFile *file, int size, XcursorBool resize); 1216b7436aeSmrg 1226b7436aeSmrgXcursorImages * 1236b7436aeSmrg_XcursorFileLoadImages (FILE *file, int size, XcursorBool resize); 1246b7436aeSmrg 1256b7436aeSmrgXcursorImages * 1266b7436aeSmrg_XcursorFilenameLoadImages (const char *file, int size, XcursorBool resize); 1276b7436aeSmrg 1286b7436aeSmrgXcursorImages * 1296b7436aeSmrg_XcursorShapeLoadImages (Display *dpy, unsigned int shape); 1306b7436aeSmrg 1316b7436aeSmrg#ifdef DEBUG_XCURSOR 1326b7436aeSmrgvoid _XcursorTrace(const char *fmt, ...) __attribute__((format(printf,1,2))); 1336b7436aeSmrgvoid *_XcursorReturnAddr(void *addr); 1346b7436aeSmrgint _XcursorReturnCode(int code); 1356b7436aeSmrgunsigned long _XcursorReturnLong(unsigned long code); 1366b7436aeSmrgunsigned _XcursorReturnUint(unsigned code); 1376b7436aeSmrgvoid _XcursorReturnVoid(void); 1386b7436aeSmrg#define T_CALLED(func) "called: { " #func 1396b7436aeSmrg#define T_OPTION(opts) "option: : " #opts 1406b7436aeSmrg#define T_RETURN(form) "return: } %" #form "\n" 1416b7436aeSmrg#define enterFunc(params) _XcursorTrace params 1426b7436aeSmrg#define traceOpts(params) _XcursorTrace params 1436b7436aeSmrg#define returnAddr(addr) return _XcursorReturnAddr(addr) 1446b7436aeSmrg#define returnCode(code) return _XcursorReturnCode(code) 1456b7436aeSmrg#define returnLong(code) return _XcursorReturnLong(code) 1466b7436aeSmrg#define returnUint(code) return _XcursorReturnUint(code) 1476b7436aeSmrg#define returnVoid() do { _XcursorReturnVoid(); return; } while (0) 1486b7436aeSmrg#else 1496b7436aeSmrg#define enterFunc(params) /* nothing */ 1506b7436aeSmrg#define traceOpts(params) /* nothing */ 1516b7436aeSmrg#define returnAddr(addr) return (addr) 1526b7436aeSmrg#define returnCode(code) return (code) 1536b7436aeSmrg#define returnLong(code) return (code) 1546b7436aeSmrg#define returnUint(code) return (code) 1556b7436aeSmrg#define returnVoid() return 1566b7436aeSmrg#endif 1576b7436aeSmrg 1586b7436aeSmrg#define NonNull(p) ((p) != NULL ? (p) : "<null>") 1596b7436aeSmrg 1607914d74bSmrg#endif /* _XCURSORINT_H_ */ 161