extgrbdev.c 6.16 KB
Newer Older
1
/*
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * Copyright 2007-2008 Peter Hutterer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Author: Peter Hutterer, UniSA, NICTA
 */
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44

/***********************************************************************
 *
 * Request to fake data for a given device.
 *
 */

#define	 NEED_EVENTS
#define	 NEED_REPLIES
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif

#include <X11/X.h>	/* for inputstr.h    */
#include <X11/Xproto.h>	/* Request macro     */
#include "inputstr.h"	/* DeviceIntPtr      */
#include "windowstr.h"	/* window structure  */
#include "scrnintstr.h"	/* screen structure  */
#include <X11/extensions/XI.h>
#include <X11/extensions/XIproto.h>
45
#include <X11/extensions/Xge.h>
46 47 48 49
#include "extnsionst.h"
#include "exevents.h"
#include "exglobals.h"

50 51
#include "grabdev.h"    /* CreateMaskFromList */

52 53
#include "extgrbdev.h"

54
int
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
SProcXExtendedGrabDevice(ClientPtr client)
{
    char        n;
    int         i;
    long*       p;

    REQUEST(xExtendedGrabDeviceReq);
    swaps(&stuff->length, n);
    REQUEST_AT_LEAST_SIZE(xExtendedGrabDeviceReq);

    swapl(&stuff->grab_window, n);
    swapl(&stuff->time, n);
    swapl(&stuff->confine_to, n);
    swapl(&stuff->cursor, n);
    swaps(&stuff->event_count, n);
70
    swaps(&stuff->generic_event_count, n);
71 72 73 74 75 76 77

    p = (long *)&stuff[1];
    for (i = 0; i < stuff->event_count; i++) {
	swapl(p, n);
	p++;
    }

78
    for (i = 0; i < stuff->generic_event_count; i++) {
79 80 81 82 83 84 85 86 87
        p++; /* first 4 bytes are extension type and padding */
        swapl(p, n);
        p++;
    }

    return ProcXExtendedGrabDevice(client);
}


88
int
89 90 91 92
ProcXExtendedGrabDevice(ClientPtr client)
{
    xExtendedGrabDeviceReply rep;
    DeviceIntPtr             dev;
93
    int                      rc = Success,
94 95
                             errval = 0,
                             i;
96
    WindowPtr                grab_window,
97 98 99 100
                             confineTo = 0;
    CursorPtr                cursor = NULL;
    struct tmask             tmp[EMASKSIZE];
    TimeStamp                time;
101
    XGenericEventMask*       xgeMask;
102 103 104 105 106
    GenericMaskPtr           gemasks = NULL;

    REQUEST(xExtendedGrabDeviceReq);
    REQUEST_AT_LEAST_SIZE(xExtendedGrabDeviceReq);

107 108 109 110 111
    rep.repType         = X_Reply;
    rep.RepType         = X_ExtendedGrabDevice;
    rep.sequenceNumber  = client->sequence;
    rep.length          = 0;

112 113
    if (stuff->length != (sizeof(xExtendedGrabDeviceReq) >> 2) +
            stuff->event_count + 2 * stuff->generic_event_count)
114 115
    {
        errval = 0;
116
        rc = BadLength;
117 118 119
        goto cleanup;
    }

120 121
    rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess);
    if (rc != Success) {
122 123 124
	goto cleanup;
    }

125
    rc = dixLookupWindow(&grab_window,
126 127
                          stuff->grab_window,
                          client,
128
                          DixReadAccess);
129
    if (rc != Success)
130 131 132 133
    {
        errval = stuff->grab_window;
        goto cleanup;
    }
134

135 136
    if (stuff->confine_to)
    {
137
        rc = dixLookupWindow(&confineTo,
138 139
                              stuff->confine_to,
                              client,
140
                              DixReadAccess);
141
        if (rc != Success)
142 143 144 145 146 147 148 149
        {
            errval = stuff->confine_to;
            goto cleanup;
        }
    }

    if (stuff->cursor)
    {
150
        cursor = (CursorPtr)SecurityLookupIDByType(client,
151
                                                    stuff->cursor,
152 153
                                                    RT_CURSOR,
                                                    DixReadAccess);
154 155 156
        if (!cursor)
        {
            errval = stuff->cursor;
157
            rc = BadCursor;
158 159 160 161
            goto cleanup;
        }
    }

162
    if (CreateMaskFromList(client,
163
                           (XEventClass*)&stuff[1],
164 165 166
                           stuff->event_count,
                           tmp,
                           dev,
167 168 169 170 171
                           X_GrabDevice) != Success)
        return Success;

    time = ClientTimeToServerTime(stuff->time);

172
    if (stuff->generic_event_count)
173
    {
174
        xgeMask =
175
            (XGenericEventMask*)(((XEventClass*)&stuff[1]) + stuff->event_count);
176 177

        gemasks = xcalloc(1, sizeof(GenericMaskRec));
178
        gemasks->client = client;
179
        gemasks->next = NULL;
180
        gemasks->eventMask[xgeMask->extension & 0x7F] = xgeMask->evmask;
181

182
        xgeMask++;
183
        for (i = 1; i < stuff->generic_event_count; i++, xgeMask++)
184
            gemasks->eventMask[xgeMask->extension & 0x7F]= xgeMask->evmask;
185 186
    }

187 188 189
    ExtGrabDevice(client, dev, stuff->device_mode,
                  grab_window, confineTo, time, stuff->owner_events,
                  cursor, tmp[stuff->deviceid].mask,
190 191
                  gemasks);

192
    if (rc != Success) {
193 194 195
        errval = 0;
        goto cleanup;
    }
196

197 198
cleanup:

199 200
    if (gemasks)
        xfree(gemasks);
201

202
    if (rc == Success)
203 204
    {
        WriteReplyToClient(client, sizeof(xGrabDeviceReply), &rep);
205 206
    }
    else
207
    {
208
        return rc;
209 210 211 212 213
    }
    return Success;
}

void
214
SRepXExtendedGrabDevice(ClientPtr client, int size,
215 216 217 218 219 220 221
                        xExtendedGrabDeviceReply* rep)
{
    char n;
    swaps(&rep->sequenceNumber, n);
    swaps(&rep->length, n);
    WriteToClient(client, size, (char*)rep);
}