CrGlCur.c revision 2e9c7c8c
1/* $Xorg: CrGlCur.c,v 1.4 2001/02/09 02:03:32 xorgcvs Exp $ */ 2/* 3 4Copyright 1986, 1998 The Open Group 5 6Permission to use, copy, modify, distribute, and sell this software and its 7documentation for any purpose is hereby granted without fee, provided that 8the above copyright notice appear in all copies and that both that 9copyright notice and this permission notice appear in supporting 10documentation. 11 12The above copyright notice and this permission notice shall be included in 13all copies or substantial portions of the Software. 14 15THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 19AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 22Except as contained in this notice, the name of The Open Group shall not be 23used in advertising or otherwise to promote the sale, use or other dealings 24in this Software without prior written authorization from The Open Group. 25 26*/ 27/* $XFree86: xc/lib/X11/CrGlCur.c,v 1.7 2003/04/13 19:22:15 dawes Exp $ */ 28 29#ifdef HAVE_CONFIG_H 30#include <config.h> 31#endif 32#include "Xlibint.h" 33 34#ifdef USE_DYNAMIC_XCURSOR 35 36#ifdef __UNIXOS2__ 37#define RTLD_LAZY 1 38#define LIBXCURSOR "Xcursor.dll" 39#endif 40#include <stdio.h> 41#include <string.h> 42#if defined(hpux) 43#include <dl.h> 44#else 45#include <dlfcn.h> 46#endif 47#include "Cr.h" 48 49#ifdef __CYGWIN__ 50#define LIBXCURSOR "cygXcursor-1.dll" 51#endif 52 53#if defined(hpux) 54typedef shl_dt XModuleType; 55#else 56typedef void *XModuleType; 57#endif 58 59#ifndef LIBXCURSOR 60#define LIBXCURSOR "libXcursor.so.1" 61#endif 62 63static char libraryName[] = LIBXCURSOR; 64 65static XModuleType 66open_library (void) 67{ 68 char *library = libraryName; 69 char *dot; 70 XModuleType module; 71 for (;;) 72 { 73#if defined(hpux) 74 module = shl_load(library, BIND_DEFERRED, 0L); 75#else 76 module = dlopen(library, RTLD_LAZY); 77#endif 78 if (module) 79 return module; 80 dot = strrchr (library, '.'); 81 if (!dot) 82 break; 83 *dot = '\0'; 84 } 85 return NULL; 86} 87 88static void * 89fetch_symbol (XModuleType module, const char *under_symbol) 90{ 91 void *result = NULL; 92 const char *symbol = under_symbol + 1; 93#if defined(hpux) 94 int getsyms_cnt, i; 95 struct shl_symbol *symbols; 96 97 getsyms_cnt = shl_getsymbols(module, TYPE_PROCEDURE, 98 EXPORT_SYMBOLS, malloc, &symbols); 99 100 for(i=0; i<getsyms_cnt; i++) { 101 if(!strcmp(symbols[i].name, symbol)) { 102 result = symbols[i].value; 103 break; 104 } 105 } 106 107 if(getsyms_cnt > 0) { 108 free(symbols); 109 } 110#else 111 result = dlsym (module, symbol); 112 if (!result) 113 result = dlsym (module, under_symbol); 114#endif 115 return result; 116} 117 118typedef void (*NoticeCreateBitmapFunc) (Display *dpy, 119 Pixmap pid, 120 unsigned int width, 121 unsigned int height); 122 123typedef void (*NoticePutBitmapFunc) (Display *dpy, 124 Drawable draw, 125 XImage *image); 126 127typedef Cursor (*TryShapeBitmapCursorFunc) (Display *dpy, 128 Pixmap source, 129 Pixmap mask, 130 XColor *foreground, 131 XColor *background, 132 unsigned int x, 133 unsigned int y); 134 135typedef Cursor (*TryShapeCursorFunc) (Display *dpy, 136 Font source_font, 137 Font mask_font, 138 unsigned int source_char, 139 unsigned int mask_char, 140 XColor _Xconst *foreground, 141 XColor _Xconst *background); 142 143static XModuleType _XcursorModule; 144static Bool _XcursorModuleTried; 145 146#define GetFunc(type,name,ret) {\ 147 static Bool been_here; \ 148 static type staticFunc; \ 149 \ 150 _XLockMutex (_Xglobal_lock); \ 151 if (!been_here) \ 152 { \ 153 been_here = True; \ 154 if (!_XcursorModuleTried) \ 155 { \ 156 _XcursorModuleTried = True; \ 157 _XcursorModule = open_library (); \ 158 } \ 159 if (_XcursorModule) \ 160 staticFunc = (type) fetch_symbol (_XcursorModule, "_" name); \ 161 } \ 162 ret = staticFunc; \ 163 _XUnlockMutex (_Xglobal_lock); \ 164} 165 166static Cursor 167_XTryShapeCursor (Display *dpy, 168 Font source_font, 169 Font mask_font, 170 unsigned int source_char, 171 unsigned int mask_char, 172 XColor _Xconst *foreground, 173 XColor _Xconst *background) 174{ 175 TryShapeCursorFunc func; 176 177 GetFunc (TryShapeCursorFunc, "XcursorTryShapeCursor", func); 178 if (func) 179 return (*func) (dpy, source_font, mask_font, source_char, mask_char, 180 foreground, background); 181 return None; 182} 183 184void 185_XNoticeCreateBitmap (Display *dpy, 186 Pixmap pid, 187 unsigned int width, 188 unsigned int height) 189{ 190 NoticeCreateBitmapFunc func; 191 192 GetFunc (NoticeCreateBitmapFunc, "XcursorNoticeCreateBitmap", func); 193 if (func) 194 (*func) (dpy, pid, width, height); 195} 196 197void 198_XNoticePutBitmap (Display *dpy, 199 Drawable draw, 200 XImage *image) 201{ 202 NoticePutBitmapFunc func; 203 204 GetFunc (NoticePutBitmapFunc, "XcursorNoticePutBitmap", func); 205 if (func) 206 (*func) (dpy, draw, image); 207} 208 209Cursor 210_XTryShapeBitmapCursor (Display *dpy, 211 Pixmap source, 212 Pixmap mask, 213 XColor *foreground, 214 XColor *background, 215 unsigned int x, 216 unsigned int y) 217{ 218 TryShapeBitmapCursorFunc func; 219 220 GetFunc (TryShapeBitmapCursorFunc, "XcursorTryShapeBitmapCursor", func); 221 if (func) 222 return (*func) (dpy, source, mask, foreground, background, x, y); 223 return None; 224} 225#endif 226 227Cursor XCreateGlyphCursor( 228 register Display *dpy, 229 Font source_font, 230 Font mask_font, 231 unsigned int source_char, 232 unsigned int mask_char, 233 XColor _Xconst *foreground, 234 XColor _Xconst *background) 235{ 236 Cursor cid; 237 register xCreateGlyphCursorReq *req; 238 239#ifdef USE_DYNAMIC_XCURSOR 240 cid = _XTryShapeCursor (dpy, source_font, mask_font, 241 source_char, mask_char, foreground, background); 242 if (cid) 243 return cid; 244#endif 245 LockDisplay(dpy); 246 GetReq(CreateGlyphCursor, req); 247 cid = req->cid = XAllocID(dpy); 248 req->source = source_font; 249 req->mask = mask_font; 250 req->sourceChar = source_char; 251 req->maskChar = mask_char; 252 req->foreRed = foreground->red; 253 req->foreGreen = foreground->green; 254 req->foreBlue = foreground->blue; 255 req->backRed = background->red; 256 req->backGreen = background->green; 257 req->backBlue = background->blue; 258 UnlockDisplay(dpy); 259 SyncHandle(); 260 return (cid); 261} 262 263