xfixes.c revision 7e31ba66
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
10835c4bbdfSmrgint (*ProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = {
10905b261ecSmrg/*************** Version 1 ******************/
11005b261ecSmrg    ProcXFixesQueryVersion,
11135c4bbdfSmrg        ProcXFixesChangeSaveSet,
11235c4bbdfSmrg        ProcXFixesSelectSelectionInput,
11335c4bbdfSmrg        ProcXFixesSelectCursorInput, ProcXFixesGetCursorImage,
11405b261ecSmrg/*************** Version 2 ******************/
11535c4bbdfSmrg        ProcXFixesCreateRegion,
11635c4bbdfSmrg        ProcXFixesCreateRegionFromBitmap,
11735c4bbdfSmrg        ProcXFixesCreateRegionFromWindow,
11835c4bbdfSmrg        ProcXFixesCreateRegionFromGC,
11935c4bbdfSmrg        ProcXFixesCreateRegionFromPicture,
12035c4bbdfSmrg        ProcXFixesDestroyRegion,
12135c4bbdfSmrg        ProcXFixesSetRegion,
12235c4bbdfSmrg        ProcXFixesCopyRegion,
12335c4bbdfSmrg        ProcXFixesCombineRegion,
12435c4bbdfSmrg        ProcXFixesCombineRegion,
12535c4bbdfSmrg        ProcXFixesCombineRegion,
12635c4bbdfSmrg        ProcXFixesInvertRegion,
12735c4bbdfSmrg        ProcXFixesTranslateRegion,
12835c4bbdfSmrg        ProcXFixesRegionExtents,
12935c4bbdfSmrg        ProcXFixesFetchRegion,
13035c4bbdfSmrg        ProcXFixesSetGCClipRegion,
13135c4bbdfSmrg        ProcXFixesSetWindowShapeRegion,
13235c4bbdfSmrg        ProcXFixesSetPictureClipRegion,
13335c4bbdfSmrg        ProcXFixesSetCursorName,
13435c4bbdfSmrg        ProcXFixesGetCursorName,
13535c4bbdfSmrg        ProcXFixesGetCursorImageAndName,
13635c4bbdfSmrg        ProcXFixesChangeCursor, ProcXFixesChangeCursorByName,
13705b261ecSmrg/*************** Version 3 ******************/
13835c4bbdfSmrg        ProcXFixesExpandRegion,
13905b261ecSmrg/*************** Version 4 ****************/
14035c4bbdfSmrg        ProcXFixesHideCursor, ProcXFixesShowCursor,
14135c4bbdfSmrg/*************** Version 5 ****************/
14235c4bbdfSmrgProcXFixesCreatePointerBarrier, ProcXFixesDestroyPointerBarrier,};
14305b261ecSmrg
14405b261ecSmrgstatic int
14535c4bbdfSmrgProcXFixesDispatch(ClientPtr client)
14605b261ecSmrg{
14705b261ecSmrg    REQUEST(xXFixesReq);
14835c4bbdfSmrg    XFixesClientPtr pXFixesClient = GetXFixesClient(client);
14905b261ecSmrg
1507e31ba66Smrg    if (pXFixesClient->major_version >= ARRAY_SIZE(version_requests))
15135c4bbdfSmrg        return BadRequest;
15205b261ecSmrg    if (stuff->xfixesReqType > version_requests[pXFixesClient->major_version])
15335c4bbdfSmrg        return BadRequest;
15405b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
15505b261ecSmrg}
15605b261ecSmrg
1577e31ba66Smrgstatic _X_COLD int
15805b261ecSmrgSProcXFixesQueryVersion(ClientPtr client)
15905b261ecSmrg{
16005b261ecSmrg    REQUEST(xXFixesQueryVersionReq);
1616e78d31fSmrg    REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
16205b261ecSmrg
16335c4bbdfSmrg    swaps(&stuff->length);
16435c4bbdfSmrg    swapl(&stuff->majorVersion);
16535c4bbdfSmrg    swapl(&stuff->minorVersion);
16605b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
16705b261ecSmrg}
16805b261ecSmrg
16935c4bbdfSmrgstatic int (*SProcXFixesVector[XFixesNumberRequests]) (ClientPtr) = {
17005b261ecSmrg/*************** Version 1 ******************/
17105b261ecSmrg    SProcXFixesQueryVersion,
17235c4bbdfSmrg        SProcXFixesChangeSaveSet,
17335c4bbdfSmrg        SProcXFixesSelectSelectionInput,
17435c4bbdfSmrg        SProcXFixesSelectCursorInput, SProcXFixesGetCursorImage,
17505b261ecSmrg/*************** Version 2 ******************/
17635c4bbdfSmrg        SProcXFixesCreateRegion,
17735c4bbdfSmrg        SProcXFixesCreateRegionFromBitmap,
17835c4bbdfSmrg        SProcXFixesCreateRegionFromWindow,
17935c4bbdfSmrg        SProcXFixesCreateRegionFromGC,
18035c4bbdfSmrg        SProcXFixesCreateRegionFromPicture,
18135c4bbdfSmrg        SProcXFixesDestroyRegion,
18235c4bbdfSmrg        SProcXFixesSetRegion,
18335c4bbdfSmrg        SProcXFixesCopyRegion,
18435c4bbdfSmrg        SProcXFixesCombineRegion,
18535c4bbdfSmrg        SProcXFixesCombineRegion,
18635c4bbdfSmrg        SProcXFixesCombineRegion,
18735c4bbdfSmrg        SProcXFixesInvertRegion,
18835c4bbdfSmrg        SProcXFixesTranslateRegion,
18935c4bbdfSmrg        SProcXFixesRegionExtents,
19035c4bbdfSmrg        SProcXFixesFetchRegion,
19135c4bbdfSmrg        SProcXFixesSetGCClipRegion,
19235c4bbdfSmrg        SProcXFixesSetWindowShapeRegion,
19335c4bbdfSmrg        SProcXFixesSetPictureClipRegion,
19435c4bbdfSmrg        SProcXFixesSetCursorName,
19535c4bbdfSmrg        SProcXFixesGetCursorName,
19635c4bbdfSmrg        SProcXFixesGetCursorImageAndName,
19735c4bbdfSmrg        SProcXFixesChangeCursor, SProcXFixesChangeCursorByName,
19805b261ecSmrg/*************** Version 3 ******************/
19935c4bbdfSmrg        SProcXFixesExpandRegion,
20005b261ecSmrg/*************** Version 4 ****************/
20135c4bbdfSmrg        SProcXFixesHideCursor, SProcXFixesShowCursor,
20235c4bbdfSmrg/*************** Version 5 ****************/
20335c4bbdfSmrgSProcXFixesCreatePointerBarrier, SProcXFixesDestroyPointerBarrier,};
20405b261ecSmrg
2057e31ba66Smrgstatic _X_COLD int
20635c4bbdfSmrgSProcXFixesDispatch(ClientPtr client)
20705b261ecSmrg{
20805b261ecSmrg    REQUEST(xXFixesReq);
20905b261ecSmrg    if (stuff->xfixesReqType >= XFixesNumberRequests)
21035c4bbdfSmrg        return BadRequest;
21105b261ecSmrg    return (*SProcXFixesVector[stuff->xfixesReqType]) (client);
21205b261ecSmrg}
21305b261ecSmrg
21405b261ecSmrgvoid
21505b261ecSmrgXFixesExtensionInit(void)
21605b261ecSmrg{
21705b261ecSmrg    ExtensionEntry *extEntry;
21805b261ecSmrg
21935c4bbdfSmrg    if (!dixRegisterPrivateKey
22035c4bbdfSmrg        (&XFixesClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XFixesClientRec)))
22135c4bbdfSmrg        return;
22235c4bbdfSmrg
22335c4bbdfSmrg    if (XFixesSelectionInit() && XFixesCursorInit() && XFixesRegionInit() &&
22435c4bbdfSmrg        (extEntry = AddExtension(XFIXES_NAME, XFixesNumberEvents,
22535c4bbdfSmrg                                 XFixesNumberErrors,
22635c4bbdfSmrg                                 ProcXFixesDispatch, SProcXFixesDispatch,
2277e31ba66Smrg                                 NULL, StandardMinorOpcode)) != 0) {
22835c4bbdfSmrg        XFixesReqCode = (unsigned char) extEntry->base;
22935c4bbdfSmrg        XFixesEventBase = extEntry->eventBase;
23035c4bbdfSmrg        XFixesErrorBase = extEntry->errorBase;
23135c4bbdfSmrg        EventSwapVector[XFixesEventBase + XFixesSelectionNotify] =
23235c4bbdfSmrg            (EventSwapPtr) SXFixesSelectionNotifyEvent;
23335c4bbdfSmrg        EventSwapVector[XFixesEventBase + XFixesCursorNotify] =
23435c4bbdfSmrg            (EventSwapPtr) SXFixesCursorNotifyEvent;
23535c4bbdfSmrg        SetResourceTypeErrorValue(RegionResType, XFixesErrorBase + BadRegion);
23635c4bbdfSmrg        SetResourceTypeErrorValue(PointerBarrierType,
23735c4bbdfSmrg                                  XFixesErrorBase + BadBarrier);
23805b261ecSmrg    }
23905b261ecSmrg}
2409ace9065Smrg
2419ace9065Smrg#ifdef PANORAMIX
2429ace9065Smrg
24335c4bbdfSmrgint (*PanoramiXSaveXFixesVector[XFixesNumberRequests]) (ClientPtr);
2449ace9065Smrg
2459ace9065Smrgvoid
24635c4bbdfSmrgPanoramiXFixesInit(void)
2479ace9065Smrg{
2489ace9065Smrg    int i;
2499ace9065Smrg
2509ace9065Smrg    for (i = 0; i < XFixesNumberRequests; i++)
25135c4bbdfSmrg        PanoramiXSaveXFixesVector[i] = ProcXFixesVector[i];
2529ace9065Smrg    /*
2539ace9065Smrg     * Stuff in Xinerama aware request processing hooks
2549ace9065Smrg     */
2559ace9065Smrg    ProcXFixesVector[X_XFixesSetGCClipRegion] = PanoramiXFixesSetGCClipRegion;
25635c4bbdfSmrg    ProcXFixesVector[X_XFixesSetWindowShapeRegion] =
25735c4bbdfSmrg        PanoramiXFixesSetWindowShapeRegion;
25835c4bbdfSmrg    ProcXFixesVector[X_XFixesSetPictureClipRegion] =
25935c4bbdfSmrg        PanoramiXFixesSetPictureClipRegion;
2609ace9065Smrg}
2619ace9065Smrg
2629ace9065Smrgvoid
26335c4bbdfSmrgPanoramiXFixesReset(void)
2649ace9065Smrg{
2659ace9065Smrg    int i;
2669ace9065Smrg
2679ace9065Smrg    for (i = 0; i < XFixesNumberRequests; i++)
26835c4bbdfSmrg        ProcXFixesVector[i] = PanoramiXSaveXFixesVector[i];
2699ace9065Smrg}
2709ace9065Smrg
2719ace9065Smrg#endif
272