#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xlibint.h>
#include <X11/extensions/render.h>
#include <X11/extensions/Xrender.h>
#include "Xrandrint.h"
#define OutputInfoExtra (SIZEOF(xRRGetOutputInfoReply) - 32)
XRROutputInfo *
XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
{
XExtDisplayInfo *info = XRRFindDisplay(dpy);
xRRGetOutputInfoReply rep;
xRRGetOutputInfoReq *req;
int nbytes, nbytesRead, rbytes;
int i;
xRRQueryVersionReq *vreq;
XRROutputInfo *xoi;
RRCheckExtension (dpy, info, 0);
LockDisplay (dpy);
GetReq (RRGetOutputInfo, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRGetOutputInfo;
req->output = output;
req->configTimestamp = resources->configTimestamp;
if (!_XReply (dpy, (xReply *) &rep, OutputInfoExtra >> 2, xFalse))
{
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
nbytes = ((long) (rep.length) << 2) - OutputInfoExtra;
nbytesRead = (long) (rep.nCrtcs * 4 +
rep.nModes * 4 +
rep.nClones * 4 +
((rep.nameLength + 3) & ~3));
rbytes = (sizeof (XRROutputInfo) +
rep.nCrtcs * sizeof (RRCrtc) +
rep.nModes * sizeof (RRMode) +
rep.nClones * sizeof (RROutput) +
rep.nameLength + 1);
xoi = (XRROutputInfo *) Xmalloc(rbytes);
if (xoi == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
xoi->timestamp = rep.timestamp;
xoi->crtc = rep.crtc;
xoi->mm_width = rep.mmWidth;
xoi->mm_height = rep.mmHeight;
xoi->connection = rep.connection;
xoi->subpixel_order = rep.subpixelOrder;
xoi->ncrtc = rep.nCrtcs;
xoi->crtcs = (RRCrtc *) (xoi + 1);
xoi->nmode = rep.nModes;
xoi->npreferred = rep.nPreferred;
xoi->modes = (RRMode *) (xoi->crtcs + rep.nCrtcs);
xoi->nclone = rep.nClones;
xoi->clones = (RROutput *) (xoi->modes + rep.nModes);
xoi->name = (char *) (xoi->clones + rep.nClones);
_XRead32 (dpy, xoi->crtcs, rep.nCrtcs << 2);
_XRead32 (dpy, xoi->modes, rep.nModes << 2);
_XRead32 (dpy, xoi->clones, rep.nClones << 2);
_XReadPad (dpy, xoi->name, rep.nameLength);
xoi->name[rep.nameLength] = '\0';
if (nbytes > nbytesRead)
_XEatData (dpy, (unsigned long) (nbytes - nbytesRead));
UnlockDisplay (dpy);
SyncHandle ();
return (XRROutputInfo *) xoi;
}
void
XRRFreeOutputInfo (XRROutputInfo *outputInfo)
{
Xfree (outputInfo);
}