2 * Copyright © 2006 Keith Packard
3 * Copyright © 2008 Red Hat, Inc.
5 * Permission to use, copy, modify, distribute, and sell this software and its
6 * documentation for any purpose is hereby granted without fee, provided that
7 * the above copyright notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting documentation, and
9 * that the name of the copyright holders not be used in advertising or
10 * publicity pertaining to distribution of the software without specific,
11 * written prior permission. The copyright holders make no representations
12 * about the suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
30 /* we need to be able to manipulate the Display structure on events */
31 #include <X11/Xlibint.h>
32 #include <X11/extensions/render.h>
33 #include <X11/extensions/Xrender.h>
34 #include "Xrandrint.h"
36 #define OutputInfoExtra (SIZEOF(xRRGetOutputInfoReply) - 32)
39 XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
41 XExtDisplayInfo *info = XRRFindDisplay(dpy);
42 xRRGetOutputInfoReply rep;
43 xRRGetOutputInfoReq *req;
44 int nbytes, nbytesRead, rbytes;
47 RRCheckExtension (dpy, info, NULL);
50 GetReq (RRGetOutputInfo, req);
51 req->reqType = info->codes->major_opcode;
52 req->randrReqType = X_RRGetOutputInfo;
54 req->configTimestamp = resources->configTimestamp;
56 if (!_XReply (dpy, (xReply *) &rep, OutputInfoExtra >> 2, xFalse))
63 nbytes = ((long) (rep.length) << 2) - OutputInfoExtra;
65 nbytesRead = (long) (rep.nCrtcs * 4 +
68 ((rep.nameLength + 3) & ~3));
71 * first we must compute how much space to allocate for
72 * randr library's use; we'll allocate the structures in a single
73 * allocation, on cleanlyness grounds.
76 rbytes = (sizeof (XRROutputInfo) +
77 rep.nCrtcs * sizeof (RRCrtc) +
78 rep.nModes * sizeof (RRMode) +
79 rep.nClones * sizeof (RROutput) +
80 rep.nameLength + 1); /* '\0' terminate name */
82 xoi = (XRROutputInfo *) Xmalloc(rbytes);
84 _XEatData (dpy, (unsigned long) nbytes);
90 xoi->timestamp = rep.timestamp;
92 xoi->mm_width = rep.mmWidth;
93 xoi->mm_height = rep.mmHeight;
94 xoi->connection = rep.connection;
95 xoi->subpixel_order = rep.subpixelOrder;
96 xoi->ncrtc = rep.nCrtcs;
97 xoi->crtcs = (RRCrtc *) (xoi + 1);
98 xoi->nmode = rep.nModes;
99 xoi->npreferred = rep.nPreferred;
100 xoi->modes = (RRMode *) (xoi->crtcs + rep.nCrtcs);
101 xoi->nclone = rep.nClones;
102 xoi->clones = (RROutput *) (xoi->modes + rep.nModes);
103 xoi->name = (char *) (xoi->clones + rep.nClones);
105 _XRead32 (dpy, xoi->crtcs, rep.nCrtcs << 2);
106 _XRead32 (dpy, xoi->modes, rep.nModes << 2);
107 _XRead32 (dpy, xoi->clones, rep.nClones << 2);
110 * Read name and '\0' terminate
112 _XReadPad (dpy, xoi->name, rep.nameLength);
113 xoi->name[rep.nameLength] = '\0';
116 * Skip any extra data
118 if (nbytes > nbytesRead)
119 _XEatData (dpy, (unsigned long) (nbytes - nbytesRead));
123 return (XRROutputInfo *) xoi;
127 XRRFreeOutputInfo (XRROutputInfo *outputInfo)
133 _XRRHasOutputPrimary (int major, int minor)
135 return major > 1 || (major == 1 && minor >= 3);
139 XRRSetOutputPrimary(Display *dpy, Window window, RROutput output)
141 XExtDisplayInfo *info = XRRFindDisplay(dpy);
142 xRRSetOutputPrimaryReq *req;
143 int major_version, minor_version;
145 RRSimpleCheckExtension (dpy, info);
147 if (!XRRQueryVersion (dpy, &major_version, &minor_version) ||
148 !_XRRHasOutputPrimary (major_version, minor_version))
152 GetReq (RRSetOutputPrimary, req);
153 req->reqType = info->codes->major_opcode;
154 req->randrReqType = X_RRSetOutputPrimary;
155 req->window = window;
156 req->output = output;
163 XRRGetOutputPrimary(Display *dpy, Window window)
165 XExtDisplayInfo *info = XRRFindDisplay(dpy);
166 xRRGetOutputPrimaryReq *req;
167 xRRGetOutputPrimaryReply rep;
168 int major_version, minor_version;
170 RRCheckExtension (dpy, info, 0);
172 if (!XRRQueryVersion (dpy, &major_version, &minor_version) ||
173 !_XRRHasOutputPrimary (major_version, minor_version))
177 GetReq (RRGetOutputPrimary, req);
178 req->reqType = info->codes->major_opcode;
179 req->randrReqType = X_RRGetOutputPrimary;
180 req->window = window;
182 if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))