|
|
1.1 root 1: /***********************************************************
2: Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
3: and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
4:
5: All Rights Reserved
6:
7: Permission to use, copy, modify, and distribute this software and its
8: documentation for any purpose and without fee is hereby granted,
9: provided that the above copyright notice appear in all copies and that
10: both that copyright notice and this permission notice appear in
11: supporting documentation, and that the names of Digital or MIT not be
12: used in advertising or publicity pertaining to distribution of the
13: software without specific, written prior permission.
14:
15: DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
16: ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
17: DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
18: ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
19: WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
20: ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
21: SOFTWARE.
22:
23: ******************************************************************/
24:
25:
26: /* $Header: dixutils.c,v 1.23 87/09/11 17:56:56 sun Exp $ */
27:
28: #include "X.h"
29: #include "Xmd.h"
30: #include "misc.h"
31: #include "window.h"
32: #include "dixstruct.h"
33: #include "pixmapstr.h"
34: #include "scrnintstr.h"
35:
36:
37: /*
38: * CompareTimeStamps returns -1, 0, or +1 depending on if the first
39: * argument is less than, equal to or greater than the second argument.
40: */
41:
42: int
43: CompareTimeStamps(a, b)
44: TimeStamp a, b;
45: {
46: if (a.months < b.months)
47: return EARLIER;
48: if (a.months > b.months)
49: return LATER;
50: if (a.milliseconds < b.milliseconds)
51: return EARLIER;
52: if (a.milliseconds > b.milliseconds)
53: return LATER;
54: return SAMETIME;
55: }
56:
57: /*
58: * convert client times to server TimeStamps
59: */
60:
61: #define HALFMONTH ((unsigned long) 1<<31)
62: TimeStamp
63: ClientTimeToServerTime(c)
64: CARD32 c;
65: {
66: TimeStamp ts;
67: if (c == CurrentTime)
68: return currentTime;
69: ts.months = currentTime.months;
70: ts.milliseconds = c;
71: if (c > currentTime.milliseconds)
72: {
73: if (((unsigned long) c - currentTime.milliseconds) > HALFMONTH)
74: ts.months -= 1;
75: }
76: else if (c < currentTime.milliseconds)
77: {
78: if (((unsigned long)currentTime.milliseconds - c) > HALFMONTH)
79: ts.months -= 1L;
80: }
81: return ts;
82: }
83:
84: WindowPtr
85: LookupWindow(rid, client)
86: int rid;
87: ClientPtr client;
88: {
89: WindowPtr pWin;
90:
91: if(rid == INVALID)
92: return NULL;
93: if (client->lastDrawableID == rid)
94: {
95: DrawablePtr pDraw = (DrawablePtr)client->lastDrawable;
96: if (pDraw->type != DRAWABLE_PIXMAP)
97: return ((WindowPtr) client->lastDrawable);
98: return (WindowPtr) NULL;
99: }
100: pWin = (WindowPtr)LookupID(rid, RT_WINDOW, RC_CORE);
101: client->errorValue = rid;
102: return pWin;
103: }
104:
105:
106: pointer
107: LookupDrawable(rid, client)
108: int rid;
109: ClientPtr client;
110: {
111: DrawablePtr pDraw;
112:
113: if(rid == INVALID)
114: return NULL;
115: if (client->lastDrawableID == rid)
116: {
117: DrawablePtr pDrawT = client->lastDrawable;
118: if (pDrawT->type == DRAWABLE_WINDOW)
119: return ((pointer) client->lastDrawable);
120: return ((pointer) NULL);
121: }
122: pDraw = (DrawablePtr)LookupID(rid, RT_DRAWABLE, RC_CORE);
123: if (!pDraw)
124: return ((pointer)pDraw);
125: if ((pDraw->type == DRAWABLE_WINDOW) || (pDraw->type == DRAWABLE_PIXMAP))
126: return (pointer)pDraw;
127: else
128: return (pointer)NULL;
129: }
130:
131:
132: int
133: AlterSaveSetForClient(client, pWin, mode)
134: ClientPtr client;
135: pointer pWin;
136: char mode;
137: {
138: int numnow;
139: pointer *pTmp;
140: int j;
141:
142: numnow = client->numSaved;
143: j = 0;
144: if (numnow)
145: {
146: pTmp = client->saveSet;
147: while ((j < numnow) && (pTmp[j] != pWin))
148: j++;
149: }
150: if (mode == SetModeInsert)
151: {
152: if (j < numnow) /* duplicate */
153: return(Success);
154: numnow++;
155: client->saveSet = (pointer * )Xrealloc(
156: client->saveSet,
157: sizeof(int) * numnow);
158: client->numSaved = numnow;
159: client->saveSet[numnow - 1] = pWin;
160: return(Success);
161: }
162: else if ((mode == SetModeDelete) && (j < numnow))
163: {
164: while (j < numnow-1)
165: {
166: pTmp[j] = pTmp[j+1];
167: j++;
168: }
169: numnow--;
170: if (numnow)
171: client->saveSet = (pointer * )Xrealloc(
172: client->saveSet,
173: sizeof(int) * numnow);
174: else
175: {
176: Xfree(client->saveSet);
177: client->saveSet = (pointer *)NULL;
178: }
179: client->numSaved = numnow;
180: return(Success);
181: }
182: return(Success);
183: }
184:
185:
186: DeleteWindowFromAnySaveSet(pWin)
187: pointer pWin;
188: {
189: register int i;
190: register ClientPtr client;
191:
192: for (i = 0; i< currentMaxClients; i++)
193: {
194: client = clients[i];
195: if (client && client->numSaved)
196: AlterSaveSetForClient(client, pWin, SetModeDelete);
197: }
198: }
199:
200: /* No-op Don't Do Anything : sometimes we need to be able to call a procedure
201: * that doesn't do anything. For example, on screen with only static
202: * colormaps, if someone calls install colormap, it's easier to have a dummy
203: * procedure to call than to check if there's a procedure
204: */
205: void
206: NoopDDA()
207: {
208: }
209:
210:
211: /* called from the OS layer */
212: BlockHandler(pTimeout, pReadmask)
213: pointer pTimeout; /* DIX doesn't want to know how OS represents time */
214: pointer pReadmask; /* nor how it represents the set of descriptors */
215: {
216: register int i;
217: for (i = 0; i < screenInfo.numScreens; i++)
218: (* screenInfo.screen[i].BlockHandler)(i,
219: screenInfo.screen[i].blockData,
220: pTimeout, pReadmask);
221: }
222:
223:
224: WakeupHandler(result, pReadmask)
225: unsigned long result; /* 32 bits of undefined result from the wait */
226: pointer pReadmask; /* the resulting descriptor mask */
227: {
228: register int i;
229: for (i = 0; i < screenInfo.numScreens; i++)
230: (* screenInfo.screen[i].WakeupHandler)(i,
231: screenInfo.screen[i].wakeupData,
232: result, pReadmask);
233: }
234:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.