Commit | Line | Data |
---|---|---|
a09e091a JB |
1 | /************************************************************ |
2 | ||
3 | Copyright 1989, 1998 The Open Group | |
4 | ||
5 | Permission to use, copy, modify, distribute, and sell this software and its | |
6 | documentation for any purpose is hereby granted without fee, provided that | |
7 | the above copyright notice appear in all copies and that both that | |
8 | copyright notice and this permission notice appear in supporting | |
9 | documentation. | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in | |
12 | all copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN | |
18 | AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | |
19 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
20 | ||
21 | Except as contained in this notice, the name of The Open Group shall not be | |
22 | used in advertising or otherwise to promote the sale, use or other dealings | |
23 | in this Software without prior written authorization from The Open Group. | |
24 | ||
25 | Copyright 1989 by Hewlett-Packard Company, Palo Alto, California. | |
26 | ||
27 | All Rights Reserved | |
28 | ||
29 | Permission to use, copy, modify, and distribute this software and its | |
30 | documentation for any purpose and without fee is hereby granted, | |
31 | provided that the above copyright notice appear in all copies and that | |
32 | both that copyright notice and this permission notice appear in | |
33 | supporting documentation, and that the name of Hewlett-Packard not be | |
34 | used in advertising or publicity pertaining to distribution of the | |
35 | software without specific, written prior permission. | |
36 | ||
37 | HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |
38 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |
39 | HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR | |
40 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
41 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
42 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
43 | SOFTWARE. | |
44 | ||
45 | ********************************************************/ | |
46 | ||
47 | /*********************************************************************** | |
48 | * | |
49 | * Extension function to grab an extension device. | |
50 | * | |
51 | */ | |
52 | ||
53 | #ifdef HAVE_DIX_CONFIG_H | |
54 | #include <dix-config.h> | |
55 | #endif | |
56 | ||
57 | #include "inputstr.h" /* DeviceIntPtr */ | |
58 | #include "windowstr.h" /* window structure */ | |
59 | #include <X11/extensions/XI.h> | |
60 | #include <X11/extensions/XIproto.h> | |
61 | #include "exglobals.h" | |
62 | #include "dixevents.h" /* GrabDevice */ | |
63 | ||
64 | #include "grabdev.h" | |
65 | ||
66 | extern XExtEventInfo EventInfo[]; | |
67 | extern int ExtEventIndex; | |
68 | ||
69 | /*********************************************************************** | |
70 | * | |
71 | * Swap the request if the requestor has a different byte order than us. | |
72 | * | |
73 | */ | |
74 | ||
75 | int | |
76 | SProcXGrabDevice(ClientPtr client) | |
77 | { | |
78 | REQUEST(xGrabDeviceReq); | |
79 | swaps(&stuff->length); | |
80 | REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); | |
81 | swapl(&stuff->grabWindow); | |
82 | swapl(&stuff->time); | |
83 | swaps(&stuff->event_count); | |
84 | ||
85 | if (stuff->length != | |
86 | bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count) | |
87 | return BadLength; | |
88 | ||
89 | SwapLongs((CARD32 *) (&stuff[1]), stuff->event_count); | |
90 | ||
91 | return (ProcXGrabDevice(client)); | |
92 | } | |
93 | ||
94 | /*********************************************************************** | |
95 | * | |
96 | * Grab an extension device. | |
97 | * | |
98 | */ | |
99 | ||
100 | int | |
101 | ProcXGrabDevice(ClientPtr client) | |
102 | { | |
103 | int rc; | |
104 | xGrabDeviceReply rep; | |
105 | DeviceIntPtr dev; | |
106 | GrabMask mask; | |
107 | struct tmask tmp[EMASKSIZE]; | |
108 | ||
109 | REQUEST(xGrabDeviceReq); | |
110 | REQUEST_AT_LEAST_SIZE(xGrabDeviceReq); | |
111 | ||
112 | if (stuff->length != | |
113 | bytes_to_int32(sizeof(xGrabDeviceReq)) + stuff->event_count) | |
114 | return BadLength; | |
115 | ||
116 | rep = (xGrabDeviceReply) { | |
117 | .repType = X_Reply, | |
118 | .RepType = X_GrabDevice, | |
119 | .sequenceNumber = client->sequence, | |
120 | .length = 0, | |
121 | }; | |
122 | ||
123 | rc = dixLookupDevice(&dev, stuff->deviceid, client, DixGrabAccess); | |
124 | if (rc != Success) | |
125 | return rc; | |
126 | ||
127 | if ((rc = CreateMaskFromList(client, (XEventClass *) &stuff[1], | |
128 | stuff->event_count, tmp, dev, | |
129 | X_GrabDevice)) != Success) | |
130 | return rc; | |
131 | ||
132 | mask.xi = tmp[stuff->deviceid].mask; | |
133 | ||
134 | rc = GrabDevice(client, dev, stuff->other_devices_mode, | |
135 | stuff->this_device_mode, stuff->grabWindow, | |
136 | stuff->ownerEvents, stuff->time, | |
137 | &mask, XI, None, None, &rep.status); | |
138 | ||
139 | if (rc != Success) | |
140 | return rc; | |
141 | ||
142 | WriteReplyToClient(client, sizeof(xGrabDeviceReply), &rep); | |
143 | return Success; | |
144 | } | |
145 | ||
146 | /*********************************************************************** | |
147 | * | |
148 | * This procedure creates an event mask from a list of XEventClasses. | |
149 | * | |
150 | * Procedure is as follows: | |
151 | * An XEventClass is (deviceid << 8 | eventtype). For each entry in the list, | |
152 | * get the device. Then run through all available event indices (those are | |
153 | * set when XI starts up) and binary OR's the device's mask to whatever the | |
154 | * event mask for the given event type was. | |
155 | * If an error occurs, it is sent to the client. Errors are generated if | |
156 | * - if the device given in the event classs is invalid | |
157 | * - if the device in the class list is not the device given as parameter (no | |
158 | * error if parameter is NULL) | |
159 | * | |
160 | * mask has to be size EMASKSIZE and pre-allocated. | |
161 | * | |
162 | * @param client The client to send the error to (if one occurs) | |
163 | * @param list List of event classes as sent from the client. | |
164 | * @param count Number of elements in list. | |
165 | * @param mask Preallocated mask (size EMASKSIZE). | |
166 | * @param dev The device we're creating masks for. | |
167 | * @param req The request we're processing. Used to fill in error fields. | |
168 | */ | |
169 | ||
170 | int | |
171 | CreateMaskFromList(ClientPtr client, XEventClass * list, int count, | |
172 | struct tmask *mask, DeviceIntPtr dev, int req) | |
173 | { | |
174 | int rc, i, j; | |
175 | int device; | |
176 | DeviceIntPtr tdev; | |
177 | ||
178 | memset(mask, 0, EMASKSIZE * sizeof(struct tmask)); | |
179 | ||
180 | for (i = 0; i < count; i++, list++) { | |
181 | device = *list >> 8; | |
182 | if (device > 255) | |
183 | return BadClass; | |
184 | ||
185 | rc = dixLookupDevice(&tdev, device, client, DixUseAccess); | |
186 | if (rc != BadDevice && rc != Success) | |
187 | return rc; | |
188 | if (rc == BadDevice || (dev != NULL && tdev != dev)) | |
189 | return BadClass; | |
190 | ||
191 | for (j = 0; j < ExtEventIndex; j++) | |
192 | if (EventInfo[j].type == (*list & 0xff)) { | |
193 | mask[device].mask |= EventInfo[j].mask; | |
194 | mask[device].dev = (Pointer) tdev; | |
195 | break; | |
196 | } | |
197 | } | |
198 | return Success; | |
199 | } | |
200 | ||
201 | /*********************************************************************** | |
202 | * | |
203 | * This procedure writes the reply for the XGrabDevice function, | |
204 | * if the client and server have a different byte ordering. | |
205 | * | |
206 | */ | |
207 | ||
208 | void | |
209 | SRepXGrabDevice(ClientPtr client, int size, xGrabDeviceReply * rep) | |
210 | { | |
211 | swaps(&rep->sequenceNumber); | |
212 | swapl(&rep->length); | |
213 | WriteToClient(client, size, rep); | |
214 | } |