xichangecursor.c revision 7e31ba66
16747b715Smrg/*
26747b715Smrg * Copyright 2007-2008 Peter Hutterer
36747b715Smrg *
46747b715Smrg * Permission is hereby granted, free of charge, to any person obtaining a
56747b715Smrg * copy of this software and associated documentation files (the "Software"),
66747b715Smrg * to deal in the Software without restriction, including without limitation
76747b715Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
86747b715Smrg * and/or sell copies of the Software, and to permit persons to whom the
96747b715Smrg * Software is furnished to do so, subject to the following conditions:
106747b715Smrg *
116747b715Smrg * The above copyright notice and this permission notice (including the next
126747b715Smrg * paragraph) shall be included in all copies or substantial portions of the
136747b715Smrg * Software.
146747b715Smrg *
156747b715Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
166747b715Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
176747b715Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
186747b715Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
196747b715Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
206747b715Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
216747b715Smrg * DEALINGS IN THE SOFTWARE.
226747b715Smrg *
236747b715Smrg * Author: Peter Hutterer, University of South Australia, NICTA
246747b715Smrg */
256747b715Smrg
266747b715Smrg/***********************************************************************
276747b715Smrg *
286747b715Smrg * Request to change a given device pointer's cursor.
296747b715Smrg *
306747b715Smrg */
316747b715Smrg
326747b715Smrg#ifdef HAVE_DIX_CONFIG_H
336747b715Smrg#include <dix-config.h>
346747b715Smrg#endif
356747b715Smrg
36f7df2e56Smrg#include <X11/X.h>              /* for inputstr.h    */
37f7df2e56Smrg#include <X11/Xproto.h>         /* Request macro     */
38f7df2e56Smrg#include "inputstr.h"           /* DeviceIntPtr      */
39f7df2e56Smrg#include "windowstr.h"          /* window structure  */
40f7df2e56Smrg#include "scrnintstr.h"         /* screen structure  */
416747b715Smrg#include <X11/extensions/XI.h>
426747b715Smrg#include <X11/extensions/XI2proto.h>
436747b715Smrg#include "extnsionst.h"
446747b715Smrg#include "exevents.h"
456747b715Smrg#include "exglobals.h"
466747b715Smrg#include "input.h"
476747b715Smrg
486747b715Smrg#include "xichangecursor.h"
496747b715Smrg
506747b715Smrg/***********************************************************************
516747b715Smrg *
526747b715Smrg * This procedure allows a client to set one pointer's cursor.
536747b715Smrg *
546747b715Smrg */
556747b715Smrg
567e31ba66Smrgint _X_COLD
576747b715SmrgSProcXIChangeCursor(ClientPtr client)
586747b715Smrg{
596747b715Smrg    REQUEST(xXIChangeCursorReq);
600b0d8713Smrg    REQUEST_SIZE_MATCH(xXIChangeCursorReq);
61f7df2e56Smrg    swaps(&stuff->length);
62f7df2e56Smrg    swapl(&stuff->win);
63f7df2e56Smrg    swapl(&stuff->cursor);
64f7df2e56Smrg    swaps(&stuff->deviceid);
656747b715Smrg    return (ProcXIChangeCursor(client));
666747b715Smrg}
676747b715Smrg
68f7df2e56Smrgint
69f7df2e56SmrgProcXIChangeCursor(ClientPtr client)
706747b715Smrg{
716747b715Smrg    int rc;
72f7df2e56Smrg    WindowPtr pWin = NULL;
736747b715Smrg    DeviceIntPtr pDev = NULL;
746747b715Smrg    CursorPtr pCursor = NULL;
756747b715Smrg
766747b715Smrg    REQUEST(xXIChangeCursorReq);
776747b715Smrg    REQUEST_SIZE_MATCH(xXIChangeCursorReq);
786747b715Smrg
796747b715Smrg    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixSetAttrAccess);
806747b715Smrg    if (rc != Success)
816747b715Smrg        return rc;
826747b715Smrg
836747b715Smrg    if (!IsMaster(pDev) || !IsPointerDevice(pDev))
846747b715Smrg        return BadDevice;
856747b715Smrg
86f7df2e56Smrg    if (stuff->win != None) {
876747b715Smrg        rc = dixLookupWindow(&pWin, stuff->win, client, DixSetAttrAccess);
886747b715Smrg        if (rc != Success)
896747b715Smrg            return rc;
906747b715Smrg    }
916747b715Smrg
92f7df2e56Smrg    if (stuff->cursor == None) {
936747b715Smrg        if (pWin == pWin->drawable.pScreen->root)
946747b715Smrg            pCursor = rootCursor;
956747b715Smrg        else
96f7df2e56Smrg            pCursor = (CursorPtr) None;
976747b715Smrg    }
98f7df2e56Smrg    else {
99f7df2e56Smrg        rc = dixLookupResourceByType((void **) &pCursor, stuff->cursor,
100f7df2e56Smrg                                     RT_CURSOR, client, DixUseAccess);
101f7df2e56Smrg        if (rc != Success)
102f7df2e56Smrg            return rc;
1036747b715Smrg    }
1046747b715Smrg
1056747b715Smrg    ChangeWindowDeviceCursor(pWin, pDev, pCursor);
1066747b715Smrg
1076747b715Smrg    return Success;
1086747b715Smrg}
109