summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/X11/extensions/Xrandr.h27
-rw-r--r--src/Makefile.am3
-rw-r--r--src/XrrProvider.c142
3 files changed, 171 insertions, 1 deletions
diff --git a/include/X11/extensions/Xrandr.h b/include/X11/extensions/Xrandr.h
index 6b756a7..8216bd3 100644
--- a/include/X11/extensions/Xrandr.h
+++ b/include/X11/extensions/Xrandr.h
@@ -39,6 +39,8 @@ _XFUNCPROTOBEGIN
typedef XID RROutput;
typedef XID RRCrtc;
typedef XID RRMode;
+typedef XID RRProvider;
+//typedef XID RRProviderScreen;
typedef struct {
int width, height;
@@ -451,6 +453,31 @@ RROutput
XRRGetOutputPrimary(Display *dpy,
Window window);
+typedef struct _XRRProviderResources {
+ Time timestamp;
+ int nproviders;
+ RRProvider *providers;
+} XRRProviderResources;
+
+XRRProviderResources *
+XRRGetProviderResources(Display *dpy, Window window);
+
+void
+XRRFreeProviderResources(XRRProviderResources *resources);
+
+typedef struct _XRRProviderInfo {
+ unsigned int current_role;
+ unsigned int allowed_roles;
+ int ncrtcs;
+ int noutputs;
+} XRRProviderInfo;
+
+XRRProviderInfo *
+XRRGetProviderInfo(Display *dpy, XID provider);
+
+void
+XRRFreeProviderInfo(XRRProviderInfo *provider);
+
_XFUNCPROTOEND
#endif /* _XRANDR_H_ */
diff --git a/src/Makefile.am b/src/Makefile.am
index 85b05da..0c4865d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -8,7 +8,8 @@ libXrandr_la_SOURCES = \
XrrMode.c \
XrrOutput.c \
XrrProperty.c \
- XrrScreen.c
+ XrrScreen.c \
+ XrrProvider.c
libXrandr_la_LIBADD = @RANDR_LIBS@
diff --git a/src/XrrProvider.c b/src/XrrProvider.c
new file mode 100644
index 0000000..5a264ee
--- /dev/null
+++ b/src/XrrProvider.c
@@ -0,0 +1,142 @@
+/*
+ * Copyright © 2011 Dave Airlie
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. The copyright holders make no representations
+ * about the suitability of this software for any purpose. It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <X11/Xlib.h>
+/* we need to be able to manipulate the Display structure on events */
+#include <X11/Xlibint.h>
+#include <X11/extensions/render.h>
+#include <X11/extensions/Xrender.h>
+#include "Xrandrint.h"
+
+XRRProviderResources *
+XRRGetProviderResources(Display *dpy, Window window)
+{
+ XExtDisplayInfo *info = XRRFindDisplay(dpy);
+ xRRGetProvidersReply rep;
+ xRRGetProvidersReq *req;
+ XRRProviderResources *xrpr;
+ long nbytes, nbytesRead;
+ int rbytes;
+
+ RRCheckExtension (dpy, info, NULL);
+
+ LockDisplay (dpy);
+
+ GetReq(RRGetProviders, req);
+ req->reqType = info->codes->major_opcode;
+ req->randrReqType = X_RRGetProviders;
+ req->window = window;
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
+ {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ nbytes = (long) rep.length << 2;
+
+ nbytesRead = (long) (rep.nProviders * 4);
+
+ rbytes = (sizeof(XRRProviderResources) + rep.nProviders * sizeof(RRProvider));
+ xrpr = (XRRProviderResources *) Xmalloc(rbytes);
+
+ if (xrpr == NULL) {
+ _XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ xrpr->timestamp = rep.timestamp;
+ xrpr->nproviders = rep.nProviders;
+
+ xrpr->providers = (RRProvider *)(xrpr + 1);
+
+ _XRead32(dpy, xrpr->providers, rep.nProviders << 2);
+
+ if (nbytes > nbytesRead)
+ _XEatData (dpy, (unsigned long) (nbytes - nbytesRead));
+
+
+ UnlockDisplay (dpy);
+ SyncHandle();
+
+ return (XRRProviderResources *) xrpr;
+}
+
+
+XRRProviderInfo *
+XRRGetProviderInfo(Display *dpy, XID provider)
+{
+ XExtDisplayInfo *info = XRRFindDisplay(dpy);
+ xRRGetProviderInfoReply rep;
+ xRRGetProviderInfoReq *req;
+ int nbytes, nbytesRead, rbytes;
+ XRRProviderInfo *xpi;
+
+ RRCheckExtension (dpy, info, NULL);
+
+ LockDisplay (dpy);
+ GetReq (RRGetProviderInfo, req);
+ req->reqType = info->codes->major_opcode;
+ req->randrReqType = X_RRGetProviderInfo;
+ req->provider = provider;
+
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
+ {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ nbytes = (long) rep.length << 2;
+
+ xpi = (XRRProviderInfo *)Xmalloc(rbytes);
+ if (xpi == NULL) {
+ _XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ xpi->allowed_roles = rep.allowed_roles;
+ xpi->current_role = rep.current_role;
+ xpi->ncrtcs = rep.nCrtcs;
+ xpi->noutputs = rep.nOutputs;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return (XRRProviderInfo *) xpi;
+}
+
+void
+XRRFreeProviderInfo(XRRProviderInfo *provider)
+{
+ free(provider);
+}