summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/X11/extensions/Xrandr.h18
-rw-r--r--src/XrrConfig.c19
-rw-r--r--src/XrrCrtc.c121
-rw-r--r--src/XrrOutput.c7
-rw-r--r--src/XrrScreen.c62
5 files changed, 198 insertions, 29 deletions
diff --git a/include/X11/extensions/Xrandr.h b/include/X11/extensions/Xrandr.h
index 795649a..f56331c 100644
--- a/include/X11/extensions/Xrandr.h
+++ b/include/X11/extensions/Xrandr.h
@@ -195,7 +195,7 @@ Time XRRTimes (Display *dpy, int screen, Time *config_timestamp);
/* Version 1.2 additions */
-void
+Status
XRRGetScreenSizeRange (Display *dpy, Window window,
int *minWidth, int *minHeight,
int *maxWidth, int *maxHeight);
@@ -322,13 +322,15 @@ void
XRRFreeCrtcInfo (XRRCrtcInfo *crtcInfo);
Status
-XRRSetCrtc (Display *dpy,
- XRRScreenResources *resources,
- RRCrtc crtc,
- RRMode mode,
- Rotation rotation,
- RROutput *outputs,
- int noutputs);
+XRRSetCrtcConfig (Display *dpy,
+ XRRScreenResources *resources,
+ RRCrtc crtc,
+ Time timestamp,
+ int x, int y,
+ RRMode mode,
+ Rotation rotation,
+ RROutput *outputs,
+ int noutputs);
int
XRRGetCrtcGammaSize (Display *dpy, RRCrtc crtc);
diff --git a/src/XrrConfig.c b/src/XrrConfig.c
index 443a77b..577ccd6 100644
--- a/src/XrrConfig.c
+++ b/src/XrrConfig.c
@@ -247,7 +247,9 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy, Window window)
DeqAsyncHandler (dpy, &async);
if (async_state.error)
{
- SyncHandle();
+ UnlockDisplay (dpy);
+ SyncHandle();
+ LockDisplay (dpy);
}
xrri->major_version = async_state.major_version;
xrri->minor_version = async_state.minor_version;
@@ -281,7 +283,6 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy, Window window)
scp = (struct _XRRScreenConfiguration *) Xmalloc(rbytes);
if (scp == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
- SyncHandle ();
return NULL;
}
@@ -335,13 +336,13 @@ static XRRScreenConfiguration *_XRRGetScreenInfo (Display *dpy, Window window)
XRRScreenConfiguration *XRRGetScreenInfo (Display *dpy, Window window)
{
- XRRScreenConfiguration *config;
- XRRFindDisplay(dpy);
- LockDisplay (dpy);
- config = _XRRGetScreenInfo(dpy, window);
- UnlockDisplay (dpy);
- SyncHandle ();
- return config;
+ XRRScreenConfiguration *config;
+ XRRFindDisplay(dpy);
+ LockDisplay (dpy);
+ config = _XRRGetScreenInfo(dpy, window);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return config;
}
diff --git a/src/XrrCrtc.c b/src/XrrCrtc.c
index 9d46668..a1372a1 100644
--- a/src/XrrCrtc.c
+++ b/src/XrrCrtc.c
@@ -33,20 +33,123 @@
#include "Xrandrint.h"
XRRCrtcInfo *
-XRRGetCrtcInfo (Display *dpy, XRRScreenResources *resources, RRCrtc crtc);
+XRRGetCrtcInfo (Display *dpy, XRRScreenResources *resources, RRCrtc crtc)
+{
+ XExtDisplayInfo *info = XRRFindDisplay(dpy);
+ xRRGetCrtcInfoReply rep;
+ xRRGetCrtcInfoReq *req;
+ int nbytes, nbytesRead, rbytes;
+ int i;
+ XRRCrtcInfo *xci;
+
+ RRCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (RRGetCrtcInfo, req);
+ req->reqType = info->codes->major_opcode;
+ req->randrReqType = X_RRGetCrtcInfo;
+ req->crtc = crtc;
+ req->configTimestamp = resources->configTimestamp;
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
+ {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ nbytes = (long) rep.length << 2;
+
+ nbytesRead = (long) (rep.nOutput * 4 +
+ rep.nPossibleOutput * 4);
+
+ /*
+ * first we must compute how much space to allocate for
+ * randr library's use; we'll allocate the structures in a single
+ * allocation, on cleanlyness grounds.
+ */
+
+ rbytes = (sizeof (XRRCrtcInfo) +
+ rep.nOutput * sizeof (RROutput) +
+ rep.nPossibleOutput * sizeof (RROutput));
+
+ xci = (XRRCrtcInfo *) Xmalloc(rbytes);
+ if (xci == NULL) {
+ _XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ xci->timestamp = rep.timestamp;
+ xci->x = rep.x;
+ xci->y = rep.y;
+ xci->width = rep.width;
+ xci->height = rep.height;
+ xci->mode = rep.mode;
+ xci->rotation = rep.rotation;
+ xci->noutput = rep.nOutput;
+ xci->outputs = (RROutput *) (xci + 1);
+ xci->npossible = rep.nPossibleOutput;
+ xci->possible = (RROutput *) (xci->outputs + rep.nOutput);
+
+ _XRead32 (dpy, xci->outputs, rep.nOutput << 2);
+ _XRead32 (dpy, xci->possible, rep.nPossibleOutput << 2);
+
+ /*
+ * Skip any extra data
+ */
+ if (nbytes > nbytesRead)
+ _XEatData (dpy, (unsigned long) (nbytes - nbytesRead));
+
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return (XRRCrtcInfo *) xci;
+}
void
-XRRFreeCrtcInfo (XRRCrtcInfo *crtcInfo);
+XRRFreeCrtcInfo (XRRCrtcInfo *crtcInfo)
+{
+ Xfree (crtcInfo);
+}
Status
-XRRSetCrtc (Display *dpy,
- XRRScreenResources *resources,
- RRCrtc crtc,
- RRMode mode,
- Rotation rotation,
- RROutput *outputs,
- int noutputs)
+XRRSetCrtcConfig (Display *dpy,
+ XRRScreenResources *resources,
+ RRCrtc crtc,
+ Time timestamp,
+ int x, int y,
+ RRMode mode,
+ Rotation rotation,
+ RROutput *outputs,
+ int noutputs)
{
+ XExtDisplayInfo *info = XRRFindDisplay(dpy);
+ xRRSetCrtcConfigReply rep;
+ xRRSetCrtcConfigReq *req;
+ int i;
+
+ RRCheckExtension (dpy, info, 0);
+
+ LockDisplay(dpy);
+ GetReq (RRSetCrtcConfig, req);
+ req->reqType = info->codes->major_opcode;
+ req->randrReqType = X_RRSetCrtcConfig;
+ req->length += noutputs;
+ req->crtc = crtc;
+ req->timestamp = timestamp;
+ req->configTimestamp = resources->configTimestamp;
+ req->x = x;
+ req->y = y;
+ req->mode = mode;
+ req->rotation = rotation;
+ Data32 (dpy, outputs, noutputs << 2);
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
+ rep.status = RRSetConfigFailed;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return rep.status;
}
int
diff --git a/src/XrrOutput.c b/src/XrrOutput.c
index f06e329..1c93660 100644
--- a/src/XrrOutput.c
+++ b/src/XrrOutput.c
@@ -45,6 +45,7 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
RRCheckExtension (dpy, info, 0);
+ LockDisplay (dpy);
GetReq (RRGetOutputInfo, req);
req->reqType = info->codes->major_opcode;
req->randrReqType = X_RRGetOutputInfo;
@@ -53,6 +54,7 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
{
+ UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
@@ -79,6 +81,7 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
xoi = (XRROutputInfo *) Xmalloc(rbytes);
if (xoi == NULL) {
_XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
@@ -102,7 +105,7 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
/*
* Read name and '\0' terminate
*/
- _XRead (dpy, xoi->name, rep.nameLength);
+ _XReadPad (dpy, xoi->name, rep.nameLength);
xoi->name[rep.nameLength] = '\0';
/*
@@ -111,6 +114,8 @@ XRRGetOutputInfo (Display *dpy, XRRScreenResources *resources, RROutput output)
if (nbytes > nbytesRead)
_XEatData (dpy, (unsigned long) (nbytes - nbytesRead));
+ UnlockDisplay (dpy);
+ SyncHandle ();
return (XRROutputInfo *) xoi;
}
diff --git a/src/XrrScreen.c b/src/XrrScreen.c
index 53c1dde..1b79c8f 100644
--- a/src/XrrScreen.c
+++ b/src/XrrScreen.c
@@ -51,6 +51,7 @@ XRRGetScreenResources (Display *dpy, Window window)
RRCheckExtension (dpy, info, 0);
+ LockDisplay (dpy);
xrri = (XRandRInfo *) info->data;
if (xrri->major_version == -1)
@@ -81,6 +82,7 @@ XRRGetScreenResources (Display *dpy, Window window)
{
if (getting_version)
DeqAsyncHandler (dpy, &async);
+ UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
@@ -89,7 +91,9 @@ XRRGetScreenResources (Display *dpy, Window window)
DeqAsyncHandler (dpy, &async);
if (async_state.error)
{
- SyncHandle();
+ UnlockDisplay (dpy);
+ SyncHandle();
+ LockDisplay (dpy);
}
xrri->major_version = async_state.major_version;
xrri->minor_version = async_state.minor_version;
@@ -121,6 +125,7 @@ XRRGetScreenResources (Display *dpy, Window window)
if (xrsr) Xfree (xrsr);
if (wire_names) Xfree (wire_names);
_XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay (dpy);
SyncHandle ();
return NULL;
}
@@ -162,7 +167,7 @@ XRRGetScreenResources (Display *dpy, Window window)
/*
* Read names and '\0' pad each one
*/
- _XRead (dpy, wire_names, rep.nbytesNames);
+ _XReadPad (dpy, wire_names, rep.nbytesNames);
wire_name = wire_names;
for (i = 0; i < rep.nModes; i++) {
xrsr->modes[i].name = names;
@@ -179,6 +184,8 @@ XRRGetScreenResources (Display *dpy, Window window)
if (nbytes > nbytesRead)
_XEatData (dpy, (unsigned long) (nbytes - nbytesRead));
+ UnlockDisplay (dpy);
+ SyncHandle();
return (XRRScreenResources *) xrsr;
}
@@ -188,3 +195,54 @@ XRRFreeScreenResources (XRRScreenResources *resources)
Xfree (resources);
}
+Status
+XRRGetScreenSizeRange (Display *dpy, Window window,
+ int *minWidth, int *minHeight,
+ int *maxWidth, int *maxHeight)
+{
+ XExtDisplayInfo *info = XRRFindDisplay(dpy);
+ xRRGetScreenSizeRangeReq *req;
+ xRRGetScreenSizeRangeReply rep;
+
+ RRCheckExtension (dpy, info, 0);
+ LockDisplay (dpy);
+ GetReq (RRGetScreenSizeRange, req);
+ req->reqType = info->codes->major_opcode;
+ req->randrReqType = X_RRGetScreenSizeRange;
+ req->window = window;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
+ {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return False;
+ }
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ *minWidth = rep.minWidth;
+ *minHeight = rep.minHeight;
+ *maxWidth = rep.maxWidth;
+ *maxHeight = rep.maxHeight;
+ return True;
+}
+
+void
+XRRSetScreenSize (Display *dpy, Window window,
+ int width, int height,
+ int mmWidth, int mmHeight)
+{
+ XExtDisplayInfo *info = XRRFindDisplay(dpy);
+ xRRSetScreenSizeReq *req;
+
+ RRSimpleCheckExtension (dpy, info);
+ LockDisplay (dpy);
+ GetReq (RRSetScreenSize, req);
+ req->reqType = info->codes->major_opcode;
+ req->randrReqType = X_RRSetScreenSize;
+ req->window = window;
+ req->width = width;
+ req->height = height;
+ req->widthInMillimeters = mmWidth;
+ req->heightInMillimeters = mmHeight;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+}