| 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 _XCURSORINT_H_ |
| 25 |
#define _XCURSORINT_H_ |
| 26 |
|
| 27 |
#ifdef HAVE_CONFIG_H |
| 28 |
#include "config.h" |
| 29 |
#endif |
| 30 |
|
| 31 |
#include <X11/Xlib.h> |
| 32 |
#include <X11/cursorfont.h> |
| 33 |
#include <X11/extensions/Xrender.h> |
| 34 |
|
| 35 |
#ifdef HAVE_XFIXES |
| 36 |
#include <X11/extensions/Xfixes.h> |
| 37 |
#endif |
| 38 |
|
| 39 |
#include "Xcursor.h" |
| 40 |
|
| 41 |
#include <fcntl.h> |
| 42 |
#ifdef O_CLOEXEC |
| 43 |
#define FOPEN_CLOEXEC "e" |
| 44 |
#else |
| 45 |
#define FOPEN_CLOEXEC "" |
| 46 |
#endif |
| 47 |
|
| 48 |
typedef struct _XcursorFontInfo { |
| 49 |
struct _XcursorFontInfo *next; |
| 50 |
Font font; |
| 51 |
XcursorBool is_cursor_font; |
| 52 |
} XcursorFontInfo; |
| 53 |
|
| 54 |
/* |
| 55 |
* Track a few recently created bitmaps to see |
| 56 |
* if they get used to create cursors. This |
| 57 |
* is done by hooking into Xlib and watching |
| 58 |
* for XCreatePixmap, XPutImage, XCreatePixmapCursor |
| 59 |
* with appropriate arguments. When this happens |
| 60 |
* Xcursor computes a hash value for the source image |
| 61 |
* and tries to load a library cursor of that name. |
| 62 |
*/ |
| 63 |
|
| 64 |
/* large bitmaps are unlikely to be cursors */ |
| 65 |
#define MAX_BITMAP_CURSOR_SIZE 64 |
| 66 |
/* don't need to remember very many; in fact, 2 is likely sufficient */ |
| 67 |
#define NUM_BITMAPS 8 |
| 68 |
|
| 69 |
typedef struct _XcursorBitmapInfo { |
| 70 |
Pixmap bitmap; |
| 71 |
unsigned long sequence; |
| 72 |
unsigned int width, height; |
| 73 |
Bool has_image; |
| 74 |
unsigned char hash[XCURSOR_BITMAP_HASH_SIZE]; |
| 75 |
} XcursorBitmapInfo; |
| 76 |
|
| 77 |
typedef enum _XcursorDither { |
| 78 |
XcursorDitherThreshold, |
| 79 |
XcursorDitherMedian, |
| 80 |
XcursorDitherOrdered, |
| 81 |
XcursorDitherDiffuse |
| 82 |
} XcursorDither; |
| 83 |
|
| 84 |
typedef struct _XcursorDisplayInfo { |
| 85 |
struct _XcursorDisplayInfo *next; |
| 86 |
Display *display; |
| 87 |
XExtCodes *codes; |
| 88 |
XcursorBool has_render_cursor; |
| 89 |
XcursorBool has_anim_cursor; |
| 90 |
XcursorBool resized_cursors; |
| 91 |
XcursorBool theme_core; |
| 92 |
int size; |
| 93 |
XcursorFontInfo *fonts; |
| 94 |
char *theme; |
| 95 |
char *theme_from_config; |
| 96 |
XcursorDither dither; |
| 97 |
XcursorBitmapInfo bitmaps[NUM_BITMAPS]; |
| 98 |
} XcursorDisplayInfo; |
| 99 |
|
| 100 |
XcursorDisplayInfo * |
| 101 |
_XcursorGetDisplayInfo (Display *dpy); |
| 102 |
|
| 103 |
Cursor |
| 104 |
_XcursorCreateGlyphCursor(Display *dpy, |
| 105 |
Font source_font, |
| 106 |
Font mask_font, |
| 107 |
unsigned int source_char, |
| 108 |
unsigned int mask_char, |
| 109 |
XColor _Xconst *foreground, |
| 110 |
XColor _Xconst *background); |
| 111 |
|
| 112 |
Cursor |
| 113 |
_XcursorCreateFontCursor (Display *dpy, unsigned int shape); |
| 114 |
|
| 115 |
/* provide for XCURSOR_RESIZED */ |
| 116 |
XcursorImage * |
| 117 |
_XcursorFileLoadImage (FILE *file, int size, XcursorBool resize); |
| 118 |
|
| 119 |
XcursorImages * |
| 120 |
_XcursorXcFileLoadImages (XcursorFile *file, int size, XcursorBool resize); |
| 121 |
|
| 122 |
XcursorImages * |
| 123 |
_XcursorFileLoadImages (FILE *file, int size, XcursorBool resize); |
| 124 |
|
| 125 |
XcursorImages * |
| 126 |
_XcursorFilenameLoadImages (const char *file, int size, XcursorBool resize); |
| 127 |
|
| 128 |
XcursorImages * |
| 129 |
_XcursorShapeLoadImages (Display *dpy, unsigned int shape); |
| 130 |
|
| 131 |
#ifdef DEBUG_XCURSOR |
| 132 |
void _XcursorTrace(const char *fmt, ...) __attribute__((format(printf,1,2))); |
| 133 |
void *_XcursorReturnAddr(void *addr); |
| 134 |
int _XcursorReturnCode(int code); |
| 135 |
unsigned long _XcursorReturnLong(unsigned long code); |
| 136 |
unsigned _XcursorReturnUint(unsigned code); |
| 137 |
void _XcursorReturnVoid(void); |
| 138 |
#define T_CALLED(func) "called: { " #func |
| 139 |
#define T_OPTION(opts) "option: : " #opts |
| 140 |
#define T_RETURN(form) "return: } %" #form "\n" |
| 141 |
#define enterFunc(params) _XcursorTrace params |
| 142 |
#define traceOpts(params) _XcursorTrace params |
| 143 |
#define returnAddr(addr) return _XcursorReturnAddr(addr) |
| 144 |
#define returnCode(code) return _XcursorReturnCode(code) |
| 145 |
#define returnLong(code) return _XcursorReturnLong(code) |
| 146 |
#define returnUint(code) return _XcursorReturnUint(code) |
| 147 |
#define returnVoid() do { _XcursorReturnVoid(); return; } while (0) |
| 148 |
#else |
| 149 |
#define enterFunc(params) /* nothing */ |
| 150 |
#define traceOpts(params) /* nothing */ |
| 151 |
#define returnAddr(addr) return (addr) |
| 152 |
#define returnCode(code) return (code) |
| 153 |
#define returnLong(code) return (code) |
| 154 |
#define returnUint(code) return (code) |
| 155 |
#define returnVoid() return |
| 156 |
#endif |
| 157 |
|
| 158 |
#define NonNull(p) ((p) != NULL ? (p) : "<null>") |
| 159 |
|
| 160 |
#endif /* _XCURSORINT_H_ */ |