1 /* $XConsortium: XF86VMode.c /main/2 1995/11/14 18:17:58 kaleb $ */
2 /* $XFree86: xc/lib/Xxf86vm/XF86VMode.c,v 3.32 2001/07/25 15:04:54 dawes Exp $ */
3 /*
4
5 Copyright (c) 1995 Kaleb S. KEITHLEY
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be
16 included in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL Kaleb S. KEITHLEY BE LIABLE FOR ANY CLAIM, DAMAGES
22 OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25
26 Except as contained in this notice, the name of Kaleb S. KEITHLEY
27 shall not be used in advertising or otherwise to promote the sale, use
28 or other dealings in this Software without prior written authorization
29 from Kaleb S. KEITHLEY.
30
31 */
32 /* $XConsortium: XF86VMode.c /main/4 1996/01/16 07:52:25 kaleb CHECKEDOUT $ */
33
34 /* THIS IS NOT AN X CONSORTIUM STANDARD */
35
36 #define NEED_EVENTS
37 #define NEED_REPLIES
38
39 #ifndef XBUILD_IN_CLIENT
40 #include <X11/Xlibint.h>
41 #include "../extensions/xf86vmstr.h"
42 #include "../extensions/Xext.h"
43 #include "../extensions/extutil.h"
44 #else
45 #include "lib/X11/Xlibint.h"
46 #include "include/extensions/xf86vmstr.h"
47 #include "include/extensions/Xext.h"
48 #include "include/extensions/extutil.h"
49 #endif
50
51 #ifdef DEBUG
52 #include <stdio.h>
53 #endif
54
55 #ifndef MODE_BAD
56 #define MODE_BAD 255
57 #endif
58
59 static XExtensionInfo _xf86vidmode_info_data;
60 static XExtensionInfo *xf86vidmode_info = &_xf86vidmode_info_data;
61 static char *xf86vidmode_extension_name = XF86VIDMODENAME;
62
63 #define XF86VidModeCheckExtension(dpy,i,val) \
64 XextCheckExtension (dpy, i, xf86vidmode_extension_name, val)
65
66 /*****************************************************************************
67 * *
68 * private utility routines *
69 * *
70 *****************************************************************************/
71
72 static XEXT_CLOSE_DISPLAY_PROTO(close_display);
73 static /* const */ XExtensionHooks xf86vidmode_extension_hooks = {
74 NULL, /* create_gc */
75 NULL, /* copy_gc */
76 NULL, /* flush_gc */
77 NULL, /* free_gc */
78 NULL, /* create_font */
79 NULL, /* free_font */
80 close_display, /* close_display */
81 NULL, /* wire_to_event */
82 NULL, /* event_to_wire */
83 NULL, /* error */
84 NULL, /* error_string */
85 };
86
87 static XEXT_GENERATE_FIND_DISPLAY (find_display, xf86vidmode_info,
88 xf86vidmode_extension_name,
89 &xf86vidmode_extension_hooks,
90 0, NULL)
91
92 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xf86vidmode_info)
93
94
95 /*****************************************************************************
96 * *
97 * public XFree86-VidMode Extension routines *
98 * *
99 *****************************************************************************/
100
101 Bool
102 SDL_NAME(XF86VidModeQueryExtension) (dpy, event_basep, error_basep)
103 Display *dpy;
104 int *event_basep, *error_basep;
105 {
106 XExtDisplayInfo *info = find_display (dpy);
107
108 if (XextHasExtension(info)) {
109 *event_basep = info->codes->first_event;
110 *error_basep = info->codes->first_error;
111 return True;
112 } else {
113 return False;
114 }
115 }
116
117 Bool
118 SDL_NAME(XF86VidModeQueryVersion)(dpy, majorVersion, minorVersion)
119 Display* dpy;
120 int* majorVersion;
121 int* minorVersion;
122 {
123 XExtDisplayInfo *info = find_display (dpy);
124 xXF86VidModeQueryVersionReply rep;
125 xXF86VidModeQueryVersionReq *req;
126
127 XF86VidModeCheckExtension (dpy, info, False);
128
129 LockDisplay(dpy);
130 GetReq(XF86VidModeQueryVersion, req);
131 req->reqType = info->codes->major_opcode;
132 req->xf86vidmodeReqType = X_XF86VidModeQueryVersion;
133 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
134 UnlockDisplay(dpy);
135 SyncHandle();
136 return False;
137 }
138 *majorVersion = rep.majorVersion;
139 *minorVersion = rep.minorVersion;
140 UnlockDisplay(dpy);
141 SyncHandle();
142 if (*majorVersion >= 2)
143 SDL_NAME(XF86VidModeSetClientVersion)(dpy);
144 return True;
145 }
146
147 Bool
SDL_NAME(XF86VidModeSetClientVersion)148 SDL_NAME(XF86VidModeSetClientVersion)(Display *dpy)
149 {
150 XExtDisplayInfo *info = find_display(dpy);
151 xXF86VidModeSetClientVersionReq *req;
152
153 XF86VidModeCheckExtension(dpy, info, False);
154
155 LockDisplay(dpy);
156 GetReq(XF86VidModeSetClientVersion, req);
157 req->reqType = info->codes->major_opcode;
158 req->xf86vidmodeReqType = X_XF86VidModeSetClientVersion;
159 req->major = XF86VIDMODE_MAJOR_VERSION;
160 req->minor = XF86VIDMODE_MINOR_VERSION;
161 UnlockDisplay(dpy);
162 SyncHandle();
163 return True;
164 }
165
166 Bool
SDL_NAME(XF86VidModeSetGamma)167 SDL_NAME(XF86VidModeSetGamma)(Display *dpy, int screen, SDL_NAME(XF86VidModeGamma) *Gamma)
168 {
169 XExtDisplayInfo *info = find_display(dpy);
170 xXF86VidModeSetGammaReq *req;
171
172 XF86VidModeCheckExtension(dpy, info, False);
173
174 LockDisplay(dpy);
175 GetReq(XF86VidModeSetGamma, req);
176 req->reqType = info->codes->major_opcode;
177 req->xf86vidmodeReqType = X_XF86VidModeSetGamma;
178 req->screen = screen;
179 req->red = (CARD32)(Gamma->red * 10000.);
180 req->green = (CARD32)(Gamma->green * 10000.);
181 req->blue = (CARD32)(Gamma->blue * 10000.);
182 UnlockDisplay(dpy);
183 SyncHandle();
184 return True;
185 }
186
187 Bool
SDL_NAME(XF86VidModeGetGamma)188 SDL_NAME(XF86VidModeGetGamma)(Display *dpy, int screen, SDL_NAME(XF86VidModeGamma) *Gamma)
189 {
190 XExtDisplayInfo *info = find_display (dpy);
191 xXF86VidModeGetGammaReply rep;
192 xXF86VidModeGetGammaReq *req;
193
194 XF86VidModeCheckExtension (dpy, info, False);
195
196 LockDisplay(dpy);
197 GetReq(XF86VidModeGetGamma, req);
198 req->reqType = info->codes->major_opcode;
199 req->xf86vidmodeReqType = X_XF86VidModeGetGamma;
200 req->screen = screen;
201 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
202 UnlockDisplay(dpy);
203 SyncHandle();
204 return False;
205 }
206 Gamma->red = ((float)rep.red) / 10000.;
207 Gamma->green = ((float)rep.green) / 10000.;
208 Gamma->blue = ((float)rep.blue) / 10000.;
209 UnlockDisplay(dpy);
210 SyncHandle();
211 return True;
212 }
213
214 Bool
215 SDL_NAME(XF86VidModeGetModeLine)(dpy, screen, dotclock, modeline)
216 Display* dpy;
217 int screen;
218 int* dotclock;
SDL_NAME(XF86VidModeModeLine)219 SDL_NAME(XF86VidModeModeLine)* modeline;
220 {
221 XExtDisplayInfo *info = find_display (dpy);
222 xXF86VidModeGetModeLineReply rep;
223 xXF86OldVidModeGetModeLineReply oldrep;
224 xXF86VidModeGetModeLineReq *req;
225 int majorVersion, minorVersion;
226
227 XF86VidModeCheckExtension (dpy, info, False);
228 SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion);
229
230 LockDisplay(dpy);
231 GetReq(XF86VidModeGetModeLine, req);
232 req->reqType = info->codes->major_opcode;
233 req->xf86vidmodeReqType = X_XF86VidModeGetModeLine;
234 req->screen = screen;
235
236 if (majorVersion < 2) {
237 if (!_XReply(dpy, (xReply *)&oldrep,
238 (SIZEOF(xXF86OldVidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) {
239 UnlockDisplay(dpy);
240 SyncHandle();
241 return False;
242 }
243 *dotclock = oldrep.dotclock;
244 modeline->hdisplay = oldrep.hdisplay;
245 modeline->hsyncstart = oldrep.hsyncstart;
246 modeline->hsyncend = oldrep.hsyncend;
247 modeline->htotal = oldrep.htotal;
248 modeline->hskew = 0;
249 modeline->vdisplay = oldrep.vdisplay;
250 modeline->vsyncstart = oldrep.vsyncstart;
251 modeline->vsyncend = oldrep.vsyncend;
252 modeline->vtotal = oldrep.vtotal;
253 modeline->flags = oldrep.flags;
254 modeline->privsize = oldrep.privsize;
255 } else {
256 if (!_XReply(dpy, (xReply *)&rep,
257 (SIZEOF(xXF86VidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) {
258 UnlockDisplay(dpy);
259 SyncHandle();
260 return False;
261 }
262 *dotclock = rep.dotclock;
263 modeline->hdisplay = rep.hdisplay;
264 modeline->hsyncstart = rep.hsyncstart;
265 modeline->hsyncend = rep.hsyncend;
266 modeline->htotal = rep.htotal;
267 modeline->hskew = rep.hskew;
268 modeline->vdisplay = rep.vdisplay;
269 modeline->vsyncstart = rep.vsyncstart;
270 modeline->vsyncend = rep.vsyncend;
271 modeline->vtotal = rep.vtotal;
272 modeline->flags = rep.flags;
273 modeline->privsize = rep.privsize;
274 }
275
276 if (modeline->privsize > 0) {
277 if (!(modeline->private = Xcalloc(modeline->privsize, sizeof(INT32)))) {
278 _XEatData(dpy, (modeline->privsize) * sizeof(INT32));
279 Xfree(modeline->private);
280 return False;
281 }
282 _XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
283 } else {
284 modeline->private = NULL;
285 }
286 UnlockDisplay(dpy);
287 SyncHandle();
288 return True;
289 }
290
291 Bool
292 SDL_NAME(XF86VidModeGetAllModeLines)(dpy, screen, modecount, modelinesPtr)
293 Display* dpy;
294 int screen;
295 int* modecount;
SDL_NAME(XF86VidModeModeInfo)296 SDL_NAME(XF86VidModeModeInfo) ***modelinesPtr;
297 {
298 XExtDisplayInfo *info = find_display (dpy);
299 xXF86VidModeGetAllModeLinesReply rep;
300 xXF86VidModeGetAllModeLinesReq *req;
301 SDL_NAME(XF86VidModeModeInfo) *mdinfptr, **modelines;
302 xXF86VidModeModeInfo xmdline;
303 xXF86OldVidModeModeInfo oldxmdline;
304 int i;
305 int majorVersion, minorVersion;
306 Bool protocolBug = False;
307
308 XF86VidModeCheckExtension (dpy, info, False);
309
310 /*
311 * Note: There was a bug in the protocol implementation in versions
312 * 0.x with x < 8 (the .private field wasn't being passed over the wire).
313 * Check the server's version, and accept the old format if appropriate.
314 */
315
316 SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion);
317 if (majorVersion == 0 && minorVersion < 8) {
318 protocolBug = True;
319 #ifdef DEBUG
320 fprintf(stderr, "XF86VidModeGetAllModeLines: Warning: Xserver is"
321 "running an old version (%d.%d)\n", majorVersion,
322 minorVersion);
323 #endif
324 }
325
326 LockDisplay(dpy);
327 GetReq(XF86VidModeGetAllModeLines, req);
328 req->reqType = info->codes->major_opcode;
329 req->xf86vidmodeReqType = X_XF86VidModeGetAllModeLines;
330 req->screen = screen;
331 if (!_XReply(dpy, (xReply *)&rep,
332 (SIZEOF(xXF86VidModeGetAllModeLinesReply) - SIZEOF(xReply)) >> 2, xFalse)) {
333 UnlockDisplay(dpy);
334 SyncHandle();
335 return False;
336 }
337
338 *modecount = rep.modecount;
339
340 if (!(modelines = (SDL_NAME(XF86VidModeModeInfo) **) Xcalloc(rep.modecount,
341 sizeof(SDL_NAME(XF86VidModeModeInfo) *)
342 +sizeof(SDL_NAME(XF86VidModeModeInfo))))) {
343 if (majorVersion < 2)
344 _XEatData(dpy, (rep.modecount) * sizeof(xXF86OldVidModeModeInfo));
345 else
346 _XEatData(dpy, (rep.modecount) * sizeof(xXF86VidModeModeInfo));
347 Xfree(modelines);
348 UnlockDisplay(dpy);
349 SyncHandle();
350 return False;
351 }
352 mdinfptr = (SDL_NAME(XF86VidModeModeInfo) *) (
353 (char *) modelines
354 + rep.modecount*sizeof(SDL_NAME(XF86VidModeModeInfo) *)
355 );
356
357 for (i = 0; i < rep.modecount; i++) {
358 modelines[i] = mdinfptr++;
359 if (majorVersion < 2) {
360 _XRead(dpy, (char*)&oldxmdline, sizeof(xXF86OldVidModeModeInfo));
361 modelines[i]->dotclock = oldxmdline.dotclock;
362 modelines[i]->hdisplay = oldxmdline.hdisplay;
363 modelines[i]->hsyncstart = oldxmdline.hsyncstart;
364 modelines[i]->hsyncend = oldxmdline.hsyncend;
365 modelines[i]->htotal = oldxmdline.htotal;
366 modelines[i]->hskew = 0;
367 modelines[i]->vdisplay = oldxmdline.vdisplay;
368 modelines[i]->vsyncstart = oldxmdline.vsyncstart;
369 modelines[i]->vsyncend = oldxmdline.vsyncend;
370 modelines[i]->vtotal = oldxmdline.vtotal;
371 modelines[i]->flags = oldxmdline.flags;
372 if (protocolBug) {
373 modelines[i]->privsize = 0;
374 modelines[i]->private = NULL;
375 } else {
376 modelines[i]->privsize = oldxmdline.privsize;
377 if (oldxmdline.privsize > 0) {
378 if (!(modelines[i]->private =
379 Xcalloc(oldxmdline.privsize, sizeof(INT32)))) {
380 _XEatData(dpy, (oldxmdline.privsize) * sizeof(INT32));
381 Xfree(modelines[i]->private);
382 } else {
383 _XRead(dpy, (char*)modelines[i]->private,
384 oldxmdline.privsize * sizeof(INT32));
385 }
386 } else {
387 modelines[i]->private = NULL;
388 }
389 }
390 } else {
391 _XRead(dpy, (char*)&xmdline, sizeof(xXF86VidModeModeInfo));
392 modelines[i]->dotclock = xmdline.dotclock;
393 modelines[i]->hdisplay = xmdline.hdisplay;
394 modelines[i]->hsyncstart = xmdline.hsyncstart;
395 modelines[i]->hsyncend = xmdline.hsyncend;
396 modelines[i]->htotal = xmdline.htotal;
397 modelines[i]->hskew = xmdline.hskew;
398 modelines[i]->vdisplay = xmdline.vdisplay;
399 modelines[i]->vsyncstart = xmdline.vsyncstart;
400 modelines[i]->vsyncend = xmdline.vsyncend;
401 modelines[i]->vtotal = xmdline.vtotal;
402 modelines[i]->flags = xmdline.flags;
403 if (protocolBug) {
404 modelines[i]->privsize = 0;
405 modelines[i]->private = NULL;
406 } else {
407 modelines[i]->privsize = xmdline.privsize;
408 if (xmdline.privsize > 0) {
409 if (!(modelines[i]->private =
410 Xcalloc(xmdline.privsize, sizeof(INT32)))) {
411 _XEatData(dpy, (xmdline.privsize) * sizeof(INT32));
412 Xfree(modelines[i]->private);
413 } else {
414 _XRead(dpy, (char*)modelines[i]->private,
415 xmdline.privsize * sizeof(INT32));
416 }
417 } else {
418 modelines[i]->private = NULL;
419 }
420 }
421 }
422 }
423 *modelinesPtr = modelines;
424 UnlockDisplay(dpy);
425 SyncHandle();
426 return True;
427 }
428
429 /*
430 * GetReq replacement for use with VidMode protocols earlier than 2.0
431 */
432 #if !defined(UNIXCPP) || defined(ANSICPP)
433 #define GetOldReq(name, oldname, req) \
434 WORD64ALIGN\
435 if ((dpy->bufptr + SIZEOF(x##oldname##Req)) > dpy->bufmax)\
436 _XFlush(dpy);\
437 req = (x##oldname##Req *)(dpy->last_req = dpy->bufptr);\
438 req->reqType = X_##name;\
439 req->length = (SIZEOF(x##oldname##Req))>>2;\
440 dpy->bufptr += SIZEOF(x##oldname##Req);\
441 dpy->request++
442
443 #else /* non-ANSI C uses empty comment instead of "##" for token concatenation */
444 #define GetOldReq(name, oldname, req) \
445 WORD64ALIGN\
446 if ((dpy->bufptr + SIZEOF(x/**/oldname/**/Req)) > dpy->bufmax)\
447 _XFlush(dpy);\
448 req = (x/**/oldname/**/Req *)(dpy->last_req = dpy->bufptr);\
449 req->reqType = X_/**/name;\
450 req->length = (SIZEOF(x/**/oldname/**/Req))>>2;\
451 dpy->bufptr += SIZEOF(x/**/oldname/**/Req);\
452 dpy->request++
453 #endif
454
455 Bool
456 SDL_NAME(XF86VidModeAddModeLine) (dpy, screen, newmodeline, aftermodeline)
457 Display *dpy;
458 int screen;
459 SDL_NAME(XF86VidModeModeInfo)* newmodeline;
460 SDL_NAME(XF86VidModeModeInfo)* aftermodeline;
461 {
462 XExtDisplayInfo *info = find_display (dpy);
463 xXF86VidModeAddModeLineReq *req;
464 xXF86OldVidModeAddModeLineReq *oldreq;
465 int majorVersion, minorVersion;
466
467 XF86VidModeCheckExtension (dpy, info, False);
468 SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion);
469
470 LockDisplay(dpy);
471 if (majorVersion < 2) {
472 GetOldReq(XF86VidModeAddModeLine, XF86OldVidModeAddModeLine, oldreq);
473 oldreq->reqType = info->codes->major_opcode;
474 oldreq->xf86vidmodeReqType = X_XF86VidModeAddModeLine;
475 oldreq->screen = screen;
476 oldreq->dotclock = newmodeline->dotclock;
477 oldreq->hdisplay = newmodeline->hdisplay;
478 oldreq->hsyncstart = newmodeline->hsyncstart;
479 oldreq->hsyncend = newmodeline->hsyncend;
480 oldreq->htotal = newmodeline->htotal;
481 oldreq->vdisplay = newmodeline->vdisplay;
482 oldreq->vsyncstart = newmodeline->vsyncstart;
483 oldreq->vsyncend = newmodeline->vsyncend;
484 oldreq->vtotal = newmodeline->vtotal;
485 oldreq->flags = newmodeline->flags;
486 oldreq->privsize = newmodeline->privsize;
487 if (aftermodeline != NULL) {
488 oldreq->after_dotclock = aftermodeline->dotclock;
489 oldreq->after_hdisplay = aftermodeline->hdisplay;
490 oldreq->after_hsyncstart = aftermodeline->hsyncstart;
491 oldreq->after_hsyncend = aftermodeline->hsyncend;
492 oldreq->after_htotal = aftermodeline->htotal;
493 oldreq->after_vdisplay = aftermodeline->vdisplay;
494 oldreq->after_vsyncstart = aftermodeline->vsyncstart;
495 oldreq->after_vsyncend = aftermodeline->vsyncend;
496 oldreq->after_vtotal = aftermodeline->vtotal;
497 oldreq->after_flags = aftermodeline->flags;
498 } else {
499 oldreq->after_dotclock = 0;
500 oldreq->after_hdisplay = 0;
501 oldreq->after_hsyncstart = 0;
502 oldreq->after_hsyncend = 0;
503 oldreq->after_htotal = 0;
504 oldreq->after_vdisplay = 0;
505 oldreq->after_vsyncstart = 0;
506 oldreq->after_vsyncend = 0;
507 oldreq->after_vtotal = 0;
508 oldreq->after_flags = 0;
509 }
510 if (newmodeline->privsize) {
511 oldreq->length += newmodeline->privsize;
512 Data32(dpy, (long *) newmodeline->private,
513 newmodeline->privsize * sizeof(INT32));
514 }
515 } else {
516 GetReq(XF86VidModeAddModeLine, req);
517 req->reqType = info->codes->major_opcode;
518 req->xf86vidmodeReqType = X_XF86VidModeAddModeLine;
519 req->screen = screen;
520 req->dotclock = newmodeline->dotclock;
521 req->hdisplay = newmodeline->hdisplay;
522 req->hsyncstart = newmodeline->hsyncstart;
523 req->hsyncend = newmodeline->hsyncend;
524 req->htotal = newmodeline->htotal;
525 req->hskew = newmodeline->hskew;
526 req->vdisplay = newmodeline->vdisplay;
527 req->vsyncstart = newmodeline->vsyncstart;
528 req->vsyncend = newmodeline->vsyncend;
529 req->vtotal = newmodeline->vtotal;
530 req->flags = newmodeline->flags;
531 req->privsize = newmodeline->privsize;
532 if (aftermodeline != NULL) {
533 req->after_dotclock = aftermodeline->dotclock;
534 req->after_hdisplay = aftermodeline->hdisplay;
535 req->after_hsyncstart = aftermodeline->hsyncstart;
536 req->after_hsyncend = aftermodeline->hsyncend;
537 req->after_htotal = aftermodeline->htotal;
538 req->after_hskew = aftermodeline->hskew;
539 req->after_vdisplay = aftermodeline->vdisplay;
540 req->after_vsyncstart = aftermodeline->vsyncstart;
541 req->after_vsyncend = aftermodeline->vsyncend;
542 req->after_vtotal = aftermodeline->vtotal;
543 req->after_flags = aftermodeline->flags;
544 } else {
545 req->after_dotclock = 0;
546 req->after_hdisplay = 0;
547 req->after_hsyncstart = 0;
548 req->after_hsyncend = 0;
549 req->after_htotal = 0;
550 req->after_hskew = 0;
551 req->after_vdisplay = 0;
552 req->after_vsyncstart = 0;
553 req->after_vsyncend = 0;
554 req->after_vtotal = 0;
555 req->after_flags = 0;
556 }
557 if (newmodeline->privsize) {
558 req->length += newmodeline->privsize;
559 Data32(dpy, (long *) newmodeline->private,
560 newmodeline->privsize * sizeof(INT32));
561 }
562 }
563 UnlockDisplay(dpy);
564 SyncHandle();
565 return True;
566 }
567
568 Bool
569 SDL_NAME(XF86VidModeDeleteModeLine) (dpy, screen, modeline)
570 Display *dpy;
571 int screen;
SDL_NAME(XF86VidModeModeInfo)572 SDL_NAME(XF86VidModeModeInfo)* modeline;
573 {
574 XExtDisplayInfo *info = find_display (dpy);
575 xXF86VidModeDeleteModeLineReq *req;
576 xXF86OldVidModeDeleteModeLineReq *oldreq;
577 int majorVersion, minorVersion;
578
579 XF86VidModeCheckExtension (dpy, info, 0);
580 SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion);
581
582 LockDisplay(dpy);
583 if (majorVersion < 2) {
584 GetOldReq(XF86VidModeDeleteModeLine, XF86OldVidModeDeleteModeLine, oldreq);
585 oldreq->reqType = info->codes->major_opcode;
586 oldreq->xf86vidmodeReqType = X_XF86VidModeDeleteModeLine;
587 oldreq->screen = screen;
588 oldreq->dotclock = modeline->dotclock;
589 oldreq->hdisplay = modeline->hdisplay;
590 oldreq->hsyncstart = modeline->hsyncstart;
591 oldreq->hsyncend = modeline->hsyncend;
592 oldreq->htotal = modeline->htotal;
593 oldreq->vdisplay = modeline->vdisplay;
594 oldreq->vsyncstart = modeline->vsyncstart;
595 oldreq->vsyncend = modeline->vsyncend;
596 oldreq->vtotal = modeline->vtotal;
597 oldreq->flags = modeline->flags;
598 oldreq->privsize = modeline->privsize;
599 if (modeline->privsize) {
600 oldreq->length += modeline->privsize;
601 Data32(dpy, (long *) modeline->private,
602 modeline->privsize * sizeof(INT32));
603 }
604 } else {
605 GetReq(XF86VidModeDeleteModeLine, req);
606 req->reqType = info->codes->major_opcode;
607 req->xf86vidmodeReqType = X_XF86VidModeDeleteModeLine;
608 req->screen = screen;
609 req->dotclock = modeline->dotclock;
610 req->hdisplay = modeline->hdisplay;
611 req->hsyncstart = modeline->hsyncstart;
612 req->hsyncend = modeline->hsyncend;
613 req->htotal = modeline->htotal;
614 req->hskew = modeline->hskew;
615 req->vdisplay = modeline->vdisplay;
616 req->vsyncstart = modeline->vsyncstart;
617 req->vsyncend = modeline->vsyncend;
618 req->vtotal = modeline->vtotal;
619 req->flags = modeline->flags;
620 req->privsize = modeline->privsize;
621 if (modeline->privsize) {
622 req->length += modeline->privsize;
623 Data32(dpy, (long *) modeline->private,
624 modeline->privsize * sizeof(INT32));
625 }
626 }
627 UnlockDisplay(dpy);
628 SyncHandle();
629 return True;
630 }
631
632 Bool
633 SDL_NAME(XF86VidModeModModeLine) (dpy, screen, modeline)
634 Display *dpy;
635 int screen;
SDL_NAME(XF86VidModeModeLine)636 SDL_NAME(XF86VidModeModeLine)* modeline;
637 {
638 XExtDisplayInfo *info = find_display (dpy);
639 xXF86VidModeModModeLineReq *req;
640 xXF86OldVidModeModModeLineReq *oldreq;
641 int majorVersion, minorVersion;
642
643 XF86VidModeCheckExtension (dpy, info, 0);
644 SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion);
645
646 LockDisplay(dpy);
647 if (majorVersion < 2) {
648 GetOldReq(XF86VidModeModModeLine, XF86OldVidModeModModeLine, oldreq);
649 oldreq->reqType = info->codes->major_opcode;
650 oldreq->xf86vidmodeReqType = X_XF86VidModeModModeLine;
651 oldreq->screen = screen;
652 oldreq->hdisplay = modeline->hdisplay;
653 oldreq->hsyncstart = modeline->hsyncstart;
654 oldreq->hsyncend = modeline->hsyncend;
655 oldreq->htotal = modeline->htotal;
656 oldreq->vdisplay = modeline->vdisplay;
657 oldreq->vsyncstart = modeline->vsyncstart;
658 oldreq->vsyncend = modeline->vsyncend;
659 oldreq->vtotal = modeline->vtotal;
660 oldreq->flags = modeline->flags;
661 oldreq->privsize = modeline->privsize;
662 if (modeline->privsize) {
663 oldreq->length += modeline->privsize;
664 Data32(dpy, (long *) modeline->private,
665 modeline->privsize * sizeof(INT32));
666 }
667 } else {
668 GetReq(XF86VidModeModModeLine, req);
669 req->reqType = info->codes->major_opcode;
670 req->xf86vidmodeReqType = X_XF86VidModeModModeLine;
671 req->screen = screen;
672 req->hdisplay = modeline->hdisplay;
673 req->hsyncstart = modeline->hsyncstart;
674 req->hsyncend = modeline->hsyncend;
675 req->htotal = modeline->htotal;
676 req->hskew = modeline->hskew;
677 req->vdisplay = modeline->vdisplay;
678 req->vsyncstart = modeline->vsyncstart;
679 req->vsyncend = modeline->vsyncend;
680 req->vtotal = modeline->vtotal;
681 req->flags = modeline->flags;
682 req->privsize = modeline->privsize;
683 if (modeline->privsize) {
684 req->length += modeline->privsize;
685 Data32(dpy, (long *) modeline->private,
686 modeline->privsize * sizeof(INT32));
687 }
688 }
689 UnlockDisplay(dpy);
690 SyncHandle();
691 return True;
692 }
693
694 Status
695 SDL_NAME(XF86VidModeValidateModeLine) (dpy, screen, modeline)
696 Display *dpy;
697 int screen;
SDL_NAME(XF86VidModeModeInfo)698 SDL_NAME(XF86VidModeModeInfo)* modeline;
699 {
700 XExtDisplayInfo *info = find_display (dpy);
701 xXF86VidModeValidateModeLineReq *req;
702 xXF86OldVidModeValidateModeLineReq *oldreq;
703 xXF86VidModeValidateModeLineReply rep;
704 int majorVersion, minorVersion;
705
706 XF86VidModeCheckExtension (dpy, info, 0);
707 SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion);
708
709 LockDisplay(dpy);
710
711 if (majorVersion < 2) {
712 GetOldReq(XF86VidModeValidateModeLine, XF86OldVidModeValidateModeLine, oldreq);
713 oldreq->reqType = info->codes->major_opcode;
714 oldreq->xf86vidmodeReqType = X_XF86VidModeValidateModeLine;
715 oldreq->screen = screen;
716 oldreq->dotclock = modeline->dotclock;
717 oldreq->hdisplay = modeline->hdisplay;
718 oldreq->hsyncstart = modeline->hsyncstart;
719 oldreq->hsyncend = modeline->hsyncend;
720 oldreq->htotal = modeline->htotal;
721 oldreq->vdisplay = modeline->vdisplay;
722 oldreq->vsyncstart = modeline->vsyncstart;
723 oldreq->vsyncend = modeline->vsyncend;
724 oldreq->vtotal = modeline->vtotal;
725 oldreq->flags = modeline->flags;
726 oldreq->privsize = modeline->privsize;
727 if (modeline->privsize) {
728 oldreq->length += modeline->privsize;
729 Data32(dpy, (long *) modeline->private,
730 modeline->privsize * sizeof(INT32));
731 }
732 } else {
733 GetReq(XF86VidModeValidateModeLine, req);
734 req->reqType = info->codes->major_opcode;
735 req->xf86vidmodeReqType = X_XF86VidModeValidateModeLine;
736 req->screen = screen;
737 req->dotclock = modeline->dotclock;
738 req->hdisplay = modeline->hdisplay;
739 req->hsyncstart = modeline->hsyncstart;
740 req->hsyncend = modeline->hsyncend;
741 req->htotal = modeline->htotal;
742 req->hskew = modeline->hskew;
743 req->vdisplay = modeline->vdisplay;
744 req->vsyncstart = modeline->vsyncstart;
745 req->vsyncend = modeline->vsyncend;
746 req->vtotal = modeline->vtotal;
747 req->flags = modeline->flags;
748 req->privsize = modeline->privsize;
749 if (modeline->privsize) {
750 req->length += modeline->privsize;
751 Data32(dpy, (long *) modeline->private,
752 modeline->privsize * sizeof(INT32));
753 }
754 }
755 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
756 UnlockDisplay(dpy);
757 SyncHandle();
758 return MODE_BAD;
759 }
760 UnlockDisplay(dpy);
761 SyncHandle();
762 return rep.status;
763 }
764
765 Bool
766 SDL_NAME(XF86VidModeSwitchMode)(dpy, screen, zoom)
767 Display* dpy;
768 int screen;
769 int zoom;
770 {
771 XExtDisplayInfo *info = find_display (dpy);
772 xXF86VidModeSwitchModeReq *req;
773
774 XF86VidModeCheckExtension (dpy, info, False);
775
776 LockDisplay(dpy);
777 GetReq(XF86VidModeSwitchMode, req);
778 req->reqType = info->codes->major_opcode;
779 req->xf86vidmodeReqType = X_XF86VidModeSwitchMode;
780 req->screen = screen;
781 req->zoom = zoom;
782 UnlockDisplay(dpy);
783 SyncHandle();
784 return True;
785 }
786
787 Bool
788 SDL_NAME(XF86VidModeSwitchToMode)(dpy, screen, modeline)
789 Display* dpy;
790 int screen;
SDL_NAME(XF86VidModeModeInfo)791 SDL_NAME(XF86VidModeModeInfo)* modeline;
792 {
793 XExtDisplayInfo *info = find_display (dpy);
794 xXF86VidModeSwitchToModeReq *req;
795 xXF86OldVidModeSwitchToModeReq *oldreq;
796 int majorVersion, minorVersion;
797 Bool protocolBug = False;
798
799 XF86VidModeCheckExtension (dpy, info, False);
800
801 /*
802 * Note: There was a bug in the protocol implementation in versions
803 * 0.x with x < 8 (the .private field wasn't expected to be sent over
804 * the wire). Check the server's version, and accept the old format
805 * if appropriate.
806 */
807
808 SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion);
809 if (majorVersion == 0 && minorVersion < 8) {
810 protocolBug = True;
811 #ifdef DEBUG
812 fprintf(stderr, "XF86VidModeSwitchToMode: Warning: Xserver is"
813 "running an old version (%d.%d)\n", majorVersion,
814 minorVersion);
815 #endif
816 }
817
818 LockDisplay(dpy);
819 if (majorVersion < 2) {
820 GetOldReq(XF86VidModeSwitchToMode, XF86OldVidModeSwitchToMode, oldreq);
821 oldreq->reqType = info->codes->major_opcode;
822 oldreq->xf86vidmodeReqType = X_XF86VidModeSwitchToMode;
823 oldreq->screen = screen;
824 oldreq->dotclock = modeline->dotclock;
825 oldreq->hdisplay = modeline->hdisplay;
826 oldreq->hsyncstart = modeline->hsyncstart;
827 oldreq->hsyncend = modeline->hsyncend;
828 oldreq->htotal = modeline->htotal;
829 oldreq->vdisplay = modeline->vdisplay;
830 oldreq->vsyncstart = modeline->vsyncstart;
831 oldreq->vsyncend = modeline->vsyncend;
832 oldreq->vtotal = modeline->vtotal;
833 oldreq->flags = modeline->flags;
834 if (protocolBug) {
835 oldreq->privsize = 0;
836 } else {
837 oldreq->privsize = modeline->privsize;
838 if (modeline->privsize) {
839 oldreq->length += modeline->privsize;
840 Data32(dpy, (long *) modeline->private,
841 modeline->privsize * sizeof(INT32));
842 }
843 }
844 } else {
845 GetReq(XF86VidModeSwitchToMode, req);
846 req->reqType = info->codes->major_opcode;
847 req->xf86vidmodeReqType = X_XF86VidModeSwitchToMode;
848 req->screen = screen;
849 req->dotclock = modeline->dotclock;
850 req->hdisplay = modeline->hdisplay;
851 req->hsyncstart = modeline->hsyncstart;
852 req->hsyncend = modeline->hsyncend;
853 req->htotal = modeline->htotal;
854 req->hskew = modeline->hskew;
855 req->vdisplay = modeline->vdisplay;
856 req->vsyncstart = modeline->vsyncstart;
857 req->vsyncend = modeline->vsyncend;
858 req->vtotal = modeline->vtotal;
859 req->flags = modeline->flags;
860 if (protocolBug) {
861 req->privsize = 0;
862 } else {
863 req->privsize = modeline->privsize;
864 if (modeline->privsize) {
865 req->length += modeline->privsize;
866 Data32(dpy, (long *) modeline->private,
867 modeline->privsize * sizeof(INT32));
868 }
869 }
870 }
871 UnlockDisplay(dpy);
872 SyncHandle();
873 return True;
874 }
875
876 Bool
877 SDL_NAME(XF86VidModeLockModeSwitch)(dpy, screen, lock)
878 Display* dpy;
879 int screen;
880 int lock;
881 {
882 XExtDisplayInfo *info = find_display (dpy);
883 xXF86VidModeLockModeSwitchReq *req;
884
885 XF86VidModeCheckExtension (dpy, info, False);
886
887 LockDisplay(dpy);
888 GetReq(XF86VidModeLockModeSwitch, req);
889 req->reqType = info->codes->major_opcode;
890 req->xf86vidmodeReqType = X_XF86VidModeLockModeSwitch;
891 req->screen = screen;
892 req->lock = lock;
893 UnlockDisplay(dpy);
894 SyncHandle();
895 return True;
896 }
897
898 Bool
899 SDL_NAME(XF86VidModeGetMonitor)(dpy, screen, monitor)
900 Display* dpy;
901 int screen;
SDL_NAME(XF86VidModeMonitor)902 SDL_NAME(XF86VidModeMonitor)* monitor;
903 {
904 XExtDisplayInfo *info = find_display (dpy);
905 xXF86VidModeGetMonitorReply rep;
906 xXF86VidModeGetMonitorReq *req;
907 CARD32 syncrange;
908 int i;
909
910 XF86VidModeCheckExtension (dpy, info, False);
911
912 LockDisplay(dpy);
913 GetReq(XF86VidModeGetMonitor, req);
914 req->reqType = info->codes->major_opcode;
915 req->xf86vidmodeReqType = X_XF86VidModeGetMonitor;
916 req->screen = screen;
917 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
918 UnlockDisplay(dpy);
919 SyncHandle();
920 return False;
921 }
922 monitor->nhsync = rep.nhsync;
923 monitor->nvsync = rep.nvsync;
924 #if 0
925 monitor->bandwidth = (float)rep.bandwidth / 1e6;
926 #endif
927 if (rep.vendorLength) {
928 if (!(monitor->vendor = (char *)Xcalloc(rep.vendorLength + 1, 1))) {
929 _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
930 ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
931 UnlockDisplay(dpy);
932 SyncHandle();
933 return False;
934 }
935 } else {
936 monitor->vendor = NULL;
937 }
938 if (rep.modelLength) {
939 if (!(monitor->model = Xcalloc(rep.modelLength + 1, 1))) {
940 _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
941 ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
942 if (monitor->vendor)
943 Xfree(monitor->vendor);
944 UnlockDisplay(dpy);
945 SyncHandle();
946 return False;
947 }
948 } else {
949 monitor->model = NULL;
950 }
951 if (!(monitor->hsync = Xcalloc(rep.nhsync, sizeof(SDL_NAME(XF86VidModeSyncRange))))) {
952 _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
953 ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
954
955 if (monitor->vendor)
956 Xfree(monitor->vendor);
957 if (monitor->model)
958 Xfree(monitor->model);
959 UnlockDisplay(dpy);
960 SyncHandle();
961 return False;
962 }
963 if (!(monitor->vsync = Xcalloc(rep.nvsync, sizeof(SDL_NAME(XF86VidModeSyncRange))))) {
964 _XEatData(dpy, (rep.nhsync + rep.nvsync) * 4 +
965 ((rep.vendorLength+3) & ~3) + ((rep.modelLength+3) & ~3));
966 if (monitor->vendor)
967 Xfree(monitor->vendor);
968 if (monitor->model)
969 Xfree(monitor->model);
970 Xfree(monitor->hsync);
971 UnlockDisplay(dpy);
972 SyncHandle();
973 return False;
974 }
975 for (i = 0; i < rep.nhsync; i++) {
976 _XRead(dpy, (char *)&syncrange, 4);
977 monitor->hsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
978 monitor->hsync[i].hi = (float)(syncrange >> 16) / 100.0;
979 }
980 for (i = 0; i < rep.nvsync; i++) {
981 _XRead(dpy, (char *)&syncrange, 4);
982 monitor->vsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
983 monitor->vsync[i].hi = (float)(syncrange >> 16) / 100.0;
984 }
985 if (rep.vendorLength)
986 _XReadPad(dpy, monitor->vendor, rep.vendorLength);
987 else
988 monitor->vendor = "";
989 if (rep.modelLength)
990 _XReadPad(dpy, monitor->model, rep.modelLength);
991 else
992 monitor->model = "";
993
994 UnlockDisplay(dpy);
995 SyncHandle();
996 return True;
997 }
998
999 Bool
1000 SDL_NAME(XF86VidModeGetViewPort)(dpy, screen, x, y)
1001 Display* dpy;
1002 int screen;
1003 int *x, *y;
1004 {
1005 XExtDisplayInfo *info = find_display (dpy);
1006 xXF86VidModeGetViewPortReply rep;
1007 xXF86VidModeGetViewPortReq *req;
1008 int majorVersion, minorVersion;
1009 Bool protocolBug = False;
1010
1011 XF86VidModeCheckExtension (dpy, info, False);
1012
1013 /*
1014 * Note: There was a bug in the protocol implementation in versions
1015 * 0.x with x < 8 (no reply was sent, so the client would hang)
1016 * Check the server's version, and don't wait for a reply with older
1017 * versions.
1018 */
1019
1020 SDL_NAME(XF86VidModeQueryVersion)(dpy, &majorVersion, &minorVersion);
1021 if (majorVersion == 0 && minorVersion < 8) {
1022 protocolBug = True;
1023 #ifdef DEBUG
1024 fprintf(stderr, "XF86VidModeGetViewPort: Warning: Xserver is"
1025 "running an old version (%d.%d)\n", majorVersion,
1026 minorVersion);
1027 #endif
1028 }
1029 LockDisplay(dpy);
1030 GetReq(XF86VidModeGetViewPort, req);
1031 req->reqType = info->codes->major_opcode;
1032 req->xf86vidmodeReqType = X_XF86VidModeGetViewPort;
1033 req->screen = screen;
1034 if (protocolBug) {
1035 *x = 0;
1036 *y = 0;
1037 } else {
1038 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
1039 UnlockDisplay(dpy);
1040 SyncHandle();
1041 return False;
1042 }
1043 *x = rep.x;
1044 *y = rep.y;
1045 }
1046
1047 UnlockDisplay(dpy);
1048 SyncHandle();
1049 return True;
1050 }
1051
1052 Bool
1053 SDL_NAME(XF86VidModeSetViewPort)(dpy, screen, x, y)
1054 Display* dpy;
1055 int screen;
1056 int x, y;
1057 {
1058 XExtDisplayInfo *info = find_display (dpy);
1059 xXF86VidModeSetViewPortReq *req;
1060
1061 XF86VidModeCheckExtension (dpy, info, False);
1062
1063 LockDisplay(dpy);
1064 GetReq(XF86VidModeSetViewPort, req);
1065 req->reqType = info->codes->major_opcode;
1066 req->xf86vidmodeReqType = X_XF86VidModeSetViewPort;
1067 req->screen = screen;
1068 req->x = x;
1069 req->y = y;
1070
1071 UnlockDisplay(dpy);
1072 SyncHandle();
1073 return True;
1074 }
1075
1076 Bool
1077 SDL_NAME(XF86VidModeGetDotClocks)(dpy, screen,
1078 flagsPtr, numclocksPtr, maxclocksPtr, clocksPtr)
1079 Display* dpy;
1080 int screen;
1081 int *flagsPtr, *numclocksPtr, *maxclocksPtr, *clocksPtr[];
1082 {
1083 XExtDisplayInfo *info = find_display (dpy);
1084 xXF86VidModeGetDotClocksReply rep;
1085 xXF86VidModeGetDotClocksReq *req;
1086 int i, *dotclocks;
1087 CARD32 dotclk;
1088
1089 XF86VidModeCheckExtension (dpy, info, False);
1090
1091 LockDisplay(dpy);
1092 GetReq(XF86VidModeGetDotClocks, req);
1093 req->reqType = info->codes->major_opcode;
1094 req->xf86vidmodeReqType = X_XF86VidModeGetDotClocks;
1095 req->screen = screen;
1096 if (!_XReply(dpy, (xReply *)&rep,
1097 (SIZEOF(xXF86VidModeGetDotClocksReply) - SIZEOF(xReply)) >> 2, xFalse))
1098 {
1099 UnlockDisplay(dpy);
1100 SyncHandle();
1101 return False;
1102 }
1103 *numclocksPtr = rep.clocks;
1104 *maxclocksPtr = rep.maxclocks;
1105 *flagsPtr = rep.flags;
1106
1107 if (!(dotclocks = (int*) Xcalloc(rep.clocks, sizeof(int)))) {
1108 _XEatData(dpy, (rep.clocks) * 4);
1109 Xfree(dotclocks);
1110 UnlockDisplay(dpy);
1111 SyncHandle();
1112 return False;
1113 }
1114
1115 for (i = 0; i < rep.clocks; i++) {
1116 _XRead(dpy, (char*)&dotclk, 4);
1117 dotclocks[i] = dotclk;
1118 }
1119 *clocksPtr = dotclocks;
1120 UnlockDisplay(dpy);
1121 SyncHandle();
1122 return True;
1123 }
1124
1125 Bool
SDL_NAME(XF86VidModeSetGammaRamp)1126 SDL_NAME(XF86VidModeSetGammaRamp) (
1127 Display *dpy,
1128 int screen,
1129 int size,
1130 unsigned short *red,
1131 unsigned short *green,
1132 unsigned short *blue
1133 )
1134 {
1135 int length = (size + 1) & ~1;
1136 XExtDisplayInfo *info = find_display (dpy);
1137 xXF86VidModeSetGammaRampReq *req;
1138
1139 XF86VidModeCheckExtension (dpy, info, False);
1140 LockDisplay(dpy);
1141 GetReq(XF86VidModeSetGammaRamp, req);
1142 req->reqType = info->codes->major_opcode;
1143 req->xf86vidmodeReqType = X_XF86VidModeSetGammaRamp;
1144 req->screen = screen;
1145 req->length += (length >> 1) * 3;
1146 req->size = size;
1147 _XSend(dpy, (char*)red, size * 2);
1148 _XSend(dpy, (char*)green, size * 2);
1149 _XSend(dpy, (char*)blue, size * 2);
1150 UnlockDisplay(dpy);
1151 SyncHandle();
1152 return True;
1153 }
1154
1155
1156 Bool
SDL_NAME(XF86VidModeGetGammaRamp)1157 SDL_NAME(XF86VidModeGetGammaRamp) (
1158 Display *dpy,
1159 int screen,
1160 int size,
1161 unsigned short *red,
1162 unsigned short *green,
1163 unsigned short *blue
1164 )
1165 {
1166 XExtDisplayInfo *info = find_display (dpy);
1167 xXF86VidModeGetGammaRampReq *req;
1168 xXF86VidModeGetGammaRampReply rep;
1169
1170 XF86VidModeCheckExtension (dpy, info, False);
1171
1172 LockDisplay(dpy);
1173 GetReq(XF86VidModeGetGammaRamp, req);
1174 req->reqType = info->codes->major_opcode;
1175 req->xf86vidmodeReqType = X_XF86VidModeGetGammaRamp;
1176 req->screen = screen;
1177 req->size = size;
1178 if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
1179 UnlockDisplay (dpy);
1180 SyncHandle ();
1181 return False;
1182 }
1183 if(rep.size) {
1184 _XRead(dpy, (char*)red, rep.size << 1);
1185 _XRead(dpy, (char*)green, rep.size << 1);
1186 _XRead(dpy, (char*)blue, rep.size << 1);
1187 }
1188
1189 UnlockDisplay(dpy);
1190 SyncHandle();
1191 return True;
1192 }
1193
SDL_NAME(XF86VidModeGetGammaRampSize)1194 Bool SDL_NAME(XF86VidModeGetGammaRampSize)(
1195 Display *dpy,
1196 int screen,
1197 int *size
1198 )
1199 {
1200 XExtDisplayInfo *info = find_display (dpy);
1201 xXF86VidModeGetGammaRampSizeReq *req;
1202 xXF86VidModeGetGammaRampSizeReply rep;
1203
1204 *size = 0;
1205
1206 XF86VidModeCheckExtension (dpy, info, False);
1207
1208 LockDisplay(dpy);
1209 GetReq(XF86VidModeGetGammaRampSize, req);
1210 req->reqType = info->codes->major_opcode;
1211 req->xf86vidmodeReqType = X_XF86VidModeGetGammaRampSize;
1212 req->screen = screen;
1213 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
1214 UnlockDisplay (dpy);
1215 SyncHandle ();
1216 return False;
1217 }
1218 *size = rep.size;
1219 UnlockDisplay(dpy);
1220 SyncHandle();
1221 return True;
1222 }
1223
1224