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 "mi.h"
39 #include "eventstr.h"
40 #include <X11/extensions/XI2.h>
41 #include <X11/extensions/XI2proto.h>
42
43 #include "exglobals.h" /* BadDevice */
44 #include "exevents.h"
45 #include "xiallowev.h"
46
47 int _X_COLD
SProcXIAllowEvents(ClientPtr client)48 SProcXIAllowEvents(ClientPtr client)
49 {
50 REQUEST(xXIAllowEventsReq);
51 REQUEST_AT_LEAST_SIZE(xXIAllowEventsReq);
52
53 swaps(&stuff->length);
54 swaps(&stuff->deviceid);
55 swapl(&stuff->time);
56 if (stuff->length > 3) {
57 xXI2_2AllowEventsReq *req_xi22 = (xXI2_2AllowEventsReq *) stuff;
58
59 REQUEST_AT_LEAST_SIZE(xXI2_2AllowEventsReq);
60 swapl(&req_xi22->touchid);
61 swapl(&req_xi22->grab_window);
62 }
63
64 return ProcXIAllowEvents(client);
65 }
66
67 int
ProcXIAllowEvents(ClientPtr client)68 ProcXIAllowEvents(ClientPtr client)
69 {
70 TimeStamp time;
71 DeviceIntPtr dev;
72 int ret = Success;
73 XIClientPtr xi_client;
74 Bool have_xi22 = FALSE;
75
76 REQUEST(xXI2_2AllowEventsReq);
77
78 xi_client = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
79
80 if (version_compare(xi_client->major_version,
81 xi_client->minor_version, 2, 2) >= 0) {
82 REQUEST_AT_LEAST_SIZE(xXI2_2AllowEventsReq);
83 have_xi22 = TRUE;
84 }
85 else {
86 REQUEST_AT_LEAST_SIZE(xXIAllowEventsReq);
87 }
88
89 ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
90 if (ret != Success)
91 return ret;
92
93 time = ClientTimeToServerTime(stuff->time);
94
95 switch (stuff->mode) {
96 case XIReplayDevice:
97 AllowSome(client, time, dev, NOT_GRABBED);
98 break;
99 case XISyncDevice:
100 AllowSome(client, time, dev, FREEZE_NEXT_EVENT);
101 break;
102 case XIAsyncDevice:
103 AllowSome(client, time, dev, THAWED);
104 break;
105 case XIAsyncPairedDevice:
106 if (IsMaster(dev))
107 AllowSome(client, time, dev, THAW_OTHERS);
108 break;
109 case XISyncPair:
110 if (IsMaster(dev))
111 AllowSome(client, time, dev, FREEZE_BOTH_NEXT_EVENT);
112 break;
113 case XIAsyncPair:
114 if (IsMaster(dev))
115 AllowSome(client, time, dev, THAWED_BOTH);
116 break;
117 case XIRejectTouch:
118 case XIAcceptTouch:
119 {
120 int rc;
121 WindowPtr win;
122
123 if (!have_xi22)
124 return BadValue;
125
126 rc = dixLookupWindow(&win, stuff->grab_window, client, DixReadAccess);
127 if (rc != Success)
128 return rc;
129
130 ret = TouchAcceptReject(client, dev, stuff->mode, stuff->touchid,
131 stuff->grab_window, &client->errorValue);
132 }
133 break;
134 default:
135 client->errorValue = stuff->mode;
136 ret = BadValue;
137 }
138
139 return ret;
140 }
141