xisetclientpointer.c revision 6747b715
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 set the client pointer for the owner of the given window.
296747b715Smrg * All subsequent calls that are ambiguous will choose the client pointer as
306747b715Smrg * default value.
316747b715Smrg */
326747b715Smrg
336747b715Smrg
346747b715Smrg#ifdef HAVE_DIX_CONFIG_H
356747b715Smrg#include <dix-config.h>
366747b715Smrg#endif
376747b715Smrg
386747b715Smrg#include <X11/X.h>	/* for inputstr.h    */
396747b715Smrg#include <X11/Xproto.h>	/* Request macro     */
406747b715Smrg#include "inputstr.h"	/* DeviceIntPtr      */
416747b715Smrg#include "windowstr.h"	/* window structure  */
426747b715Smrg#include "scrnintstr.h"	/* screen structure  */
436747b715Smrg#include <X11/extensions/XI.h>
446747b715Smrg#include <X11/extensions/XI2proto.h>
456747b715Smrg#include "extnsionst.h"
466747b715Smrg#include "exevents.h"
476747b715Smrg#include "exglobals.h"
486747b715Smrg
496747b715Smrg#include "xisetclientpointer.h"
506747b715Smrg
516747b715Smrgint
526747b715SmrgSProcXISetClientPointer(ClientPtr client)
536747b715Smrg{
546747b715Smrg    char n;
556747b715Smrg
566747b715Smrg    REQUEST(xXISetClientPointerReq);
576747b715Smrg    swaps(&stuff->length, n);
586747b715Smrg    swapl(&stuff->win, n);
596747b715Smrg    swaps(&stuff->deviceid, n);
606747b715Smrg    REQUEST_SIZE_MATCH(xXISetClientPointerReq);
616747b715Smrg    return (ProcXISetClientPointer(client));
626747b715Smrg}
636747b715Smrg
646747b715Smrgint
656747b715SmrgProcXISetClientPointer(ClientPtr client)
666747b715Smrg{
676747b715Smrg    DeviceIntPtr pDev;
686747b715Smrg    ClientPtr targetClient;
696747b715Smrg    int rc;
706747b715Smrg
716747b715Smrg    REQUEST(xXISetClientPointerReq);
726747b715Smrg    REQUEST_SIZE_MATCH(xXISetClientPointerReq);
736747b715Smrg
746747b715Smrg
756747b715Smrg    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixManageAccess);
766747b715Smrg    if (rc != Success)
776747b715Smrg    {
786747b715Smrg        client->errorValue = stuff->deviceid;
796747b715Smrg        return rc;
806747b715Smrg    }
816747b715Smrg
826747b715Smrg    if (!IsMaster(pDev))
836747b715Smrg    {
846747b715Smrg        client->errorValue = stuff->deviceid;
856747b715Smrg        return BadDevice;
866747b715Smrg    }
876747b715Smrg
886747b715Smrg    pDev = GetMaster(pDev, MASTER_POINTER);
896747b715Smrg
906747b715Smrg    if (stuff->win != None)
916747b715Smrg    {
926747b715Smrg        rc = dixLookupClient(&targetClient, stuff->win, client,
936747b715Smrg                DixManageAccess);
946747b715Smrg
956747b715Smrg        if (rc != Success)
966747b715Smrg            return BadWindow;
976747b715Smrg
986747b715Smrg    } else
996747b715Smrg        targetClient = client;
1006747b715Smrg
1016747b715Smrg    rc = SetClientPointer(targetClient, pDev);
1026747b715Smrg    if (rc != Success)
1036747b715Smrg    {
1046747b715Smrg        client->errorValue = stuff->deviceid;
1056747b715Smrg        return rc;
1066747b715Smrg    }
1076747b715Smrg
1086747b715Smrg    return Success;
1096747b715Smrg}
110