e0ebedd80827b028c0c6af0fbc8a0d5e20a24d9d
1 /*
2 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2010 Red Hat, Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 *
24 * Copyright © 2002 Keith Packard
25 *
26 * Permission to use, copy, modify, distribute, and sell this software and its
27 * documentation for any purpose is hereby granted without fee, provided that
28 * the above copyright notice appear in all copies and that both that
29 * copyright notice and this permission notice appear in supporting
30 * documentation, and that the name of Keith Packard not be used in
31 * advertising or publicity pertaining to distribution of the software without
32 * specific, written prior permission. Keith Packard makes no
33 * representations about the suitability of this software for any purpose. It
34 * is provided "as is" without express or implied warranty.
35 *
36 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
37 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
38 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
39 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
40 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
41 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
42 * PERFORMANCE OF THIS SOFTWARE.
43 */
45 #ifdef HAVE_DIX_CONFIG_H
46 #include <dix-config.h>
47 #endif
49 #include "xfixesint.h"
50 #include "protocol-versions.h"
52 static unsigned char XFixesReqCode;
53 int XFixesEventBase;
54 int XFixesErrorBase;
56 static DevPrivateKeyRec XFixesClientPrivateKeyRec;
57 #define XFixesClientPrivateKey (&XFixesClientPrivateKeyRec)
59 static int
60 ProcXFixesQueryVersion(ClientPtr client)
61 {
62 XFixesClientPtr pXFixesClient = GetXFixesClient (client);
63 xXFixesQueryVersionReply rep;
64 register int n;
65 REQUEST(xXFixesQueryVersionReq);
67 REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
68 memset(&rep, 0, sizeof(xXFixesQueryVersionReply));
69 rep.type = X_Reply;
70 rep.length = 0;
71 rep.sequenceNumber = client->sequence;
73 if (version_compare(stuff->majorVersion, stuff->minorVersion,
74 SERVER_XFIXES_MAJOR_VERSION, SERVER_XFIXES_MAJOR_VERSION) < 0)
75 {
76 rep.majorVersion = stuff->majorVersion;
77 rep.minorVersion = stuff->minorVersion;
78 } else {
79 rep.majorVersion = SERVER_XFIXES_MAJOR_VERSION;
80 rep.minorVersion = SERVER_XFIXES_MINOR_VERSION;
81 }
83 pXFixesClient->major_version = rep.majorVersion;
84 pXFixesClient->minor_version = rep.minorVersion;
85 if (client->swapped) {
86 swaps(&rep.sequenceNumber, n);
87 swapl(&rep.length, n);
88 swapl(&rep.majorVersion, n);
89 swapl(&rep.minorVersion, n);
90 }
91 WriteToClient(client, sizeof(xXFixesQueryVersionReply), (char *)&rep);
92 return Success;
93 }
95 /* Major version controls available requests */
96 static const int version_requests[] = {
97 X_XFixesQueryVersion, /* before client sends QueryVersion */
98 X_XFixesGetCursorImage, /* Version 1 */
99 X_XFixesChangeCursorByName, /* Version 2 */
100 X_XFixesExpandRegion, /* Version 3 */
101 X_XFixesShowCursor, /* Version 4 */
102 X_XFixesDestroyPointerBarrier, /* Version 5 */
103 };
105 #define NUM_VERSION_REQUESTS (sizeof (version_requests) / sizeof (version_requests[0]))
107 int (*ProcXFixesVector[XFixesNumberRequests])(ClientPtr) = {
108 /*************** Version 1 ******************/
109 ProcXFixesQueryVersion,
110 ProcXFixesChangeSaveSet,
111 ProcXFixesSelectSelectionInput,
112 ProcXFixesSelectCursorInput,
113 ProcXFixesGetCursorImage,
114 /*************** Version 2 ******************/
115 ProcXFixesCreateRegion,
116 ProcXFixesCreateRegionFromBitmap,
117 ProcXFixesCreateRegionFromWindow,
118 ProcXFixesCreateRegionFromGC,
119 ProcXFixesCreateRegionFromPicture,
120 ProcXFixesDestroyRegion,
121 ProcXFixesSetRegion,
122 ProcXFixesCopyRegion,
123 ProcXFixesCombineRegion,
124 ProcXFixesCombineRegion,
125 ProcXFixesCombineRegion,
126 ProcXFixesInvertRegion,
127 ProcXFixesTranslateRegion,
128 ProcXFixesRegionExtents,
129 ProcXFixesFetchRegion,
130 ProcXFixesSetGCClipRegion,
131 ProcXFixesSetWindowShapeRegion,
132 ProcXFixesSetPictureClipRegion,
133 ProcXFixesSetCursorName,
134 ProcXFixesGetCursorName,
135 ProcXFixesGetCursorImageAndName,
136 ProcXFixesChangeCursor,
137 ProcXFixesChangeCursorByName,
138 /*************** Version 3 ******************/
139 ProcXFixesExpandRegion,
140 /*************** Version 4 ****************/
141 ProcXFixesHideCursor,
142 ProcXFixesShowCursor,
143 /*************** Version 5 ****************/
144 ProcXFixesCreatePointerBarrier,
145 ProcXFixesDestroyPointerBarrier,
146 };
148 static int
149 ProcXFixesDispatch (ClientPtr client)
150 {
151 REQUEST(xXFixesReq);
152 XFixesClientPtr pXFixesClient = GetXFixesClient (client);
154 if (pXFixesClient->major_version >= NUM_VERSION_REQUESTS)
155 return BadRequest;
156 if (stuff->xfixesReqType > version_requests[pXFixesClient->major_version])
157 return BadRequest;
158 return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
159 }
161 static int
162 SProcXFixesQueryVersion(ClientPtr client)
163 {
164 register int n;
165 REQUEST(xXFixesQueryVersionReq);
167 swaps(&stuff->length, n);
168 swapl(&stuff->majorVersion, n);
169 swapl(&stuff->minorVersion, n);
170 return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
171 }
173 static int (*SProcXFixesVector[XFixesNumberRequests])(ClientPtr) = {
174 /*************** Version 1 ******************/
175 SProcXFixesQueryVersion,
176 SProcXFixesChangeSaveSet,
177 SProcXFixesSelectSelectionInput,
178 SProcXFixesSelectCursorInput,
179 SProcXFixesGetCursorImage,
180 /*************** Version 2 ******************/
181 SProcXFixesCreateRegion,
182 SProcXFixesCreateRegionFromBitmap,
183 SProcXFixesCreateRegionFromWindow,
184 SProcXFixesCreateRegionFromGC,
185 SProcXFixesCreateRegionFromPicture,
186 SProcXFixesDestroyRegion,
187 SProcXFixesSetRegion,
188 SProcXFixesCopyRegion,
189 SProcXFixesCombineRegion,
190 SProcXFixesCombineRegion,
191 SProcXFixesCombineRegion,
192 SProcXFixesInvertRegion,
193 SProcXFixesTranslateRegion,
194 SProcXFixesRegionExtents,
195 SProcXFixesFetchRegion,
196 SProcXFixesSetGCClipRegion,
197 SProcXFixesSetWindowShapeRegion,
198 SProcXFixesSetPictureClipRegion,
199 SProcXFixesSetCursorName,
200 SProcXFixesGetCursorName,
201 SProcXFixesGetCursorImageAndName,
202 SProcXFixesChangeCursor,
203 SProcXFixesChangeCursorByName,
204 /*************** Version 3 ******************/
205 SProcXFixesExpandRegion,
206 /*************** Version 4 ****************/
207 SProcXFixesHideCursor,
208 SProcXFixesShowCursor,
209 /*************** Version 5 ****************/
210 SProcXFixesCreatePointerBarrier,
211 SProcXFixesDestroyPointerBarrier,
212 };
214 static int
215 SProcXFixesDispatch (ClientPtr client)
216 {
217 REQUEST(xXFixesReq);
218 if (stuff->xfixesReqType >= XFixesNumberRequests)
219 return BadRequest;
220 return (*SProcXFixesVector[stuff->xfixesReqType]) (client);
221 }
223 static void
224 XFixesClientCallback (CallbackListPtr *list,
225 pointer closure,
226 pointer data)
227 {
228 NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
229 ClientPtr pClient = clientinfo->client;
230 XFixesClientPtr pXFixesClient = GetXFixesClient (pClient);
232 pXFixesClient->major_version = 0;
233 pXFixesClient->minor_version = 0;
234 }
236 /*ARGSUSED*/
237 static void
238 XFixesResetProc (ExtensionEntry *extEntry)
239 {
240 DeleteCallback (&ClientStateCallback, XFixesClientCallback, 0);
241 }
243 void
244 XFixesExtensionInit(void)
245 {
246 ExtensionEntry *extEntry;
248 if (!dixRegisterPrivateKey(&XFixesClientPrivateKeyRec, PRIVATE_CLIENT, sizeof (XFixesClientRec)))
249 return;
250 if (!AddCallback (&ClientStateCallback, XFixesClientCallback, 0))
251 return;
253 if (XFixesSelectionInit() && XFixesCursorInit () && XFixesRegionInit () &&
254 (extEntry = AddExtension(XFIXES_NAME, XFixesNumberEvents,
255 XFixesNumberErrors,
256 ProcXFixesDispatch, SProcXFixesDispatch,
257 XFixesResetProc, StandardMinorOpcode)) != 0)
258 {
259 XFixesReqCode = (unsigned char)extEntry->base;
260 XFixesEventBase = extEntry->eventBase;
261 XFixesErrorBase = extEntry->errorBase;
262 EventSwapVector[XFixesEventBase + XFixesSelectionNotify] =
263 (EventSwapPtr) SXFixesSelectionNotifyEvent;
264 EventSwapVector[XFixesEventBase + XFixesCursorNotify] =
265 (EventSwapPtr) SXFixesCursorNotifyEvent;
266 SetResourceTypeErrorValue(RegionResType, XFixesErrorBase + BadRegion);
267 SetResourceTypeErrorValue(PointerBarrierType,
268 XFixesErrorBase + BadBarrier);
269 }
270 }
272 #ifdef PANORAMIX
274 int (*PanoramiXSaveXFixesVector[XFixesNumberRequests])(ClientPtr);
276 void
277 PanoramiXFixesInit (void)
278 {
279 int i;
281 for (i = 0; i < XFixesNumberRequests; i++)
282 PanoramiXSaveXFixesVector[i] = ProcXFixesVector[i];
283 /*
284 * Stuff in Xinerama aware request processing hooks
285 */
286 ProcXFixesVector[X_XFixesSetGCClipRegion] = PanoramiXFixesSetGCClipRegion;
287 ProcXFixesVector[X_XFixesSetWindowShapeRegion] = PanoramiXFixesSetWindowShapeRegion;
288 ProcXFixesVector[X_XFixesSetPictureClipRegion] = PanoramiXFixesSetPictureClipRegion;
289 }
291 void
292 PanoramiXFixesReset (void)
293 {
294 int i;
296 for (i = 0; i < XFixesNumberRequests; i++)
297 ProcXFixesVector[i] = PanoramiXSaveXFixesVector[i];
298 }
300 #endif