1 /***********************************************************
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47 ******************************************************************/
50 /* $XConsortium: cursor.c /main/19 1996/08/01 19:20:16 dpw $ */
51 /* $XFree86: xc/programs/Xserver/dix/cursor.c,v 3.1 1996/12/23 06:29:36 dawes Exp $ */
56 #include "scrnintstr.h"
57 #include "dixstruct.h"
58 #include "cursorstr.h"
59 #include "dixfontstr.h"
62 typedef struct _GlyphShare {
64 unsigned short sourceChar;
65 unsigned short maskChar;
67 struct _GlyphShare *next;
68 } GlyphShare, *GlyphSharePtr;
70 static GlyphSharePtr sharedGlyphs = (GlyphSharePtr)NULL;
73 #if NeedFunctionPrototypes
74 FreeCursorBits(CursorBitsPtr bits)
80 if (--bits->refcnt > 0)
84 if (bits->refcnt == 0)
86 register GlyphSharePtr *prev, this;
88 for (prev = &sharedGlyphs;
89 (this = *prev) && (this->bits != bits);
95 CloseFont(this->font, (Font)0);
103 * To be called indirectly by DeleteResource; must use exactly two args
107 FreeCursor(value, cid)
108 pointer value; /* must conform to DeleteType */
112 CursorPtr pCurs = (CursorPtr)value;
116 if ( --pCurs->refcnt > 0)
119 for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
121 pscr = screenInfo.screens[nscr];
122 (void)( *pscr->UnrealizeCursor)( pscr, pCurs);
124 FreeCursorBits(pCurs->bits);
130 * does nothing about the resource table, just creates the data structure.
131 * does not copy the src and mask bits
134 AllocCursor(psrcbits, pmaskbits, cm,
135 foreRed, foreGreen, foreBlue, backRed, backGreen, backBlue)
136 unsigned char * psrcbits; /* server-defined padding */
137 unsigned char * pmaskbits; /* server-defined padding */
139 unsigned foreRed, foreGreen, foreBlue;
140 unsigned backRed, backGreen, backBlue;
147 pCurs = (CursorPtr)xalloc(sizeof(CursorRec) + sizeof(CursorBits));
152 return (CursorPtr)NULL;
154 bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
155 bits->source = psrcbits;
156 bits->mask = pmaskbits;
157 bits->width = cm->width;
158 bits->height = cm->height;
159 bits->xhot = cm->xhot;
160 bits->yhot = cm->yhot;
166 pCurs->foreRed = foreRed;
167 pCurs->foreGreen = foreGreen;
168 pCurs->foreBlue = foreBlue;
170 pCurs->backRed = backRed;
171 pCurs->backGreen = backGreen;
172 pCurs->backBlue = backBlue;
175 * realize the cursor for every screen
177 for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
179 pscr = screenInfo.screens[nscr];
180 if (!( *pscr->RealizeCursor)( pscr, pCurs))
184 pscr = screenInfo.screens[nscr];
185 ( *pscr->UnrealizeCursor)( pscr, pCurs);
187 FreeCursorBits(bits);
189 return (CursorPtr)NULL;
196 AllocGlyphCursor(source, sourceChar, mask, maskChar,
197 foreRed, foreGreen, foreBlue, backRed, backGreen, backBlue,
200 unsigned int sourceChar, maskChar;
201 unsigned foreRed, foreGreen, foreBlue;
202 unsigned backRed, backGreen, backBlue;
206 FontPtr sourcefont, maskfont;
207 unsigned char *srcbits;
208 unsigned char *mskbits;
215 GlyphSharePtr pShare;
217 sourcefont = (FontPtr) SecurityLookupIDByType(client, source, RT_FONT,
219 maskfont = (FontPtr) SecurityLookupIDByType(client, mask, RT_FONT,
224 client->errorValue = source;
227 if (!maskfont && (mask != None))
229 client->errorValue = mask;
232 if (sourcefont != maskfont)
233 pShare = (GlyphSharePtr)NULL;
236 for (pShare = sharedGlyphs;
238 ((pShare->font != sourcefont) ||
239 (pShare->sourceChar != sourceChar) ||
240 (pShare->maskChar != maskChar));
241 pShare = pShare->next)
246 pCurs = (CursorPtr)xalloc(sizeof(CursorRec));
254 if (!CursorMetricsFromGlyph(sourcefont, sourceChar, &cm))
256 client->errorValue = sourceChar;
262 register unsigned char *mskptr;
264 n = BitmapBytePad(cm.width)*(long)cm.height;
265 mskptr = mskbits = (unsigned char *)xalloc(n);
273 if (!CursorMetricsFromGlyph(maskfont, maskChar, &cm))
275 client->errorValue = maskChar;
278 if ((res = ServerBitsFromGlyph(maskfont, maskChar, &cm, &mskbits)) != 0)
281 if ((res = ServerBitsFromGlyph(sourcefont, sourceChar, &cm, &srcbits)) != 0)
286 if (sourcefont != maskfont)
288 pCurs = (CursorPtr)xalloc(sizeof(CursorRec) + sizeof(CursorBits));
290 bits = (CursorBitsPtr)((char *)pCurs + sizeof(CursorRec));
292 bits = (CursorBitsPtr)NULL;
296 pCurs = (CursorPtr)xalloc(sizeof(CursorRec));
298 bits = (CursorBitsPtr)xalloc(sizeof(CursorBits));
300 bits = (CursorBitsPtr)NULL;
309 bits->source = srcbits;
310 bits->mask = mskbits;
311 bits->width = cm.width;
312 bits->height = cm.height;
313 bits->xhot = cm.xhot;
314 bits->yhot = cm.yhot;
315 if (sourcefont != maskfont)
320 pShare = (GlyphSharePtr)xalloc(sizeof(GlyphShare));
323 FreeCursorBits(bits);
326 pShare->font = sourcefont;
327 sourcefont->refcnt++;
328 pShare->sourceChar = sourceChar;
329 pShare->maskChar = maskChar;
331 pShare->next = sharedGlyphs;
332 sharedGlyphs = pShare;
338 pCurs->foreRed = foreRed;
339 pCurs->foreGreen = foreGreen;
340 pCurs->foreBlue = foreBlue;
342 pCurs->backRed = backRed;
343 pCurs->backGreen = backGreen;
344 pCurs->backBlue = backBlue;
347 * realize the cursor for every screen
349 for (nscr = 0; nscr < screenInfo.numScreens; nscr++)
351 pscr = screenInfo.screens[nscr];
352 if (!( *pscr->RealizeCursor)( pscr, pCurs))
356 pscr = screenInfo.screens[nscr];
357 ( *pscr->UnrealizeCursor)( pscr, pCurs);
359 FreeCursorBits(pCurs->bits);
368 /***********************************************************
371 * look up the name of a font
373 * add the font to the resource table
374 * make a cursor from the glyphs
375 * add the cursor to the resource table
376 *************************************************************/
379 CreateRootCursor(pfilename, glyph)
388 fontID = FakeClientID(0);
389 err = OpenFont(serverClient, fontID, FontLoadAll | FontOpenSync,
390 (unsigned)strlen( pfilename), pfilename);
394 cursorfont = (FontPtr)LookupIDByType(fontID, RT_FONT);
397 if (AllocGlyphCursor(fontID, glyph, fontID, glyph + 1,
398 0, 0, 0, ~0, ~0, ~0, &curs, serverClient) != Success)
401 if (!AddResource(FakeClientID(0), RT_CURSOR, (pointer)curs))