os: Add CryptoAPI as a choice of SHA1 implementation
[xserver/hramrach.git] / randr / rrdispatch.c
blob85cf0373888bc7b581965f573aaa6ceb54bbe31c
1 /*
2 * Copyright © 2006 Keith Packard
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.
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.
23 #include "randrstr.h"
24 #include "protocol-versions.h"
26 Bool
27 RRClientKnowsRates(ClientPtr pClient)
29 rrClientPriv(pClient);
31 return version_compare(pRRClient->major_version, pRRClient->minor_version,
32 1, 1) >= 0;
35 static int
36 ProcRRQueryVersion(ClientPtr client)
38 xRRQueryVersionReply rep = { 0 };
39 REQUEST(xRRQueryVersionReq);
40 rrClientPriv(client);
42 REQUEST_SIZE_MATCH(xRRQueryVersionReq);
43 pRRClient->major_version = stuff->majorVersion;
44 pRRClient->minor_version = stuff->minorVersion;
45 rep.type = X_Reply;
46 rep.length = 0;
47 rep.sequenceNumber = client->sequence;
49 if (version_compare(stuff->majorVersion, stuff->minorVersion,
50 SERVER_RANDR_MAJOR_VERSION,
51 SERVER_RANDR_MINOR_VERSION) < 0) {
52 rep.majorVersion = stuff->majorVersion;
53 rep.minorVersion = stuff->minorVersion;
55 else {
56 rep.majorVersion = SERVER_RANDR_MAJOR_VERSION;
57 rep.minorVersion = SERVER_RANDR_MINOR_VERSION;
60 if (client->swapped) {
61 swaps(&rep.sequenceNumber);
62 swapl(&rep.length);
63 swapl(&rep.majorVersion);
64 swapl(&rep.minorVersion);
66 WriteToClient(client, sizeof(xRRQueryVersionReply), (char *) &rep);
67 return Success;
70 static int
71 ProcRRSelectInput(ClientPtr client)
73 REQUEST(xRRSelectInputReq);
74 rrClientPriv(client);
75 RRTimesPtr pTimes;
76 WindowPtr pWin;
77 RREventPtr pRREvent, *pHead;
78 XID clientResource;
79 int rc;
81 REQUEST_SIZE_MATCH(xRRSelectInputReq);
82 rc = dixLookupWindow(&pWin, stuff->window, client, DixReceiveAccess);
83 if (rc != Success)
84 return rc;
85 rc = dixLookupResourceByType((pointer *) &pHead, pWin->drawable.id,
86 RREventType, client, DixWriteAccess);
87 if (rc != Success && rc != BadValue)
88 return rc;
90 if (stuff->enable & (RRScreenChangeNotifyMask |
91 RRCrtcChangeNotifyMask |
92 RROutputChangeNotifyMask |
93 RROutputPropertyNotifyMask)) {
94 ScreenPtr pScreen = pWin->drawable.pScreen;
96 rrScrPriv(pScreen);
98 pRREvent = NULL;
99 if (pHead) {
100 /* check for existing entry. */
101 for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next)
102 if (pRREvent->client == client)
103 break;
106 if (!pRREvent) {
107 /* build the entry */
108 pRREvent = (RREventPtr) malloc(sizeof(RREventRec));
109 if (!pRREvent)
110 return BadAlloc;
111 pRREvent->next = 0;
112 pRREvent->client = client;
113 pRREvent->window = pWin;
114 pRREvent->mask = stuff->enable;
116 * add a resource that will be deleted when
117 * the client goes away
119 clientResource = FakeClientID(client->index);
120 pRREvent->clientResource = clientResource;
121 if (!AddResource(clientResource, RRClientType, (pointer) pRREvent))
122 return BadAlloc;
124 * create a resource to contain a pointer to the list
125 * of clients selecting input. This must be indirect as
126 * the list may be arbitrarily rearranged which cannot be
127 * done through the resource database.
129 if (!pHead) {
130 pHead = (RREventPtr *) malloc(sizeof(RREventPtr));
131 if (!pHead ||
132 !AddResource(pWin->drawable.id, RREventType,
133 (pointer) pHead)) {
134 FreeResource(clientResource, RT_NONE);
135 return BadAlloc;
137 *pHead = 0;
139 pRREvent->next = *pHead;
140 *pHead = pRREvent;
143 * Now see if the client needs an event
145 if (pScrPriv) {
146 pTimes = &((RRTimesPtr) (pRRClient + 1))[pScreen->myNum];
147 if (CompareTimeStamps(pTimes->setTime,
148 pScrPriv->lastSetTime) != 0 ||
149 CompareTimeStamps(pTimes->configTime,
150 pScrPriv->lastConfigTime) != 0) {
151 if (pRREvent->mask & RRScreenChangeNotifyMask) {
152 RRDeliverScreenEvent(client, pWin, pScreen);
155 if (pRREvent->mask & RRCrtcChangeNotifyMask) {
156 int i;
158 for (i = 0; i < pScrPriv->numCrtcs; i++) {
159 RRDeliverCrtcEvent(client, pWin, pScrPriv->crtcs[i]);
163 if (pRREvent->mask & RROutputChangeNotifyMask) {
164 int i;
166 for (i = 0; i < pScrPriv->numOutputs; i++) {
167 RRDeliverOutputEvent(client, pWin,
168 pScrPriv->outputs[i]);
172 /* We don't check for RROutputPropertyNotifyMask, as randrproto.txt doesn't
173 * say if there ought to be notifications of changes to output properties
174 * if those changes occurred before the time RRSelectInput is called.
179 else if (stuff->enable == 0) {
180 /* delete the interest */
181 if (pHead) {
182 RREventPtr pNewRREvent = 0;
184 for (pRREvent = *pHead; pRREvent; pRREvent = pRREvent->next) {
185 if (pRREvent->client == client)
186 break;
187 pNewRREvent = pRREvent;
189 if (pRREvent) {
190 FreeResource(pRREvent->clientResource, RRClientType);
191 if (pNewRREvent)
192 pNewRREvent->next = pRREvent->next;
193 else
194 *pHead = pRREvent->next;
195 free(pRREvent);
199 else {
200 client->errorValue = stuff->enable;
201 return BadValue;
203 return Success;
206 int (*ProcRandrVector[RRNumberRequests]) (ClientPtr) = {
207 ProcRRQueryVersion, /* 0 */
208 /* we skip 1 to make old clients fail pretty immediately */
209 NULL, /* 1 ProcRandrOldGetScreenInfo */
210 /* V1.0 apps share the same set screen config request id */
211 ProcRRSetScreenConfig, /* 2 */
212 NULL, /* 3 ProcRandrOldScreenChangeSelectInput */
213 /* 3 used to be ScreenChangeSelectInput; deprecated */
214 ProcRRSelectInput, /* 4 */
215 ProcRRGetScreenInfo, /* 5 */
216 /* V1.2 additions */
217 ProcRRGetScreenSizeRange, /* 6 */
218 ProcRRSetScreenSize, /* 7 */
219 ProcRRGetScreenResources, /* 8 */
220 ProcRRGetOutputInfo, /* 9 */
221 ProcRRListOutputProperties, /* 10 */
222 ProcRRQueryOutputProperty, /* 11 */
223 ProcRRConfigureOutputProperty, /* 12 */
224 ProcRRChangeOutputProperty, /* 13 */
225 ProcRRDeleteOutputProperty, /* 14 */
226 ProcRRGetOutputProperty, /* 15 */
227 ProcRRCreateMode, /* 16 */
228 ProcRRDestroyMode, /* 17 */
229 ProcRRAddOutputMode, /* 18 */
230 ProcRRDeleteOutputMode, /* 19 */
231 ProcRRGetCrtcInfo, /* 20 */
232 ProcRRSetCrtcConfig, /* 21 */
233 ProcRRGetCrtcGammaSize, /* 22 */
234 ProcRRGetCrtcGamma, /* 23 */
235 ProcRRSetCrtcGamma, /* 24 */
236 /* V1.3 additions */
237 ProcRRGetScreenResourcesCurrent, /* 25 */
238 ProcRRSetCrtcTransform, /* 26 */
239 ProcRRGetCrtcTransform, /* 27 */
240 ProcRRGetPanning, /* 28 */
241 ProcRRSetPanning, /* 29 */
242 ProcRRSetOutputPrimary, /* 30 */
243 ProcRRGetOutputPrimary, /* 31 */