1/*
2 * Copyright © 2009 Red Hat, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 *
23 * Author: Peter Hutterer
24 */
25
26/***********************************************************************
27 *
28 * Request to allow some device events.
29 *
30 */
31
32#ifdef HAVE_DIX_CONFIG_H
33#include <dix-config.h>
34#endif
35
36#include "inputstr.h"	/* DeviceIntPtr      */
37#include "windowstr.h"	/* window structure  */
38#include <X11/extensions/XI2.h>
39#include <X11/extensions/XI2proto.h>
40
41#include "exglobals.h" /* BadDevice */
42#include "xiallowev.h"
43
44int
45SProcXIAllowEvents(ClientPtr client)
46{
47    char n;
48
49    REQUEST(xXIAllowEventsReq);
50    REQUEST_AT_LEAST_SIZE(xXIAllowEventsReq);
51
52    swaps(&stuff->length, n);
53    swaps(&stuff->deviceid, n);
54    swapl(&stuff->time, n);
55
56    return ProcXIAllowEvents(client);
57}
58
59int
60ProcXIAllowEvents(ClientPtr client)
61{
62    TimeStamp time;
63    DeviceIntPtr dev;
64    int ret = Success;
65
66    REQUEST(xXIAllowEventsReq);
67    REQUEST_SIZE_MATCH(xXIAllowEventsReq);
68
69    ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
70    if (ret != Success)
71	return ret;
72
73    time = ClientTimeToServerTime(stuff->time);
74
75    switch (stuff->mode) {
76    case XIReplayDevice:
77	AllowSome(client, time, dev, NOT_GRABBED);
78	break;
79    case XISyncDevice:
80	AllowSome(client, time, dev, FREEZE_NEXT_EVENT);
81	break;
82    case XIAsyncDevice:
83	AllowSome(client, time, dev, THAWED);
84	break;
85    case XIAsyncPairedDevice:
86        if (IsMaster(dev))
87            AllowSome(client, time, dev, THAW_OTHERS);
88	break;
89    case XISyncPair:
90        if (IsMaster(dev))
91            AllowSome(client, time, dev, FREEZE_BOTH_NEXT_EVENT);
92	break;
93    case XIAsyncPair:
94        if (IsMaster(dev))
95            AllowSome(client, time, dev, THAWED_BOTH);
96	break;
97    default:
98	client->errorValue = stuff->mode;
99	ret = BadValue;
100    }
101
102    return ret;
103}
104
105