xfixes.c revision 05b261ec
105b261ecSmrg/*
205b261ecSmrg * Copyright © 2006 Sun Microsystems
305b261ecSmrg *
405b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its
505b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that
605b261ecSmrg * the above copyright notice appear in all copies and that both that
705b261ecSmrg * copyright notice and this permission notice appear in supporting
805b261ecSmrg * documentation, and that the name of Sun Microsystems not be used in
905b261ecSmrg * advertising or publicity pertaining to distribution of the software without
1005b261ecSmrg * specific, written prior permission.  Sun Microsystems makes no
1105b261ecSmrg * representations about the suitability of this software for any purpose.  It
1205b261ecSmrg * is provided "as is" without express or implied warranty.
1305b261ecSmrg *
1405b261ecSmrg * SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1505b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
1605b261ecSmrg * EVENT SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1705b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
1805b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
1905b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
2005b261ecSmrg * PERFORMANCE OF THIS SOFTWARE.
2105b261ecSmrg *
2205b261ecSmrg * Copyright © 2002 Keith Packard
2305b261ecSmrg *
2405b261ecSmrg * Permission to use, copy, modify, distribute, and sell this software and its
2505b261ecSmrg * documentation for any purpose is hereby granted without fee, provided that
2605b261ecSmrg * the above copyright notice appear in all copies and that both that
2705b261ecSmrg * copyright notice and this permission notice appear in supporting
2805b261ecSmrg * documentation, and that the name of Keith Packard not be used in
2905b261ecSmrg * advertising or publicity pertaining to distribution of the software without
3005b261ecSmrg * specific, written prior permission.  Keith Packard makes no
3105b261ecSmrg * representations about the suitability of this software for any purpose.  It
3205b261ecSmrg * is provided "as is" without express or implied warranty.
3305b261ecSmrg *
3405b261ecSmrg * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
3505b261ecSmrg * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
3605b261ecSmrg * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
3705b261ecSmrg * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
3805b261ecSmrg * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
3905b261ecSmrg * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4005b261ecSmrg * PERFORMANCE OF THIS SOFTWARE.
4105b261ecSmrg */
4205b261ecSmrg
4305b261ecSmrg#ifdef HAVE_DIX_CONFIG_H
4405b261ecSmrg#include <dix-config.h>
4505b261ecSmrg#endif
4605b261ecSmrg
4705b261ecSmrg#include "xfixesint.h"
4805b261ecSmrg
4905b261ecSmrg/*
5005b261ecSmrg * Must use these instead of the constants from xfixeswire.h.  They advertise
5105b261ecSmrg * what we implement, not what the protocol headers define.
5205b261ecSmrg */
5305b261ecSmrg#define SERVER_XFIXES_MAJOR 4
5405b261ecSmrg#define SERVER_XFIXES_MINOR 0
5505b261ecSmrg
5605b261ecSmrgstatic unsigned char	XFixesReqCode;
5705b261ecSmrgint		XFixesEventBase;
5805b261ecSmrgint		XFixesErrorBase;
5905b261ecSmrgstatic int	XFixesClientPrivateIndex;
6005b261ecSmrg
6105b261ecSmrgstatic int
6205b261ecSmrgProcXFixesQueryVersion(ClientPtr client)
6305b261ecSmrg{
6405b261ecSmrg    XFixesClientPtr pXFixesClient = GetXFixesClient (client);
6505b261ecSmrg    xXFixesQueryVersionReply rep;
6605b261ecSmrg    register int n;
6705b261ecSmrg    REQUEST(xXFixesQueryVersionReq);
6805b261ecSmrg
6905b261ecSmrg    REQUEST_SIZE_MATCH(xXFixesQueryVersionReq);
7005b261ecSmrg    rep.type = X_Reply;
7105b261ecSmrg    rep.length = 0;
7205b261ecSmrg    rep.sequenceNumber = client->sequence;
7305b261ecSmrg    if (stuff->majorVersion < SERVER_XFIXES_MAJOR) {
7405b261ecSmrg	rep.majorVersion = stuff->majorVersion;
7505b261ecSmrg	rep.minorVersion = stuff->minorVersion;
7605b261ecSmrg    } else {
7705b261ecSmrg	rep.majorVersion = SERVER_XFIXES_MAJOR;
7805b261ecSmrg	if (stuff->majorVersion == SERVER_XFIXES_MAJOR &&
7905b261ecSmrg	    stuff->minorVersion < SERVER_XFIXES_MINOR)
8005b261ecSmrg	    rep.minorVersion = stuff->minorVersion;
8105b261ecSmrg	else
8205b261ecSmrg	    rep.minorVersion = SERVER_XFIXES_MINOR;
8305b261ecSmrg    }
8405b261ecSmrg    pXFixesClient->major_version = rep.majorVersion;
8505b261ecSmrg    pXFixesClient->minor_version = rep.minorVersion;
8605b261ecSmrg    if (client->swapped) {
8705b261ecSmrg    	swaps(&rep.sequenceNumber, n);
8805b261ecSmrg    	swapl(&rep.length, n);
8905b261ecSmrg	swapl(&rep.majorVersion, n);
9005b261ecSmrg	swapl(&rep.minorVersion, n);
9105b261ecSmrg    }
9205b261ecSmrg    WriteToClient(client, sizeof(xXFixesQueryVersionReply), (char *)&rep);
9305b261ecSmrg    return(client->noClientException);
9405b261ecSmrg}
9505b261ecSmrg
9605b261ecSmrg/* Major version controls available requests */
9705b261ecSmrgstatic const int version_requests[] = {
9805b261ecSmrg    X_XFixesQueryVersion,	/* before client sends QueryVersion */
9905b261ecSmrg    X_XFixesGetCursorImage,	/* Version 1 */
10005b261ecSmrg    X_XFixesChangeCursorByName,	/* Version 2 */
10105b261ecSmrg    X_XFixesExpandRegion,	/* Version 3 */
10205b261ecSmrg    X_XFixesShowCursor,	        /* Version 4 */
10305b261ecSmrg};
10405b261ecSmrg
10505b261ecSmrg#define NUM_VERSION_REQUESTS	(sizeof (version_requests) / sizeof (version_requests[0]))
10605b261ecSmrg
10705b261ecSmrgint	(*ProcXFixesVector[XFixesNumberRequests])(ClientPtr) = {
10805b261ecSmrg/*************** Version 1 ******************/
10905b261ecSmrg    ProcXFixesQueryVersion,
11005b261ecSmrg    ProcXFixesChangeSaveSet,
11105b261ecSmrg    ProcXFixesSelectSelectionInput,
11205b261ecSmrg    ProcXFixesSelectCursorInput,
11305b261ecSmrg    ProcXFixesGetCursorImage,
11405b261ecSmrg/*************** Version 2 ******************/
11505b261ecSmrg    ProcXFixesCreateRegion,
11605b261ecSmrg    ProcXFixesCreateRegionFromBitmap,
11705b261ecSmrg    ProcXFixesCreateRegionFromWindow,
11805b261ecSmrg    ProcXFixesCreateRegionFromGC,
11905b261ecSmrg    ProcXFixesCreateRegionFromPicture,
12005b261ecSmrg    ProcXFixesDestroyRegion,
12105b261ecSmrg    ProcXFixesSetRegion,
12205b261ecSmrg    ProcXFixesCopyRegion,
12305b261ecSmrg    ProcXFixesCombineRegion,
12405b261ecSmrg    ProcXFixesCombineRegion,
12505b261ecSmrg    ProcXFixesCombineRegion,
12605b261ecSmrg    ProcXFixesInvertRegion,
12705b261ecSmrg    ProcXFixesTranslateRegion,
12805b261ecSmrg    ProcXFixesRegionExtents,
12905b261ecSmrg    ProcXFixesFetchRegion,
13005b261ecSmrg    ProcXFixesSetGCClipRegion,
13105b261ecSmrg    ProcXFixesSetWindowShapeRegion,
13205b261ecSmrg    ProcXFixesSetPictureClipRegion,
13305b261ecSmrg    ProcXFixesSetCursorName,
13405b261ecSmrg    ProcXFixesGetCursorName,
13505b261ecSmrg    ProcXFixesGetCursorImageAndName,
13605b261ecSmrg    ProcXFixesChangeCursor,
13705b261ecSmrg    ProcXFixesChangeCursorByName,
13805b261ecSmrg/*************** Version 3 ******************/
13905b261ecSmrg    ProcXFixesExpandRegion,
14005b261ecSmrg/*************** Version 4 ****************/
14105b261ecSmrg    ProcXFixesHideCursor,
14205b261ecSmrg    ProcXFixesShowCursor,
14305b261ecSmrg};
14405b261ecSmrg
14505b261ecSmrgstatic int
14605b261ecSmrgProcXFixesDispatch (ClientPtr client)
14705b261ecSmrg{
14805b261ecSmrg    REQUEST(xXFixesReq);
14905b261ecSmrg    XFixesClientPtr pXFixesClient = GetXFixesClient (client);
15005b261ecSmrg
15105b261ecSmrg    if (pXFixesClient->major_version >= NUM_VERSION_REQUESTS)
15205b261ecSmrg	return BadRequest;
15305b261ecSmrg    if (stuff->xfixesReqType > version_requests[pXFixesClient->major_version])
15405b261ecSmrg	return BadRequest;
15505b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
15605b261ecSmrg}
15705b261ecSmrg
15805b261ecSmrgstatic int
15905b261ecSmrgSProcXFixesQueryVersion(ClientPtr client)
16005b261ecSmrg{
16105b261ecSmrg    register int n;
16205b261ecSmrg    REQUEST(xXFixesQueryVersionReq);
16305b261ecSmrg
16405b261ecSmrg    swaps(&stuff->length, n);
16505b261ecSmrg    swapl(&stuff->majorVersion, n);
16605b261ecSmrg    swapl(&stuff->minorVersion, n);
16705b261ecSmrg    return (*ProcXFixesVector[stuff->xfixesReqType]) (client);
16805b261ecSmrg}
16905b261ecSmrg
17005b261ecSmrgstatic int (*SProcXFixesVector[XFixesNumberRequests])(ClientPtr) = {
17105b261ecSmrg/*************** Version 1 ******************/
17205b261ecSmrg    SProcXFixesQueryVersion,
17305b261ecSmrg    SProcXFixesChangeSaveSet,
17405b261ecSmrg    SProcXFixesSelectSelectionInput,
17505b261ecSmrg    SProcXFixesSelectCursorInput,
17605b261ecSmrg    SProcXFixesGetCursorImage,
17705b261ecSmrg/*************** Version 2 ******************/
17805b261ecSmrg    SProcXFixesCreateRegion,
17905b261ecSmrg    SProcXFixesCreateRegionFromBitmap,
18005b261ecSmrg    SProcXFixesCreateRegionFromWindow,
18105b261ecSmrg    SProcXFixesCreateRegionFromGC,
18205b261ecSmrg    SProcXFixesCreateRegionFromPicture,
18305b261ecSmrg    SProcXFixesDestroyRegion,
18405b261ecSmrg    SProcXFixesSetRegion,
18505b261ecSmrg    SProcXFixesCopyRegion,
18605b261ecSmrg    SProcXFixesCombineRegion,
18705b261ecSmrg    SProcXFixesCombineRegion,
18805b261ecSmrg    SProcXFixesCombineRegion,
18905b261ecSmrg    SProcXFixesInvertRegion,
19005b261ecSmrg    SProcXFixesTranslateRegion,
19105b261ecSmrg    SProcXFixesRegionExtents,
19205b261ecSmrg    SProcXFixesFetchRegion,
19305b261ecSmrg    SProcXFixesSetGCClipRegion,
19405b261ecSmrg    SProcXFixesSetWindowShapeRegion,
19505b261ecSmrg    SProcXFixesSetPictureClipRegion,
19605b261ecSmrg    SProcXFixesSetCursorName,
19705b261ecSmrg    SProcXFixesGetCursorName,
19805b261ecSmrg    SProcXFixesGetCursorImageAndName,
19905b261ecSmrg    SProcXFixesChangeCursor,
20005b261ecSmrg    SProcXFixesChangeCursorByName,
20105b261ecSmrg/*************** Version 3 ******************/
20205b261ecSmrg    SProcXFixesExpandRegion,
20305b261ecSmrg/*************** Version 4 ****************/
20405b261ecSmrg    SProcXFixesHideCursor,
20505b261ecSmrg    SProcXFixesShowCursor,
20605b261ecSmrg};
20705b261ecSmrg
20805b261ecSmrgstatic int
20905b261ecSmrgSProcXFixesDispatch (ClientPtr client)
21005b261ecSmrg{
21105b261ecSmrg    REQUEST(xXFixesReq);
21205b261ecSmrg    if (stuff->xfixesReqType >= XFixesNumberRequests)
21305b261ecSmrg	return BadRequest;
21405b261ecSmrg    return (*SProcXFixesVector[stuff->xfixesReqType]) (client);
21505b261ecSmrg}
21605b261ecSmrg
21705b261ecSmrgstatic void
21805b261ecSmrgXFixesClientCallback (CallbackListPtr	*list,
21905b261ecSmrg		      pointer		closure,
22005b261ecSmrg		      pointer		data)
22105b261ecSmrg{
22205b261ecSmrg    NewClientInfoRec	*clientinfo = (NewClientInfoRec *) data;
22305b261ecSmrg    ClientPtr		pClient = clientinfo->client;
22405b261ecSmrg    XFixesClientPtr	pXFixesClient = GetXFixesClient (pClient);
22505b261ecSmrg
22605b261ecSmrg    pXFixesClient->major_version = 0;
22705b261ecSmrg    pXFixesClient->minor_version = 0;
22805b261ecSmrg}
22905b261ecSmrg
23005b261ecSmrg/*ARGSUSED*/
23105b261ecSmrgstatic void
23205b261ecSmrgXFixesResetProc (ExtensionEntry *extEntry)
23305b261ecSmrg{
23405b261ecSmrg    DeleteCallback (&ClientStateCallback, XFixesClientCallback, 0);
23505b261ecSmrg}
23605b261ecSmrg
23705b261ecSmrgvoid
23805b261ecSmrgXFixesExtensionInit(void)
23905b261ecSmrg{
24005b261ecSmrg    ExtensionEntry *extEntry;
24105b261ecSmrg
24205b261ecSmrg    XFixesClientPrivateIndex = AllocateClientPrivateIndex ();
24305b261ecSmrg    if (!AllocateClientPrivate (XFixesClientPrivateIndex,
24405b261ecSmrg				sizeof (XFixesClientRec)))
24505b261ecSmrg	return;
24605b261ecSmrg    if (!AddCallback (&ClientStateCallback, XFixesClientCallback, 0))
24705b261ecSmrg	return;
24805b261ecSmrg
24905b261ecSmrg    if (XFixesSelectionInit() && XFixesCursorInit () && XFixesRegionInit () &&
25005b261ecSmrg	(extEntry = AddExtension(XFIXES_NAME, XFixesNumberEvents,
25105b261ecSmrg				 XFixesNumberErrors,
25205b261ecSmrg				 ProcXFixesDispatch, SProcXFixesDispatch,
25305b261ecSmrg				 XFixesResetProc, StandardMinorOpcode)) != 0)
25405b261ecSmrg    {
25505b261ecSmrg	XFixesReqCode = (unsigned char)extEntry->base;
25605b261ecSmrg	XFixesEventBase = extEntry->eventBase;
25705b261ecSmrg	XFixesErrorBase = extEntry->errorBase;
25805b261ecSmrg	EventSwapVector[XFixesEventBase + XFixesSelectionNotify] =
25905b261ecSmrg	    (EventSwapPtr) SXFixesSelectionNotifyEvent;
26005b261ecSmrg	EventSwapVector[XFixesEventBase + XFixesCursorNotify] =
26105b261ecSmrg	    (EventSwapPtr) SXFixesCursorNotifyEvent;
26205b261ecSmrg    }
26305b261ecSmrg}
264