]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/include/misc.h
f01f3e95e2a71b853af8f593595689638b3ee039
[rdpsrv] / Xserver / programs / Xserver / include / misc.h
1 /***********************************************************
2
3 Copyright (c) 1987  X Consortium
4
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:
11
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
14
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.
21
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.
25
26
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28
29                         All Rights Reserved
30
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.  
38
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
45 SOFTWARE.
46
47 Copyright 1992, 1993 Data General Corporation;
48 Copyright 1992, 1993 OMRON Corporation  
49
50 Permission to use, copy, modify, distribute, and sell this software and its
51 documentation for any purpose is hereby granted without fee, provided that the
52 above copyright notice appear in all copies and that both that copyright
53 notice and this permission notice appear in supporting documentation, and that
54 neither the name OMRON or DATA GENERAL be used in advertising or publicity
55 pertaining to distribution of the software without specific, written prior
56 permission of the party whose name is to be used.  Neither OMRON or 
57 DATA GENERAL make any representation about the suitability of this software
58 for any purpose.  It is provided "as is" without express or implied warranty.  
59
60 OMRON AND DATA GENERAL EACH DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
61 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
62 IN NO EVENT SHALL OMRON OR DATA GENERAL BE LIABLE FOR ANY SPECIAL, INDIRECT
63 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
64 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
65 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
66 OF THIS SOFTWARE.
67
68 ******************************************************************/
69 /* $XConsortium: misc.h /main/28 1996/12/02 10:22:01 lehors $ */
70 /* $XFree86: xc/programs/Xserver/include/misc.h,v 3.5 1996/12/23 07:09:29 dawes Exp $ */
71 #ifndef MISC_H
72 #define MISC_H 1
73 /*
74  *  X internal definitions 
75  *
76  */
77
78 extern unsigned long globalSerialNumber;
79 extern unsigned long serverGeneration;
80
81 #include <X11/Xosdefs.h>
82 #include <X11/Xfuncproto.h>
83 #include <X11/Xmd.h>
84 #include <X11/X.h>
85
86 #ifndef NULL
87 #ifndef X_NOT_STDC_ENV
88 #include <stddef.h>
89 #else
90 #define NULL            0
91 #endif
92 #endif
93
94 #ifndef MAXSCREENS
95 #define MAXSCREENS      3
96 #endif
97 #define MAXCLIENTS      128
98 #define MAXDITS         1
99 #define MAXEXTENSIONS   128
100 #define MAXFORMATS      8
101 #define MAXVISUALS_PER_SCREEN 50
102
103 #if NeedFunctionPrototypes
104 typedef void *pointer;
105 #else
106 typedef unsigned char *pointer;
107 #endif
108 typedef int Bool;
109 typedef unsigned long PIXEL;
110 typedef unsigned long ATOM;
111
112
113 #ifndef TRUE
114 #define TRUE 1
115 #define FALSE 0
116 #endif
117
118 #ifndef _XTYPEDEF_FONTPTR
119 typedef struct _Font *FontPtr; /* also in fonts/include/font.h */
120 #define _XTYPEDEF_FONTPTR
121 #endif
122
123 #ifndef _XTYPEDEF_CLIENTPTR
124 typedef struct _Client *ClientPtr; /* also in dix.h */
125 #define _XTYPEDEF_CLIENTPTR
126 #endif
127
128 #ifndef _XTYPEDEF_CALLBACKLISTPTR
129 typedef struct _CallbackList *CallbackListPtr; /* also in dix.h */
130 #define _XTYPEDEF_CALLBACKLISTPTR
131 #endif
132
133 typedef struct _xReq *xReqPtr;
134
135 #include "os.h"         /* for ALLOCATE_LOCAL and DEALLOCATE_LOCAL */
136 #include <X11/Xfuncs.h> /* for bcopy, bzero, and bcmp */
137
138 #define NullBox ((BoxPtr)0)
139 #define MILLI_PER_MIN (1000 * 60)
140 #define MILLI_PER_SECOND (1000)
141
142     /* this next is used with None and ParentRelative to tell
143        PaintWin() what to use to paint the background. Also used
144        in the macro IS_VALID_PIXMAP */
145
146 #define USE_BACKGROUND_PIXEL 3
147 #define USE_BORDER_PIXEL 3
148
149
150 /* byte swap a 32-bit literal */
151 #define lswapl(x) ((((x) & 0xff) << 24) |\
152                    (((x) & 0xff00) << 8) |\
153                    (((x) & 0xff0000) >> 8) |\
154                    (((x) >> 24) & 0xff))
155
156 /* byte swap a short literal */
157 #define lswaps(x) ((((x) & 0xff) << 8) | (((x) >> 8) & 0xff))
158
159 #define min(a, b) (((a) < (b)) ? (a) : (b))
160 #define max(a, b) (((a) > (b)) ? (a) : (b))
161 #if !defined(AMOEBA) && !defined(__EMX__)
162 #ifndef abs
163 #define abs(a) ((a) > 0 ? (a) : -(a))
164 #endif
165 #else /* AMOEBA || __EMX__ */
166 /* abs() is a function, not a macro; include the file declaring
167  * it in case we haven't done that yet.
168  */  
169 #include <stdlib.h>
170 #endif /* AMOEBA */
171 #ifndef Fabs
172 #define Fabs(a) ((a) > 0.0 ? (a) : -(a))        /* floating absolute value */
173 #endif
174 #define sign(x) ((x) < 0 ? -1 : ((x) > 0 ? 1 : 0))
175 /* this assumes b > 0 */
176 #define modulus(a, b, d)    if (((d) = (a) % (b)) < 0) (d) += (b)
177 /*
178  * return the least significant bit in x which is set
179  *
180  * This works on 1's complement and 2's complement machines.
181  * If you care about the extra instruction on 2's complement
182  * machines, change to ((x) & (-(x)))
183  */
184 #define lowbit(x) ((x) & (~(x) + 1))
185
186 #ifndef MAXSHORT
187 #define MAXSHORT 32767
188 #endif
189 #ifndef MINSHORT
190 #define MINSHORT -MAXSHORT 
191 #endif
192
193
194 /* some macros to help swap requests, replies, and events */
195
196 #define LengthRestB(stuff) \
197     ((client->req_len << 2) - sizeof(*stuff))
198
199 #define LengthRestS(stuff) \
200     ((client->req_len << 1) - (sizeof(*stuff) >> 1))
201
202 #define LengthRestL(stuff) \
203     (client->req_len - (sizeof(*stuff) >> 2))
204
205 #define SwapRestS(stuff) \
206     SwapShorts((short *)(stuff + 1), LengthRestS(stuff))
207
208 #define SwapRestL(stuff) \
209     SwapLongs((CARD32 *)(stuff + 1), LengthRestL(stuff))
210
211 /* byte swap a 32-bit value */
212 #define swapl(x, n) { \
213                  n = ((char *) (x))[0];\
214                  ((char *) (x))[0] = ((char *) (x))[3];\
215                  ((char *) (x))[3] = n;\
216                  n = ((char *) (x))[1];\
217                  ((char *) (x))[1] = ((char *) (x))[2];\
218                  ((char *) (x))[2] = n; }
219
220 /* byte swap a short */
221 #define swaps(x, n) { \
222                  n = ((char *) (x))[0];\
223                  ((char *) (x))[0] = ((char *) (x))[1];\
224                  ((char *) (x))[1] = n; }
225
226 /* copy 32-bit value from src to dst byteswapping on the way */
227 #define cpswapl(src, dst) { \
228                  ((char *)&(dst))[0] = ((char *) &(src))[3];\
229                  ((char *)&(dst))[1] = ((char *) &(src))[2];\
230                  ((char *)&(dst))[2] = ((char *) &(src))[1];\
231                  ((char *)&(dst))[3] = ((char *) &(src))[0]; }
232
233 /* copy short from src to dst byteswapping on the way */
234 #define cpswaps(src, dst) { \
235                  ((char *) &(dst))[0] = ((char *) &(src))[1];\
236                  ((char *) &(dst))[1] = ((char *) &(src))[0]; }
237
238 extern void SwapLongs(
239 #if NeedFunctionPrototypes
240     CARD32 *list,
241     unsigned long count
242 #endif
243 );
244
245 extern void SwapShorts(
246 #if NeedFunctionPrototypes
247     short *list,
248     unsigned long count
249 #endif
250 );
251
252 extern void MakePredeclaredAtoms(
253 #if NeedFunctionPrototypes
254     void
255 #endif
256 );
257
258 extern int Ones(
259 #if NeedFunctionPrototypes
260     unsigned long /*mask*/
261 #endif
262 );
263
264 typedef struct _xPoint *DDXPointPtr;
265 typedef struct _Box *BoxPtr;
266 typedef struct _xEvent *xEventPtr;
267 typedef struct _xRectangle *xRectanglePtr;
268 typedef struct _GrabRec *GrabPtr;
269
270 /*  typedefs from other places - duplicated here to minimize the amount
271  *  of unnecessary junk that one would normally have to include to get
272  *  these symbols defined
273  */
274
275 #ifndef _XTYPEDEF_CHARINFOPTR
276 typedef struct _CharInfo *CharInfoPtr; /* also in fonts/include/font.h */
277 #define _XTYPEDEF_CHARINFOPTR
278 #endif
279
280 #endif /* MISC_H */