xfixes.c revision 6e78d31f
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 */
44
45#ifdef HAVE_DIX_CONFIG_H
46#include <dix-config.h>
47#endif
48
49#include "xfixesint.h"
50#include "protocol-versions.h"
51#include "extinit.h"
52
53static unsigned char XFixesReqCode;
54int XFixesEventBase;
55int XFixesErrorBase;
56
57static DevPrivateKeyRec XFixesClientPrivateKeyRec;
58
59#define XFixesClientPrivateKey (&XFixesClientPrivateKeyRec)
60
61static int
62ProcXFixesQueryVersion(ClientPtr client)
63{
64    XFixesClientPtr pXFixesClient = GetXFixesClient(client);
65    xXFixesQueryVersionReply rep = {
66        .type = X_Reply,
67        .sequenceNumber = client->sequence,
68        .length = 0
69    };
70
71    REQUEST(xXFixesQueryVersionReq);
72
73    REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
74
75    if (version_compare(stuff->majorVersion, stuff->minorVersion,
76                        SERVER_XFIXES_MAJOR_VERSION,
77                        SERVER_XFIXES_MINOR_VERSION) < 0) {
78        rep.majorVersion = stuff->majorVersion;
79        rep.minorVersion = stuff->minorVersion;
80    }
81    else {
82        rep.majorVersion = SERVER_XFIXES_MAJOR_VERSION;
83        rep.minorVersion = SERVER_XFIXES_MINOR_VERSION;
84    }
85
86    pXFixesClient->major_version = rep.majorVersion;
87    pXFixesClient->minor_version = rep.minorVersion;
88    if (client->swapped) {
89        swaps(&rep.sequenceNumber);
90        swapl(&rep.length);
91        swapl(&rep.majorVersion);
92        swapl(&rep.minorVersion);
93    }
94    WriteToClient(client, sizeof(xXFixesQueryVersionReply), &rep);
95    return Success;
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    X_XFixesDestroyPointerBarrier,      /* Version 5 */
106};
107
108#define NUM_VERSION_REQUESTS	(sizeof (version_requests) / sizeof (version_requests[0]))
109
110int (*ProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = {
111/*************** Version 1 ******************/
112    ProcXFixesQueryVersion,
113        ProcXFixesChangeSaveSet,
114        ProcXFixesSelectSelectionInput,
115        ProcXFixesSelectCursorInput, 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, ProcXFixesChangeCursorByName,
139/*************** Version 3 ******************/
140        ProcXFixesExpandRegion,
141/*************** Version 4 ****************/
142        ProcXFixesHideCursor, ProcXFixesShowCursor,
143/*************** Version 5 ****************/
144ProcXFixesCreatePointerBarrier, ProcXFixesDestroyPointerBarrier,};
145
146static int
147ProcXFixesDispatch(ClientPtr client)
148{
149    REQUEST(xXFixesReq);
150    XFixesClientPtr pXFixesClient = GetXFixesClient(client);
151
152    if (pXFixesClient->major_version >= NUM_VERSION_REQUESTS)
153        return BadRequest;
154    if (stuff->xfixesReqType > version_requests[pXFixesClient->major_version])
155        return BadRequest;
156    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
157}
158
159static int
160SProcXFixesQueryVersion(ClientPtr client)
161{
162    REQUEST(xXFixesQueryVersionReq);
163    REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
164
165    swaps(&stuff->length);
166    swapl(&stuff->majorVersion);
167    swapl(&stuff->minorVersion);
168    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
169}
170
171static int (*SProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = {
172/*************** Version 1 ******************/
173    SProcXFixesQueryVersion,
174        SProcXFixesChangeSaveSet,
175        SProcXFixesSelectSelectionInput,
176        SProcXFixesSelectCursorInput, SProcXFixesGetCursorImage,
177/*************** Version 2 ******************/
178        SProcXFixesCreateRegion,
179        SProcXFixesCreateRegionFromBitmap,
180        SProcXFixesCreateRegionFromWindow,
181        SProcXFixesCreateRegionFromGC,
182        SProcXFixesCreateRegionFromPicture,
183        SProcXFixesDestroyRegion,
184        SProcXFixesSetRegion,
185        SProcXFixesCopyRegion,
186        SProcXFixesCombineRegion,
187        SProcXFixesCombineRegion,
188        SProcXFixesCombineRegion,
189        SProcXFixesInvertRegion,
190        SProcXFixesTranslateRegion,
191        SProcXFixesRegionExtents,
192        SProcXFixesFetchRegion,
193        SProcXFixesSetGCClipRegion,
194        SProcXFixesSetWindowShapeRegion,
195        SProcXFixesSetPictureClipRegion,
196        SProcXFixesSetCursorName,
197        SProcXFixesGetCursorName,
198        SProcXFixesGetCursorImageAndName,
199        SProcXFixesChangeCursor, SProcXFixesChangeCursorByName,
200/*************** Version 3 ******************/
201        SProcXFixesExpandRegion,
202/*************** Version 4 ****************/
203        SProcXFixesHideCursor, SProcXFixesShowCursor,
204/*************** Version 5 ****************/
205SProcXFixesCreatePointerBarrier, SProcXFixesDestroyPointerBarrier,};
206
207static int
208SProcXFixesDispatch(ClientPtr client)
209{
210    REQUEST(xXFixesReq);
211    if (stuff->xfixesReqType >= XFixesNumberRequests)
212        return BadRequest;
213    return (*SProcXFixesVector[stuff->xfixesReqType]) (client);
214}
215
216static void
217XFixesClientCallback(CallbackListPtr *list, void *closure, void *data)
218{
219    NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
220    ClientPtr pClient = clientinfo->client;
221    XFixesClientPtr pXFixesClient = GetXFixesClient(pClient);
222
223    pXFixesClient->major_version = 0;
224    pXFixesClient->minor_version = 0;
225}
226
227 /*ARGSUSED*/ static void
228XFixesResetProc(ExtensionEntry * extEntry)
229{
230    DeleteCallback(&ClientStateCallback, XFixesClientCallback, 0);
231}
232
233void
234XFixesExtensionInit(void)
235{
236    ExtensionEntry *extEntry;
237
238    if (!dixRegisterPrivateKey
239        (&XFixesClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XFixesClientRec)))
240        return;
241    if (!AddCallback(&ClientStateCallback, XFixesClientCallback, 0))
242        return;
243
244    if (XFixesSelectionInit() && XFixesCursorInit() && XFixesRegionInit() &&
245        (extEntry = AddExtension(XFIXES_NAME, XFixesNumberEvents,
246                                 XFixesNumberErrors,
247                                 ProcXFixesDispatch, SProcXFixesDispatch,
248                                 XFixesResetProc, StandardMinorOpcode)) != 0) {
249        XFixesReqCode = (unsigned char) extEntry->base;
250        XFixesEventBase = extEntry->eventBase;
251        XFixesErrorBase = extEntry->errorBase;
252        EventSwapVector[XFixesEventBase + XFixesSelectionNotify] =
253            (EventSwapPtr) SXFixesSelectionNotifyEvent;
254        EventSwapVector[XFixesEventBase + XFixesCursorNotify] =
255            (EventSwapPtr) SXFixesCursorNotifyEvent;
256        SetResourceTypeErrorValue(RegionResType, XFixesErrorBase + BadRegion);
257        SetResourceTypeErrorValue(PointerBarrierType,
258                                  XFixesErrorBase + BadBarrier);
259    }
260}
261
262#ifdef PANORAMIX
263
264int (*PanoramiXSaveXFixesVector[XFixesNumberRequests]) (ClientPtr);
265
266void
267PanoramiXFixesInit(void)
268{
269    int i;
270
271    for (i = 0; i < XFixesNumberRequests; i++)
272        PanoramiXSaveXFixesVector[i] = ProcXFixesVector[i];
273    /*
274     * Stuff in Xinerama aware request processing hooks
275     */
276    ProcXFixesVector[X_XFixesSetGCClipRegion] = PanoramiXFixesSetGCClipRegion;
277    ProcXFixesVector[X_XFixesSetWindowShapeRegion] =
278        PanoramiXFixesSetWindowShapeRegion;
279    ProcXFixesVector[X_XFixesSetPictureClipRegion] =
280        PanoramiXFixesSetPictureClipRegion;
281}
282
283void
284PanoramiXFixesReset(void)
285{
286    int i;
287
288    for (i = 0; i < XFixesNumberRequests; i++)
289        ProcXFixesVector[i] = PanoramiXSaveXFixesVector[i];
290}
291
292#endif
293