From 59c8812099f33d56b43044f999ffe5df16adf5ff Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Mon, 8 Dec 2008 15:37:53 -0500 Subject: Add [GS]etOutputPrimary --- include/X11/extensions/Xrandr.h | 10 +++++++ src/XrrOutput.c | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/include/X11/extensions/Xrandr.h b/include/X11/extensions/Xrandr.h index 80d9d47..a411321 100644 --- a/include/X11/extensions/Xrandr.h +++ b/include/X11/extensions/Xrandr.h @@ -2,6 +2,7 @@ * Copyright © 2000 Compaq Computer Corporation, Inc. * Copyright © 2002 Hewlett-Packard Company, Inc. * Copyright © 2006 Intel Corporation + * Copyright © 2008 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -440,6 +441,15 @@ XRRSetPanning (Display *dpy, RRCrtc crtc, XRRPanning *panning); +void +XRRSetOutputPrimary(Display *dpy, + Window window, + RROutput output); + +RROutput +XRRGetOutputPrimary(Display *dpy, + Window window); + _XFUNCPROTOEND #endif /* _XRANDR_H_ */ diff --git a/src/XrrOutput.c b/src/XrrOutput.c index 1fe03ae..bc35fd1 100644 --- a/src/XrrOutput.c +++ b/src/XrrOutput.c @@ -1,5 +1,6 @@ /* * Copyright © 2006 Keith Packard + * Copyright © 2008 Red Hat, Inc. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -129,3 +130,64 @@ XRRFreeOutputInfo (XRROutputInfo *outputInfo) { Xfree (outputInfo); } + +static Bool +_XRRHasOutputPrimary (int major, int minor) +{ + return major > 1 || (major == 1 && minor >= 3); +} + +void +XRRSetOutputPrimary(Display *dpy, Window window, RROutput output) +{ + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRSetOutputPrimaryReq *req; + int i; + int major_version, minor_version; + + RRCheckExtension (dpy, info, 0); + + if (!XRRQueryVersion (dpy, &major_version, &minor_version) || + !_XRRHasOutputPrimary (major_version, minor_version)) + return; + + LockDisplay(dpy); + GetReq (RRSetOutputPrimary, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRSetOutputPrimary; + req->window = window; + req->output = output; + + UnlockDisplay (dpy); + SyncHandle (); +} + +RROutput +XRRGetOutputPrimary(Display *dpy, Window window) +{ + XExtDisplayInfo *info = XRRFindDisplay(dpy); + xRRGetOutputPrimaryReq *req; + xRRGetOutputPrimaryReply rep; + int i; + int major_version, minor_version; + + RRCheckExtension (dpy, info, 0); + + if (!XRRQueryVersion (dpy, &major_version, &minor_version) || + !_XRRHasOutputPrimary (major_version, minor_version)) + return None; + + LockDisplay(dpy); + GetReq (RRSetOutputPrimary, req); + req->reqType = info->codes->major_opcode; + req->randrReqType = X_RRGetOutputProperty; + req->window = window; + + if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) + rep.output = None; + + UnlockDisplay(dpy); + SyncHandle(); + + return rep.output; +} -- cgit v1.2.1