3 Copyright (c) 1995 Kaleb S. KEITHLEY
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and/or sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be
14 included in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL Kaleb S. KEITHLEY BE LIABLE FOR ANY CLAIM, DAMAGES
20 OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of Kaleb S. KEITHLEY
25 shall not be used in advertising or otherwise to promote the sale, use
26 or other dealings in this Software without prior written authorization
27 from Kaleb S. KEITHLEY.
31 /* THIS IS NOT AN X CONSORTIUM STANDARD */
37 #include <X11/Xlibint.h>
38 #include <X11/extensions/xf86vmproto.h>
39 #include <X11/extensions/xf86vmode.h>
40 #include <X11/extensions/Xext.h>
41 #include <X11/extensions/extutil.h>
44 #ifndef HAVE__XEATDATAWORDS
45 static inline void _XEatDataWords(Display *dpy, unsigned long n)
48 if (n >= (ULONG_MAX >> 2))
51 _XEatData (dpy, n << 2);
63 static XExtensionInfo _xf86vidmode_info_data;
64 static XExtensionInfo *xf86vidmode_info = &_xf86vidmode_info_data;
65 static const char *xf86vidmode_extension_name = XF86VIDMODENAME;
67 #define XF86VidModeCheckExtension(dpy,i,val) \
68 XextCheckExtension (dpy, i, xf86vidmode_extension_name, val)
70 /*****************************************************************************
72 * private utility routines *
74 *****************************************************************************/
76 static XEXT_CLOSE_DISPLAY_PROTO(close_display);
77 static /* const */ XExtensionHooks xf86vidmode_extension_hooks = {
82 NULL, /* create_font */
84 close_display, /* close_display */
85 NULL, /* wire_to_event */
86 NULL, /* event_to_wire */
88 NULL, /* error_string */
91 static XEXT_GENERATE_FIND_DISPLAY (find_display, xf86vidmode_info,
92 xf86vidmode_extension_name,
93 &xf86vidmode_extension_hooks,
96 static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xf86vidmode_info)
99 /*****************************************************************************
101 * public XFree86-VidMode Extension routines *
103 *****************************************************************************/
106 XF86VidModeQueryExtension(Display *dpy, int *event_basep, int *error_basep)
108 XExtDisplayInfo *info = find_display (dpy);
110 if (XextHasExtension(info)) {
111 *event_basep = info->codes->first_event;
112 *error_basep = info->codes->first_error;
120 XF86VidModeQueryVersion(Display* dpy, int* majorVersion, int* minorVersion)
122 XExtDisplayInfo *info = find_display (dpy);
123 xXF86VidModeQueryVersionReply rep;
124 xXF86VidModeQueryVersionReq *req;
126 XF86VidModeCheckExtension (dpy, info, False);
129 GetReq(XF86VidModeQueryVersion, req);
130 req->reqType = info->codes->major_opcode;
131 req->xf86vidmodeReqType = X_XF86VidModeQueryVersion;
132 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
137 *majorVersion = rep.majorVersion;
138 *minorVersion = rep.minorVersion;
141 if (*majorVersion >= 2)
142 XF86VidModeSetClientVersion(dpy);
147 XF86VidModeSetClientVersion(Display *dpy)
149 XExtDisplayInfo *info = find_display(dpy);
150 xXF86VidModeSetClientVersionReq *req;
152 XF86VidModeCheckExtension(dpy, info, False);
155 GetReq(XF86VidModeSetClientVersion, req);
156 req->reqType = info->codes->major_opcode;
157 req->xf86vidmodeReqType = X_XF86VidModeSetClientVersion;
158 req->major = XF86VIDMODE_MAJOR_VERSION;
159 req->minor = XF86VIDMODE_MINOR_VERSION;
166 XF86VidModeSetGamma(Display *dpy, int screen, XF86VidModeGamma *Gamma)
168 XExtDisplayInfo *info = find_display(dpy);
169 xXF86VidModeSetGammaReq *req;
171 XF86VidModeCheckExtension(dpy, info, False);
174 GetReq(XF86VidModeSetGamma, req);
175 req->reqType = info->codes->major_opcode;
176 req->xf86vidmodeReqType = X_XF86VidModeSetGamma;
177 req->screen = screen;
178 req->red = (CARD32)(Gamma->red * 10000.);
179 req->green = (CARD32)(Gamma->green * 10000.);
180 req->blue = (CARD32)(Gamma->blue * 10000.);
187 XF86VidModeGetGamma(Display *dpy, int screen, XF86VidModeGamma *Gamma)
189 XExtDisplayInfo *info = find_display (dpy);
190 xXF86VidModeGetGammaReply rep;
191 xXF86VidModeGetGammaReq *req;
193 XF86VidModeCheckExtension (dpy, info, False);
196 GetReq(XF86VidModeGetGamma, req);
197 req->reqType = info->codes->major_opcode;
198 req->xf86vidmodeReqType = X_XF86VidModeGetGamma;
199 req->screen = screen;
200 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
205 Gamma->red = ((float)rep.red) / 10000.;
206 Gamma->green = ((float)rep.green) / 10000.;
207 Gamma->blue = ((float)rep.blue) / 10000.;
214 XF86VidModeGetModeLine(Display* dpy, int screen, int* dotclock,
215 XF86VidModeModeLine* modeline)
217 XExtDisplayInfo *info = find_display (dpy);
218 xXF86VidModeGetModeLineReply rep;
219 xXF86OldVidModeGetModeLineReply oldrep;
220 xXF86VidModeGetModeLineReq *req;
221 int majorVersion, minorVersion;
224 XF86VidModeCheckExtension (dpy, info, False);
225 XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
228 GetReq(XF86VidModeGetModeLine, req);
229 req->reqType = info->codes->major_opcode;
230 req->xf86vidmodeReqType = X_XF86VidModeGetModeLine;
231 req->screen = screen;
233 if (majorVersion < 2) {
234 if (!_XReply(dpy, (xReply *)&oldrep,
235 (SIZEOF(xXF86OldVidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) {
240 *dotclock = oldrep.dotclock;
241 modeline->hdisplay = oldrep.hdisplay;
242 modeline->hsyncstart = oldrep.hsyncstart;
243 modeline->hsyncend = oldrep.hsyncend;
244 modeline->htotal = oldrep.htotal;
246 modeline->vdisplay = oldrep.vdisplay;
247 modeline->vsyncstart = oldrep.vsyncstart;
248 modeline->vsyncend = oldrep.vsyncend;
249 modeline->vtotal = oldrep.vtotal;
250 modeline->flags = oldrep.flags;
251 modeline->privsize = oldrep.privsize;
253 if (!_XReply(dpy, (xReply *)&rep,
254 (SIZEOF(xXF86VidModeGetModeLineReply) - SIZEOF(xReply)) >> 2, xFalse)) {
259 *dotclock = rep.dotclock;
260 modeline->hdisplay = rep.hdisplay;
261 modeline->hsyncstart = rep.hsyncstart;
262 modeline->hsyncend = rep.hsyncend;
263 modeline->htotal = rep.htotal;
264 modeline->hskew = rep.hskew;
265 modeline->vdisplay = rep.vdisplay;
266 modeline->vsyncstart = rep.vsyncstart;
267 modeline->vsyncend = rep.vsyncend;
268 modeline->vtotal = rep.vtotal;
269 modeline->flags = rep.flags;
270 modeline->privsize = rep.privsize;
273 if (modeline->privsize > 0) {
274 if (modeline->privsize < (INT_MAX / sizeof(INT32)))
275 modeline->private = Xcalloc(modeline->privsize, sizeof(INT32));
277 modeline->private = NULL;
278 if (modeline->private == NULL) {
279 _XEatDataWords(dpy, rep.length -
280 ((SIZEOF(xXF86VidModeGetModeLineReply) - SIZEOF(xReply)) >> 2));
283 _XRead(dpy, (char*)modeline->private, modeline->privsize * sizeof(INT32));
285 modeline->private = NULL;
293 XF86VidModeGetAllModeLines(Display* dpy, int screen, int* modecount,
294 XF86VidModeModeInfo ***modelinesPtr)
296 XExtDisplayInfo *info = find_display (dpy);
297 xXF86VidModeGetAllModeLinesReply rep;
298 xXF86VidModeGetAllModeLinesReq *req;
299 XF86VidModeModeInfo *mdinfptr, **modelines;
300 xXF86VidModeModeInfo xmdline;
301 xXF86OldVidModeModeInfo oldxmdline;
303 int majorVersion, minorVersion;
304 Bool protocolBug = False;
306 XF86VidModeCheckExtension (dpy, info, False);
309 * Note: There was a bug in the protocol implementation in versions
310 * 0.x with x < 8 (the .private field wasn't being passed over the wire).
311 * Check the server's version, and accept the old format if appropriate.
314 XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
315 if (majorVersion == 0 && minorVersion < 8) {
318 fprintf(stderr, "XF86VidModeGetAllModeLines: Warning: Xserver is"
319 "running an old version (%d.%d)\n", majorVersion,
325 GetReq(XF86VidModeGetAllModeLines, req);
326 req->reqType = info->codes->major_opcode;
327 req->xf86vidmodeReqType = X_XF86VidModeGetAllModeLines;
328 req->screen = screen;
329 if (!_XReply(dpy, (xReply *)&rep,
330 (SIZEOF(xXF86VidModeGetAllModeLinesReply) - SIZEOF(xReply)) >> 2, xFalse)) {
336 *modecount = rep.modecount;
338 if (!(modelines = (XF86VidModeModeInfo **) Xcalloc(rep.modecount,
339 sizeof(XF86VidModeModeInfo *)
340 +sizeof(XF86VidModeModeInfo)))) {
341 _XEatDataWords(dpy, rep.length -
342 ((SIZEOF(xXF86VidModeGetAllModeLinesReply) - SIZEOF(xReply)) >> 2));
347 mdinfptr = (XF86VidModeModeInfo *) (
349 + rep.modecount*sizeof(XF86VidModeModeInfo *)
352 for (i = 0; i < rep.modecount; i++) {
353 modelines[i] = mdinfptr++;
354 if (majorVersion < 2) {
355 _XRead(dpy, (char*)&oldxmdline, sizeof(xXF86OldVidModeModeInfo));
356 modelines[i]->dotclock = oldxmdline.dotclock;
357 modelines[i]->hdisplay = oldxmdline.hdisplay;
358 modelines[i]->hsyncstart = oldxmdline.hsyncstart;
359 modelines[i]->hsyncend = oldxmdline.hsyncend;
360 modelines[i]->htotal = oldxmdline.htotal;
361 modelines[i]->hskew = 0;
362 modelines[i]->vdisplay = oldxmdline.vdisplay;
363 modelines[i]->vsyncstart = oldxmdline.vsyncstart;
364 modelines[i]->vsyncend = oldxmdline.vsyncend;
365 modelines[i]->vtotal = oldxmdline.vtotal;
366 modelines[i]->flags = oldxmdline.flags;
368 modelines[i]->privsize = 0;
369 modelines[i]->private = NULL;
371 modelines[i]->privsize = oldxmdline.privsize;
372 if (oldxmdline.privsize > 0) {
373 if (!(modelines[i]->private =
374 Xcalloc(oldxmdline.privsize, sizeof(INT32)))) {
375 _XEatDataWords(dpy, oldxmdline.privsize);
377 _XRead(dpy, (char*)modelines[i]->private,
378 oldxmdline.privsize * sizeof(INT32));
381 modelines[i]->private = NULL;
385 _XRead(dpy, (char*)&xmdline, sizeof(xXF86VidModeModeInfo));
386 modelines[i]->dotclock = xmdline.dotclock;
387 modelines[i]->hdisplay = xmdline.hdisplay;
388 modelines[i]->hsyncstart = xmdline.hsyncstart;
389 modelines[i]->hsyncend = xmdline.hsyncend;
390 modelines[i]->htotal = xmdline.htotal;
391 modelines[i]->hskew = xmdline.hskew;
392 modelines[i]->vdisplay = xmdline.vdisplay;
393 modelines[i]->vsyncstart = xmdline.vsyncstart;
394 modelines[i]->vsyncend = xmdline.vsyncend;
395 modelines[i]->vtotal = xmdline.vtotal;
396 modelines[i]->flags = xmdline.flags;
398 modelines[i]->privsize = 0;
399 modelines[i]->private = NULL;
401 modelines[i]->privsize = xmdline.privsize;
402 if (xmdline.privsize > 0) {
403 if (!(modelines[i]->private =
404 Xcalloc(xmdline.privsize, sizeof(INT32)))) {
405 _XEatDataWords(dpy, xmdline.privsize);
407 _XRead(dpy, (char*)modelines[i]->private,
408 xmdline.privsize * sizeof(INT32));
411 modelines[i]->private = NULL;
416 *modelinesPtr = modelines;
423 * GetReq replacement for use with VidMode protocols earlier than 2.0
425 #if !defined(UNIXCPP) || defined(ANSICPP)
426 #define GetOldReq(name, oldname, req) \
428 if ((dpy->bufptr + SIZEOF(x##oldname##Req)) > dpy->bufmax)\
430 req = (x##oldname##Req *)(dpy->last_req = dpy->bufptr);\
431 req->reqType = X_##name;\
432 req->length = (SIZEOF(x##oldname##Req))>>2;\
433 dpy->bufptr += SIZEOF(x##oldname##Req);\
436 #else /* non-ANSI C uses empty comment instead of "##" for token concatenation */
437 #define GetOldReq(name, oldname, req) \
439 if ((dpy->bufptr + SIZEOF(x/**/oldname/**/Req)) > dpy->bufmax)\
441 req = (x/**/oldname/**/Req *)(dpy->last_req = dpy->bufptr);\
442 req->reqType = X_/**/name;\
443 req->length = (SIZEOF(x/**/oldname/**/Req))>>2;\
444 dpy->bufptr += SIZEOF(x/**/oldname/**/Req);\
449 XF86VidModeAddModeLine(Display *dpy, int screen,
450 XF86VidModeModeInfo* newmodeline,
451 XF86VidModeModeInfo* aftermodeline)
453 XExtDisplayInfo *info = find_display (dpy);
454 xXF86VidModeAddModeLineReq *req;
455 xXF86OldVidModeAddModeLineReq *oldreq;
456 int majorVersion, minorVersion;
458 XF86VidModeCheckExtension (dpy, info, False);
459 XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
462 if (majorVersion < 2) {
463 GetOldReq(XF86VidModeAddModeLine, XF86OldVidModeAddModeLine, oldreq);
464 oldreq->reqType = info->codes->major_opcode;
465 oldreq->xf86vidmodeReqType = X_XF86VidModeAddModeLine;
466 oldreq->screen = screen;
467 oldreq->dotclock = newmodeline->dotclock;
468 oldreq->hdisplay = newmodeline->hdisplay;
469 oldreq->hsyncstart = newmodeline->hsyncstart;
470 oldreq->hsyncend = newmodeline->hsyncend;
471 oldreq->htotal = newmodeline->htotal;
472 oldreq->vdisplay = newmodeline->vdisplay;
473 oldreq->vsyncstart = newmodeline->vsyncstart;
474 oldreq->vsyncend = newmodeline->vsyncend;
475 oldreq->vtotal = newmodeline->vtotal;
476 oldreq->flags = newmodeline->flags;
477 oldreq->privsize = newmodeline->privsize;
478 if (aftermodeline != NULL) {
479 oldreq->after_dotclock = aftermodeline->dotclock;
480 oldreq->after_hdisplay = aftermodeline->hdisplay;
481 oldreq->after_hsyncstart = aftermodeline->hsyncstart;
482 oldreq->after_hsyncend = aftermodeline->hsyncend;
483 oldreq->after_htotal = aftermodeline->htotal;
484 oldreq->after_vdisplay = aftermodeline->vdisplay;
485 oldreq->after_vsyncstart = aftermodeline->vsyncstart;
486 oldreq->after_vsyncend = aftermodeline->vsyncend;
487 oldreq->after_vtotal = aftermodeline->vtotal;
488 oldreq->after_flags = aftermodeline->flags;
490 oldreq->after_dotclock = 0;
491 oldreq->after_hdisplay = 0;
492 oldreq->after_hsyncstart = 0;
493 oldreq->after_hsyncend = 0;
494 oldreq->after_htotal = 0;
495 oldreq->after_vdisplay = 0;
496 oldreq->after_vsyncstart = 0;
497 oldreq->after_vsyncend = 0;
498 oldreq->after_vtotal = 0;
499 oldreq->after_flags = 0;
501 if (newmodeline->privsize) {
502 oldreq->length += newmodeline->privsize;
503 Data32(dpy, (long *) newmodeline->private,
504 newmodeline->privsize * sizeof(INT32));
507 GetReq(XF86VidModeAddModeLine, req);
508 req->reqType = info->codes->major_opcode;
509 req->xf86vidmodeReqType = X_XF86VidModeAddModeLine;
510 req->screen = screen;
511 req->dotclock = newmodeline->dotclock;
512 req->hdisplay = newmodeline->hdisplay;
513 req->hsyncstart = newmodeline->hsyncstart;
514 req->hsyncend = newmodeline->hsyncend;
515 req->htotal = newmodeline->htotal;
516 req->hskew = newmodeline->hskew;
517 req->vdisplay = newmodeline->vdisplay;
518 req->vsyncstart = newmodeline->vsyncstart;
519 req->vsyncend = newmodeline->vsyncend;
520 req->vtotal = newmodeline->vtotal;
521 req->flags = newmodeline->flags;
522 req->privsize = newmodeline->privsize;
523 if (aftermodeline != NULL) {
524 req->after_dotclock = aftermodeline->dotclock;
525 req->after_hdisplay = aftermodeline->hdisplay;
526 req->after_hsyncstart = aftermodeline->hsyncstart;
527 req->after_hsyncend = aftermodeline->hsyncend;
528 req->after_htotal = aftermodeline->htotal;
529 req->after_hskew = aftermodeline->hskew;
530 req->after_vdisplay = aftermodeline->vdisplay;
531 req->after_vsyncstart = aftermodeline->vsyncstart;
532 req->after_vsyncend = aftermodeline->vsyncend;
533 req->after_vtotal = aftermodeline->vtotal;
534 req->after_flags = aftermodeline->flags;
536 req->after_dotclock = 0;
537 req->after_hdisplay = 0;
538 req->after_hsyncstart = 0;
539 req->after_hsyncend = 0;
540 req->after_htotal = 0;
541 req->after_hskew = 0;
542 req->after_vdisplay = 0;
543 req->after_vsyncstart = 0;
544 req->after_vsyncend = 0;
545 req->after_vtotal = 0;
546 req->after_flags = 0;
548 if (newmodeline->privsize) {
549 req->length += newmodeline->privsize;
550 Data32(dpy, (long *) newmodeline->private,
551 newmodeline->privsize * sizeof(INT32));
560 XF86VidModeDeleteModeLine(Display *dpy, int screen,
561 XF86VidModeModeInfo* modeline)
563 XExtDisplayInfo *info = find_display (dpy);
564 xXF86VidModeDeleteModeLineReq *req;
565 xXF86OldVidModeDeleteModeLineReq *oldreq;
566 int majorVersion, minorVersion;
568 XF86VidModeCheckExtension (dpy, info, 0);
569 XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
572 if (majorVersion < 2) {
573 GetOldReq(XF86VidModeDeleteModeLine, XF86OldVidModeDeleteModeLine, oldreq);
574 oldreq->reqType = info->codes->major_opcode;
575 oldreq->xf86vidmodeReqType = X_XF86VidModeDeleteModeLine;
576 oldreq->screen = screen;
577 oldreq->dotclock = modeline->dotclock;
578 oldreq->hdisplay = modeline->hdisplay;
579 oldreq->hsyncstart = modeline->hsyncstart;
580 oldreq->hsyncend = modeline->hsyncend;
581 oldreq->htotal = modeline->htotal;
582 oldreq->vdisplay = modeline->vdisplay;
583 oldreq->vsyncstart = modeline->vsyncstart;
584 oldreq->vsyncend = modeline->vsyncend;
585 oldreq->vtotal = modeline->vtotal;
586 oldreq->flags = modeline->flags;
587 oldreq->privsize = modeline->privsize;
588 if (modeline->privsize) {
589 oldreq->length += modeline->privsize;
590 Data32(dpy, (long *) modeline->private,
591 modeline->privsize * sizeof(INT32));
594 GetReq(XF86VidModeDeleteModeLine, req);
595 req->reqType = info->codes->major_opcode;
596 req->xf86vidmodeReqType = X_XF86VidModeDeleteModeLine;
597 req->screen = screen;
598 req->dotclock = modeline->dotclock;
599 req->hdisplay = modeline->hdisplay;
600 req->hsyncstart = modeline->hsyncstart;
601 req->hsyncend = modeline->hsyncend;
602 req->htotal = modeline->htotal;
603 req->hskew = modeline->hskew;
604 req->vdisplay = modeline->vdisplay;
605 req->vsyncstart = modeline->vsyncstart;
606 req->vsyncend = modeline->vsyncend;
607 req->vtotal = modeline->vtotal;
608 req->flags = modeline->flags;
609 req->privsize = modeline->privsize;
610 if (modeline->privsize) {
611 req->length += modeline->privsize;
612 Data32(dpy, (long *) modeline->private,
613 modeline->privsize * sizeof(INT32));
622 XF86VidModeModModeLine(Display *dpy, int screen, XF86VidModeModeLine* modeline)
624 XExtDisplayInfo *info = find_display (dpy);
625 xXF86VidModeModModeLineReq *req;
626 xXF86OldVidModeModModeLineReq *oldreq;
627 int majorVersion, minorVersion;
629 XF86VidModeCheckExtension (dpy, info, 0);
630 XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
633 if (majorVersion < 2) {
634 GetOldReq(XF86VidModeModModeLine, XF86OldVidModeModModeLine, oldreq);
635 oldreq->reqType = info->codes->major_opcode;
636 oldreq->xf86vidmodeReqType = X_XF86VidModeModModeLine;
637 oldreq->screen = screen;
638 oldreq->hdisplay = modeline->hdisplay;
639 oldreq->hsyncstart = modeline->hsyncstart;
640 oldreq->hsyncend = modeline->hsyncend;
641 oldreq->htotal = modeline->htotal;
642 oldreq->vdisplay = modeline->vdisplay;
643 oldreq->vsyncstart = modeline->vsyncstart;
644 oldreq->vsyncend = modeline->vsyncend;
645 oldreq->vtotal = modeline->vtotal;
646 oldreq->flags = modeline->flags;
647 oldreq->privsize = modeline->privsize;
648 if (modeline->privsize) {
649 oldreq->length += modeline->privsize;
650 Data32(dpy, (long *) modeline->private,
651 modeline->privsize * sizeof(INT32));
654 GetReq(XF86VidModeModModeLine, req);
655 req->reqType = info->codes->major_opcode;
656 req->xf86vidmodeReqType = X_XF86VidModeModModeLine;
657 req->screen = screen;
658 req->hdisplay = modeline->hdisplay;
659 req->hsyncstart = modeline->hsyncstart;
660 req->hsyncend = modeline->hsyncend;
661 req->htotal = modeline->htotal;
662 req->hskew = modeline->hskew;
663 req->vdisplay = modeline->vdisplay;
664 req->vsyncstart = modeline->vsyncstart;
665 req->vsyncend = modeline->vsyncend;
666 req->vtotal = modeline->vtotal;
667 req->flags = modeline->flags;
668 req->privsize = modeline->privsize;
669 if (modeline->privsize) {
670 req->length += modeline->privsize;
671 Data32(dpy, (long *) modeline->private,
672 modeline->privsize * sizeof(INT32));
681 XF86VidModeValidateModeLine(Display *dpy, int screen,
682 XF86VidModeModeInfo* modeline)
684 XExtDisplayInfo *info = find_display (dpy);
685 xXF86VidModeValidateModeLineReq *req;
686 xXF86OldVidModeValidateModeLineReq *oldreq;
687 xXF86VidModeValidateModeLineReply rep;
688 int majorVersion, minorVersion;
690 XF86VidModeCheckExtension (dpy, info, 0);
691 XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
695 if (majorVersion < 2) {
696 GetOldReq(XF86VidModeValidateModeLine, XF86OldVidModeValidateModeLine, oldreq);
697 oldreq->reqType = info->codes->major_opcode;
698 oldreq->xf86vidmodeReqType = X_XF86VidModeValidateModeLine;
699 oldreq->screen = screen;
700 oldreq->dotclock = modeline->dotclock;
701 oldreq->hdisplay = modeline->hdisplay;
702 oldreq->hsyncstart = modeline->hsyncstart;
703 oldreq->hsyncend = modeline->hsyncend;
704 oldreq->htotal = modeline->htotal;
705 oldreq->vdisplay = modeline->vdisplay;
706 oldreq->vsyncstart = modeline->vsyncstart;
707 oldreq->vsyncend = modeline->vsyncend;
708 oldreq->vtotal = modeline->vtotal;
709 oldreq->flags = modeline->flags;
710 oldreq->privsize = modeline->privsize;
711 if (modeline->privsize) {
712 oldreq->length += modeline->privsize;
713 Data32(dpy, (long *) modeline->private,
714 modeline->privsize * sizeof(INT32));
717 GetReq(XF86VidModeValidateModeLine, req);
718 req->reqType = info->codes->major_opcode;
719 req->xf86vidmodeReqType = X_XF86VidModeValidateModeLine;
720 req->screen = screen;
721 req->dotclock = modeline->dotclock;
722 req->hdisplay = modeline->hdisplay;
723 req->hsyncstart = modeline->hsyncstart;
724 req->hsyncend = modeline->hsyncend;
725 req->htotal = modeline->htotal;
726 req->hskew = modeline->hskew;
727 req->vdisplay = modeline->vdisplay;
728 req->vsyncstart = modeline->vsyncstart;
729 req->vsyncend = modeline->vsyncend;
730 req->vtotal = modeline->vtotal;
731 req->flags = modeline->flags;
732 req->privsize = modeline->privsize;
733 if (modeline->privsize) {
734 req->length += modeline->privsize;
735 Data32(dpy, (long *) modeline->private,
736 modeline->privsize * sizeof(INT32));
739 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
750 XF86VidModeSwitchMode(Display* dpy, int screen, int zoom)
752 XExtDisplayInfo *info = find_display (dpy);
753 xXF86VidModeSwitchModeReq *req;
755 XF86VidModeCheckExtension (dpy, info, False);
758 GetReq(XF86VidModeSwitchMode, req);
759 req->reqType = info->codes->major_opcode;
760 req->xf86vidmodeReqType = X_XF86VidModeSwitchMode;
761 req->screen = screen;
769 XF86VidModeSwitchToMode(Display* dpy, int screen, XF86VidModeModeInfo* modeline)
771 XExtDisplayInfo *info = find_display (dpy);
772 xXF86VidModeSwitchToModeReq *req;
773 xXF86OldVidModeSwitchToModeReq *oldreq;
774 int majorVersion, minorVersion;
775 Bool protocolBug = False;
777 XF86VidModeCheckExtension (dpy, info, False);
780 * Note: There was a bug in the protocol implementation in versions
781 * 0.x with x < 8 (the .private field wasn't expected to be sent over
782 * the wire). Check the server's version, and accept the old format
786 XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
787 if (majorVersion == 0 && minorVersion < 8) {
790 fprintf(stderr, "XF86VidModeSwitchToMode: Warning: Xserver is"
791 "running an old version (%d.%d)\n", majorVersion,
797 if (majorVersion < 2) {
798 GetOldReq(XF86VidModeSwitchToMode, XF86OldVidModeSwitchToMode, oldreq);
799 oldreq->reqType = info->codes->major_opcode;
800 oldreq->xf86vidmodeReqType = X_XF86VidModeSwitchToMode;
801 oldreq->screen = screen;
802 oldreq->dotclock = modeline->dotclock;
803 oldreq->hdisplay = modeline->hdisplay;
804 oldreq->hsyncstart = modeline->hsyncstart;
805 oldreq->hsyncend = modeline->hsyncend;
806 oldreq->htotal = modeline->htotal;
807 oldreq->vdisplay = modeline->vdisplay;
808 oldreq->vsyncstart = modeline->vsyncstart;
809 oldreq->vsyncend = modeline->vsyncend;
810 oldreq->vtotal = modeline->vtotal;
811 oldreq->flags = modeline->flags;
813 oldreq->privsize = 0;
815 oldreq->privsize = modeline->privsize;
816 if (modeline->privsize) {
817 oldreq->length += modeline->privsize;
818 Data32(dpy, (long *) modeline->private,
819 modeline->privsize * sizeof(INT32));
823 GetReq(XF86VidModeSwitchToMode, req);
824 req->reqType = info->codes->major_opcode;
825 req->xf86vidmodeReqType = X_XF86VidModeSwitchToMode;
826 req->screen = screen;
827 req->dotclock = modeline->dotclock;
828 req->hdisplay = modeline->hdisplay;
829 req->hsyncstart = modeline->hsyncstart;
830 req->hsyncend = modeline->hsyncend;
831 req->htotal = modeline->htotal;
832 req->hskew = modeline->hskew;
833 req->vdisplay = modeline->vdisplay;
834 req->vsyncstart = modeline->vsyncstart;
835 req->vsyncend = modeline->vsyncend;
836 req->vtotal = modeline->vtotal;
837 req->flags = modeline->flags;
841 req->privsize = modeline->privsize;
842 if (modeline->privsize) {
843 req->length += modeline->privsize;
844 Data32(dpy, (long *) modeline->private,
845 modeline->privsize * sizeof(INT32));
855 XF86VidModeLockModeSwitch(Display* dpy, int screen, int lock)
857 XExtDisplayInfo *info = find_display (dpy);
858 xXF86VidModeLockModeSwitchReq *req;
860 XF86VidModeCheckExtension (dpy, info, False);
863 GetReq(XF86VidModeLockModeSwitch, req);
864 req->reqType = info->codes->major_opcode;
865 req->xf86vidmodeReqType = X_XF86VidModeLockModeSwitch;
866 req->screen = screen;
874 XF86VidModeGetMonitor(Display* dpy, int screen, XF86VidModeMonitor* monitor)
876 XExtDisplayInfo *info = find_display (dpy);
877 xXF86VidModeGetMonitorReply rep;
878 xXF86VidModeGetMonitorReq *req;
883 XF86VidModeCheckExtension (dpy, info, False);
886 GetReq(XF86VidModeGetMonitor, req);
887 req->reqType = info->codes->major_opcode;
888 req->xf86vidmodeReqType = X_XF86VidModeGetMonitor;
889 req->screen = screen;
890 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
895 monitor->nhsync = rep.nhsync;
896 monitor->nvsync = rep.nvsync;
898 monitor->bandwidth = (float)rep.bandwidth / 1e6;
900 if (rep.vendorLength) {
901 monitor->vendor = Xcalloc(rep.vendorLength + 1, 1);
902 if (monitor->vendor == NULL)
905 monitor->vendor = NULL;
907 if (result && rep.modelLength) {
908 monitor->model = Xcalloc(rep.modelLength + 1, 1);
909 if (monitor->model == NULL)
912 monitor->model = NULL;
915 monitor->hsync = Xcalloc(rep.nhsync, sizeof(XF86VidModeSyncRange));
916 monitor->vsync = Xcalloc(rep.nvsync, sizeof(XF86VidModeSyncRange));
917 if ((monitor->hsync == NULL) || (monitor->vsync == NULL))
920 monitor->hsync = monitor->vsync = NULL;
922 if (result == False) {
923 _XEatDataWords(dpy, rep.length);
924 Xfree(monitor->vendor);
925 monitor->vendor = NULL;
926 Xfree(monitor->model);
927 monitor->model = NULL;
928 Xfree(monitor->hsync);
929 monitor->hsync = NULL;
930 Xfree(monitor->vsync);
931 monitor->vsync = NULL;
934 for (i = 0; i < rep.nhsync; i++) {
935 _XRead(dpy, (char *)&syncrange, 4);
936 monitor->hsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
937 monitor->hsync[i].hi = (float)(syncrange >> 16) / 100.0;
939 for (i = 0; i < rep.nvsync; i++) {
940 _XRead(dpy, (char *)&syncrange, 4);
941 monitor->vsync[i].lo = (float)(syncrange & 0xFFFF) / 100.0;
942 monitor->vsync[i].hi = (float)(syncrange >> 16) / 100.0;
944 if (rep.vendorLength)
945 _XReadPad(dpy, monitor->vendor, rep.vendorLength);
947 _XReadPad(dpy, monitor->model, rep.modelLength);
955 XF86VidModeGetViewPort(Display* dpy, int screen, int *x, int *y)
957 XExtDisplayInfo *info = find_display (dpy);
958 xXF86VidModeGetViewPortReply rep;
959 xXF86VidModeGetViewPortReq *req;
960 int majorVersion, minorVersion;
961 Bool protocolBug = False;
963 XF86VidModeCheckExtension (dpy, info, False);
966 * Note: There was a bug in the protocol implementation in versions
967 * 0.x with x < 8 (no reply was sent, so the client would hang)
968 * Check the server's version, and don't wait for a reply with older
972 XF86VidModeQueryVersion(dpy, &majorVersion, &minorVersion);
973 if (majorVersion == 0 && minorVersion < 8) {
976 fprintf(stderr, "XF86VidModeGetViewPort: Warning: Xserver is"
977 "running an old version (%d.%d)\n", majorVersion,
982 GetReq(XF86VidModeGetViewPort, req);
983 req->reqType = info->codes->major_opcode;
984 req->xf86vidmodeReqType = X_XF86VidModeGetViewPort;
985 req->screen = screen;
990 if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
1005 XF86VidModeSetViewPort(Display* dpy, int screen, int x, int y)
1007 XExtDisplayInfo *info = find_display (dpy);
1008 xXF86VidModeSetViewPortReq *req;
1010 XF86VidModeCheckExtension (dpy, info, False);
1013 GetReq(XF86VidModeSetViewPort, req);
1014 req->reqType = info->codes->major_opcode;
1015 req->xf86vidmodeReqType = X_XF86VidModeSetViewPort;
1016 req->screen = screen;
1026 XF86VidModeGetDotClocks(Display* dpy, int screen, int *flagsPtr,
1027 int *numclocksPtr, int *maxclocksPtr, int *clocksPtr[])
1029 XExtDisplayInfo *info = find_display (dpy);
1030 xXF86VidModeGetDotClocksReply rep;
1031 xXF86VidModeGetDotClocksReq *req;
1036 XF86VidModeCheckExtension (dpy, info, False);
1039 GetReq(XF86VidModeGetDotClocks, req);
1040 req->reqType = info->codes->major_opcode;
1041 req->xf86vidmodeReqType = X_XF86VidModeGetDotClocks;
1042 req->screen = screen;
1043 if (!_XReply(dpy, (xReply *)&rep,
1044 (SIZEOF(xXF86VidModeGetDotClocksReply) - SIZEOF(xReply)) >> 2, xFalse))
1050 *numclocksPtr = rep.clocks;
1051 *maxclocksPtr = rep.maxclocks;
1052 *flagsPtr = rep.flags;
1054 dotclocks = Xcalloc(rep.clocks, sizeof(int));
1055 if (dotclocks == NULL) {
1056 _XEatDataWords(dpy, rep.length -
1057 ((SIZEOF(xXF86VidModeGetDotClocksReply) - SIZEOF(xReply)) >> 2));
1061 for (i = 0; i < rep.clocks; i++) {
1062 _XRead(dpy, (char*)&dotclk, 4);
1063 dotclocks[i] = dotclk;
1066 *clocksPtr = dotclocks;
1073 XF86VidModeSetGammaRamp (
1077 unsigned short *red,
1078 unsigned short *green,
1079 unsigned short *blue
1082 int length = (size + 1) & ~1;
1083 XExtDisplayInfo *info = find_display (dpy);
1084 xXF86VidModeSetGammaRampReq *req;
1086 XF86VidModeCheckExtension (dpy, info, False);
1088 GetReq(XF86VidModeSetGammaRamp, req);
1089 req->reqType = info->codes->major_opcode;
1090 req->xf86vidmodeReqType = X_XF86VidModeSetGammaRamp;
1091 req->screen = screen;
1092 req->length += (length >> 1) * 3;
1094 _XSend(dpy, (char*)red, size * 2);
1095 _XSend(dpy, (char*)green, size * 2);
1096 _XSend(dpy, (char*)blue, size * 2);
1104 XF86VidModeGetGammaRamp (
1108 unsigned short *red,
1109 unsigned short *green,
1110 unsigned short *blue
1113 XExtDisplayInfo *info = find_display (dpy);
1114 xXF86VidModeGetGammaRampReq *req;
1115 xXF86VidModeGetGammaRampReply rep;
1118 XF86VidModeCheckExtension (dpy, info, False);
1121 GetReq(XF86VidModeGetGammaRamp, req);
1122 req->reqType = info->codes->major_opcode;
1123 req->xf86vidmodeReqType = X_XF86VidModeGetGammaRamp;
1124 req->screen = screen;
1126 if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
1129 else if (rep.size) {
1130 if (rep.size <= size) {
1131 _XRead(dpy, (char*)red, rep.size << 1);
1132 _XRead(dpy, (char*)green, rep.size << 1);
1133 _XRead(dpy, (char*)blue, rep.size << 1);
1136 _XEatDataWords(dpy, rep.length);
1146 Bool XF86VidModeGetGammaRampSize(
1152 XExtDisplayInfo *info = find_display (dpy);
1153 xXF86VidModeGetGammaRampSizeReq *req;
1154 xXF86VidModeGetGammaRampSizeReply rep;
1158 XF86VidModeCheckExtension (dpy, info, False);
1161 GetReq(XF86VidModeGetGammaRampSize, req);
1162 req->reqType = info->codes->major_opcode;
1163 req->xf86vidmodeReqType = X_XF86VidModeGetGammaRampSize;
1164 req->screen = screen;
1165 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
1166 UnlockDisplay (dpy);
1176 Bool XF86VidModeGetPermissions(
1182 XExtDisplayInfo *info = find_display (dpy);
1183 xXF86VidModeGetPermissionsReq *req;
1184 xXF86VidModeGetPermissionsReply rep;
1188 XF86VidModeCheckExtension (dpy, info, False);
1191 GetReq(XF86VidModeGetPermissions, req);
1192 req->reqType = info->codes->major_opcode;
1193 req->xf86vidmodeReqType = X_XF86VidModeGetPermissions;
1194 req->screen = screen;
1195 if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
1196 UnlockDisplay (dpy);
1200 *permissions = rep.permissions;