xfixes.c revision 6e78d31f
105b261ecSmrg/* 29ace9065Smrg * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved. 335c4bbdfSmrg * Copyright 2010 Red Hat, Inc. 405b261ecSmrg * 56747b715Smrg * Permission is hereby granted, free of charge, to any person obtaining a 66747b715Smrg * copy of this software and associated documentation files (the "Software"), 76747b715Smrg * to deal in the Software without restriction, including without limitation 86747b715Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 96747b715Smrg * and/or sell copies of the Software, and to permit persons to whom the 106747b715Smrg * Software is furnished to do so, subject to the following conditions: 1105b261ecSmrg * 126747b715Smrg * The above copyright notice and this permission notice (including the next 136747b715Smrg * paragraph) shall be included in all copies or substantial portions of the 146747b715Smrg * Software. 156747b715Smrg * 166747b715Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 176747b715Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 186747b715Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 196747b715Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 206747b715Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 216747b715Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 226747b715Smrg * DEALINGS IN THE SOFTWARE. 2305b261ecSmrg * 2405b261ecSmrg * Copyright © 2002 Keith Packard 2505b261ecSmrg * 2605b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its 2705b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that 2805b261ecSmrg * the above copyright notice appear in all copies and that both that 2905b261ecSmrg * copyright notice and this permission notice appear in supporting 3005b261ecSmrg * documentation, and that the name of Keith Packard not be used in 3105b261ecSmrg * advertising or publicity pertaining to distribution of the software without 3205b261ecSmrg * specific, written prior permission. Keith Packard makes no 3305b261ecSmrg * representations about the suitability of this software for any purpose. It 3405b261ecSmrg * is provided "as is" without express or implied warranty. 3505b261ecSmrg * 3605b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 3705b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 3805b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR 3905b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 4005b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 4105b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 4205b261ecSmrg * PERFORMANCE OF THIS SOFTWARE. 4305b261ecSmrg */ 4405b261ecSmrg 4505b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 4605b261ecSmrg#include <dix-config.h> 4705b261ecSmrg#endif 4805b261ecSmrg 4905b261ecSmrg#include "xfixesint.h" 506747b715Smrg#include "protocol-versions.h" 5135c4bbdfSmrg#include "extinit.h" 5205b261ecSmrg 5335c4bbdfSmrgstatic unsigned char XFixesReqCode; 5435c4bbdfSmrgint XFixesEventBase; 5535c4bbdfSmrgint XFixesErrorBase; 564642e01fSmrg 576747b715Smrgstatic DevPrivateKeyRec XFixesClientPrivateKeyRec; 5835c4bbdfSmrg 596747b715Smrg#define XFixesClientPrivateKey (&XFixesClientPrivateKeyRec) 6005b261ecSmrg 6105b261ecSmrgstatic int 6205b261ecSmrgProcXFixesQueryVersion(ClientPtr client) 6305b261ecSmrg{ 6435c4bbdfSmrg XFixesClientPtr pXFixesClient = GetXFixesClient(client); 6535c4bbdfSmrg xXFixesQueryVersionReply rep = { 6635c4bbdfSmrg .type = X_Reply, 6735c4bbdfSmrg .sequenceNumber = client->sequence, 6835c4bbdfSmrg .length = 0 6935c4bbdfSmrg }; 7035c4bbdfSmrg 7105b261ecSmrg REQUEST(xXFixesQueryVersionReq); 7205b261ecSmrg 7305b261ecSmrg REQUEST_SIZE_MATCH(xXFixesQueryVersionReq); 7435c4bbdfSmrg 7535c4bbdfSmrg if (version_compare(stuff->majorVersion, stuff->minorVersion, 7635c4bbdfSmrg SERVER_XFIXES_MAJOR_VERSION, 7735c4bbdfSmrg SERVER_XFIXES_MINOR_VERSION) < 0) { 7835c4bbdfSmrg rep.majorVersion = stuff->majorVersion; 7935c4bbdfSmrg rep.minorVersion = stuff->minorVersion; 8035c4bbdfSmrg } 8135c4bbdfSmrg else { 8235c4bbdfSmrg rep.majorVersion = SERVER_XFIXES_MAJOR_VERSION; 8335c4bbdfSmrg rep.minorVersion = SERVER_XFIXES_MINOR_VERSION; 8405b261ecSmrg } 8535c4bbdfSmrg 8605b261ecSmrg pXFixesClient->major_version = rep.majorVersion; 8705b261ecSmrg pXFixesClient->minor_version = rep.minorVersion; 8805b261ecSmrg if (client->swapped) { 8935c4bbdfSmrg swaps(&rep.sequenceNumber); 9035c4bbdfSmrg swapl(&rep.length); 9135c4bbdfSmrg swapl(&rep.majorVersion); 9235c4bbdfSmrg swapl(&rep.minorVersion); 9305b261ecSmrg } 9435c4bbdfSmrg WriteToClient(client, sizeof(xXFixesQueryVersionReply), &rep); 956747b715Smrg return Success; 9605b261ecSmrg} 9705b261ecSmrg 9805b261ecSmrg/* Major version controls available requests */ 9905b261ecSmrgstatic const int version_requests[] = { 10035c4bbdfSmrg X_XFixesQueryVersion, /* before client sends QueryVersion */ 10135c4bbdfSmrg X_XFixesGetCursorImage, /* Version 1 */ 10235c4bbdfSmrg X_XFixesChangeCursorByName, /* Version 2 */ 10335c4bbdfSmrg X_XFixesExpandRegion, /* Version 3 */ 10435c4bbdfSmrg X_XFixesShowCursor, /* Version 4 */ 10535c4bbdfSmrg X_XFixesDestroyPointerBarrier, /* Version 5 */ 10605b261ecSmrg}; 10705b261ecSmrg 10805b261ecSmrg#define NUM_VERSION_REQUESTS (sizeof (version_requests) / sizeof (version_requests[0])) 10935c4bbdfSmrg 11035c4bbdfSmrgint (*ProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = { 11105b261ecSmrg/*************** Version 1 ******************/ 11205b261ecSmrg ProcXFixesQueryVersion, 11335c4bbdfSmrg ProcXFixesChangeSaveSet, 11435c4bbdfSmrg ProcXFixesSelectSelectionInput, 11535c4bbdfSmrg ProcXFixesSelectCursorInput, ProcXFixesGetCursorImage, 11605b261ecSmrg/*************** Version 2 ******************/ 11735c4bbdfSmrg ProcXFixesCreateRegion, 11835c4bbdfSmrg ProcXFixesCreateRegionFromBitmap, 11935c4bbdfSmrg ProcXFixesCreateRegionFromWindow, 12035c4bbdfSmrg ProcXFixesCreateRegionFromGC, 12135c4bbdfSmrg ProcXFixesCreateRegionFromPicture, 12235c4bbdfSmrg ProcXFixesDestroyRegion, 12335c4bbdfSmrg ProcXFixesSetRegion, 12435c4bbdfSmrg ProcXFixesCopyRegion, 12535c4bbdfSmrg ProcXFixesCombineRegion, 12635c4bbdfSmrg ProcXFixesCombineRegion, 12735c4bbdfSmrg ProcXFixesCombineRegion, 12835c4bbdfSmrg ProcXFixesInvertRegion, 12935c4bbdfSmrg ProcXFixesTranslateRegion, 13035c4bbdfSmrg ProcXFixesRegionExtents, 13135c4bbdfSmrg ProcXFixesFetchRegion, 13235c4bbdfSmrg ProcXFixesSetGCClipRegion, 13335c4bbdfSmrg ProcXFixesSetWindowShapeRegion, 13435c4bbdfSmrg ProcXFixesSetPictureClipRegion, 13535c4bbdfSmrg ProcXFixesSetCursorName, 13635c4bbdfSmrg ProcXFixesGetCursorName, 13735c4bbdfSmrg ProcXFixesGetCursorImageAndName, 13835c4bbdfSmrg ProcXFixesChangeCursor, ProcXFixesChangeCursorByName, 13905b261ecSmrg/*************** Version 3 ******************/ 14035c4bbdfSmrg ProcXFixesExpandRegion, 14105b261ecSmrg/*************** Version 4 ****************/ 14235c4bbdfSmrg ProcXFixesHideCursor, ProcXFixesShowCursor, 14335c4bbdfSmrg/*************** Version 5 ****************/ 14435c4bbdfSmrgProcXFixesCreatePointerBarrier, ProcXFixesDestroyPointerBarrier,}; 14505b261ecSmrg 14605b261ecSmrgstatic int 14735c4bbdfSmrgProcXFixesDispatch(ClientPtr client) 14805b261ecSmrg{ 14905b261ecSmrg REQUEST(xXFixesReq); 15035c4bbdfSmrg XFixesClientPtr pXFixesClient = GetXFixesClient(client); 15105b261ecSmrg 15205b261ecSmrg if (pXFixesClient->major_version >= NUM_VERSION_REQUESTS) 15335c4bbdfSmrg return BadRequest; 15405b261ecSmrg if (stuff->xfixesReqType > version_requests[pXFixesClient->major_version]) 15535c4bbdfSmrg return BadRequest; 15605b261ecSmrg return (*ProcXFixesVector[stuff->xfixesReqType]) (client); 15705b261ecSmrg} 15805b261ecSmrg 15905b261ecSmrgstatic int 16005b261ecSmrgSProcXFixesQueryVersion(ClientPtr client) 16105b261ecSmrg{ 16205b261ecSmrg REQUEST(xXFixesQueryVersionReq); 1636e78d31fSmrg REQUEST_SIZE_MATCH(xXFixesQueryVersionReq); 16405b261ecSmrg 16535c4bbdfSmrg swaps(&stuff->length); 16635c4bbdfSmrg swapl(&stuff->majorVersion); 16735c4bbdfSmrg swapl(&stuff->minorVersion); 16805b261ecSmrg return (*ProcXFixesVector[stuff->xfixesReqType]) (client); 16905b261ecSmrg} 17005b261ecSmrg 17135c4bbdfSmrgstatic int (*SProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = { 17205b261ecSmrg/*************** Version 1 ******************/ 17305b261ecSmrg SProcXFixesQueryVersion, 17435c4bbdfSmrg SProcXFixesChangeSaveSet, 17535c4bbdfSmrg SProcXFixesSelectSelectionInput, 17635c4bbdfSmrg SProcXFixesSelectCursorInput, SProcXFixesGetCursorImage, 17705b261ecSmrg/*************** Version 2 ******************/ 17835c4bbdfSmrg SProcXFixesCreateRegion, 17935c4bbdfSmrg SProcXFixesCreateRegionFromBitmap, 18035c4bbdfSmrg SProcXFixesCreateRegionFromWindow, 18135c4bbdfSmrg SProcXFixesCreateRegionFromGC, 18235c4bbdfSmrg SProcXFixesCreateRegionFromPicture, 18335c4bbdfSmrg SProcXFixesDestroyRegion, 18435c4bbdfSmrg SProcXFixesSetRegion, 18535c4bbdfSmrg SProcXFixesCopyRegion, 18635c4bbdfSmrg SProcXFixesCombineRegion, 18735c4bbdfSmrg SProcXFixesCombineRegion, 18835c4bbdfSmrg SProcXFixesCombineRegion, 18935c4bbdfSmrg SProcXFixesInvertRegion, 19035c4bbdfSmrg SProcXFixesTranslateRegion, 19135c4bbdfSmrg SProcXFixesRegionExtents, 19235c4bbdfSmrg SProcXFixesFetchRegion, 19335c4bbdfSmrg SProcXFixesSetGCClipRegion, 19435c4bbdfSmrg SProcXFixesSetWindowShapeRegion, 19535c4bbdfSmrg SProcXFixesSetPictureClipRegion, 19635c4bbdfSmrg SProcXFixesSetCursorName, 19735c4bbdfSmrg SProcXFixesGetCursorName, 19835c4bbdfSmrg SProcXFixesGetCursorImageAndName, 19935c4bbdfSmrg SProcXFixesChangeCursor, SProcXFixesChangeCursorByName, 20005b261ecSmrg/*************** Version 3 ******************/ 20135c4bbdfSmrg SProcXFixesExpandRegion, 20205b261ecSmrg/*************** Version 4 ****************/ 20335c4bbdfSmrg SProcXFixesHideCursor, SProcXFixesShowCursor, 20435c4bbdfSmrg/*************** Version 5 ****************/ 20535c4bbdfSmrgSProcXFixesCreatePointerBarrier, SProcXFixesDestroyPointerBarrier,}; 20605b261ecSmrg 20705b261ecSmrgstatic int 20835c4bbdfSmrgSProcXFixesDispatch(ClientPtr client) 20905b261ecSmrg{ 21005b261ecSmrg REQUEST(xXFixesReq); 21105b261ecSmrg if (stuff->xfixesReqType >= XFixesNumberRequests) 21235c4bbdfSmrg return BadRequest; 21305b261ecSmrg return (*SProcXFixesVector[stuff->xfixesReqType]) (client); 21405b261ecSmrg} 21505b261ecSmrg 21605b261ecSmrgstatic void 21735c4bbdfSmrgXFixesClientCallback(CallbackListPtr *list, void *closure, void *data) 21805b261ecSmrg{ 21935c4bbdfSmrg NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; 22035c4bbdfSmrg ClientPtr pClient = clientinfo->client; 22135c4bbdfSmrg XFixesClientPtr pXFixesClient = GetXFixesClient(pClient); 22205b261ecSmrg 22305b261ecSmrg pXFixesClient->major_version = 0; 22405b261ecSmrg pXFixesClient->minor_version = 0; 22505b261ecSmrg} 22605b261ecSmrg 22735c4bbdfSmrg /*ARGSUSED*/ static void 22835c4bbdfSmrgXFixesResetProc(ExtensionEntry * extEntry) 22905b261ecSmrg{ 23035c4bbdfSmrg DeleteCallback(&ClientStateCallback, XFixesClientCallback, 0); 23105b261ecSmrg} 23205b261ecSmrg 23305b261ecSmrgvoid 23405b261ecSmrgXFixesExtensionInit(void) 23505b261ecSmrg{ 23605b261ecSmrg ExtensionEntry *extEntry; 23705b261ecSmrg 23835c4bbdfSmrg if (!dixRegisterPrivateKey 23935c4bbdfSmrg (&XFixesClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XFixesClientRec))) 24035c4bbdfSmrg return; 24135c4bbdfSmrg if (!AddCallback(&ClientStateCallback, XFixesClientCallback, 0)) 24235c4bbdfSmrg return; 24335c4bbdfSmrg 24435c4bbdfSmrg if (XFixesSelectionInit() && XFixesCursorInit() && XFixesRegionInit() && 24535c4bbdfSmrg (extEntry = AddExtension(XFIXES_NAME, XFixesNumberEvents, 24635c4bbdfSmrg XFixesNumberErrors, 24735c4bbdfSmrg ProcXFixesDispatch, SProcXFixesDispatch, 24835c4bbdfSmrg XFixesResetProc, StandardMinorOpcode)) != 0) { 24935c4bbdfSmrg XFixesReqCode = (unsigned char) extEntry->base; 25035c4bbdfSmrg XFixesEventBase = extEntry->eventBase; 25135c4bbdfSmrg XFixesErrorBase = extEntry->errorBase; 25235c4bbdfSmrg EventSwapVector[XFixesEventBase + XFixesSelectionNotify] = 25335c4bbdfSmrg (EventSwapPtr) SXFixesSelectionNotifyEvent; 25435c4bbdfSmrg EventSwapVector[XFixesEventBase + XFixesCursorNotify] = 25535c4bbdfSmrg (EventSwapPtr) SXFixesCursorNotifyEvent; 25635c4bbdfSmrg SetResourceTypeErrorValue(RegionResType, XFixesErrorBase + BadRegion); 25735c4bbdfSmrg SetResourceTypeErrorValue(PointerBarrierType, 25835c4bbdfSmrg XFixesErrorBase + BadBarrier); 25905b261ecSmrg } 26005b261ecSmrg} 2619ace9065Smrg 2629ace9065Smrg#ifdef PANORAMIX 2639ace9065Smrg 26435c4bbdfSmrgint (*PanoramiXSaveXFixesVector[XFixesNumberRequests]) (ClientPtr); 2659ace9065Smrg 2669ace9065Smrgvoid 26735c4bbdfSmrgPanoramiXFixesInit(void) 2689ace9065Smrg{ 2699ace9065Smrg int i; 2709ace9065Smrg 2719ace9065Smrg for (i = 0; i < XFixesNumberRequests; i++) 27235c4bbdfSmrg PanoramiXSaveXFixesVector[i] = ProcXFixesVector[i]; 2739ace9065Smrg /* 2749ace9065Smrg * Stuff in Xinerama aware request processing hooks 2759ace9065Smrg */ 2769ace9065Smrg ProcXFixesVector[X_XFixesSetGCClipRegion] = PanoramiXFixesSetGCClipRegion; 27735c4bbdfSmrg ProcXFixesVector[X_XFixesSetWindowShapeRegion] = 27835c4bbdfSmrg PanoramiXFixesSetWindowShapeRegion; 27935c4bbdfSmrg ProcXFixesVector[X_XFixesSetPictureClipRegion] = 28035c4bbdfSmrg PanoramiXFixesSetPictureClipRegion; 2819ace9065Smrg} 2829ace9065Smrg 2839ace9065Smrgvoid 28435c4bbdfSmrgPanoramiXFixesReset(void) 2859ace9065Smrg{ 2869ace9065Smrg int i; 2879ace9065Smrg 2889ace9065Smrg for (i = 0; i < XFixesNumberRequests; i++) 28935c4bbdfSmrg ProcXFixesVector[i] = PanoramiXSaveXFixesVector[i]; 2909ace9065Smrg} 2919ace9065Smrg 2929ace9065Smrg#endif 293