xfixes.c revision 48a68b89
1/* 2 * Copyright (c) 2006, Oracle and/or its affiliates. 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 REQUEST_SIZE_MATCH(xXFixesQueryVersionReq); 166 167 swaps(&stuff->length, n); 168 swapl(&stuff->majorVersion, n); 169 swapl(&stuff->minorVersion, n); 170 return (*ProcXFixesVector[stuff->xfixesReqType]) (client); 171} 172 173static 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}; 210 211static int 212SProcXFixesDispatch (ClientPtr client) 213{ 214 REQUEST(xXFixesReq); 215 if (stuff->xfixesReqType >= XFixesNumberRequests) 216 return BadRequest; 217 return (*SProcXFixesVector[stuff->xfixesReqType]) (client); 218} 219 220static void 221XFixesClientCallback (CallbackListPtr *list, 222 pointer closure, 223 pointer data) 224{ 225 NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; 226 ClientPtr pClient = clientinfo->client; 227 XFixesClientPtr pXFixesClient = GetXFixesClient (pClient); 228 229 pXFixesClient->major_version = 0; 230 pXFixesClient->minor_version = 0; 231} 232 233/*ARGSUSED*/ 234static void 235XFixesResetProc (ExtensionEntry *extEntry) 236{ 237 DeleteCallback (&ClientStateCallback, XFixesClientCallback, 0); 238} 239 240void 241XFixesExtensionInit(void) 242{ 243 ExtensionEntry *extEntry; 244 245 if (!dixRegisterPrivateKey(&XFixesClientPrivateKeyRec, PRIVATE_CLIENT, sizeof (XFixesClientRec))) 246 return; 247 if (!AddCallback (&ClientStateCallback, XFixesClientCallback, 0)) 248 return; 249 250 if (XFixesSelectionInit() && XFixesCursorInit () && XFixesRegionInit () && 251 (extEntry = AddExtension(XFIXES_NAME, XFixesNumberEvents, 252 XFixesNumberErrors, 253 ProcXFixesDispatch, SProcXFixesDispatch, 254 XFixesResetProc, StandardMinorOpcode)) != 0) 255 { 256 XFixesReqCode = (unsigned char)extEntry->base; 257 XFixesEventBase = extEntry->eventBase; 258 XFixesErrorBase = extEntry->errorBase; 259 EventSwapVector[XFixesEventBase + XFixesSelectionNotify] = 260 (EventSwapPtr) SXFixesSelectionNotifyEvent; 261 EventSwapVector[XFixesEventBase + XFixesCursorNotify] = 262 (EventSwapPtr) SXFixesCursorNotifyEvent; 263 SetResourceTypeErrorValue(RegionResType, XFixesErrorBase + BadRegion); 264 } 265} 266 267#ifdef PANORAMIX 268 269int (*PanoramiXSaveXFixesVector[XFixesNumberRequests])(ClientPtr); 270 271void 272PanoramiXFixesInit (void) 273{ 274 int i; 275 276 for (i = 0; i < XFixesNumberRequests; i++) 277 PanoramiXSaveXFixesVector[i] = ProcXFixesVector[i]; 278 /* 279 * Stuff in Xinerama aware request processing hooks 280 */ 281 ProcXFixesVector[X_XFixesSetGCClipRegion] = PanoramiXFixesSetGCClipRegion; 282 ProcXFixesVector[X_XFixesSetWindowShapeRegion] = PanoramiXFixesSetWindowShapeRegion; 283 ProcXFixesVector[X_XFixesSetPictureClipRegion] = PanoramiXFixesSetPictureClipRegion; 284} 285 286void 287PanoramiXFixesReset (void) 288{ 289 int i; 290 291 for (i = 0; i < XFixesNumberRequests; i++) 292 ProcXFixesVector[i] = PanoramiXSaveXFixesVector[i]; 293} 294 295#endif 296