1 /************************************************************
3 Copyright 1989, 1998 The Open Group
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
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
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.
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.
25 Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
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.
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
45 ********************************************************/
47 /***********************************************************************
49 * Extension function to grab an extension device.
53 #ifdef HAVE_DIX_CONFIG_H
54 #include <dix-config.h>
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 */
66 extern XExtEventInfo EventInfo
[];
67 extern int ExtEventIndex
;
69 /***********************************************************************
71 * Swap the request if the requestor has a different byte order than us.
76 SProcXGrabDevice(ClientPtr client
)
78 REQUEST(xGrabDeviceReq
);
79 swaps(&stuff
->length
);
80 REQUEST_AT_LEAST_SIZE(xGrabDeviceReq
);
81 swapl(&stuff
->grabWindow
);
83 swaps(&stuff
->event_count
);
86 bytes_to_int32(sizeof(xGrabDeviceReq
)) + stuff
->event_count
)
89 SwapLongs((CARD32
*) (&stuff
[1]), stuff
->event_count
);
91 return (ProcXGrabDevice(client
));
94 /***********************************************************************
96 * Grab an extension device.
101 ProcXGrabDevice(ClientPtr client
)
104 xGrabDeviceReply rep
;
107 struct tmask tmp
[EMASKSIZE
];
109 REQUEST(xGrabDeviceReq
);
110 REQUEST_AT_LEAST_SIZE(xGrabDeviceReq
);
113 bytes_to_int32(sizeof(xGrabDeviceReq
)) + stuff
->event_count
)
116 rep
= (xGrabDeviceReply
) {
118 .RepType
= X_GrabDevice
,
119 .sequenceNumber
= client
->sequence
,
123 rc
= dixLookupDevice(&dev
, stuff
->deviceid
, client
, DixGrabAccess
);
127 if ((rc
= CreateMaskFromList(client
, (XEventClass
*) &stuff
[1],
128 stuff
->event_count
, tmp
, dev
,
129 X_GrabDevice
)) != Success
)
132 mask
.xi
= tmp
[stuff
->deviceid
].mask
;
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
);
142 WriteReplyToClient(client
, sizeof(xGrabDeviceReply
), &rep
);
146 /***********************************************************************
148 * This procedure creates an event mask from a list of XEventClasses.
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)
160 * mask has to be size EMASKSIZE and pre-allocated.
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.
171 CreateMaskFromList(ClientPtr client
, XEventClass
* list
, int count
,
172 struct tmask
*mask
, DeviceIntPtr dev
, int req
)
178 memset(mask
, 0, EMASKSIZE
* sizeof(struct tmask
));
180 for (i
= 0; i
< count
; i
++, list
++) {
185 rc
= dixLookupDevice(&tdev
, device
, client
, DixUseAccess
);
186 if (rc
!= BadDevice
&& rc
!= Success
)
188 if (rc
== BadDevice
|| (dev
!= NULL
&& tdev
!= dev
))
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
;
201 /***********************************************************************
203 * This procedure writes the reply for the XGrabDevice function,
204 * if the client and server have a different byte ordering.
209 SRepXGrabDevice(ClientPtr client
, int size
, xGrabDeviceReply
* rep
)
211 swaps(&rep
->sequenceNumber
);
213 WriteToClient(client
, size
, rep
);