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 * Dispatch routines and initialization routines for the X input extension.
54 #ifdef HAVE_DIX_CONFIG_H
55 #include <dix-config.h>
59 #include "gcstruct.h" /* pointer for extnsionst.h */
60 #include "extnsionst.h" /* extension entry */
61 #include <X11/extensions/XI.h>
62 #include <X11/extensions/XIproto.h>
63 #include <X11/extensions/XI2proto.h>
64 #include <X11/extensions/geproto.h>
65 #include "geext.h" /* extension interfaces for ge */
67 #include "dixevents.h"
70 #include "exglobals.h"
73 #include "protocol-versions.h"
75 /* modules local to Xi */
100 #include "selectev.h"
101 #include "sendexev.h"
105 #include "setfocus.h"
109 #include "ungrdevb.h"
110 #include "ungrdevk.h"
111 #include "xiallowev.h"
112 #include "xiselectev.h"
113 #include "xigrabdev.h"
114 #include "xipassivegrab.h"
115 #include "xisetdevfocus.h"
116 #include "xiproperty.h"
117 #include "xichangecursor.h"
118 #include "xichangehierarchy.h"
119 #include "xigetclientpointer.h"
120 #include "xiquerydevice.h"
121 #include "xiquerypointer.h"
122 #include "xiqueryversion.h"
123 #include "xisetclientpointer.h"
124 #include "xiwarppointer.h"
125 #include "xibarriers.h"
127 /* Masks for XI events have to be aligned with core event (partially anyway).
128 * If DeviceButtonMotionMask is != ButtonMotionMask, event delivery
129 * breaks down. The device needs the dev->button->motionMask. If DBMM is
130 * the same as BMM, we can ensure that both core and device events can be
131 * delivered, without the need for extra structures in the DeviceIntRec. */
132 const Mask DeviceKeyPressMask
= KeyPressMask
;
133 const Mask DeviceKeyReleaseMask
= KeyReleaseMask
;
134 const Mask DeviceButtonPressMask
= ButtonPressMask
;
135 const Mask DeviceButtonReleaseMask
= ButtonReleaseMask
;
136 const Mask DeviceProximityMask
= (1L << 4);
137 const Mask DeviceStateNotifyMask
= (1L << 5);
138 const Mask DevicePointerMotionMask
= PointerMotionMask
;
139 const Mask DevicePointerMotionHintMask
= PointerMotionHintMask
;
140 const Mask DeviceButton1MotionMask
= Button1MotionMask
;
141 const Mask DeviceButton2MotionMask
= Button2MotionMask
;
142 const Mask DeviceButton3MotionMask
= Button3MotionMask
;
143 const Mask DeviceButton4MotionMask
= Button4MotionMask
;
144 const Mask DeviceButton5MotionMask
= Button5MotionMask
;
145 const Mask DeviceButtonMotionMask
= ButtonMotionMask
;
146 const Mask DeviceFocusChangeMask
= (1L << 14);
147 const Mask DeviceMappingNotifyMask
= (1L << 15);
148 const Mask ChangeDeviceNotifyMask
= (1L << 16);
149 const Mask DeviceButtonGrabMask
= (1L << 17);
150 const Mask DeviceOwnerGrabButtonMask
= (1L << 17);
151 const Mask DevicePresenceNotifyMask
= (1L << 18);
152 const Mask DevicePropertyNotifyMask
= (1L << 19);
153 const Mask XIAllMasks
= (1L << 20) - 1;
156 Mask ExtExclusiveMasks
[EMASKSIZE
];
158 static struct dev_type
{
182 CARD8 event_base
[numInputClasses
];
183 XExtEventInfo EventInfo
[32];
185 static DeviceIntRec xi_all_devices
;
186 static DeviceIntRec xi_all_master_devices
;
189 * Dispatch vector. Functions defined in here will be called when the matching
192 static int (*ProcIVector
[]) (ClientPtr
) = {
194 ProcXGetExtensionVersion
, /* 1 */
195 ProcXListInputDevices
, /* 2 */
196 ProcXOpenDevice
, /* 3 */
197 ProcXCloseDevice
, /* 4 */
198 ProcXSetDeviceMode
, /* 5 */
199 ProcXSelectExtensionEvent
, /* 6 */
200 ProcXGetSelectedExtensionEvents
, /* 7 */
201 ProcXChangeDeviceDontPropagateList
, /* 8 */
202 ProcXGetDeviceDontPropagateList
, /* 9 */
203 ProcXGetDeviceMotionEvents
, /* 10 */
204 ProcXChangeKeyboardDevice
, /* 11 */
205 ProcXChangePointerDevice
, /* 12 */
206 ProcXGrabDevice
, /* 13 */
207 ProcXUngrabDevice
, /* 14 */
208 ProcXGrabDeviceKey
, /* 15 */
209 ProcXUngrabDeviceKey
, /* 16 */
210 ProcXGrabDeviceButton
, /* 17 */
211 ProcXUngrabDeviceButton
, /* 18 */
212 ProcXAllowDeviceEvents
, /* 19 */
213 ProcXGetDeviceFocus
, /* 20 */
214 ProcXSetDeviceFocus
, /* 21 */
215 ProcXGetFeedbackControl
, /* 22 */
216 ProcXChangeFeedbackControl
, /* 23 */
217 ProcXGetDeviceKeyMapping
, /* 24 */
218 ProcXChangeDeviceKeyMapping
, /* 25 */
219 ProcXGetDeviceModifierMapping
, /* 26 */
220 ProcXSetDeviceModifierMapping
, /* 27 */
221 ProcXGetDeviceButtonMapping
, /* 28 */
222 ProcXSetDeviceButtonMapping
, /* 29 */
223 ProcXQueryDeviceState
, /* 30 */
224 ProcXSendExtensionEvent
, /* 31 */
225 ProcXDeviceBell
, /* 32 */
226 ProcXSetDeviceValuators
, /* 33 */
227 ProcXGetDeviceControl
, /* 34 */
228 ProcXChangeDeviceControl
, /* 35 */
230 ProcXListDeviceProperties
, /* 36 */
231 ProcXChangeDeviceProperty
, /* 37 */
232 ProcXDeleteDeviceProperty
, /* 38 */
233 ProcXGetDeviceProperty
, /* 39 */
235 ProcXIQueryPointer
, /* 40 */
236 ProcXIWarpPointer
, /* 41 */
237 ProcXIChangeCursor
, /* 42 */
238 ProcXIChangeHierarchy
, /* 43 */
239 ProcXISetClientPointer
, /* 44 */
240 ProcXIGetClientPointer
, /* 45 */
241 ProcXISelectEvents
, /* 46 */
242 ProcXIQueryVersion
, /* 47 */
243 ProcXIQueryDevice
, /* 48 */
244 ProcXISetFocus
, /* 49 */
245 ProcXIGetFocus
, /* 50 */
246 ProcXIGrabDevice
, /* 51 */
247 ProcXIUngrabDevice
, /* 52 */
248 ProcXIAllowEvents
, /* 53 */
249 ProcXIPassiveGrabDevice
, /* 54 */
250 ProcXIPassiveUngrabDevice
, /* 55 */
251 ProcXIListProperties
, /* 56 */
252 ProcXIChangeProperty
, /* 57 */
253 ProcXIDeleteProperty
, /* 58 */
254 ProcXIGetProperty
, /* 59 */
255 ProcXIGetSelectedEvents
, /* 60 */
256 ProcXIBarrierReleasePointer
/* 61 */
259 /* For swapped clients */
260 static int (*SProcIVector
[]) (ClientPtr
) = {
262 SProcXGetExtensionVersion
, /* 1 */
263 SProcXListInputDevices
, /* 2 */
264 SProcXOpenDevice
, /* 3 */
265 SProcXCloseDevice
, /* 4 */
266 SProcXSetDeviceMode
, /* 5 */
267 SProcXSelectExtensionEvent
, /* 6 */
268 SProcXGetSelectedExtensionEvents
, /* 7 */
269 SProcXChangeDeviceDontPropagateList
, /* 8 */
270 SProcXGetDeviceDontPropagateList
, /* 9 */
271 SProcXGetDeviceMotionEvents
, /* 10 */
272 SProcXChangeKeyboardDevice
, /* 11 */
273 SProcXChangePointerDevice
, /* 12 */
274 SProcXGrabDevice
, /* 13 */
275 SProcXUngrabDevice
, /* 14 */
276 SProcXGrabDeviceKey
, /* 15 */
277 SProcXUngrabDeviceKey
, /* 16 */
278 SProcXGrabDeviceButton
, /* 17 */
279 SProcXUngrabDeviceButton
, /* 18 */
280 SProcXAllowDeviceEvents
, /* 19 */
281 SProcXGetDeviceFocus
, /* 20 */
282 SProcXSetDeviceFocus
, /* 21 */
283 SProcXGetFeedbackControl
, /* 22 */
284 SProcXChangeFeedbackControl
, /* 23 */
285 SProcXGetDeviceKeyMapping
, /* 24 */
286 SProcXChangeDeviceKeyMapping
, /* 25 */
287 SProcXGetDeviceModifierMapping
, /* 26 */
288 SProcXSetDeviceModifierMapping
, /* 27 */
289 SProcXGetDeviceButtonMapping
, /* 28 */
290 SProcXSetDeviceButtonMapping
, /* 29 */
291 SProcXQueryDeviceState
, /* 30 */
292 SProcXSendExtensionEvent
, /* 31 */
293 SProcXDeviceBell
, /* 32 */
294 SProcXSetDeviceValuators
, /* 33 */
295 SProcXGetDeviceControl
, /* 34 */
296 SProcXChangeDeviceControl
, /* 35 */
297 SProcXListDeviceProperties
, /* 36 */
298 SProcXChangeDeviceProperty
, /* 37 */
299 SProcXDeleteDeviceProperty
, /* 38 */
300 SProcXGetDeviceProperty
, /* 39 */
301 SProcXIQueryPointer
, /* 40 */
302 SProcXIWarpPointer
, /* 41 */
303 SProcXIChangeCursor
, /* 42 */
304 SProcXIChangeHierarchy
, /* 43 */
305 SProcXISetClientPointer
, /* 44 */
306 SProcXIGetClientPointer
, /* 45 */
307 SProcXISelectEvents
, /* 46 */
308 SProcXIQueryVersion
, /* 47 */
309 SProcXIQueryDevice
, /* 48 */
310 SProcXISetFocus
, /* 49 */
311 SProcXIGetFocus
, /* 50 */
312 SProcXIGrabDevice
, /* 51 */
313 SProcXIUngrabDevice
, /* 52 */
314 SProcXIAllowEvents
, /* 53 */
315 SProcXIPassiveGrabDevice
, /* 54 */
316 SProcXIPassiveUngrabDevice
, /* 55 */
317 SProcXIListProperties
, /* 56 */
318 SProcXIChangeProperty
, /* 57 */
319 SProcXIDeleteProperty
, /* 58 */
320 SProcXIGetProperty
, /* 59 */
321 SProcXIGetSelectedEvents
, /* 60 */
322 SProcXIBarrierReleasePointer
/* 61 */
325 /*****************************************************************
327 * Globals referenced elsewhere in the server.
334 static int BadEvent
= 1;
341 int DeviceKeyRelease
;
342 int DeviceButtonPress
;
343 int DeviceButtonRelease
;
344 int DeviceMotionNotify
;
349 int DeviceStateNotify
;
350 int DeviceKeyStateNotify
;
351 int DeviceButtonStateNotify
;
352 int DeviceMappingNotify
;
353 int ChangeDeviceNotify
;
354 int DevicePresenceNotify
;
355 int DevicePropertyNotify
;
357 RESTYPE RT_INPUTCLIENT
;
359 /*****************************************************************
361 * Externs defined elsewhere in the X server.
365 extern XExtensionVersion XIVersion
;
367 Mask PropagateMask
[EMASKSIZE
];
369 /*****************************************************************
375 DevPrivateKeyRec XIClientPrivateKeyRec
;
377 /*****************************************************************
379 * Declarations of local routines.
384 XIClientCallback(CallbackListPtr
*list
, pointer closure
, pointer data
)
386 NewClientInfoRec
*clientinfo
= (NewClientInfoRec
*) data
;
387 ClientPtr pClient
= clientinfo
->client
;
388 XIClientPtr pXIClient
;
390 pXIClient
= dixLookupPrivate(&pClient
->devPrivates
, XIClientPrivateKey
);
391 pXIClient
->major_version
= 0;
392 pXIClient
->minor_version
= 0;
395 /*************************************************************************
397 * ProcIDispatch - main dispatch routine for requests to this extension.
398 * This routine is used if server and client have the same byte ordering.
403 ProcIDispatch(ClientPtr client
)
406 if (stuff
->data
>= ARRAY_SIZE(ProcIVector
) || !ProcIVector
[stuff
->data
])
409 return (*ProcIVector
[stuff
->data
]) (client
);
412 /*******************************************************************************
416 * Main swapped dispatch routine for requests to this extension.
417 * This routine is used if server and client do not have the same byte ordering.
422 SProcIDispatch(ClientPtr client
)
425 if (stuff
->data
>= ARRAY_SIZE(SProcIVector
) || !SProcIVector
[stuff
->data
])
428 return (*SProcIVector
[stuff
->data
]) (client
);
431 /**********************************************************************
434 * Swap any replies defined in this extension.
439 SReplyIDispatch(ClientPtr client
, int len
, xGrabDeviceReply
* rep
)
441 /* All we look at is the type field */
442 /* This is common to all replies */
443 if (rep
->RepType
== X_GetExtensionVersion
)
444 SRepXGetExtensionVersion(client
, len
,
445 (xGetExtensionVersionReply
*) rep
);
446 else if (rep
->RepType
== X_ListInputDevices
)
447 SRepXListInputDevices(client
, len
, (xListInputDevicesReply
*) rep
);
448 else if (rep
->RepType
== X_OpenDevice
)
449 SRepXOpenDevice(client
, len
, (xOpenDeviceReply
*) rep
);
450 else if (rep
->RepType
== X_SetDeviceMode
)
451 SRepXSetDeviceMode(client
, len
, (xSetDeviceModeReply
*) rep
);
452 else if (rep
->RepType
== X_GetSelectedExtensionEvents
)
453 SRepXGetSelectedExtensionEvents(client
, len
,
454 (xGetSelectedExtensionEventsReply
*)
456 else if (rep
->RepType
== X_GetDeviceDontPropagateList
)
457 SRepXGetDeviceDontPropagateList(client
, len
,
458 (xGetDeviceDontPropagateListReply
*)
460 else if (rep
->RepType
== X_GetDeviceMotionEvents
)
461 SRepXGetDeviceMotionEvents(client
, len
,
462 (xGetDeviceMotionEventsReply
*) rep
);
463 else if (rep
->RepType
== X_GrabDevice
)
464 SRepXGrabDevice(client
, len
, (xGrabDeviceReply
*) rep
);
465 else if (rep
->RepType
== X_GetDeviceFocus
)
466 SRepXGetDeviceFocus(client
, len
, (xGetDeviceFocusReply
*) rep
);
467 else if (rep
->RepType
== X_GetFeedbackControl
)
468 SRepXGetFeedbackControl(client
, len
, (xGetFeedbackControlReply
*) rep
);
469 else if (rep
->RepType
== X_GetDeviceKeyMapping
)
470 SRepXGetDeviceKeyMapping(client
, len
,
471 (xGetDeviceKeyMappingReply
*) rep
);
472 else if (rep
->RepType
== X_GetDeviceModifierMapping
)
473 SRepXGetDeviceModifierMapping(client
, len
,
474 (xGetDeviceModifierMappingReply
*) rep
);
475 else if (rep
->RepType
== X_SetDeviceModifierMapping
)
476 SRepXSetDeviceModifierMapping(client
, len
,
477 (xSetDeviceModifierMappingReply
*) rep
);
478 else if (rep
->RepType
== X_GetDeviceButtonMapping
)
479 SRepXGetDeviceButtonMapping(client
, len
,
480 (xGetDeviceButtonMappingReply
*) rep
);
481 else if (rep
->RepType
== X_SetDeviceButtonMapping
)
482 SRepXSetDeviceButtonMapping(client
, len
,
483 (xSetDeviceButtonMappingReply
*) rep
);
484 else if (rep
->RepType
== X_QueryDeviceState
)
485 SRepXQueryDeviceState(client
, len
, (xQueryDeviceStateReply
*) rep
);
486 else if (rep
->RepType
== X_SetDeviceValuators
)
487 SRepXSetDeviceValuators(client
, len
, (xSetDeviceValuatorsReply
*) rep
);
488 else if (rep
->RepType
== X_GetDeviceControl
)
489 SRepXGetDeviceControl(client
, len
, (xGetDeviceControlReply
*) rep
);
490 else if (rep
->RepType
== X_ChangeDeviceControl
)
491 SRepXChangeDeviceControl(client
, len
,
492 (xChangeDeviceControlReply
*) rep
);
493 else if (rep
->RepType
== X_ListDeviceProperties
)
494 SRepXListDeviceProperties(client
, len
,
495 (xListDevicePropertiesReply
*) rep
);
496 else if (rep
->RepType
== X_GetDeviceProperty
)
497 SRepXGetDeviceProperty(client
, len
, (xGetDevicePropertyReply
*) rep
);
498 else if (rep
->RepType
== X_XIQueryPointer
)
499 SRepXIQueryPointer(client
, len
, (xXIQueryPointerReply
*) rep
);
500 else if (rep
->RepType
== X_XIGetClientPointer
)
501 SRepXIGetClientPointer(client
, len
, (xXIGetClientPointerReply
*) rep
);
502 else if (rep
->RepType
== X_XIQueryVersion
)
503 SRepXIQueryVersion(client
, len
, (xXIQueryVersionReply
*) rep
);
504 else if (rep
->RepType
== X_XIQueryDevice
)
505 SRepXIQueryDevice(client
, len
, (xXIQueryDeviceReply
*) rep
);
506 else if (rep
->RepType
== X_XIGrabDevice
)
507 SRepXIGrabDevice(client
, len
, (xXIGrabDeviceReply
*) rep
);
508 else if (rep
->RepType
== X_XIPassiveGrabDevice
)
509 SRepXIPassiveGrabDevice(client
, len
, (xXIPassiveGrabDeviceReply
*) rep
);
510 else if (rep
->RepType
== X_XIListProperties
)
511 SRepXIListProperties(client
, len
, (xXIListPropertiesReply
*) rep
);
512 else if (rep
->RepType
== X_XIGetProperty
)
513 SRepXIGetProperty(client
, len
, (xXIGetPropertyReply
*) rep
);
514 else if (rep
->RepType
== X_XIGetSelectedEvents
)
515 SRepXIGetSelectedEvents(client
, len
, (xXIGetSelectedEventsReply
*) rep
);
516 else if (rep
->RepType
== X_XIGetFocus
)
517 SRepXIGetFocus(client
, len
, (xXIGetFocusReply
*) rep
);
519 FatalError("XINPUT confused sending swapped reply");
523 /************************************************************************
525 * This function swaps the DeviceValuator event.
530 SEventDeviceValuator(deviceValuator
* from
, deviceValuator
* to
)
536 swaps(&to
->sequenceNumber
);
537 swaps(&to
->device_state
);
539 for (i
= 0; i
< 6; i
++) {
545 SEventFocus(deviceFocus
* from
, deviceFocus
* to
)
548 swaps(&to
->sequenceNumber
);
554 SDeviceStateNotifyEvent(deviceStateNotify
* from
, deviceStateNotify
* to
)
560 swaps(&to
->sequenceNumber
);
563 for (i
= 0; i
< 3; i
++) {
569 SDeviceKeyStateNotifyEvent(deviceKeyStateNotify
* from
,
570 deviceKeyStateNotify
* to
)
573 swaps(&to
->sequenceNumber
);
577 SDeviceButtonStateNotifyEvent(deviceButtonStateNotify
* from
,
578 deviceButtonStateNotify
* to
)
581 swaps(&to
->sequenceNumber
);
585 SChangeDeviceNotifyEvent(changeDeviceNotify
* from
, changeDeviceNotify
* to
)
588 swaps(&to
->sequenceNumber
);
593 SDeviceMappingNotifyEvent(deviceMappingNotify
* from
, deviceMappingNotify
* to
)
596 swaps(&to
->sequenceNumber
);
601 SDevicePresenceNotifyEvent(devicePresenceNotify
* from
,
602 devicePresenceNotify
* to
)
605 swaps(&to
->sequenceNumber
);
611 SDevicePropertyNotifyEvent(devicePropertyNotify
* from
,
612 devicePropertyNotify
* to
)
615 swaps(&to
->sequenceNumber
);
621 SDeviceLeaveNotifyEvent(xXILeaveEvent
* from
, xXILeaveEvent
* to
)
624 swaps(&to
->sequenceNumber
);
627 swaps(&to
->deviceid
);
636 swaps(&to
->sourceid
);
637 swaps(&to
->buttons_len
);
638 swapl(&to
->mods
.base_mods
);
639 swapl(&to
->mods
.latched_mods
);
640 swapl(&to
->mods
.locked_mods
);
644 SDeviceChangedEvent(xXIDeviceChangedEvent
* from
, xXIDeviceChangedEvent
* to
)
650 memcpy(&to
[1], &from
[1], from
->length
* 4);
652 any
= (xXIAnyInfo
*) &to
[1];
653 for (i
= 0; i
< to
->num_classes
; i
++) {
654 int length
= any
->length
;
659 xXIKeyInfo
*ki
= (xXIKeyInfo
*) any
;
660 uint32_t *key
= (uint32_t *) &ki
[1];
662 for (j
= 0; j
< ki
->num_keycodes
; j
++, key
++)
664 swaps(&ki
->num_keycodes
);
669 xXIButtonInfo
*bi
= (xXIButtonInfo
*) any
;
670 Atom
*labels
= (Atom
*) ((char *) bi
+ sizeof(xXIButtonInfo
) +
671 pad_to_int32(bits_to_bytes
673 for (j
= 0; j
< bi
->num_buttons
; j
++)
675 swaps(&bi
->num_buttons
);
680 xXIValuatorInfo
*ai
= (xXIValuatorInfo
*) any
;
683 swapl(&ai
->min
.integral
);
684 swapl(&ai
->min
.frac
);
685 swapl(&ai
->max
.integral
);
686 swapl(&ai
->max
.frac
);
687 swapl(&ai
->resolution
);
695 swaps(&any
->sourceid
);
697 any
= (xXIAnyInfo
*) ((char *) any
+ length
* 4);
700 swaps(&to
->sequenceNumber
);
703 swaps(&to
->deviceid
);
705 swaps(&to
->num_classes
);
706 swaps(&to
->sourceid
);
711 SDeviceEvent(xXIDeviceEvent
* from
, xXIDeviceEvent
* to
)
717 memcpy(to
, from
, sizeof(xEvent
) + from
->length
* 4);
719 swaps(&to
->sequenceNumber
);
722 swaps(&to
->deviceid
);
732 swaps(&to
->buttons_len
);
733 swaps(&to
->valuators_len
);
734 swaps(&to
->sourceid
);
735 swapl(&to
->mods
.base_mods
);
736 swapl(&to
->mods
.latched_mods
);
737 swapl(&to
->mods
.locked_mods
);
738 swapl(&to
->mods
.effective_mods
);
741 ptr
= (char *) (&to
[1]);
742 ptr
+= from
->buttons_len
* 4;
743 vmask
= ptr
; /* valuator mask */
744 ptr
+= from
->valuators_len
* 4;
745 for (i
= 0; i
< from
->valuators_len
* 32; i
++) {
746 if (BitIsOn(vmask
, i
)) {
747 swapl(((uint32_t *) ptr
));
749 swapl(((uint32_t *) ptr
));
756 SDeviceHierarchyEvent(xXIHierarchyEvent
* from
, xXIHierarchyEvent
* to
)
759 xXIHierarchyInfo
*info
;
762 memcpy(&to
[1], &from
[1], from
->length
* 4);
763 swaps(&to
->sequenceNumber
);
766 swaps(&to
->deviceid
);
769 swaps(&to
->num_info
);
771 info
= (xXIHierarchyInfo
*) &to
[1];
772 for (i
= 0; i
< from
->num_info
; i
++) {
773 swaps(&info
->deviceid
);
774 swaps(&info
->attachment
);
780 SXIPropertyEvent(xXIPropertyEvent
* from
, xXIPropertyEvent
* to
)
783 swaps(&to
->sequenceNumber
);
786 swaps(&to
->deviceid
);
787 swapl(&to
->property
);
791 SRawEvent(xXIRawEvent
* from
, xXIRawEvent
* to
)
797 memcpy(to
, from
, sizeof(xEvent
) + from
->length
* 4);
799 swaps(&to
->sequenceNumber
);
802 swaps(&to
->deviceid
);
806 mask
= (unsigned char *) &to
[1];
807 values
= (FP3232
*) (mask
+ from
->valuators_len
* 4);
809 for (i
= 0; i
< from
->valuators_len
* 4 * 8; i
++) {
810 if (BitIsOn(mask
, i
)) {
811 /* for each bit set there are two FP3232 values on the wire, in
812 * the order abcABC for data and data_raw. Here we swap as if
813 * they were in aAbBcC order because it's easier and really
816 swapl(&values
->integral
);
817 swapl(&values
->frac
);
819 swapl(&values
->integral
);
820 swapl(&values
->frac
);
825 swaps(&to
->valuators_len
);
829 STouchOwnershipEvent(xXITouchOwnershipEvent
* from
, xXITouchOwnershipEvent
* to
)
832 swaps(&to
->sequenceNumber
);
835 swaps(&to
->deviceid
);
837 swaps(&to
->sourceid
);
846 SBarrierEvent(xXIBarrierEvent
* from
,
847 xXIBarrierEvent
* to
) {
851 swaps(&to
->sequenceNumber
);
855 swaps(&to
->deviceid
);
856 swaps(&to
->sourceid
);
862 swapl(&to
->dx
.integral
);
864 swapl(&to
->dy
.integral
);
871 /** Event swapping function for XI2 events. */
873 XI2EventSwap(xGenericEvent
*from
, xGenericEvent
*to
)
875 switch (from
->evtype
) {
880 SDeviceLeaveNotifyEvent((xXILeaveEvent
*) from
, (xXILeaveEvent
*) to
);
882 case XI_DeviceChanged
:
883 SDeviceChangedEvent((xXIDeviceChangedEvent
*) from
,
884 (xXIDeviceChangedEvent
*) to
);
886 case XI_HierarchyChanged
:
887 SDeviceHierarchyEvent((xXIHierarchyEvent
*) from
,
888 (xXIHierarchyEvent
*) to
);
890 case XI_PropertyEvent
:
891 SXIPropertyEvent((xXIPropertyEvent
*) from
, (xXIPropertyEvent
*) to
);
897 case XI_ButtonRelease
:
901 SDeviceEvent((xXIDeviceEvent
*) from
, (xXIDeviceEvent
*) to
);
903 case XI_TouchOwnership
:
904 STouchOwnershipEvent((xXITouchOwnershipEvent
*) from
,
905 (xXITouchOwnershipEvent
*) to
);
909 case XI_RawKeyRelease
:
910 case XI_RawButtonPress
:
911 case XI_RawButtonRelease
:
912 case XI_RawTouchBegin
:
913 case XI_RawTouchUpdate
:
915 SRawEvent((xXIRawEvent
*) from
, (xXIRawEvent
*) to
);
918 case XI_BarrierLeave
:
919 SBarrierEvent((xXIBarrierEvent
*) from
,
920 (xXIBarrierEvent
*) to
);
923 ErrorF("[Xi] Unknown event type to swap. This is a bug.\n");
928 /**************************************************************************
930 * Allow the specified event to have its propagation suppressed.
931 * The default is to not allow suppression of propagation.
936 AllowPropagateSuppress(Mask mask
)
940 for (i
= 0; i
< MAXDEVICES
; i
++)
941 PropagateMask
[i
] |= mask
;
944 /**************************************************************************
946 * Record an event mask where there is no unique corresponding event type.
947 * We can't call SetMaskForEvent, since that would clobber the existing
948 * mask for that event. MotionHint and ButtonMotion are examples.
950 * Since extension event types will never be less than 64, we can use
951 * 0-63 in the EventInfo array as the "type" to be used to look up this
952 * mask. This means that the corresponding macros such as
953 * DevicePointerMotionHint must have access to the same constants.
958 SetEventInfo(Mask mask
, int constant
)
960 EventInfo
[ExtEventIndex
].mask
= mask
;
961 EventInfo
[ExtEventIndex
++].type
= constant
;
964 /**************************************************************************
966 * Allow the specified event to be restricted to being selected by one
968 * The default is to allow more than one client to select the event.
973 SetExclusiveAccess(Mask mask
)
977 for (i
= 0; i
< MAXDEVICES
; i
++)
978 ExtExclusiveMasks
[i
] |= mask
;
981 /**************************************************************************
983 * Assign the specified mask to the specified event.
988 SetMaskForExtEvent(Mask mask
, int event
)
992 EventInfo
[ExtEventIndex
].mask
= mask
;
993 EventInfo
[ExtEventIndex
++].type
= event
;
995 if ((event
< LASTEvent
) || (event
>= 128))
996 FatalError("MaskForExtensionEvent: bogus event number");
998 for (i
= 0; i
< MAXDEVICES
; i
++)
999 SetMaskForEvent(i
, mask
, event
);
1002 /************************************************************************
1004 * This function sets up extension event types and masks.
1009 FixExtensionEvents(ExtensionEntry
* extEntry
)
1011 DeviceValuator
= extEntry
->eventBase
;
1012 DeviceKeyPress
= DeviceValuator
+ 1;
1013 DeviceKeyRelease
= DeviceKeyPress
+ 1;
1014 DeviceButtonPress
= DeviceKeyRelease
+ 1;
1015 DeviceButtonRelease
= DeviceButtonPress
+ 1;
1016 DeviceMotionNotify
= DeviceButtonRelease
+ 1;
1017 DeviceFocusIn
= DeviceMotionNotify
+ 1;
1018 DeviceFocusOut
= DeviceFocusIn
+ 1;
1019 ProximityIn
= DeviceFocusOut
+ 1;
1020 ProximityOut
= ProximityIn
+ 1;
1021 DeviceStateNotify
= ProximityOut
+ 1;
1022 DeviceMappingNotify
= DeviceStateNotify
+ 1;
1023 ChangeDeviceNotify
= DeviceMappingNotify
+ 1;
1024 DeviceKeyStateNotify
= ChangeDeviceNotify
+ 1;
1025 DeviceButtonStateNotify
= DeviceKeyStateNotify
+ 1;
1026 DevicePresenceNotify
= DeviceButtonStateNotify
+ 1;
1027 DevicePropertyNotify
= DevicePresenceNotify
+ 1;
1029 event_base
[KeyClass
] = DeviceKeyPress
;
1030 event_base
[ButtonClass
] = DeviceButtonPress
;
1031 event_base
[ValuatorClass
] = DeviceMotionNotify
;
1032 event_base
[ProximityClass
] = ProximityIn
;
1033 event_base
[FocusClass
] = DeviceFocusIn
;
1034 event_base
[OtherClass
] = DeviceStateNotify
;
1036 BadDevice
+= extEntry
->errorBase
;
1037 BadEvent
+= extEntry
->errorBase
;
1038 BadMode
+= extEntry
->errorBase
;
1039 DeviceBusy
+= extEntry
->errorBase
;
1040 BadClass
+= extEntry
->errorBase
;
1042 SetMaskForExtEvent(DeviceKeyPressMask
, DeviceKeyPress
);
1043 AllowPropagateSuppress(DeviceKeyPressMask
);
1044 SetCriticalEvent(DeviceKeyPress
);
1046 SetMaskForExtEvent(DeviceKeyReleaseMask
, DeviceKeyRelease
);
1047 AllowPropagateSuppress(DeviceKeyReleaseMask
);
1048 SetCriticalEvent(DeviceKeyRelease
);
1050 SetMaskForExtEvent(DeviceButtonPressMask
, DeviceButtonPress
);
1051 AllowPropagateSuppress(DeviceButtonPressMask
);
1052 SetCriticalEvent(DeviceButtonPress
);
1054 SetMaskForExtEvent(DeviceButtonReleaseMask
, DeviceButtonRelease
);
1055 AllowPropagateSuppress(DeviceButtonReleaseMask
);
1056 SetCriticalEvent(DeviceButtonRelease
);
1058 SetMaskForExtEvent(DeviceProximityMask
, ProximityIn
);
1059 SetMaskForExtEvent(DeviceProximityMask
, ProximityOut
);
1061 SetMaskForExtEvent(DeviceStateNotifyMask
, DeviceStateNotify
);
1063 SetMaskForExtEvent(DevicePointerMotionMask
, DeviceMotionNotify
);
1064 AllowPropagateSuppress(DevicePointerMotionMask
);
1065 SetCriticalEvent(DeviceMotionNotify
);
1067 SetEventInfo(DevicePointerMotionHintMask
, _devicePointerMotionHint
);
1068 SetEventInfo(DeviceButton1MotionMask
, _deviceButton1Motion
);
1069 SetEventInfo(DeviceButton2MotionMask
, _deviceButton2Motion
);
1070 SetEventInfo(DeviceButton3MotionMask
, _deviceButton3Motion
);
1071 SetEventInfo(DeviceButton4MotionMask
, _deviceButton4Motion
);
1072 SetEventInfo(DeviceButton5MotionMask
, _deviceButton5Motion
);
1073 SetEventInfo(DeviceButtonMotionMask
, _deviceButtonMotion
);
1075 SetMaskForExtEvent(DeviceFocusChangeMask
, DeviceFocusIn
);
1076 SetMaskForExtEvent(DeviceFocusChangeMask
, DeviceFocusOut
);
1078 SetMaskForExtEvent(DeviceMappingNotifyMask
, DeviceMappingNotify
);
1079 SetMaskForExtEvent(ChangeDeviceNotifyMask
, ChangeDeviceNotify
);
1081 SetEventInfo(DeviceButtonGrabMask
, _deviceButtonGrab
);
1082 SetExclusiveAccess(DeviceButtonGrabMask
);
1084 SetEventInfo(DeviceOwnerGrabButtonMask
, _deviceOwnerGrabButton
);
1085 SetEventInfo(DevicePresenceNotifyMask
, _devicePresence
);
1086 SetMaskForExtEvent(DevicePropertyNotifyMask
, DevicePropertyNotify
);
1088 SetEventInfo(0, _noExtensionEvent
);
1091 /************************************************************************
1093 * This function restores extension event types and masks to their
1099 RestoreExtensionEvents(void)
1106 for (i
= 0; i
< ExtEventIndex
- 1; i
++) {
1107 if ((EventInfo
[i
].type
>= LASTEvent
) && (EventInfo
[i
].type
< 128)) {
1108 for (j
= 0; j
< MAXDEVICES
; j
++)
1109 SetMaskForEvent(j
, 0, EventInfo
[i
].type
);
1111 EventInfo
[i
].mask
= 0;
1112 EventInfo
[i
].type
= 0;
1117 DeviceKeyRelease
= 2;
1118 DeviceButtonPress
= 3;
1119 DeviceButtonRelease
= 4;
1120 DeviceMotionNotify
= 5;
1125 DeviceStateNotify
= 10;
1126 DeviceMappingNotify
= 11;
1127 ChangeDeviceNotify
= 12;
1128 DeviceKeyStateNotify
= 13;
1129 DeviceButtonStateNotify
= 13;
1130 DevicePresenceNotify
= 14;
1131 DevicePropertyNotify
= 15;
1141 /***********************************************************************
1144 * Remove reply-swapping routine.
1145 * Remove event-swapping routine.
1150 IResetProc(ExtensionEntry
* unused
)
1152 ReplySwapVector
[IReqCode
] = ReplyNotSwappd
;
1153 EventSwapVector
[DeviceValuator
] = NotImplemented
;
1154 EventSwapVector
[DeviceKeyPress
] = NotImplemented
;
1155 EventSwapVector
[DeviceKeyRelease
] = NotImplemented
;
1156 EventSwapVector
[DeviceButtonPress
] = NotImplemented
;
1157 EventSwapVector
[DeviceButtonRelease
] = NotImplemented
;
1158 EventSwapVector
[DeviceMotionNotify
] = NotImplemented
;
1159 EventSwapVector
[DeviceFocusIn
] = NotImplemented
;
1160 EventSwapVector
[DeviceFocusOut
] = NotImplemented
;
1161 EventSwapVector
[ProximityIn
] = NotImplemented
;
1162 EventSwapVector
[ProximityOut
] = NotImplemented
;
1163 EventSwapVector
[DeviceStateNotify
] = NotImplemented
;
1164 EventSwapVector
[DeviceKeyStateNotify
] = NotImplemented
;
1165 EventSwapVector
[DeviceButtonStateNotify
] = NotImplemented
;
1166 EventSwapVector
[DeviceMappingNotify
] = NotImplemented
;
1167 EventSwapVector
[ChangeDeviceNotify
] = NotImplemented
;
1168 EventSwapVector
[DevicePresenceNotify
] = NotImplemented
;
1169 EventSwapVector
[DevicePropertyNotify
] = NotImplemented
;
1170 RestoreExtensionEvents();
1172 free(xi_all_devices
.name
);
1173 free(xi_all_master_devices
.name
);
1178 /***********************************************************************
1180 * Assign an id and type to an input device.
1185 AssignTypeAndName(DeviceIntPtr dev
, Atom type
, const char *name
)
1187 dev
->xinput_type
= type
;
1188 dev
->name
= strdup(name
);
1191 /***********************************************************************
1193 * Make device type atoms.
1198 MakeDeviceTypeAtoms(void)
1202 for (i
= 0; i
< NUMTYPES
; i
++)
1204 MakeAtom(dev_type
[i
].name
, strlen(dev_type
[i
].name
), 1);
1207 /*****************************************************************************
1211 * Swap any events defined in this extension.
1213 #define DO_SWAP(func,type) func ((type *)from, (type *)to)
1216 SEventIDispatch(xEvent
*from
, xEvent
*to
)
1218 int type
= from
->u
.u
.type
& 0177;
1220 if (type
== DeviceValuator
)
1221 DO_SWAP(SEventDeviceValuator
, deviceValuator
);
1222 else if (type
== DeviceKeyPress
) {
1223 SKeyButtonPtrEvent(from
, to
);
1224 to
->u
.keyButtonPointer
.pad1
= from
->u
.keyButtonPointer
.pad1
;
1226 else if (type
== DeviceKeyRelease
) {
1227 SKeyButtonPtrEvent(from
, to
);
1228 to
->u
.keyButtonPointer
.pad1
= from
->u
.keyButtonPointer
.pad1
;
1230 else if (type
== DeviceButtonPress
) {
1231 SKeyButtonPtrEvent(from
, to
);
1232 to
->u
.keyButtonPointer
.pad1
= from
->u
.keyButtonPointer
.pad1
;
1234 else if (type
== DeviceButtonRelease
) {
1235 SKeyButtonPtrEvent(from
, to
);
1236 to
->u
.keyButtonPointer
.pad1
= from
->u
.keyButtonPointer
.pad1
;
1238 else if (type
== DeviceMotionNotify
) {
1239 SKeyButtonPtrEvent(from
, to
);
1240 to
->u
.keyButtonPointer
.pad1
= from
->u
.keyButtonPointer
.pad1
;
1242 else if (type
== DeviceFocusIn
)
1243 DO_SWAP(SEventFocus
, deviceFocus
);
1244 else if (type
== DeviceFocusOut
)
1245 DO_SWAP(SEventFocus
, deviceFocus
);
1246 else if (type
== ProximityIn
) {
1247 SKeyButtonPtrEvent(from
, to
);
1248 to
->u
.keyButtonPointer
.pad1
= from
->u
.keyButtonPointer
.pad1
;
1250 else if (type
== ProximityOut
) {
1251 SKeyButtonPtrEvent(from
, to
);
1252 to
->u
.keyButtonPointer
.pad1
= from
->u
.keyButtonPointer
.pad1
;
1254 else if (type
== DeviceStateNotify
)
1255 DO_SWAP(SDeviceStateNotifyEvent
, deviceStateNotify
);
1256 else if (type
== DeviceKeyStateNotify
)
1257 DO_SWAP(SDeviceKeyStateNotifyEvent
, deviceKeyStateNotify
);
1258 else if (type
== DeviceButtonStateNotify
)
1259 DO_SWAP(SDeviceButtonStateNotifyEvent
, deviceButtonStateNotify
);
1260 else if (type
== DeviceMappingNotify
)
1261 DO_SWAP(SDeviceMappingNotifyEvent
, deviceMappingNotify
);
1262 else if (type
== ChangeDeviceNotify
)
1263 DO_SWAP(SChangeDeviceNotifyEvent
, changeDeviceNotify
);
1264 else if (type
== DevicePresenceNotify
)
1265 DO_SWAP(SDevicePresenceNotifyEvent
, devicePresenceNotify
);
1266 else if (type
== DevicePropertyNotify
)
1267 DO_SWAP(SDevicePropertyNotifyEvent
, devicePropertyNotify
);
1269 FatalError("XInputExtension: Impossible event!\n");
1273 /**********************************************************************
1275 * IExtensionInit - initialize the input extension.
1277 * Called from InitExtensions in main() or from QueryExtension() if the
1278 * extension is dynamically loaded.
1280 * This extension has several events and errors.
1282 * XI is mandatory nowadays, so if we fail to init XI, we die.
1286 XInputExtensionInit(void)
1288 ExtensionEntry
*extEntry
;
1290 XExtensionVersion thisversion
= { XI_Present
,
1291 SERVER_XI_MAJOR_VERSION
,
1292 SERVER_XI_MINOR_VERSION
,
1295 if (!dixRegisterPrivateKey
1296 (&XIClientPrivateKeyRec
, PRIVATE_CLIENT
, sizeof(XIClientRec
)))
1297 FatalError("Cannot request private for XI.\n");
1299 if (!AddCallback(&ClientStateCallback
, XIClientCallback
, 0))
1300 FatalError("Failed to add callback to XI.\n");
1302 if (!XIBarrierInit())
1303 FatalError("Could not initialize barriers.\n");
1305 extEntry
= AddExtension(INAME
, IEVENTS
, IERRORS
, ProcIDispatch
,
1306 SProcIDispatch
, IResetProc
, StandardMinorOpcode
);
1308 IReqCode
= extEntry
->base
;
1309 IEventBase
= extEntry
->eventBase
;
1310 XIVersion
= thisversion
;
1311 MakeDeviceTypeAtoms();
1312 RT_INPUTCLIENT
= CreateNewResourceType((DeleteType
) InputClientGone
,
1314 if (!RT_INPUTCLIENT
)
1315 FatalError("Failed to add resource type for XI.\n");
1316 FixExtensionEvents(extEntry
);
1317 ReplySwapVector
[IReqCode
] = (ReplySwapPtr
) SReplyIDispatch
;
1318 EventSwapVector
[DeviceValuator
] = SEventIDispatch
;
1319 EventSwapVector
[DeviceKeyPress
] = SEventIDispatch
;
1320 EventSwapVector
[DeviceKeyRelease
] = SEventIDispatch
;
1321 EventSwapVector
[DeviceButtonPress
] = SEventIDispatch
;
1322 EventSwapVector
[DeviceButtonRelease
] = SEventIDispatch
;
1323 EventSwapVector
[DeviceMotionNotify
] = SEventIDispatch
;
1324 EventSwapVector
[DeviceFocusIn
] = SEventIDispatch
;
1325 EventSwapVector
[DeviceFocusOut
] = SEventIDispatch
;
1326 EventSwapVector
[ProximityIn
] = SEventIDispatch
;
1327 EventSwapVector
[ProximityOut
] = SEventIDispatch
;
1328 EventSwapVector
[DeviceStateNotify
] = SEventIDispatch
;
1329 EventSwapVector
[DeviceKeyStateNotify
] = SEventIDispatch
;
1330 EventSwapVector
[DeviceButtonStateNotify
] = SEventIDispatch
;
1331 EventSwapVector
[DeviceMappingNotify
] = SEventIDispatch
;
1332 EventSwapVector
[ChangeDeviceNotify
] = SEventIDispatch
;
1333 EventSwapVector
[DevicePresenceNotify
] = SEventIDispatch
;
1335 GERegisterExtension(IReqCode
, XI2EventSwap
);
1337 memset(&xi_all_devices
, 0, sizeof(xi_all_devices
));
1338 memset(&xi_all_master_devices
, 0, sizeof(xi_all_master_devices
));
1339 xi_all_devices
.id
= XIAllDevices
;
1340 xi_all_devices
.name
= strdup("XIAllDevices");
1341 xi_all_master_devices
.id
= XIAllMasterDevices
;
1342 xi_all_master_devices
.name
= strdup("XIAllMasterDevices");
1344 inputInfo
.all_devices
= &xi_all_devices
;
1345 inputInfo
.all_master_devices
= &xi_all_master_devices
;
1347 XIResetProperties();
1350 FatalError("IExtensionInit: AddExtensions failed\n");