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#ifdef HAVE_DIX_CONFIG_H
346747b715Smrg#include <dix-config.h>
356747b715Smrg#endif
366747b715Smrg
37f7df2e56Smrg#include <X11/X.h>              /* for inputstr.h    */
38f7df2e56Smrg#include <X11/Xproto.h>         /* Request macro     */
39f7df2e56Smrg#include "inputstr.h"           /* DeviceIntPtr      */
40f7df2e56Smrg#include "windowstr.h"          /* window structure  */
41f7df2e56Smrg#include "scrnintstr.h"         /* screen structure  */
426747b715Smrg#include <X11/extensions/XI.h>
436747b715Smrg#include <X11/extensions/XI2proto.h>
446747b715Smrg#include "extnsionst.h"
456747b715Smrg#include "exevents.h"
466747b715Smrg#include "exglobals.h"
476747b715Smrg
486747b715Smrg#include "xisetclientpointer.h"
496747b715Smrg
507e31ba66Smrgint _X_COLD
516747b715SmrgSProcXISetClientPointer(ClientPtr client)
526747b715Smrg{
536747b715Smrg    REQUEST(xXISetClientPointerReq);
540b0d8713Smrg    REQUEST_SIZE_MATCH(xXISetClientPointerReq);
550b0d8713Smrg
56f7df2e56Smrg    swaps(&stuff->length);
57f7df2e56Smrg    swapl(&stuff->win);
58f7df2e56Smrg    swaps(&stuff->deviceid);
596747b715Smrg    return (ProcXISetClientPointer(client));
606747b715Smrg}
616747b715Smrg
626747b715Smrgint
636747b715SmrgProcXISetClientPointer(ClientPtr client)
646747b715Smrg{
656747b715Smrg    DeviceIntPtr pDev;
666747b715Smrg    ClientPtr targetClient;
676747b715Smrg    int rc;
686747b715Smrg
696747b715Smrg    REQUEST(xXISetClientPointerReq);
706747b715Smrg    REQUEST_SIZE_MATCH(xXISetClientPointerReq);
716747b715Smrg
726747b715Smrg    rc = dixLookupDevice(&pDev, stuff->deviceid, client, DixManageAccess);
73f7df2e56Smrg    if (rc != Success) {
746747b715Smrg        client->errorValue = stuff->deviceid;
756747b715Smrg        return rc;
766747b715Smrg    }
776747b715Smrg
78f7df2e56Smrg    if (!IsMaster(pDev)) {
796747b715Smrg        client->errorValue = stuff->deviceid;
806747b715Smrg        return BadDevice;
816747b715Smrg    }
826747b715Smrg
836747b715Smrg    pDev = GetMaster(pDev, MASTER_POINTER);
846747b715Smrg
85f7df2e56Smrg    if (stuff->win != None) {
866747b715Smrg        rc = dixLookupClient(&targetClient, stuff->win, client,
87f7df2e56Smrg                             DixManageAccess);
886747b715Smrg
896747b715Smrg        if (rc != Success)
906747b715Smrg            return BadWindow;
916747b715Smrg
92f7df2e56Smrg    }
93f7df2e56Smrg    else
946747b715Smrg        targetClient = client;
956747b715Smrg
966747b715Smrg    rc = SetClientPointer(targetClient, pDev);
97f7df2e56Smrg    if (rc != Success) {
986747b715Smrg        client->errorValue = stuff->deviceid;
996747b715Smrg        return rc;
1006747b715Smrg    }
1016747b715Smrg
1026747b715Smrg    return Success;
1036747b715Smrg}
104