xfixes.c revision 4642e01f
1/*
2 * Copyright © 2006 Sun Microsystems
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
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Sun Microsystems not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission.  Sun Microsystems makes no
11 * representations about the suitability of this software for any purpose.  It
12 * is provided "as is" without express or implied warranty.
13 *
14 * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL SUN MICROSYSTEMS 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
20 * PERFORMANCE OF THIS SOFTWARE.
21 *
22 * Copyright © 2002 Keith Packard
23 *
24 * Permission to use, copy, modify, distribute, and sell this software and its
25 * documentation for any purpose is hereby granted without fee, provided that
26 * the above copyright notice appear in all copies and that both that
27 * copyright notice and this permission notice appear in supporting
28 * documentation, and that the name of Keith Packard not be used in
29 * advertising or publicity pertaining to distribution of the software without
30 * specific, written prior permission.  Keith Packard makes no
31 * representations about the suitability of this software for any purpose.  It
32 * is provided "as is" without express or implied warranty.
33 *
34 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
35 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
36 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
37 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
38 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
39 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
40 * PERFORMANCE OF THIS SOFTWARE.
41 */
42
43#ifdef HAVE_DIX_CONFIG_H
44#include <dix-config.h>
45#endif
46
47#include "xfixesint.h"
48
49/*
50 * Must use these instead of the constants from xfixeswire.h.  They advertise
51 * what we implement, not what the protocol headers define.
52 */
53#define SERVER_XFIXES_MAJOR 4
54#define SERVER_XFIXES_MINOR 0
55
56static unsigned char	XFixesReqCode;
57int		XFixesEventBase;
58int		XFixesErrorBase;
59
60static int XFixesClientPrivateKeyIndex;
61static DevPrivateKey XFixesClientPrivateKey = &XFixesClientPrivateKeyIndex;
62
63static int
64ProcXFixesQueryVersion(ClientPtr client)
65{
66    XFixesClientPtr pXFixesClient = GetXFixesClient (client);
67    xXFixesQueryVersionReply rep;
68    register int n;
69    REQUEST(xXFixesQueryVersionReq);
70
71    REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
72    rep.type = X_Reply;
73    rep.length = 0;
74    rep.sequenceNumber = client->sequence;
75    if (stuff->majorVersion < SERVER_XFIXES_MAJOR) {
76	rep.majorVersion = stuff->majorVersion;
77	rep.minorVersion = stuff->minorVersion;
78    } else {
79	rep.majorVersion = SERVER_XFIXES_MAJOR;
80	if (stuff->majorVersion == SERVER_XFIXES_MAJOR &&
81	    stuff->minorVersion < SERVER_XFIXES_MINOR)
82	    rep.minorVersion = stuff->minorVersion;
83	else
84	    rep.minorVersion = SERVER_XFIXES_MINOR;
85    }
86    pXFixesClient->major_version = rep.majorVersion;
87    pXFixesClient->minor_version = rep.minorVersion;
88    if (client->swapped) {
89    	swaps(&rep.sequenceNumber, n);
90    	swapl(&rep.length, n);
91	swapl(&rep.majorVersion, n);
92	swapl(&rep.minorVersion, n);
93    }
94    WriteToClient(client, sizeof(xXFixesQueryVersionReply), (char *)&rep);
95    return(client->noClientException);
96}
97
98/* Major version controls available requests */
99static const int version_requests[] = {
100    X_XFixesQueryVersion,	/* before client sends QueryVersion */
101    X_XFixesGetCursorImage,	/* Version 1 */
102    X_XFixesChangeCursorByName,	/* Version 2 */
103    X_XFixesExpandRegion,	/* Version 3 */
104    X_XFixesShowCursor,	        /* Version 4 */
105};
106
107#define NUM_VERSION_REQUESTS	(sizeof (version_requests) / sizeof (version_requests[0]))
108
109int	(*ProcXFixesVector[XFixesNumberRequests])(ClientPtr) = {
110/*************** Version 1 ******************/
111    ProcXFixesQueryVersion,
112    ProcXFixesChangeSaveSet,
113    ProcXFixesSelectSelectionInput,
114    ProcXFixesSelectCursorInput,
115    ProcXFixesGetCursorImage,
116/*************** Version 2 ******************/
117    ProcXFixesCreateRegion,
118    ProcXFixesCreateRegionFromBitmap,
119    ProcXFixesCreateRegionFromWindow,
120    ProcXFixesCreateRegionFromGC,
121    ProcXFixesCreateRegionFromPicture,
122    ProcXFixesDestroyRegion,
123    ProcXFixesSetRegion,
124    ProcXFixesCopyRegion,
125    ProcXFixesCombineRegion,
126    ProcXFixesCombineRegion,
127    ProcXFixesCombineRegion,
128    ProcXFixesInvertRegion,
129    ProcXFixesTranslateRegion,
130    ProcXFixesRegionExtents,
131    ProcXFixesFetchRegion,
132    ProcXFixesSetGCClipRegion,
133    ProcXFixesSetWindowShapeRegion,
134    ProcXFixesSetPictureClipRegion,
135    ProcXFixesSetCursorName,
136    ProcXFixesGetCursorName,
137    ProcXFixesGetCursorImageAndName,
138    ProcXFixesChangeCursor,
139    ProcXFixesChangeCursorByName,
140/*************** Version 3 ******************/
141    ProcXFixesExpandRegion,
142/*************** Version 4 ****************/
143    ProcXFixesHideCursor,
144    ProcXFixesShowCursor,
145};
146
147static int
148ProcXFixesDispatch (ClientPtr client)
149{
150    REQUEST(xXFixesReq);
151    XFixesClientPtr pXFixesClient = GetXFixesClient (client);
152
153    if (pXFixesClient->major_version >= NUM_VERSION_REQUESTS)
154	return BadRequest;
155    if (stuff->xfixesReqType > version_requests[pXFixesClient->major_version])
156	return BadRequest;
157    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
158}
159
160static int
161SProcXFixesQueryVersion(ClientPtr client)
162{
163    register int n;
164    REQUEST(xXFixesQueryVersionReq);
165
166    swaps(&stuff->length, n);
167    swapl(&stuff->majorVersion, n);
168    swapl(&stuff->minorVersion, n);
169    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
170}
171
172static int (*SProcXFixesVector[XFixesNumberRequests])(ClientPtr) = {
173/*************** Version 1 ******************/
174    SProcXFixesQueryVersion,
175    SProcXFixesChangeSaveSet,
176    SProcXFixesSelectSelectionInput,
177    SProcXFixesSelectCursorInput,
178    SProcXFixesGetCursorImage,
179/*************** Version 2 ******************/
180    SProcXFixesCreateRegion,
181    SProcXFixesCreateRegionFromBitmap,
182    SProcXFixesCreateRegionFromWindow,
183    SProcXFixesCreateRegionFromGC,
184    SProcXFixesCreateRegionFromPicture,
185    SProcXFixesDestroyRegion,
186    SProcXFixesSetRegion,
187    SProcXFixesCopyRegion,
188    SProcXFixesCombineRegion,
189    SProcXFixesCombineRegion,
190    SProcXFixesCombineRegion,
191    SProcXFixesInvertRegion,
192    SProcXFixesTranslateRegion,
193    SProcXFixesRegionExtents,
194    SProcXFixesFetchRegion,
195    SProcXFixesSetGCClipRegion,
196    SProcXFixesSetWindowShapeRegion,
197    SProcXFixesSetPictureClipRegion,
198    SProcXFixesSetCursorName,
199    SProcXFixesGetCursorName,
200    SProcXFixesGetCursorImageAndName,
201    SProcXFixesChangeCursor,
202    SProcXFixesChangeCursorByName,
203/*************** Version 3 ******************/
204    SProcXFixesExpandRegion,
205/*************** Version 4 ****************/
206    SProcXFixesHideCursor,
207    SProcXFixesShowCursor,
208};
209
210static int
211SProcXFixesDispatch (ClientPtr client)
212{
213    REQUEST(xXFixesReq);
214    if (stuff->xfixesReqType >= XFixesNumberRequests)
215	return BadRequest;
216    return (*SProcXFixesVector[stuff->xfixesReqType]) (client);
217}
218
219static void
220XFixesClientCallback (CallbackListPtr	*list,
221		      pointer		closure,
222		      pointer		data)
223{
224    NewClientInfoRec	*clientinfo = (NewClientInfoRec *) data;
225    ClientPtr		pClient = clientinfo->client;
226    XFixesClientPtr	pXFixesClient = GetXFixesClient (pClient);
227
228    pXFixesClient->major_version = 0;
229    pXFixesClient->minor_version = 0;
230}
231
232/*ARGSUSED*/
233static void
234XFixesResetProc (ExtensionEntry *extEntry)
235{
236    DeleteCallback (&ClientStateCallback, XFixesClientCallback, 0);
237}
238
239void
240XFixesExtensionInit(void)
241{
242    ExtensionEntry *extEntry;
243
244    if (!dixRequestPrivate(XFixesClientPrivateKey, sizeof (XFixesClientRec)))
245	return;
246    if (!AddCallback (&ClientStateCallback, XFixesClientCallback, 0))
247	return;
248
249    if (XFixesSelectionInit() && XFixesCursorInit () && XFixesRegionInit () &&
250	(extEntry = AddExtension(XFIXES_NAME, XFixesNumberEvents,
251				 XFixesNumberErrors,
252				 ProcXFixesDispatch, SProcXFixesDispatch,
253				 XFixesResetProc, StandardMinorOpcode)) != 0)
254    {
255	XFixesReqCode = (unsigned char)extEntry->base;
256	XFixesEventBase = extEntry->eventBase;
257	XFixesErrorBase = extEntry->errorBase;
258	EventSwapVector[XFixesEventBase + XFixesSelectionNotify] =
259	    (EventSwapPtr) SXFixesSelectionNotifyEvent;
260	EventSwapVector[XFixesEventBase + XFixesCursorNotify] =
261	    (EventSwapPtr) SXFixesCursorNotifyEvent;
262    }
263}
264