xfixes.c revision 6747b715
1/* 2 * Copyright © 2006 Sun Microsystems, Inc. All rights reserved. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 * 23 * Copyright © 2002 Keith Packard 24 * 25 * Permission to use, copy, modify, distribute, and sell this software and its 26 * documentation for any purpose is hereby granted without fee, provided that 27 * the above copyright notice appear in all copies and that both that 28 * copyright notice and this permission notice appear in supporting 29 * documentation, and that the name of Keith Packard not be used in 30 * advertising or publicity pertaining to distribution of the software without 31 * specific, written prior permission. Keith Packard makes no 32 * representations about the suitability of this software for any purpose. It 33 * is provided "as is" without express or implied warranty. 34 * 35 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 36 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 37 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 38 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 39 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 40 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 41 * PERFORMANCE OF THIS SOFTWARE. 42 */ 43 44#ifdef HAVE_DIX_CONFIG_H 45#include <dix-config.h> 46#endif 47 48#include "xfixesint.h" 49#include "protocol-versions.h" 50/* 51 * Must use these instead of the constants from xfixeswire.h. They advertise 52 * what we implement, not what the protocol headers define. 53 */ 54 55static unsigned char XFixesReqCode; 56int XFixesEventBase; 57int XFixesErrorBase; 58 59static DevPrivateKeyRec XFixesClientPrivateKeyRec; 60#define XFixesClientPrivateKey (&XFixesClientPrivateKeyRec) 61 62static int 63ProcXFixesQueryVersion(ClientPtr client) 64{ 65 XFixesClientPtr pXFixesClient = GetXFixesClient (client); 66 xXFixesQueryVersionReply rep; 67 register int n; 68 REQUEST(xXFixesQueryVersionReq); 69 70 REQUEST_SIZE_MATCH(xXFixesQueryVersionReq); 71 memset(&rep, 0, sizeof(xXFixesQueryVersionReply)); 72 rep.type = X_Reply; 73 rep.length = 0; 74 rep.sequenceNumber = client->sequence; 75 if (stuff->majorVersion < SERVER_XFIXES_MAJOR_VERSION) { 76 rep.majorVersion = stuff->majorVersion; 77 rep.minorVersion = stuff->minorVersion; 78 } else { 79 rep.majorVersion = SERVER_XFIXES_MAJOR_VERSION; 80 if (stuff->majorVersion == SERVER_XFIXES_MAJOR_VERSION && 81 stuff->minorVersion < SERVER_XFIXES_MINOR_VERSION) 82 rep.minorVersion = stuff->minorVersion; 83 else 84 rep.minorVersion = SERVER_XFIXES_MINOR_VERSION; 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 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}; 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 (!dixRegisterPrivateKey(&XFixesClientPrivateKeyRec, PRIVATE_CLIENT, 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 SetResourceTypeErrorValue(RegionResType, XFixesErrorBase + BadRegion); 263 } 264} 265