| 1 |
/* |
| 2 |
* Copyright © 2006 Keith Packard |
| 3 |
* |
| 4 |
* Permission to use, copy, modify, distribute, and sell this software and its |
| 5 |
* documentation for any purpose is hereby granted without fee, provided that |
| 6 |
* the above copyright notice appear in all copies and that both that copyright |
| 7 |
* notice and this permission notice appear in supporting documentation, and |
| 8 |
* that the name of the copyright holders not be used in advertising or |
| 9 |
* publicity pertaining to distribution of the software without specific, |
| 10 |
* written prior permission. The copyright holders make no representations |
| 11 |
* about the suitability of this software for any purpose. It is provided "as |
| 12 |
* is" without express or implied warranty. |
| 13 |
* |
| 14 |
* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 |
* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 20 |
* OF THIS SOFTWARE. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifdef HAVE_CONFIG_H |
| 24 |
#include <config.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <stdio.h> |
| 28 |
#include <X11/Xlib.h> |
| 29 |
/* we need to be able to manipulate the Display structure on events */ |
| 30 |
#include <X11/Xlibint.h> |
| 31 |
#include <X11/extensions/render.h> |
| 32 |
#include <X11/extensions/Xrender.h> |
| 33 |
#include "Xrandrint.h" |
| 34 |
|
| 35 |
XRRModeInfo * |
| 36 |
XRRAllocModeInfo (_Xconst char *name, int nameLength) |
| 37 |
{ |
| 38 |
XRRModeInfo *mode_info; |
| 39 |
|
| 40 |
mode_info = Xmalloc (sizeof (XRRModeInfo) + nameLength + 1); |
| 41 |
if (!mode_info) |
| 42 |
return NULL; |
| 43 |
memset (mode_info, '\0', sizeof (XRRModeInfo)); |
| 44 |
mode_info->nameLength = nameLength; |
| 45 |
mode_info->name = (char *) (mode_info + 1); |
| 46 |
memcpy (mode_info->name, name, nameLength); |
| 47 |
mode_info->name[nameLength] = '\0'; |
| 48 |
return mode_info; |
| 49 |
} |
| 50 |
|
| 51 |
RRMode |
| 52 |
XRRCreateMode (Display *dpy, Window window, XRRModeInfo *mode_info) |
| 53 |
{ |
| 54 |
XExtDisplayInfo *info = XRRFindDisplay(dpy); |
| 55 |
xRRCreateModeReq *req; |
| 56 |
xRRCreateModeReply rep; |
| 57 |
|
| 58 |
RRCheckExtension (dpy, info, None); |
| 59 |
|
| 60 |
LockDisplay(dpy); |
| 61 |
GetReq (RRCreateMode, req); |
| 62 |
req->reqType = info->codes->major_opcode; |
| 63 |
req->randrReqType = X_RRCreateMode; |
| 64 |
req->length += (mode_info->nameLength + 3) >> 2; |
| 65 |
|
| 66 |
req->window = window; |
| 67 |
|
| 68 |
req->modeInfo.id = 0; |
| 69 |
req->modeInfo.width = mode_info->width; |
| 70 |
req->modeInfo.height = mode_info->height; |
| 71 |
req->modeInfo.dotClock = mode_info->dotClock; |
| 72 |
req->modeInfo.hSyncStart = mode_info->hSyncStart; |
| 73 |
req->modeInfo.hSyncEnd = mode_info->hSyncEnd; |
| 74 |
req->modeInfo.hTotal = mode_info->hTotal; |
| 75 |
req->modeInfo.hSkew = mode_info->hSkew; |
| 76 |
req->modeInfo.vSyncStart = mode_info->vSyncStart; |
| 77 |
req->modeInfo.vSyncEnd = mode_info->vSyncEnd; |
| 78 |
req->modeInfo.vTotal = mode_info->vTotal; |
| 79 |
req->modeInfo.nameLength = mode_info->nameLength; |
| 80 |
req->modeInfo.modeFlags = mode_info->modeFlags; |
| 81 |
|
| 82 |
Data (dpy, mode_info->name, mode_info->nameLength); |
| 83 |
if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) |
| 84 |
{ |
| 85 |
UnlockDisplay (dpy); |
| 86 |
SyncHandle (); |
| 87 |
return None; |
| 88 |
} |
| 89 |
|
| 90 |
UnlockDisplay (dpy); |
| 91 |
SyncHandle (); |
| 92 |
return rep.mode; |
| 93 |
} |
| 94 |
|
| 95 |
void |
| 96 |
XRRDestroyMode (Display *dpy, RRMode mode) |
| 97 |
{ |
| 98 |
XExtDisplayInfo *info = XRRFindDisplay(dpy); |
| 99 |
xRRDestroyModeReq *req; |
| 100 |
RRSimpleCheckExtension (dpy, info); |
| 101 |
|
| 102 |
LockDisplay(dpy); |
| 103 |
GetReq (RRDestroyMode, req); |
| 104 |
req->reqType = info->codes->major_opcode; |
| 105 |
req->randrReqType = X_RRDestroyMode; |
| 106 |
req->mode = mode; |
| 107 |
UnlockDisplay (dpy); |
| 108 |
SyncHandle (); |
| 109 |
} |
| 110 |
|
| 111 |
void |
| 112 |
XRRAddOutputMode (Display *dpy, RROutput output, RRMode mode) |
| 113 |
{ |
| 114 |
XExtDisplayInfo *info = XRRFindDisplay(dpy); |
| 115 |
xRRAddOutputModeReq *req; |
| 116 |
RRSimpleCheckExtension (dpy, info); |
| 117 |
|
| 118 |
LockDisplay(dpy); |
| 119 |
GetReq (RRAddOutputMode, req); |
| 120 |
req->reqType = info->codes->major_opcode; |
| 121 |
req->randrReqType = X_RRAddOutputMode; |
| 122 |
req->output = output; |
| 123 |
req->mode = mode; |
| 124 |
UnlockDisplay (dpy); |
| 125 |
SyncHandle (); |
| 126 |
} |
| 127 |
|
| 128 |
void |
| 129 |
XRRDeleteOutputMode (Display *dpy, RROutput output, RRMode mode) |
| 130 |
{ |
| 131 |
XExtDisplayInfo *info = XRRFindDisplay(dpy); |
| 132 |
xRRDeleteOutputModeReq *req; |
| 133 |
RRSimpleCheckExtension (dpy, info); |
| 134 |
|
| 135 |
LockDisplay(dpy); |
| 136 |
GetReq (RRDeleteOutputMode, req); |
| 137 |
req->reqType = info->codes->major_opcode; |
| 138 |
req->randrReqType = X_RRDeleteOutputMode; |
| 139 |
req->output = output; |
| 140 |
req->mode = mode; |
| 141 |
UnlockDisplay (dpy); |
| 142 |
SyncHandle (); |
| 143 |
} |
| 144 |
|
| 145 |
void |
| 146 |
XRRFreeModeInfo (XRRModeInfo *modeInfo) |
| 147 |
{ |
| 148 |
Xfree (modeInfo); |
| 149 |
} |