xref: /OK3568_Linux_fs/external/xserver/Xi/extinit.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /************************************************************
2*4882a593Smuzhiyun 
3*4882a593Smuzhiyun Copyright 1989, 1998  The Open Group
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun Permission to use, copy, modify, distribute, and sell this software and its
6*4882a593Smuzhiyun documentation for any purpose is hereby granted without fee, provided that
7*4882a593Smuzhiyun the above copyright notice appear in all copies and that both that
8*4882a593Smuzhiyun copyright notice and this permission notice appear in supporting
9*4882a593Smuzhiyun documentation.
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun The above copyright notice and this permission notice shall be included in
12*4882a593Smuzhiyun all copies or substantial portions of the Software.
13*4882a593Smuzhiyun 
14*4882a593Smuzhiyun THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15*4882a593Smuzhiyun IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16*4882a593Smuzhiyun FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17*4882a593Smuzhiyun OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18*4882a593Smuzhiyun AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19*4882a593Smuzhiyun CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun Except as contained in this notice, the name of The Open Group shall not be
22*4882a593Smuzhiyun used in advertising or otherwise to promote the sale, use or other dealings
23*4882a593Smuzhiyun in this Software without prior written authorization from The Open Group.
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun 			All Rights Reserved
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun Permission to use, copy, modify, and distribute this software and its
30*4882a593Smuzhiyun documentation for any purpose and without fee is hereby granted,
31*4882a593Smuzhiyun provided that the above copyright notice appear in all copies and that
32*4882a593Smuzhiyun both that copyright notice and this permission notice appear in
33*4882a593Smuzhiyun supporting documentation, and that the name of Hewlett-Packard not be
34*4882a593Smuzhiyun used in advertising or publicity pertaining to distribution of the
35*4882a593Smuzhiyun software without specific, written prior permission.
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38*4882a593Smuzhiyun ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39*4882a593Smuzhiyun HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40*4882a593Smuzhiyun ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41*4882a593Smuzhiyun WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42*4882a593Smuzhiyun ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43*4882a593Smuzhiyun SOFTWARE.
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun ********************************************************/
46*4882a593Smuzhiyun 
47*4882a593Smuzhiyun /********************************************************************
48*4882a593Smuzhiyun  *
49*4882a593Smuzhiyun  *  Dispatch routines and initialization routines for the X input extension.
50*4882a593Smuzhiyun  *
51*4882a593Smuzhiyun  */
52*4882a593Smuzhiyun #define	 NUMTYPES 15
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun #ifdef HAVE_DIX_CONFIG_H
55*4882a593Smuzhiyun #include <dix-config.h>
56*4882a593Smuzhiyun #endif
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #include "inputstr.h"
59*4882a593Smuzhiyun #include "gcstruct.h"           /* pointer for extnsionst.h */
60*4882a593Smuzhiyun #include "extnsionst.h"         /* extension entry   */
61*4882a593Smuzhiyun #include <X11/extensions/XI.h>
62*4882a593Smuzhiyun #include <X11/extensions/XIproto.h>
63*4882a593Smuzhiyun #include <X11/extensions/XI2proto.h>
64*4882a593Smuzhiyun #include <X11/extensions/geproto.h>
65*4882a593Smuzhiyun #include "geext.h"              /* extension interfaces for ge */
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun #include "dixevents.h"
68*4882a593Smuzhiyun #include "exevents.h"
69*4882a593Smuzhiyun #include "extinit.h"
70*4882a593Smuzhiyun #include "exglobals.h"
71*4882a593Smuzhiyun #include "swaprep.h"
72*4882a593Smuzhiyun #include "privates.h"
73*4882a593Smuzhiyun #include "protocol-versions.h"
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun /* modules local to Xi */
76*4882a593Smuzhiyun #include "allowev.h"
77*4882a593Smuzhiyun #include "chgdctl.h"
78*4882a593Smuzhiyun #include "chgfctl.h"
79*4882a593Smuzhiyun #include "chgkbd.h"
80*4882a593Smuzhiyun #include "chgprop.h"
81*4882a593Smuzhiyun #include "chgptr.h"
82*4882a593Smuzhiyun #include "closedev.h"
83*4882a593Smuzhiyun #include "devbell.h"
84*4882a593Smuzhiyun #include "getbmap.h"
85*4882a593Smuzhiyun #include "getdctl.h"
86*4882a593Smuzhiyun #include "getfctl.h"
87*4882a593Smuzhiyun #include "getfocus.h"
88*4882a593Smuzhiyun #include "getkmap.h"
89*4882a593Smuzhiyun #include "getmmap.h"
90*4882a593Smuzhiyun #include "getprop.h"
91*4882a593Smuzhiyun #include "getselev.h"
92*4882a593Smuzhiyun #include "getvers.h"
93*4882a593Smuzhiyun #include "grabdev.h"
94*4882a593Smuzhiyun #include "grabdevb.h"
95*4882a593Smuzhiyun #include "grabdevk.h"
96*4882a593Smuzhiyun #include "gtmotion.h"
97*4882a593Smuzhiyun #include "listdev.h"
98*4882a593Smuzhiyun #include "opendev.h"
99*4882a593Smuzhiyun #include "queryst.h"
100*4882a593Smuzhiyun #include "selectev.h"
101*4882a593Smuzhiyun #include "sendexev.h"
102*4882a593Smuzhiyun #include "chgkmap.h"
103*4882a593Smuzhiyun #include "setbmap.h"
104*4882a593Smuzhiyun #include "setdval.h"
105*4882a593Smuzhiyun #include "setfocus.h"
106*4882a593Smuzhiyun #include "setmmap.h"
107*4882a593Smuzhiyun #include "setmode.h"
108*4882a593Smuzhiyun #include "ungrdev.h"
109*4882a593Smuzhiyun #include "ungrdevb.h"
110*4882a593Smuzhiyun #include "ungrdevk.h"
111*4882a593Smuzhiyun #include "xiallowev.h"
112*4882a593Smuzhiyun #include "xiselectev.h"
113*4882a593Smuzhiyun #include "xigrabdev.h"
114*4882a593Smuzhiyun #include "xipassivegrab.h"
115*4882a593Smuzhiyun #include "xisetdevfocus.h"
116*4882a593Smuzhiyun #include "xiproperty.h"
117*4882a593Smuzhiyun #include "xichangecursor.h"
118*4882a593Smuzhiyun #include "xichangehierarchy.h"
119*4882a593Smuzhiyun #include "xigetclientpointer.h"
120*4882a593Smuzhiyun #include "xiquerydevice.h"
121*4882a593Smuzhiyun #include "xiquerypointer.h"
122*4882a593Smuzhiyun #include "xiqueryversion.h"
123*4882a593Smuzhiyun #include "xisetclientpointer.h"
124*4882a593Smuzhiyun #include "xiwarppointer.h"
125*4882a593Smuzhiyun #include "xibarriers.h"
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun /* Masks for XI events have to be aligned with core event (partially anyway).
128*4882a593Smuzhiyun  * If DeviceButtonMotionMask is != ButtonMotionMask, event delivery
129*4882a593Smuzhiyun  * breaks down. The device needs the dev->button->motionMask. If DBMM is
130*4882a593Smuzhiyun  * the same as BMM, we can ensure that both core and device events can be
131*4882a593Smuzhiyun  * delivered, without the need for extra structures in the DeviceIntRec. */
132*4882a593Smuzhiyun const Mask DeviceKeyPressMask = KeyPressMask;
133*4882a593Smuzhiyun const Mask DeviceKeyReleaseMask = KeyReleaseMask;
134*4882a593Smuzhiyun const Mask DeviceButtonPressMask = ButtonPressMask;
135*4882a593Smuzhiyun const Mask DeviceButtonReleaseMask = ButtonReleaseMask;
136*4882a593Smuzhiyun const Mask DeviceProximityMask = (1L << 4);
137*4882a593Smuzhiyun const Mask DeviceStateNotifyMask = (1L << 5);
138*4882a593Smuzhiyun const Mask DevicePointerMotionMask = PointerMotionMask;
139*4882a593Smuzhiyun const Mask DevicePointerMotionHintMask = PointerMotionHintMask;
140*4882a593Smuzhiyun const Mask DeviceButton1MotionMask = Button1MotionMask;
141*4882a593Smuzhiyun const Mask DeviceButton2MotionMask = Button2MotionMask;
142*4882a593Smuzhiyun const Mask DeviceButton3MotionMask = Button3MotionMask;
143*4882a593Smuzhiyun const Mask DeviceButton4MotionMask = Button4MotionMask;
144*4882a593Smuzhiyun const Mask DeviceButton5MotionMask = Button5MotionMask;
145*4882a593Smuzhiyun const Mask DeviceButtonMotionMask = ButtonMotionMask;
146*4882a593Smuzhiyun const Mask DeviceFocusChangeMask = (1L << 14);
147*4882a593Smuzhiyun const Mask DeviceMappingNotifyMask = (1L << 15);
148*4882a593Smuzhiyun const Mask ChangeDeviceNotifyMask = (1L << 16);
149*4882a593Smuzhiyun const Mask DeviceButtonGrabMask = (1L << 17);
150*4882a593Smuzhiyun const Mask DeviceOwnerGrabButtonMask = (1L << 17);
151*4882a593Smuzhiyun const Mask DevicePresenceNotifyMask = (1L << 18);
152*4882a593Smuzhiyun const Mask DevicePropertyNotifyMask = (1L << 19);
153*4882a593Smuzhiyun const Mask XIAllMasks = (1L << 20) - 1;
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun int ExtEventIndex;
156*4882a593Smuzhiyun Mask ExtExclusiveMasks[EMASKSIZE];
157*4882a593Smuzhiyun 
158*4882a593Smuzhiyun static struct dev_type {
159*4882a593Smuzhiyun     Atom type;
160*4882a593Smuzhiyun     const char *name;
161*4882a593Smuzhiyun } dev_type[] = {
162*4882a593Smuzhiyun     {0, XI_KEYBOARD},
163*4882a593Smuzhiyun     {0, XI_MOUSE},
164*4882a593Smuzhiyun     {0, XI_TABLET},
165*4882a593Smuzhiyun     {0, XI_TOUCHSCREEN},
166*4882a593Smuzhiyun     {0, XI_TOUCHPAD},
167*4882a593Smuzhiyun     {0, XI_BARCODE},
168*4882a593Smuzhiyun     {0, XI_BUTTONBOX},
169*4882a593Smuzhiyun     {0, XI_KNOB_BOX},
170*4882a593Smuzhiyun     {0, XI_ONE_KNOB},
171*4882a593Smuzhiyun     {0, XI_NINE_KNOB},
172*4882a593Smuzhiyun     {0, XI_TRACKBALL},
173*4882a593Smuzhiyun     {0, XI_QUADRATURE},
174*4882a593Smuzhiyun     {0, XI_ID_MODULE},
175*4882a593Smuzhiyun     {0, XI_SPACEBALL},
176*4882a593Smuzhiyun     {0, XI_DATAGLOVE},
177*4882a593Smuzhiyun     {0, XI_EYETRACKER},
178*4882a593Smuzhiyun     {0, XI_CURSORKEYS},
179*4882a593Smuzhiyun     {0, XI_FOOTMOUSE}
180*4882a593Smuzhiyun };
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun CARD8 event_base[numInputClasses];
183*4882a593Smuzhiyun XExtEventInfo EventInfo[32];
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun static DeviceIntRec xi_all_devices;
186*4882a593Smuzhiyun static DeviceIntRec xi_all_master_devices;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun /**
189*4882a593Smuzhiyun  * Dispatch vector. Functions defined in here will be called when the matching
190*4882a593Smuzhiyun  * request arrives.
191*4882a593Smuzhiyun  */
192*4882a593Smuzhiyun static int (*ProcIVector[]) (ClientPtr) = {
193*4882a593Smuzhiyun     NULL,                       /*  0 */
194*4882a593Smuzhiyun         ProcXGetExtensionVersion,       /*  1 */
195*4882a593Smuzhiyun         ProcXListInputDevices,  /*  2 */
196*4882a593Smuzhiyun         ProcXOpenDevice,        /*  3 */
197*4882a593Smuzhiyun         ProcXCloseDevice,       /*  4 */
198*4882a593Smuzhiyun         ProcXSetDeviceMode,     /*  5 */
199*4882a593Smuzhiyun         ProcXSelectExtensionEvent,      /*  6 */
200*4882a593Smuzhiyun         ProcXGetSelectedExtensionEvents,        /*  7 */
201*4882a593Smuzhiyun         ProcXChangeDeviceDontPropagateList,     /*  8 */
202*4882a593Smuzhiyun         ProcXGetDeviceDontPropagateList,        /*  9 */
203*4882a593Smuzhiyun         ProcXGetDeviceMotionEvents,     /* 10 */
204*4882a593Smuzhiyun         ProcXChangeKeyboardDevice,      /* 11 */
205*4882a593Smuzhiyun         ProcXChangePointerDevice,       /* 12 */
206*4882a593Smuzhiyun         ProcXGrabDevice,        /* 13 */
207*4882a593Smuzhiyun         ProcXUngrabDevice,      /* 14 */
208*4882a593Smuzhiyun         ProcXGrabDeviceKey,     /* 15 */
209*4882a593Smuzhiyun         ProcXUngrabDeviceKey,   /* 16 */
210*4882a593Smuzhiyun         ProcXGrabDeviceButton,  /* 17 */
211*4882a593Smuzhiyun         ProcXUngrabDeviceButton,        /* 18 */
212*4882a593Smuzhiyun         ProcXAllowDeviceEvents, /* 19 */
213*4882a593Smuzhiyun         ProcXGetDeviceFocus,    /* 20 */
214*4882a593Smuzhiyun         ProcXSetDeviceFocus,    /* 21 */
215*4882a593Smuzhiyun         ProcXGetFeedbackControl,        /* 22 */
216*4882a593Smuzhiyun         ProcXChangeFeedbackControl,     /* 23 */
217*4882a593Smuzhiyun         ProcXGetDeviceKeyMapping,       /* 24 */
218*4882a593Smuzhiyun         ProcXChangeDeviceKeyMapping,    /* 25 */
219*4882a593Smuzhiyun         ProcXGetDeviceModifierMapping,  /* 26 */
220*4882a593Smuzhiyun         ProcXSetDeviceModifierMapping,  /* 27 */
221*4882a593Smuzhiyun         ProcXGetDeviceButtonMapping,    /* 28 */
222*4882a593Smuzhiyun         ProcXSetDeviceButtonMapping,    /* 29 */
223*4882a593Smuzhiyun         ProcXQueryDeviceState,  /* 30 */
224*4882a593Smuzhiyun         ProcXSendExtensionEvent,        /* 31 */
225*4882a593Smuzhiyun         ProcXDeviceBell,        /* 32 */
226*4882a593Smuzhiyun         ProcXSetDeviceValuators,        /* 33 */
227*4882a593Smuzhiyun         ProcXGetDeviceControl,  /* 34 */
228*4882a593Smuzhiyun         ProcXChangeDeviceControl,       /* 35 */
229*4882a593Smuzhiyun         /* XI 1.5 */
230*4882a593Smuzhiyun         ProcXListDeviceProperties,      /* 36 */
231*4882a593Smuzhiyun         ProcXChangeDeviceProperty,      /* 37 */
232*4882a593Smuzhiyun         ProcXDeleteDeviceProperty,      /* 38 */
233*4882a593Smuzhiyun         ProcXGetDeviceProperty, /* 39 */
234*4882a593Smuzhiyun         /* XI 2 */
235*4882a593Smuzhiyun         ProcXIQueryPointer,     /* 40 */
236*4882a593Smuzhiyun         ProcXIWarpPointer,      /* 41 */
237*4882a593Smuzhiyun         ProcXIChangeCursor,     /* 42 */
238*4882a593Smuzhiyun         ProcXIChangeHierarchy,  /* 43 */
239*4882a593Smuzhiyun         ProcXISetClientPointer, /* 44 */
240*4882a593Smuzhiyun         ProcXIGetClientPointer, /* 45 */
241*4882a593Smuzhiyun         ProcXISelectEvents,     /* 46 */
242*4882a593Smuzhiyun         ProcXIQueryVersion,     /* 47 */
243*4882a593Smuzhiyun         ProcXIQueryDevice,      /* 48 */
244*4882a593Smuzhiyun         ProcXISetFocus,         /* 49 */
245*4882a593Smuzhiyun         ProcXIGetFocus,         /* 50 */
246*4882a593Smuzhiyun         ProcXIGrabDevice,       /* 51 */
247*4882a593Smuzhiyun         ProcXIUngrabDevice,     /* 52 */
248*4882a593Smuzhiyun         ProcXIAllowEvents,      /* 53 */
249*4882a593Smuzhiyun         ProcXIPassiveGrabDevice,        /* 54 */
250*4882a593Smuzhiyun         ProcXIPassiveUngrabDevice,      /* 55 */
251*4882a593Smuzhiyun         ProcXIListProperties,   /* 56 */
252*4882a593Smuzhiyun         ProcXIChangeProperty,   /* 57 */
253*4882a593Smuzhiyun         ProcXIDeleteProperty,   /* 58 */
254*4882a593Smuzhiyun         ProcXIGetProperty,      /* 59 */
255*4882a593Smuzhiyun         ProcXIGetSelectedEvents, /* 60 */
256*4882a593Smuzhiyun         ProcXIBarrierReleasePointer /* 61 */
257*4882a593Smuzhiyun };
258*4882a593Smuzhiyun 
259*4882a593Smuzhiyun /* For swapped clients */
260*4882a593Smuzhiyun static int (*SProcIVector[]) (ClientPtr) = {
261*4882a593Smuzhiyun     NULL,                       /*  0 */
262*4882a593Smuzhiyun         SProcXGetExtensionVersion,      /*  1 */
263*4882a593Smuzhiyun         SProcXListInputDevices, /*  2 */
264*4882a593Smuzhiyun         SProcXOpenDevice,       /*  3 */
265*4882a593Smuzhiyun         SProcXCloseDevice,      /*  4 */
266*4882a593Smuzhiyun         SProcXSetDeviceMode,    /*  5 */
267*4882a593Smuzhiyun         SProcXSelectExtensionEvent,     /*  6 */
268*4882a593Smuzhiyun         SProcXGetSelectedExtensionEvents,       /*  7 */
269*4882a593Smuzhiyun         SProcXChangeDeviceDontPropagateList,    /*  8 */
270*4882a593Smuzhiyun         SProcXGetDeviceDontPropagateList,       /*  9 */
271*4882a593Smuzhiyun         SProcXGetDeviceMotionEvents,    /* 10 */
272*4882a593Smuzhiyun         SProcXChangeKeyboardDevice,     /* 11 */
273*4882a593Smuzhiyun         SProcXChangePointerDevice,      /* 12 */
274*4882a593Smuzhiyun         SProcXGrabDevice,       /* 13 */
275*4882a593Smuzhiyun         SProcXUngrabDevice,     /* 14 */
276*4882a593Smuzhiyun         SProcXGrabDeviceKey,    /* 15 */
277*4882a593Smuzhiyun         SProcXUngrabDeviceKey,  /* 16 */
278*4882a593Smuzhiyun         SProcXGrabDeviceButton, /* 17 */
279*4882a593Smuzhiyun         SProcXUngrabDeviceButton,       /* 18 */
280*4882a593Smuzhiyun         SProcXAllowDeviceEvents,        /* 19 */
281*4882a593Smuzhiyun         SProcXGetDeviceFocus,   /* 20 */
282*4882a593Smuzhiyun         SProcXSetDeviceFocus,   /* 21 */
283*4882a593Smuzhiyun         SProcXGetFeedbackControl,       /* 22 */
284*4882a593Smuzhiyun         SProcXChangeFeedbackControl,    /* 23 */
285*4882a593Smuzhiyun         SProcXGetDeviceKeyMapping,      /* 24 */
286*4882a593Smuzhiyun         SProcXChangeDeviceKeyMapping,   /* 25 */
287*4882a593Smuzhiyun         SProcXGetDeviceModifierMapping, /* 26 */
288*4882a593Smuzhiyun         SProcXSetDeviceModifierMapping, /* 27 */
289*4882a593Smuzhiyun         SProcXGetDeviceButtonMapping,   /* 28 */
290*4882a593Smuzhiyun         SProcXSetDeviceButtonMapping,   /* 29 */
291*4882a593Smuzhiyun         SProcXQueryDeviceState, /* 30 */
292*4882a593Smuzhiyun         SProcXSendExtensionEvent,       /* 31 */
293*4882a593Smuzhiyun         SProcXDeviceBell,       /* 32 */
294*4882a593Smuzhiyun         SProcXSetDeviceValuators,       /* 33 */
295*4882a593Smuzhiyun         SProcXGetDeviceControl, /* 34 */
296*4882a593Smuzhiyun         SProcXChangeDeviceControl,      /* 35 */
297*4882a593Smuzhiyun         SProcXListDeviceProperties,     /* 36 */
298*4882a593Smuzhiyun         SProcXChangeDeviceProperty,     /* 37 */
299*4882a593Smuzhiyun         SProcXDeleteDeviceProperty,     /* 38 */
300*4882a593Smuzhiyun         SProcXGetDeviceProperty,        /* 39 */
301*4882a593Smuzhiyun         SProcXIQueryPointer,    /* 40 */
302*4882a593Smuzhiyun         SProcXIWarpPointer,     /* 41 */
303*4882a593Smuzhiyun         SProcXIChangeCursor,    /* 42 */
304*4882a593Smuzhiyun         SProcXIChangeHierarchy, /* 43 */
305*4882a593Smuzhiyun         SProcXISetClientPointer,        /* 44 */
306*4882a593Smuzhiyun         SProcXIGetClientPointer,        /* 45 */
307*4882a593Smuzhiyun         SProcXISelectEvents,    /* 46 */
308*4882a593Smuzhiyun         SProcXIQueryVersion,    /* 47 */
309*4882a593Smuzhiyun         SProcXIQueryDevice,     /* 48 */
310*4882a593Smuzhiyun         SProcXISetFocus,        /* 49 */
311*4882a593Smuzhiyun         SProcXIGetFocus,        /* 50 */
312*4882a593Smuzhiyun         SProcXIGrabDevice,      /* 51 */
313*4882a593Smuzhiyun         SProcXIUngrabDevice,    /* 52 */
314*4882a593Smuzhiyun         SProcXIAllowEvents,     /* 53 */
315*4882a593Smuzhiyun         SProcXIPassiveGrabDevice,       /* 54 */
316*4882a593Smuzhiyun         SProcXIPassiveUngrabDevice,     /* 55 */
317*4882a593Smuzhiyun         SProcXIListProperties,  /* 56 */
318*4882a593Smuzhiyun         SProcXIChangeProperty,  /* 57 */
319*4882a593Smuzhiyun         SProcXIDeleteProperty,  /* 58 */
320*4882a593Smuzhiyun         SProcXIGetProperty,     /* 59 */
321*4882a593Smuzhiyun         SProcXIGetSelectedEvents,       /* 60 */
322*4882a593Smuzhiyun         SProcXIBarrierReleasePointer /* 61 */
323*4882a593Smuzhiyun };
324*4882a593Smuzhiyun 
325*4882a593Smuzhiyun /*****************************************************************
326*4882a593Smuzhiyun  *
327*4882a593Smuzhiyun  * Globals referenced elsewhere in the server.
328*4882a593Smuzhiyun  *
329*4882a593Smuzhiyun  */
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun int IReqCode = 0;
332*4882a593Smuzhiyun int IEventBase = 0;
333*4882a593Smuzhiyun int BadDevice = 0;
334*4882a593Smuzhiyun static int BadEvent = 1;
335*4882a593Smuzhiyun int BadMode = 2;
336*4882a593Smuzhiyun int DeviceBusy = 3;
337*4882a593Smuzhiyun int BadClass = 4;
338*4882a593Smuzhiyun 
339*4882a593Smuzhiyun int DeviceValuator;
340*4882a593Smuzhiyun int DeviceKeyPress;
341*4882a593Smuzhiyun int DeviceKeyRelease;
342*4882a593Smuzhiyun int DeviceButtonPress;
343*4882a593Smuzhiyun int DeviceButtonRelease;
344*4882a593Smuzhiyun int DeviceMotionNotify;
345*4882a593Smuzhiyun int DeviceFocusIn;
346*4882a593Smuzhiyun int DeviceFocusOut;
347*4882a593Smuzhiyun int ProximityIn;
348*4882a593Smuzhiyun int ProximityOut;
349*4882a593Smuzhiyun int DeviceStateNotify;
350*4882a593Smuzhiyun int DeviceKeyStateNotify;
351*4882a593Smuzhiyun int DeviceButtonStateNotify;
352*4882a593Smuzhiyun int DeviceMappingNotify;
353*4882a593Smuzhiyun int ChangeDeviceNotify;
354*4882a593Smuzhiyun int DevicePresenceNotify;
355*4882a593Smuzhiyun int DevicePropertyNotify;
356*4882a593Smuzhiyun 
357*4882a593Smuzhiyun RESTYPE RT_INPUTCLIENT;
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun /*****************************************************************
360*4882a593Smuzhiyun  *
361*4882a593Smuzhiyun  * Externs defined elsewhere in the X server.
362*4882a593Smuzhiyun  *
363*4882a593Smuzhiyun  */
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun extern XExtensionVersion XIVersion;
366*4882a593Smuzhiyun 
367*4882a593Smuzhiyun Mask PropagateMask[EMASKSIZE];
368*4882a593Smuzhiyun 
369*4882a593Smuzhiyun /*****************************************************************
370*4882a593Smuzhiyun  *
371*4882a593Smuzhiyun  * Versioning support
372*4882a593Smuzhiyun  *
373*4882a593Smuzhiyun  */
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun DevPrivateKeyRec XIClientPrivateKeyRec;
376*4882a593Smuzhiyun 
377*4882a593Smuzhiyun /*****************************************************************
378*4882a593Smuzhiyun  *
379*4882a593Smuzhiyun  * Declarations of local routines.
380*4882a593Smuzhiyun  *
381*4882a593Smuzhiyun  */
382*4882a593Smuzhiyun 
383*4882a593Smuzhiyun /*************************************************************************
384*4882a593Smuzhiyun  *
385*4882a593Smuzhiyun  * ProcIDispatch - main dispatch routine for requests to this extension.
386*4882a593Smuzhiyun  * This routine is used if server and client have the same byte ordering.
387*4882a593Smuzhiyun  *
388*4882a593Smuzhiyun  */
389*4882a593Smuzhiyun 
390*4882a593Smuzhiyun static int
ProcIDispatch(ClientPtr client)391*4882a593Smuzhiyun ProcIDispatch(ClientPtr client)
392*4882a593Smuzhiyun {
393*4882a593Smuzhiyun     REQUEST(xReq);
394*4882a593Smuzhiyun     if (stuff->data >= ARRAY_SIZE(ProcIVector) || !ProcIVector[stuff->data])
395*4882a593Smuzhiyun         return BadRequest;
396*4882a593Smuzhiyun 
397*4882a593Smuzhiyun     UpdateCurrentTimeIf();
398*4882a593Smuzhiyun     return (*ProcIVector[stuff->data]) (client);
399*4882a593Smuzhiyun }
400*4882a593Smuzhiyun 
401*4882a593Smuzhiyun /*******************************************************************************
402*4882a593Smuzhiyun  *
403*4882a593Smuzhiyun  * SProcXDispatch
404*4882a593Smuzhiyun  *
405*4882a593Smuzhiyun  * Main swapped dispatch routine for requests to this extension.
406*4882a593Smuzhiyun  * This routine is used if server and client do not have the same byte ordering.
407*4882a593Smuzhiyun  *
408*4882a593Smuzhiyun  */
409*4882a593Smuzhiyun 
410*4882a593Smuzhiyun static int _X_COLD
SProcIDispatch(ClientPtr client)411*4882a593Smuzhiyun SProcIDispatch(ClientPtr client)
412*4882a593Smuzhiyun {
413*4882a593Smuzhiyun     REQUEST(xReq);
414*4882a593Smuzhiyun     if (stuff->data >= ARRAY_SIZE(SProcIVector) || !SProcIVector[stuff->data])
415*4882a593Smuzhiyun         return BadRequest;
416*4882a593Smuzhiyun 
417*4882a593Smuzhiyun     UpdateCurrentTimeIf();
418*4882a593Smuzhiyun     return (*SProcIVector[stuff->data]) (client);
419*4882a593Smuzhiyun }
420*4882a593Smuzhiyun 
421*4882a593Smuzhiyun /**********************************************************************
422*4882a593Smuzhiyun  *
423*4882a593Smuzhiyun  * SReplyIDispatch
424*4882a593Smuzhiyun  * Swap any replies defined in this extension.
425*4882a593Smuzhiyun  *
426*4882a593Smuzhiyun  */
427*4882a593Smuzhiyun 
428*4882a593Smuzhiyun static void _X_COLD
SReplyIDispatch(ClientPtr client,int len,xGrabDeviceReply * rep)429*4882a593Smuzhiyun SReplyIDispatch(ClientPtr client, int len, xGrabDeviceReply * rep)
430*4882a593Smuzhiyun {
431*4882a593Smuzhiyun     /* All we look at is the type field */
432*4882a593Smuzhiyun     /* This is common to all replies    */
433*4882a593Smuzhiyun     if (rep->RepType == X_GetExtensionVersion)
434*4882a593Smuzhiyun         SRepXGetExtensionVersion(client, len,
435*4882a593Smuzhiyun                                  (xGetExtensionVersionReply *) rep);
436*4882a593Smuzhiyun     else if (rep->RepType == X_ListInputDevices)
437*4882a593Smuzhiyun         SRepXListInputDevices(client, len, (xListInputDevicesReply *) rep);
438*4882a593Smuzhiyun     else if (rep->RepType == X_OpenDevice)
439*4882a593Smuzhiyun         SRepXOpenDevice(client, len, (xOpenDeviceReply *) rep);
440*4882a593Smuzhiyun     else if (rep->RepType == X_SetDeviceMode)
441*4882a593Smuzhiyun         SRepXSetDeviceMode(client, len, (xSetDeviceModeReply *) rep);
442*4882a593Smuzhiyun     else if (rep->RepType == X_GetSelectedExtensionEvents)
443*4882a593Smuzhiyun         SRepXGetSelectedExtensionEvents(client, len,
444*4882a593Smuzhiyun                                         (xGetSelectedExtensionEventsReply *)
445*4882a593Smuzhiyun                                         rep);
446*4882a593Smuzhiyun     else if (rep->RepType == X_GetDeviceDontPropagateList)
447*4882a593Smuzhiyun         SRepXGetDeviceDontPropagateList(client, len,
448*4882a593Smuzhiyun                                         (xGetDeviceDontPropagateListReply *)
449*4882a593Smuzhiyun                                         rep);
450*4882a593Smuzhiyun     else if (rep->RepType == X_GetDeviceMotionEvents)
451*4882a593Smuzhiyun         SRepXGetDeviceMotionEvents(client, len,
452*4882a593Smuzhiyun                                    (xGetDeviceMotionEventsReply *) rep);
453*4882a593Smuzhiyun     else if (rep->RepType == X_GrabDevice)
454*4882a593Smuzhiyun         SRepXGrabDevice(client, len, (xGrabDeviceReply *) rep);
455*4882a593Smuzhiyun     else if (rep->RepType == X_GetDeviceFocus)
456*4882a593Smuzhiyun         SRepXGetDeviceFocus(client, len, (xGetDeviceFocusReply *) rep);
457*4882a593Smuzhiyun     else if (rep->RepType == X_GetFeedbackControl)
458*4882a593Smuzhiyun         SRepXGetFeedbackControl(client, len, (xGetFeedbackControlReply *) rep);
459*4882a593Smuzhiyun     else if (rep->RepType == X_GetDeviceKeyMapping)
460*4882a593Smuzhiyun         SRepXGetDeviceKeyMapping(client, len,
461*4882a593Smuzhiyun                                  (xGetDeviceKeyMappingReply *) rep);
462*4882a593Smuzhiyun     else if (rep->RepType == X_GetDeviceModifierMapping)
463*4882a593Smuzhiyun         SRepXGetDeviceModifierMapping(client, len,
464*4882a593Smuzhiyun                                       (xGetDeviceModifierMappingReply *) rep);
465*4882a593Smuzhiyun     else if (rep->RepType == X_SetDeviceModifierMapping)
466*4882a593Smuzhiyun         SRepXSetDeviceModifierMapping(client, len,
467*4882a593Smuzhiyun                                       (xSetDeviceModifierMappingReply *) rep);
468*4882a593Smuzhiyun     else if (rep->RepType == X_GetDeviceButtonMapping)
469*4882a593Smuzhiyun         SRepXGetDeviceButtonMapping(client, len,
470*4882a593Smuzhiyun                                     (xGetDeviceButtonMappingReply *) rep);
471*4882a593Smuzhiyun     else if (rep->RepType == X_SetDeviceButtonMapping)
472*4882a593Smuzhiyun         SRepXSetDeviceButtonMapping(client, len,
473*4882a593Smuzhiyun                                     (xSetDeviceButtonMappingReply *) rep);
474*4882a593Smuzhiyun     else if (rep->RepType == X_QueryDeviceState)
475*4882a593Smuzhiyun         SRepXQueryDeviceState(client, len, (xQueryDeviceStateReply *) rep);
476*4882a593Smuzhiyun     else if (rep->RepType == X_SetDeviceValuators)
477*4882a593Smuzhiyun         SRepXSetDeviceValuators(client, len, (xSetDeviceValuatorsReply *) rep);
478*4882a593Smuzhiyun     else if (rep->RepType == X_GetDeviceControl)
479*4882a593Smuzhiyun         SRepXGetDeviceControl(client, len, (xGetDeviceControlReply *) rep);
480*4882a593Smuzhiyun     else if (rep->RepType == X_ChangeDeviceControl)
481*4882a593Smuzhiyun         SRepXChangeDeviceControl(client, len,
482*4882a593Smuzhiyun                                  (xChangeDeviceControlReply *) rep);
483*4882a593Smuzhiyun     else if (rep->RepType == X_ListDeviceProperties)
484*4882a593Smuzhiyun         SRepXListDeviceProperties(client, len,
485*4882a593Smuzhiyun                                   (xListDevicePropertiesReply *) rep);
486*4882a593Smuzhiyun     else if (rep->RepType == X_GetDeviceProperty)
487*4882a593Smuzhiyun         SRepXGetDeviceProperty(client, len, (xGetDevicePropertyReply *) rep);
488*4882a593Smuzhiyun     else if (rep->RepType == X_XIQueryPointer)
489*4882a593Smuzhiyun         SRepXIQueryPointer(client, len, (xXIQueryPointerReply *) rep);
490*4882a593Smuzhiyun     else if (rep->RepType == X_XIGetClientPointer)
491*4882a593Smuzhiyun         SRepXIGetClientPointer(client, len, (xXIGetClientPointerReply *) rep);
492*4882a593Smuzhiyun     else if (rep->RepType == X_XIQueryVersion)
493*4882a593Smuzhiyun         SRepXIQueryVersion(client, len, (xXIQueryVersionReply *) rep);
494*4882a593Smuzhiyun     else if (rep->RepType == X_XIQueryDevice)
495*4882a593Smuzhiyun         SRepXIQueryDevice(client, len, (xXIQueryDeviceReply *) rep);
496*4882a593Smuzhiyun     else if (rep->RepType == X_XIGrabDevice)
497*4882a593Smuzhiyun         SRepXIGrabDevice(client, len, (xXIGrabDeviceReply *) rep);
498*4882a593Smuzhiyun     else if (rep->RepType == X_XIPassiveGrabDevice)
499*4882a593Smuzhiyun         SRepXIPassiveGrabDevice(client, len, (xXIPassiveGrabDeviceReply *) rep);
500*4882a593Smuzhiyun     else if (rep->RepType == X_XIListProperties)
501*4882a593Smuzhiyun         SRepXIListProperties(client, len, (xXIListPropertiesReply *) rep);
502*4882a593Smuzhiyun     else if (rep->RepType == X_XIGetProperty)
503*4882a593Smuzhiyun         SRepXIGetProperty(client, len, (xXIGetPropertyReply *) rep);
504*4882a593Smuzhiyun     else if (rep->RepType == X_XIGetSelectedEvents)
505*4882a593Smuzhiyun         SRepXIGetSelectedEvents(client, len, (xXIGetSelectedEventsReply *) rep);
506*4882a593Smuzhiyun     else if (rep->RepType == X_XIGetFocus)
507*4882a593Smuzhiyun         SRepXIGetFocus(client, len, (xXIGetFocusReply *) rep);
508*4882a593Smuzhiyun     else {
509*4882a593Smuzhiyun         FatalError("XINPUT confused sending swapped reply");
510*4882a593Smuzhiyun     }
511*4882a593Smuzhiyun }
512*4882a593Smuzhiyun 
513*4882a593Smuzhiyun /************************************************************************
514*4882a593Smuzhiyun  *
515*4882a593Smuzhiyun  * This function swaps the DeviceValuator event.
516*4882a593Smuzhiyun  *
517*4882a593Smuzhiyun  */
518*4882a593Smuzhiyun 
519*4882a593Smuzhiyun static void
SEventDeviceValuator(deviceValuator * from,deviceValuator * to)520*4882a593Smuzhiyun SEventDeviceValuator(deviceValuator * from, deviceValuator * to)
521*4882a593Smuzhiyun {
522*4882a593Smuzhiyun     int i;
523*4882a593Smuzhiyun     INT32 *ip B32;
524*4882a593Smuzhiyun 
525*4882a593Smuzhiyun     *to = *from;
526*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
527*4882a593Smuzhiyun     swaps(&to->device_state);
528*4882a593Smuzhiyun     ip = &to->valuator0;
529*4882a593Smuzhiyun     for (i = 0; i < 6; i++) {
530*4882a593Smuzhiyun         swapl(ip + i);
531*4882a593Smuzhiyun     }
532*4882a593Smuzhiyun }
533*4882a593Smuzhiyun 
534*4882a593Smuzhiyun static void
SEventFocus(deviceFocus * from,deviceFocus * to)535*4882a593Smuzhiyun SEventFocus(deviceFocus * from, deviceFocus * to)
536*4882a593Smuzhiyun {
537*4882a593Smuzhiyun     *to = *from;
538*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
539*4882a593Smuzhiyun     swapl(&to->time);
540*4882a593Smuzhiyun     swapl(&to->window);
541*4882a593Smuzhiyun }
542*4882a593Smuzhiyun 
543*4882a593Smuzhiyun static void
SDeviceStateNotifyEvent(deviceStateNotify * from,deviceStateNotify * to)544*4882a593Smuzhiyun SDeviceStateNotifyEvent(deviceStateNotify * from, deviceStateNotify * to)
545*4882a593Smuzhiyun {
546*4882a593Smuzhiyun     int i;
547*4882a593Smuzhiyun     INT32 *ip B32;
548*4882a593Smuzhiyun 
549*4882a593Smuzhiyun     *to = *from;
550*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
551*4882a593Smuzhiyun     swapl(&to->time);
552*4882a593Smuzhiyun     ip = &to->valuator0;
553*4882a593Smuzhiyun     for (i = 0; i < 3; i++) {
554*4882a593Smuzhiyun         swapl(ip + i);
555*4882a593Smuzhiyun     }
556*4882a593Smuzhiyun }
557*4882a593Smuzhiyun 
558*4882a593Smuzhiyun static void
SDeviceKeyStateNotifyEvent(deviceKeyStateNotify * from,deviceKeyStateNotify * to)559*4882a593Smuzhiyun SDeviceKeyStateNotifyEvent(deviceKeyStateNotify * from,
560*4882a593Smuzhiyun                            deviceKeyStateNotify * to)
561*4882a593Smuzhiyun {
562*4882a593Smuzhiyun     *to = *from;
563*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
564*4882a593Smuzhiyun }
565*4882a593Smuzhiyun 
566*4882a593Smuzhiyun static void
SDeviceButtonStateNotifyEvent(deviceButtonStateNotify * from,deviceButtonStateNotify * to)567*4882a593Smuzhiyun SDeviceButtonStateNotifyEvent(deviceButtonStateNotify * from,
568*4882a593Smuzhiyun                               deviceButtonStateNotify * to)
569*4882a593Smuzhiyun {
570*4882a593Smuzhiyun     *to = *from;
571*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
572*4882a593Smuzhiyun }
573*4882a593Smuzhiyun 
574*4882a593Smuzhiyun static void
SChangeDeviceNotifyEvent(changeDeviceNotify * from,changeDeviceNotify * to)575*4882a593Smuzhiyun SChangeDeviceNotifyEvent(changeDeviceNotify * from, changeDeviceNotify * to)
576*4882a593Smuzhiyun {
577*4882a593Smuzhiyun     *to = *from;
578*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
579*4882a593Smuzhiyun     swapl(&to->time);
580*4882a593Smuzhiyun }
581*4882a593Smuzhiyun 
582*4882a593Smuzhiyun static void
SDeviceMappingNotifyEvent(deviceMappingNotify * from,deviceMappingNotify * to)583*4882a593Smuzhiyun SDeviceMappingNotifyEvent(deviceMappingNotify * from, deviceMappingNotify * to)
584*4882a593Smuzhiyun {
585*4882a593Smuzhiyun     *to = *from;
586*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
587*4882a593Smuzhiyun     swapl(&to->time);
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun 
590*4882a593Smuzhiyun static void
SDevicePresenceNotifyEvent(devicePresenceNotify * from,devicePresenceNotify * to)591*4882a593Smuzhiyun SDevicePresenceNotifyEvent(devicePresenceNotify * from,
592*4882a593Smuzhiyun                            devicePresenceNotify * to)
593*4882a593Smuzhiyun {
594*4882a593Smuzhiyun     *to = *from;
595*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
596*4882a593Smuzhiyun     swapl(&to->time);
597*4882a593Smuzhiyun     swaps(&to->control);
598*4882a593Smuzhiyun }
599*4882a593Smuzhiyun 
600*4882a593Smuzhiyun static void
SDevicePropertyNotifyEvent(devicePropertyNotify * from,devicePropertyNotify * to)601*4882a593Smuzhiyun SDevicePropertyNotifyEvent(devicePropertyNotify * from,
602*4882a593Smuzhiyun                            devicePropertyNotify * to)
603*4882a593Smuzhiyun {
604*4882a593Smuzhiyun     *to = *from;
605*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
606*4882a593Smuzhiyun     swapl(&to->time);
607*4882a593Smuzhiyun     swapl(&to->atom);
608*4882a593Smuzhiyun }
609*4882a593Smuzhiyun 
610*4882a593Smuzhiyun static void
SDeviceLeaveNotifyEvent(xXILeaveEvent * from,xXILeaveEvent * to)611*4882a593Smuzhiyun SDeviceLeaveNotifyEvent(xXILeaveEvent * from, xXILeaveEvent * to)
612*4882a593Smuzhiyun {
613*4882a593Smuzhiyun     *to = *from;
614*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
615*4882a593Smuzhiyun     swapl(&to->length);
616*4882a593Smuzhiyun     swaps(&to->evtype);
617*4882a593Smuzhiyun     swaps(&to->deviceid);
618*4882a593Smuzhiyun     swapl(&to->time);
619*4882a593Smuzhiyun     swapl(&to->root);
620*4882a593Smuzhiyun     swapl(&to->event);
621*4882a593Smuzhiyun     swapl(&to->child);
622*4882a593Smuzhiyun     swapl(&to->root_x);
623*4882a593Smuzhiyun     swapl(&to->root_y);
624*4882a593Smuzhiyun     swapl(&to->event_x);
625*4882a593Smuzhiyun     swapl(&to->event_y);
626*4882a593Smuzhiyun     swaps(&to->sourceid);
627*4882a593Smuzhiyun     swaps(&to->buttons_len);
628*4882a593Smuzhiyun     swapl(&to->mods.base_mods);
629*4882a593Smuzhiyun     swapl(&to->mods.latched_mods);
630*4882a593Smuzhiyun     swapl(&to->mods.locked_mods);
631*4882a593Smuzhiyun }
632*4882a593Smuzhiyun 
633*4882a593Smuzhiyun static void
SDeviceChangedEvent(xXIDeviceChangedEvent * from,xXIDeviceChangedEvent * to)634*4882a593Smuzhiyun SDeviceChangedEvent(xXIDeviceChangedEvent * from, xXIDeviceChangedEvent * to)
635*4882a593Smuzhiyun {
636*4882a593Smuzhiyun     int i, j;
637*4882a593Smuzhiyun     xXIAnyInfo *any;
638*4882a593Smuzhiyun 
639*4882a593Smuzhiyun     *to = *from;
640*4882a593Smuzhiyun     memcpy(&to[1], &from[1], from->length * 4);
641*4882a593Smuzhiyun 
642*4882a593Smuzhiyun     any = (xXIAnyInfo *) &to[1];
643*4882a593Smuzhiyun     for (i = 0; i < to->num_classes; i++) {
644*4882a593Smuzhiyun         int length = any->length;
645*4882a593Smuzhiyun 
646*4882a593Smuzhiyun         switch (any->type) {
647*4882a593Smuzhiyun         case KeyClass:
648*4882a593Smuzhiyun         {
649*4882a593Smuzhiyun             xXIKeyInfo *ki = (xXIKeyInfo *) any;
650*4882a593Smuzhiyun             uint32_t *key = (uint32_t *) &ki[1];
651*4882a593Smuzhiyun 
652*4882a593Smuzhiyun             for (j = 0; j < ki->num_keycodes; j++, key++)
653*4882a593Smuzhiyun                 swapl(key);
654*4882a593Smuzhiyun             swaps(&ki->num_keycodes);
655*4882a593Smuzhiyun         }
656*4882a593Smuzhiyun             break;
657*4882a593Smuzhiyun         case ButtonClass:
658*4882a593Smuzhiyun         {
659*4882a593Smuzhiyun             xXIButtonInfo *bi = (xXIButtonInfo *) any;
660*4882a593Smuzhiyun             Atom *labels = (Atom *) ((char *) bi + sizeof(xXIButtonInfo) +
661*4882a593Smuzhiyun                                      pad_to_int32(bits_to_bytes
662*4882a593Smuzhiyun                                                   (bi->num_buttons)));
663*4882a593Smuzhiyun             for (j = 0; j < bi->num_buttons; j++)
664*4882a593Smuzhiyun                 swapl(&labels[j]);
665*4882a593Smuzhiyun             swaps(&bi->num_buttons);
666*4882a593Smuzhiyun         }
667*4882a593Smuzhiyun             break;
668*4882a593Smuzhiyun         case ValuatorClass:
669*4882a593Smuzhiyun         {
670*4882a593Smuzhiyun             xXIValuatorInfo *ai = (xXIValuatorInfo *) any;
671*4882a593Smuzhiyun 
672*4882a593Smuzhiyun             swapl(&ai->label);
673*4882a593Smuzhiyun             swapl(&ai->min.integral);
674*4882a593Smuzhiyun             swapl(&ai->min.frac);
675*4882a593Smuzhiyun             swapl(&ai->max.integral);
676*4882a593Smuzhiyun             swapl(&ai->max.frac);
677*4882a593Smuzhiyun             swapl(&ai->resolution);
678*4882a593Smuzhiyun             swaps(&ai->number);
679*4882a593Smuzhiyun         }
680*4882a593Smuzhiyun             break;
681*4882a593Smuzhiyun         }
682*4882a593Smuzhiyun 
683*4882a593Smuzhiyun         swaps(&any->type);
684*4882a593Smuzhiyun         swaps(&any->length);
685*4882a593Smuzhiyun         swaps(&any->sourceid);
686*4882a593Smuzhiyun 
687*4882a593Smuzhiyun         any = (xXIAnyInfo *) ((char *) any + length * 4);
688*4882a593Smuzhiyun     }
689*4882a593Smuzhiyun 
690*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
691*4882a593Smuzhiyun     swapl(&to->length);
692*4882a593Smuzhiyun     swaps(&to->evtype);
693*4882a593Smuzhiyun     swaps(&to->deviceid);
694*4882a593Smuzhiyun     swapl(&to->time);
695*4882a593Smuzhiyun     swaps(&to->num_classes);
696*4882a593Smuzhiyun     swaps(&to->sourceid);
697*4882a593Smuzhiyun 
698*4882a593Smuzhiyun }
699*4882a593Smuzhiyun 
700*4882a593Smuzhiyun static void
SDeviceEvent(xXIDeviceEvent * from,xXIDeviceEvent * to)701*4882a593Smuzhiyun SDeviceEvent(xXIDeviceEvent * from, xXIDeviceEvent * to)
702*4882a593Smuzhiyun {
703*4882a593Smuzhiyun     int i;
704*4882a593Smuzhiyun     char *ptr;
705*4882a593Smuzhiyun     char *vmask;
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun     memcpy(to, from, sizeof(xEvent) + from->length * 4);
708*4882a593Smuzhiyun 
709*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
710*4882a593Smuzhiyun     swapl(&to->length);
711*4882a593Smuzhiyun     swaps(&to->evtype);
712*4882a593Smuzhiyun     swaps(&to->deviceid);
713*4882a593Smuzhiyun     swapl(&to->time);
714*4882a593Smuzhiyun     swapl(&to->detail);
715*4882a593Smuzhiyun     swapl(&to->root);
716*4882a593Smuzhiyun     swapl(&to->event);
717*4882a593Smuzhiyun     swapl(&to->child);
718*4882a593Smuzhiyun     swapl(&to->root_x);
719*4882a593Smuzhiyun     swapl(&to->root_y);
720*4882a593Smuzhiyun     swapl(&to->event_x);
721*4882a593Smuzhiyun     swapl(&to->event_y);
722*4882a593Smuzhiyun     swaps(&to->buttons_len);
723*4882a593Smuzhiyun     swaps(&to->valuators_len);
724*4882a593Smuzhiyun     swaps(&to->sourceid);
725*4882a593Smuzhiyun     swapl(&to->mods.base_mods);
726*4882a593Smuzhiyun     swapl(&to->mods.latched_mods);
727*4882a593Smuzhiyun     swapl(&to->mods.locked_mods);
728*4882a593Smuzhiyun     swapl(&to->mods.effective_mods);
729*4882a593Smuzhiyun     swapl(&to->flags);
730*4882a593Smuzhiyun 
731*4882a593Smuzhiyun     ptr = (char *) (&to[1]);
732*4882a593Smuzhiyun     ptr += from->buttons_len * 4;
733*4882a593Smuzhiyun     vmask = ptr;                /* valuator mask */
734*4882a593Smuzhiyun     ptr += from->valuators_len * 4;
735*4882a593Smuzhiyun     for (i = 0; i < from->valuators_len * 32; i++) {
736*4882a593Smuzhiyun         if (BitIsOn(vmask, i)) {
737*4882a593Smuzhiyun             swapl(((uint32_t *) ptr));
738*4882a593Smuzhiyun             ptr += 4;
739*4882a593Smuzhiyun             swapl(((uint32_t *) ptr));
740*4882a593Smuzhiyun             ptr += 4;
741*4882a593Smuzhiyun         }
742*4882a593Smuzhiyun     }
743*4882a593Smuzhiyun }
744*4882a593Smuzhiyun 
745*4882a593Smuzhiyun static void
SDeviceHierarchyEvent(xXIHierarchyEvent * from,xXIHierarchyEvent * to)746*4882a593Smuzhiyun SDeviceHierarchyEvent(xXIHierarchyEvent * from, xXIHierarchyEvent * to)
747*4882a593Smuzhiyun {
748*4882a593Smuzhiyun     int i;
749*4882a593Smuzhiyun     xXIHierarchyInfo *info;
750*4882a593Smuzhiyun 
751*4882a593Smuzhiyun     *to = *from;
752*4882a593Smuzhiyun     memcpy(&to[1], &from[1], from->length * 4);
753*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
754*4882a593Smuzhiyun     swapl(&to->length);
755*4882a593Smuzhiyun     swaps(&to->evtype);
756*4882a593Smuzhiyun     swaps(&to->deviceid);
757*4882a593Smuzhiyun     swapl(&to->time);
758*4882a593Smuzhiyun     swapl(&to->flags);
759*4882a593Smuzhiyun     swaps(&to->num_info);
760*4882a593Smuzhiyun 
761*4882a593Smuzhiyun     info = (xXIHierarchyInfo *) &to[1];
762*4882a593Smuzhiyun     for (i = 0; i < from->num_info; i++) {
763*4882a593Smuzhiyun         swaps(&info->deviceid);
764*4882a593Smuzhiyun         swaps(&info->attachment);
765*4882a593Smuzhiyun         info++;
766*4882a593Smuzhiyun     }
767*4882a593Smuzhiyun }
768*4882a593Smuzhiyun 
769*4882a593Smuzhiyun static void
SXIPropertyEvent(xXIPropertyEvent * from,xXIPropertyEvent * to)770*4882a593Smuzhiyun SXIPropertyEvent(xXIPropertyEvent * from, xXIPropertyEvent * to)
771*4882a593Smuzhiyun {
772*4882a593Smuzhiyun     *to = *from;
773*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
774*4882a593Smuzhiyun     swapl(&to->length);
775*4882a593Smuzhiyun     swaps(&to->evtype);
776*4882a593Smuzhiyun     swaps(&to->deviceid);
777*4882a593Smuzhiyun     swapl(&to->property);
778*4882a593Smuzhiyun }
779*4882a593Smuzhiyun 
780*4882a593Smuzhiyun static void
SRawEvent(xXIRawEvent * from,xXIRawEvent * to)781*4882a593Smuzhiyun SRawEvent(xXIRawEvent * from, xXIRawEvent * to)
782*4882a593Smuzhiyun {
783*4882a593Smuzhiyun     int i;
784*4882a593Smuzhiyun     FP3232 *values;
785*4882a593Smuzhiyun     unsigned char *mask;
786*4882a593Smuzhiyun 
787*4882a593Smuzhiyun     memcpy(to, from, sizeof(xEvent) + from->length * 4);
788*4882a593Smuzhiyun 
789*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
790*4882a593Smuzhiyun     swapl(&to->length);
791*4882a593Smuzhiyun     swaps(&to->evtype);
792*4882a593Smuzhiyun     swaps(&to->deviceid);
793*4882a593Smuzhiyun     swapl(&to->time);
794*4882a593Smuzhiyun     swapl(&to->detail);
795*4882a593Smuzhiyun 
796*4882a593Smuzhiyun     mask = (unsigned char *) &to[1];
797*4882a593Smuzhiyun     values = (FP3232 *) (mask + from->valuators_len * 4);
798*4882a593Smuzhiyun 
799*4882a593Smuzhiyun     for (i = 0; i < from->valuators_len * 4 * 8; i++) {
800*4882a593Smuzhiyun         if (BitIsOn(mask, i)) {
801*4882a593Smuzhiyun             /* for each bit set there are two FP3232 values on the wire, in
802*4882a593Smuzhiyun              * the order abcABC for data and data_raw. Here we swap as if
803*4882a593Smuzhiyun              * they were in aAbBcC order because it's easier and really
804*4882a593Smuzhiyun              * doesn't matter.
805*4882a593Smuzhiyun              */
806*4882a593Smuzhiyun             swapl(&values->integral);
807*4882a593Smuzhiyun             swapl(&values->frac);
808*4882a593Smuzhiyun             values++;
809*4882a593Smuzhiyun             swapl(&values->integral);
810*4882a593Smuzhiyun             swapl(&values->frac);
811*4882a593Smuzhiyun             values++;
812*4882a593Smuzhiyun         }
813*4882a593Smuzhiyun     }
814*4882a593Smuzhiyun 
815*4882a593Smuzhiyun     swaps(&to->valuators_len);
816*4882a593Smuzhiyun }
817*4882a593Smuzhiyun 
818*4882a593Smuzhiyun static void
STouchOwnershipEvent(xXITouchOwnershipEvent * from,xXITouchOwnershipEvent * to)819*4882a593Smuzhiyun STouchOwnershipEvent(xXITouchOwnershipEvent * from, xXITouchOwnershipEvent * to)
820*4882a593Smuzhiyun {
821*4882a593Smuzhiyun     *to = *from;
822*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
823*4882a593Smuzhiyun     swapl(&to->length);
824*4882a593Smuzhiyun     swaps(&to->evtype);
825*4882a593Smuzhiyun     swaps(&to->deviceid);
826*4882a593Smuzhiyun     swapl(&to->time);
827*4882a593Smuzhiyun     swaps(&to->sourceid);
828*4882a593Smuzhiyun     swapl(&to->touchid);
829*4882a593Smuzhiyun     swapl(&to->flags);
830*4882a593Smuzhiyun     swapl(&to->root);
831*4882a593Smuzhiyun     swapl(&to->event);
832*4882a593Smuzhiyun     swapl(&to->child);
833*4882a593Smuzhiyun }
834*4882a593Smuzhiyun 
835*4882a593Smuzhiyun static void
SBarrierEvent(xXIBarrierEvent * from,xXIBarrierEvent * to)836*4882a593Smuzhiyun SBarrierEvent(xXIBarrierEvent * from,
837*4882a593Smuzhiyun               xXIBarrierEvent * to) {
838*4882a593Smuzhiyun 
839*4882a593Smuzhiyun     *to = *from;
840*4882a593Smuzhiyun 
841*4882a593Smuzhiyun     swaps(&to->sequenceNumber);
842*4882a593Smuzhiyun     swapl(&to->length);
843*4882a593Smuzhiyun     swaps(&to->evtype);
844*4882a593Smuzhiyun     swapl(&to->time);
845*4882a593Smuzhiyun     swaps(&to->deviceid);
846*4882a593Smuzhiyun     swaps(&to->sourceid);
847*4882a593Smuzhiyun     swapl(&to->event);
848*4882a593Smuzhiyun     swapl(&to->root);
849*4882a593Smuzhiyun     swapl(&to->root_x);
850*4882a593Smuzhiyun     swapl(&to->root_y);
851*4882a593Smuzhiyun 
852*4882a593Smuzhiyun     swapl(&to->dx.integral);
853*4882a593Smuzhiyun     swapl(&to->dx.frac);
854*4882a593Smuzhiyun     swapl(&to->dy.integral);
855*4882a593Smuzhiyun     swapl(&to->dy.frac);
856*4882a593Smuzhiyun     swapl(&to->dtime);
857*4882a593Smuzhiyun     swapl(&to->barrier);
858*4882a593Smuzhiyun     swapl(&to->eventid);
859*4882a593Smuzhiyun }
860*4882a593Smuzhiyun 
861*4882a593Smuzhiyun /** Event swapping function for XI2 events. */
862*4882a593Smuzhiyun void _X_COLD
XI2EventSwap(xGenericEvent * from,xGenericEvent * to)863*4882a593Smuzhiyun XI2EventSwap(xGenericEvent *from, xGenericEvent *to)
864*4882a593Smuzhiyun {
865*4882a593Smuzhiyun     switch (from->evtype) {
866*4882a593Smuzhiyun     case XI_Enter:
867*4882a593Smuzhiyun     case XI_Leave:
868*4882a593Smuzhiyun     case XI_FocusIn:
869*4882a593Smuzhiyun     case XI_FocusOut:
870*4882a593Smuzhiyun         SDeviceLeaveNotifyEvent((xXILeaveEvent *) from, (xXILeaveEvent *) to);
871*4882a593Smuzhiyun         break;
872*4882a593Smuzhiyun     case XI_DeviceChanged:
873*4882a593Smuzhiyun         SDeviceChangedEvent((xXIDeviceChangedEvent *) from,
874*4882a593Smuzhiyun                             (xXIDeviceChangedEvent *) to);
875*4882a593Smuzhiyun         break;
876*4882a593Smuzhiyun     case XI_HierarchyChanged:
877*4882a593Smuzhiyun         SDeviceHierarchyEvent((xXIHierarchyEvent *) from,
878*4882a593Smuzhiyun                               (xXIHierarchyEvent *) to);
879*4882a593Smuzhiyun         break;
880*4882a593Smuzhiyun     case XI_PropertyEvent:
881*4882a593Smuzhiyun         SXIPropertyEvent((xXIPropertyEvent *) from, (xXIPropertyEvent *) to);
882*4882a593Smuzhiyun         break;
883*4882a593Smuzhiyun     case XI_Motion:
884*4882a593Smuzhiyun     case XI_KeyPress:
885*4882a593Smuzhiyun     case XI_KeyRelease:
886*4882a593Smuzhiyun     case XI_ButtonPress:
887*4882a593Smuzhiyun     case XI_ButtonRelease:
888*4882a593Smuzhiyun     case XI_TouchBegin:
889*4882a593Smuzhiyun     case XI_TouchUpdate:
890*4882a593Smuzhiyun     case XI_TouchEnd:
891*4882a593Smuzhiyun         SDeviceEvent((xXIDeviceEvent *) from, (xXIDeviceEvent *) to);
892*4882a593Smuzhiyun         break;
893*4882a593Smuzhiyun     case XI_TouchOwnership:
894*4882a593Smuzhiyun         STouchOwnershipEvent((xXITouchOwnershipEvent *) from,
895*4882a593Smuzhiyun                              (xXITouchOwnershipEvent *) to);
896*4882a593Smuzhiyun         break;
897*4882a593Smuzhiyun     case XI_RawMotion:
898*4882a593Smuzhiyun     case XI_RawKeyPress:
899*4882a593Smuzhiyun     case XI_RawKeyRelease:
900*4882a593Smuzhiyun     case XI_RawButtonPress:
901*4882a593Smuzhiyun     case XI_RawButtonRelease:
902*4882a593Smuzhiyun     case XI_RawTouchBegin:
903*4882a593Smuzhiyun     case XI_RawTouchUpdate:
904*4882a593Smuzhiyun     case XI_RawTouchEnd:
905*4882a593Smuzhiyun         SRawEvent((xXIRawEvent *) from, (xXIRawEvent *) to);
906*4882a593Smuzhiyun         break;
907*4882a593Smuzhiyun     case XI_BarrierHit:
908*4882a593Smuzhiyun     case XI_BarrierLeave:
909*4882a593Smuzhiyun         SBarrierEvent((xXIBarrierEvent *) from,
910*4882a593Smuzhiyun                       (xXIBarrierEvent *) to);
911*4882a593Smuzhiyun         break;
912*4882a593Smuzhiyun     default:
913*4882a593Smuzhiyun         ErrorF("[Xi] Unknown event type to swap. This is a bug.\n");
914*4882a593Smuzhiyun         break;
915*4882a593Smuzhiyun     }
916*4882a593Smuzhiyun }
917*4882a593Smuzhiyun 
918*4882a593Smuzhiyun /**************************************************************************
919*4882a593Smuzhiyun  *
920*4882a593Smuzhiyun  * Allow the specified event to have its propagation suppressed.
921*4882a593Smuzhiyun  * The default is to not allow suppression of propagation.
922*4882a593Smuzhiyun  *
923*4882a593Smuzhiyun  */
924*4882a593Smuzhiyun 
925*4882a593Smuzhiyun static void
AllowPropagateSuppress(Mask mask)926*4882a593Smuzhiyun AllowPropagateSuppress(Mask mask)
927*4882a593Smuzhiyun {
928*4882a593Smuzhiyun     int i;
929*4882a593Smuzhiyun 
930*4882a593Smuzhiyun     for (i = 0; i < MAXDEVICES; i++)
931*4882a593Smuzhiyun         PropagateMask[i] |= mask;
932*4882a593Smuzhiyun }
933*4882a593Smuzhiyun 
934*4882a593Smuzhiyun /**************************************************************************
935*4882a593Smuzhiyun  *
936*4882a593Smuzhiyun  * Record an event mask where there is no unique corresponding event type.
937*4882a593Smuzhiyun  * We can't call SetMaskForEvent, since that would clobber the existing
938*4882a593Smuzhiyun  * mask for that event.  MotionHint and ButtonMotion are examples.
939*4882a593Smuzhiyun  *
940*4882a593Smuzhiyun  * Since extension event types will never be less than 64, we can use
941*4882a593Smuzhiyun  * 0-63 in the EventInfo array as the "type" to be used to look up this
942*4882a593Smuzhiyun  * mask.  This means that the corresponding macros such as
943*4882a593Smuzhiyun  * DevicePointerMotionHint must have access to the same constants.
944*4882a593Smuzhiyun  *
945*4882a593Smuzhiyun  */
946*4882a593Smuzhiyun 
947*4882a593Smuzhiyun static void
SetEventInfo(Mask mask,int constant)948*4882a593Smuzhiyun SetEventInfo(Mask mask, int constant)
949*4882a593Smuzhiyun {
950*4882a593Smuzhiyun     EventInfo[ExtEventIndex].mask = mask;
951*4882a593Smuzhiyun     EventInfo[ExtEventIndex++].type = constant;
952*4882a593Smuzhiyun }
953*4882a593Smuzhiyun 
954*4882a593Smuzhiyun /**************************************************************************
955*4882a593Smuzhiyun  *
956*4882a593Smuzhiyun  * Allow the specified event to be restricted to being selected by one
957*4882a593Smuzhiyun  * client at a time.
958*4882a593Smuzhiyun  * The default is to allow more than one client to select the event.
959*4882a593Smuzhiyun  *
960*4882a593Smuzhiyun  */
961*4882a593Smuzhiyun 
962*4882a593Smuzhiyun static void
SetExclusiveAccess(Mask mask)963*4882a593Smuzhiyun SetExclusiveAccess(Mask mask)
964*4882a593Smuzhiyun {
965*4882a593Smuzhiyun     int i;
966*4882a593Smuzhiyun 
967*4882a593Smuzhiyun     for (i = 0; i < MAXDEVICES; i++)
968*4882a593Smuzhiyun         ExtExclusiveMasks[i] |= mask;
969*4882a593Smuzhiyun }
970*4882a593Smuzhiyun 
971*4882a593Smuzhiyun /**************************************************************************
972*4882a593Smuzhiyun  *
973*4882a593Smuzhiyun  * Assign the specified mask to the specified event.
974*4882a593Smuzhiyun  *
975*4882a593Smuzhiyun  */
976*4882a593Smuzhiyun 
977*4882a593Smuzhiyun static void
SetMaskForExtEvent(Mask mask,int event)978*4882a593Smuzhiyun SetMaskForExtEvent(Mask mask, int event)
979*4882a593Smuzhiyun {
980*4882a593Smuzhiyun     int i;
981*4882a593Smuzhiyun 
982*4882a593Smuzhiyun     EventInfo[ExtEventIndex].mask = mask;
983*4882a593Smuzhiyun     EventInfo[ExtEventIndex++].type = event;
984*4882a593Smuzhiyun 
985*4882a593Smuzhiyun     if ((event < LASTEvent) || (event >= 128))
986*4882a593Smuzhiyun         FatalError("MaskForExtensionEvent: bogus event number");
987*4882a593Smuzhiyun 
988*4882a593Smuzhiyun     for (i = 0; i < MAXDEVICES; i++)
989*4882a593Smuzhiyun         SetMaskForEvent(i, mask, event);
990*4882a593Smuzhiyun }
991*4882a593Smuzhiyun 
992*4882a593Smuzhiyun /************************************************************************
993*4882a593Smuzhiyun  *
994*4882a593Smuzhiyun  * This function sets up extension event types and masks.
995*4882a593Smuzhiyun  *
996*4882a593Smuzhiyun  */
997*4882a593Smuzhiyun 
998*4882a593Smuzhiyun static void
FixExtensionEvents(ExtensionEntry * extEntry)999*4882a593Smuzhiyun FixExtensionEvents(ExtensionEntry * extEntry)
1000*4882a593Smuzhiyun {
1001*4882a593Smuzhiyun     DeviceValuator = extEntry->eventBase;
1002*4882a593Smuzhiyun     DeviceKeyPress = DeviceValuator + 1;
1003*4882a593Smuzhiyun     DeviceKeyRelease = DeviceKeyPress + 1;
1004*4882a593Smuzhiyun     DeviceButtonPress = DeviceKeyRelease + 1;
1005*4882a593Smuzhiyun     DeviceButtonRelease = DeviceButtonPress + 1;
1006*4882a593Smuzhiyun     DeviceMotionNotify = DeviceButtonRelease + 1;
1007*4882a593Smuzhiyun     DeviceFocusIn = DeviceMotionNotify + 1;
1008*4882a593Smuzhiyun     DeviceFocusOut = DeviceFocusIn + 1;
1009*4882a593Smuzhiyun     ProximityIn = DeviceFocusOut + 1;
1010*4882a593Smuzhiyun     ProximityOut = ProximityIn + 1;
1011*4882a593Smuzhiyun     DeviceStateNotify = ProximityOut + 1;
1012*4882a593Smuzhiyun     DeviceMappingNotify = DeviceStateNotify + 1;
1013*4882a593Smuzhiyun     ChangeDeviceNotify = DeviceMappingNotify + 1;
1014*4882a593Smuzhiyun     DeviceKeyStateNotify = ChangeDeviceNotify + 1;
1015*4882a593Smuzhiyun     DeviceButtonStateNotify = DeviceKeyStateNotify + 1;
1016*4882a593Smuzhiyun     DevicePresenceNotify = DeviceButtonStateNotify + 1;
1017*4882a593Smuzhiyun     DevicePropertyNotify = DevicePresenceNotify + 1;
1018*4882a593Smuzhiyun 
1019*4882a593Smuzhiyun     event_base[KeyClass] = DeviceKeyPress;
1020*4882a593Smuzhiyun     event_base[ButtonClass] = DeviceButtonPress;
1021*4882a593Smuzhiyun     event_base[ValuatorClass] = DeviceMotionNotify;
1022*4882a593Smuzhiyun     event_base[ProximityClass] = ProximityIn;
1023*4882a593Smuzhiyun     event_base[FocusClass] = DeviceFocusIn;
1024*4882a593Smuzhiyun     event_base[OtherClass] = DeviceStateNotify;
1025*4882a593Smuzhiyun 
1026*4882a593Smuzhiyun     BadDevice += extEntry->errorBase;
1027*4882a593Smuzhiyun     BadEvent += extEntry->errorBase;
1028*4882a593Smuzhiyun     BadMode += extEntry->errorBase;
1029*4882a593Smuzhiyun     DeviceBusy += extEntry->errorBase;
1030*4882a593Smuzhiyun     BadClass += extEntry->errorBase;
1031*4882a593Smuzhiyun 
1032*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceKeyPressMask, DeviceKeyPress);
1033*4882a593Smuzhiyun     AllowPropagateSuppress(DeviceKeyPressMask);
1034*4882a593Smuzhiyun     SetCriticalEvent(DeviceKeyPress);
1035*4882a593Smuzhiyun 
1036*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceKeyReleaseMask, DeviceKeyRelease);
1037*4882a593Smuzhiyun     AllowPropagateSuppress(DeviceKeyReleaseMask);
1038*4882a593Smuzhiyun     SetCriticalEvent(DeviceKeyRelease);
1039*4882a593Smuzhiyun 
1040*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceButtonPressMask, DeviceButtonPress);
1041*4882a593Smuzhiyun     AllowPropagateSuppress(DeviceButtonPressMask);
1042*4882a593Smuzhiyun     SetCriticalEvent(DeviceButtonPress);
1043*4882a593Smuzhiyun 
1044*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceButtonReleaseMask, DeviceButtonRelease);
1045*4882a593Smuzhiyun     AllowPropagateSuppress(DeviceButtonReleaseMask);
1046*4882a593Smuzhiyun     SetCriticalEvent(DeviceButtonRelease);
1047*4882a593Smuzhiyun 
1048*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceProximityMask, ProximityIn);
1049*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceProximityMask, ProximityOut);
1050*4882a593Smuzhiyun 
1051*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceStateNotifyMask, DeviceStateNotify);
1052*4882a593Smuzhiyun 
1053*4882a593Smuzhiyun     SetMaskForExtEvent(DevicePointerMotionMask, DeviceMotionNotify);
1054*4882a593Smuzhiyun     AllowPropagateSuppress(DevicePointerMotionMask);
1055*4882a593Smuzhiyun     SetCriticalEvent(DeviceMotionNotify);
1056*4882a593Smuzhiyun 
1057*4882a593Smuzhiyun     SetEventInfo(DevicePointerMotionHintMask, _devicePointerMotionHint);
1058*4882a593Smuzhiyun     SetEventInfo(DeviceButton1MotionMask, _deviceButton1Motion);
1059*4882a593Smuzhiyun     SetEventInfo(DeviceButton2MotionMask, _deviceButton2Motion);
1060*4882a593Smuzhiyun     SetEventInfo(DeviceButton3MotionMask, _deviceButton3Motion);
1061*4882a593Smuzhiyun     SetEventInfo(DeviceButton4MotionMask, _deviceButton4Motion);
1062*4882a593Smuzhiyun     SetEventInfo(DeviceButton5MotionMask, _deviceButton5Motion);
1063*4882a593Smuzhiyun     SetEventInfo(DeviceButtonMotionMask, _deviceButtonMotion);
1064*4882a593Smuzhiyun 
1065*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceFocusChangeMask, DeviceFocusIn);
1066*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceFocusChangeMask, DeviceFocusOut);
1067*4882a593Smuzhiyun 
1068*4882a593Smuzhiyun     SetMaskForExtEvent(DeviceMappingNotifyMask, DeviceMappingNotify);
1069*4882a593Smuzhiyun     SetMaskForExtEvent(ChangeDeviceNotifyMask, ChangeDeviceNotify);
1070*4882a593Smuzhiyun 
1071*4882a593Smuzhiyun     SetEventInfo(DeviceButtonGrabMask, _deviceButtonGrab);
1072*4882a593Smuzhiyun     SetExclusiveAccess(DeviceButtonGrabMask);
1073*4882a593Smuzhiyun 
1074*4882a593Smuzhiyun     SetEventInfo(DeviceOwnerGrabButtonMask, _deviceOwnerGrabButton);
1075*4882a593Smuzhiyun     SetEventInfo(DevicePresenceNotifyMask, _devicePresence);
1076*4882a593Smuzhiyun     SetMaskForExtEvent(DevicePropertyNotifyMask, DevicePropertyNotify);
1077*4882a593Smuzhiyun 
1078*4882a593Smuzhiyun     SetEventInfo(0, _noExtensionEvent);
1079*4882a593Smuzhiyun }
1080*4882a593Smuzhiyun 
1081*4882a593Smuzhiyun /************************************************************************
1082*4882a593Smuzhiyun  *
1083*4882a593Smuzhiyun  * This function restores extension event types and masks to their
1084*4882a593Smuzhiyun  * initial state.
1085*4882a593Smuzhiyun  *
1086*4882a593Smuzhiyun  */
1087*4882a593Smuzhiyun 
1088*4882a593Smuzhiyun static void
RestoreExtensionEvents(void)1089*4882a593Smuzhiyun RestoreExtensionEvents(void)
1090*4882a593Smuzhiyun {
1091*4882a593Smuzhiyun     int i, j;
1092*4882a593Smuzhiyun 
1093*4882a593Smuzhiyun     IReqCode = 0;
1094*4882a593Smuzhiyun     IEventBase = 0;
1095*4882a593Smuzhiyun 
1096*4882a593Smuzhiyun     for (i = 0; i < ExtEventIndex - 1; i++) {
1097*4882a593Smuzhiyun         if ((EventInfo[i].type >= LASTEvent) && (EventInfo[i].type < 128)) {
1098*4882a593Smuzhiyun             for (j = 0; j < MAXDEVICES; j++)
1099*4882a593Smuzhiyun                 SetMaskForEvent(j, 0, EventInfo[i].type);
1100*4882a593Smuzhiyun         }
1101*4882a593Smuzhiyun         EventInfo[i].mask = 0;
1102*4882a593Smuzhiyun         EventInfo[i].type = 0;
1103*4882a593Smuzhiyun     }
1104*4882a593Smuzhiyun     ExtEventIndex = 0;
1105*4882a593Smuzhiyun     DeviceValuator = 0;
1106*4882a593Smuzhiyun     DeviceKeyPress = 1;
1107*4882a593Smuzhiyun     DeviceKeyRelease = 2;
1108*4882a593Smuzhiyun     DeviceButtonPress = 3;
1109*4882a593Smuzhiyun     DeviceButtonRelease = 4;
1110*4882a593Smuzhiyun     DeviceMotionNotify = 5;
1111*4882a593Smuzhiyun     DeviceFocusIn = 6;
1112*4882a593Smuzhiyun     DeviceFocusOut = 7;
1113*4882a593Smuzhiyun     ProximityIn = 8;
1114*4882a593Smuzhiyun     ProximityOut = 9;
1115*4882a593Smuzhiyun     DeviceStateNotify = 10;
1116*4882a593Smuzhiyun     DeviceMappingNotify = 11;
1117*4882a593Smuzhiyun     ChangeDeviceNotify = 12;
1118*4882a593Smuzhiyun     DeviceKeyStateNotify = 13;
1119*4882a593Smuzhiyun     DeviceButtonStateNotify = 13;
1120*4882a593Smuzhiyun     DevicePresenceNotify = 14;
1121*4882a593Smuzhiyun     DevicePropertyNotify = 15;
1122*4882a593Smuzhiyun 
1123*4882a593Smuzhiyun     BadDevice = 0;
1124*4882a593Smuzhiyun     BadEvent = 1;
1125*4882a593Smuzhiyun     BadMode = 2;
1126*4882a593Smuzhiyun     DeviceBusy = 3;
1127*4882a593Smuzhiyun     BadClass = 4;
1128*4882a593Smuzhiyun 
1129*4882a593Smuzhiyun }
1130*4882a593Smuzhiyun 
1131*4882a593Smuzhiyun /***********************************************************************
1132*4882a593Smuzhiyun  *
1133*4882a593Smuzhiyun  * IResetProc.
1134*4882a593Smuzhiyun  * Remove reply-swapping routine.
1135*4882a593Smuzhiyun  * Remove event-swapping routine.
1136*4882a593Smuzhiyun  *
1137*4882a593Smuzhiyun  */
1138*4882a593Smuzhiyun 
1139*4882a593Smuzhiyun static void
IResetProc(ExtensionEntry * unused)1140*4882a593Smuzhiyun IResetProc(ExtensionEntry * unused)
1141*4882a593Smuzhiyun {
1142*4882a593Smuzhiyun     ReplySwapVector[IReqCode] = ReplyNotSwappd;
1143*4882a593Smuzhiyun     EventSwapVector[DeviceValuator] = NotImplemented;
1144*4882a593Smuzhiyun     EventSwapVector[DeviceKeyPress] = NotImplemented;
1145*4882a593Smuzhiyun     EventSwapVector[DeviceKeyRelease] = NotImplemented;
1146*4882a593Smuzhiyun     EventSwapVector[DeviceButtonPress] = NotImplemented;
1147*4882a593Smuzhiyun     EventSwapVector[DeviceButtonRelease] = NotImplemented;
1148*4882a593Smuzhiyun     EventSwapVector[DeviceMotionNotify] = NotImplemented;
1149*4882a593Smuzhiyun     EventSwapVector[DeviceFocusIn] = NotImplemented;
1150*4882a593Smuzhiyun     EventSwapVector[DeviceFocusOut] = NotImplemented;
1151*4882a593Smuzhiyun     EventSwapVector[ProximityIn] = NotImplemented;
1152*4882a593Smuzhiyun     EventSwapVector[ProximityOut] = NotImplemented;
1153*4882a593Smuzhiyun     EventSwapVector[DeviceStateNotify] = NotImplemented;
1154*4882a593Smuzhiyun     EventSwapVector[DeviceKeyStateNotify] = NotImplemented;
1155*4882a593Smuzhiyun     EventSwapVector[DeviceButtonStateNotify] = NotImplemented;
1156*4882a593Smuzhiyun     EventSwapVector[DeviceMappingNotify] = NotImplemented;
1157*4882a593Smuzhiyun     EventSwapVector[ChangeDeviceNotify] = NotImplemented;
1158*4882a593Smuzhiyun     EventSwapVector[DevicePresenceNotify] = NotImplemented;
1159*4882a593Smuzhiyun     EventSwapVector[DevicePropertyNotify] = NotImplemented;
1160*4882a593Smuzhiyun     RestoreExtensionEvents();
1161*4882a593Smuzhiyun 
1162*4882a593Smuzhiyun     free(xi_all_devices.name);
1163*4882a593Smuzhiyun     free(xi_all_master_devices.name);
1164*4882a593Smuzhiyun 
1165*4882a593Smuzhiyun     XIBarrierReset();
1166*4882a593Smuzhiyun }
1167*4882a593Smuzhiyun 
1168*4882a593Smuzhiyun /***********************************************************************
1169*4882a593Smuzhiyun  *
1170*4882a593Smuzhiyun  * Assign an id and type to an input device.
1171*4882a593Smuzhiyun  *
1172*4882a593Smuzhiyun  */
1173*4882a593Smuzhiyun 
1174*4882a593Smuzhiyun void
AssignTypeAndName(DeviceIntPtr dev,Atom type,const char * name)1175*4882a593Smuzhiyun AssignTypeAndName(DeviceIntPtr dev, Atom type, const char *name)
1176*4882a593Smuzhiyun {
1177*4882a593Smuzhiyun     dev->xinput_type = type;
1178*4882a593Smuzhiyun     dev->name = strdup(name);
1179*4882a593Smuzhiyun }
1180*4882a593Smuzhiyun 
1181*4882a593Smuzhiyun /***********************************************************************
1182*4882a593Smuzhiyun  *
1183*4882a593Smuzhiyun  * Make device type atoms.
1184*4882a593Smuzhiyun  *
1185*4882a593Smuzhiyun  */
1186*4882a593Smuzhiyun 
1187*4882a593Smuzhiyun static void
MakeDeviceTypeAtoms(void)1188*4882a593Smuzhiyun MakeDeviceTypeAtoms(void)
1189*4882a593Smuzhiyun {
1190*4882a593Smuzhiyun     int i;
1191*4882a593Smuzhiyun 
1192*4882a593Smuzhiyun     for (i = 0; i < NUMTYPES; i++)
1193*4882a593Smuzhiyun         dev_type[i].type =
1194*4882a593Smuzhiyun             MakeAtom(dev_type[i].name, strlen(dev_type[i].name), 1);
1195*4882a593Smuzhiyun }
1196*4882a593Smuzhiyun 
1197*4882a593Smuzhiyun /*****************************************************************************
1198*4882a593Smuzhiyun  *
1199*4882a593Smuzhiyun  *	SEventIDispatch
1200*4882a593Smuzhiyun  *
1201*4882a593Smuzhiyun  *	Swap any events defined in this extension.
1202*4882a593Smuzhiyun  */
1203*4882a593Smuzhiyun #define DO_SWAP(func,type) func ((type *)from, (type *)to)
1204*4882a593Smuzhiyun 
1205*4882a593Smuzhiyun static void _X_COLD
SEventIDispatch(xEvent * from,xEvent * to)1206*4882a593Smuzhiyun SEventIDispatch(xEvent *from, xEvent *to)
1207*4882a593Smuzhiyun {
1208*4882a593Smuzhiyun     int type = from->u.u.type & 0177;
1209*4882a593Smuzhiyun 
1210*4882a593Smuzhiyun     if (type == DeviceValuator)
1211*4882a593Smuzhiyun         DO_SWAP(SEventDeviceValuator, deviceValuator);
1212*4882a593Smuzhiyun     else if (type == DeviceKeyPress) {
1213*4882a593Smuzhiyun         SKeyButtonPtrEvent(from, to);
1214*4882a593Smuzhiyun         to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
1215*4882a593Smuzhiyun     }
1216*4882a593Smuzhiyun     else if (type == DeviceKeyRelease) {
1217*4882a593Smuzhiyun         SKeyButtonPtrEvent(from, to);
1218*4882a593Smuzhiyun         to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
1219*4882a593Smuzhiyun     }
1220*4882a593Smuzhiyun     else if (type == DeviceButtonPress) {
1221*4882a593Smuzhiyun         SKeyButtonPtrEvent(from, to);
1222*4882a593Smuzhiyun         to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
1223*4882a593Smuzhiyun     }
1224*4882a593Smuzhiyun     else if (type == DeviceButtonRelease) {
1225*4882a593Smuzhiyun         SKeyButtonPtrEvent(from, to);
1226*4882a593Smuzhiyun         to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
1227*4882a593Smuzhiyun     }
1228*4882a593Smuzhiyun     else if (type == DeviceMotionNotify) {
1229*4882a593Smuzhiyun         SKeyButtonPtrEvent(from, to);
1230*4882a593Smuzhiyun         to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
1231*4882a593Smuzhiyun     }
1232*4882a593Smuzhiyun     else if (type == DeviceFocusIn)
1233*4882a593Smuzhiyun         DO_SWAP(SEventFocus, deviceFocus);
1234*4882a593Smuzhiyun     else if (type == DeviceFocusOut)
1235*4882a593Smuzhiyun         DO_SWAP(SEventFocus, deviceFocus);
1236*4882a593Smuzhiyun     else if (type == ProximityIn) {
1237*4882a593Smuzhiyun         SKeyButtonPtrEvent(from, to);
1238*4882a593Smuzhiyun         to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
1239*4882a593Smuzhiyun     }
1240*4882a593Smuzhiyun     else if (type == ProximityOut) {
1241*4882a593Smuzhiyun         SKeyButtonPtrEvent(from, to);
1242*4882a593Smuzhiyun         to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
1243*4882a593Smuzhiyun     }
1244*4882a593Smuzhiyun     else if (type == DeviceStateNotify)
1245*4882a593Smuzhiyun         DO_SWAP(SDeviceStateNotifyEvent, deviceStateNotify);
1246*4882a593Smuzhiyun     else if (type == DeviceKeyStateNotify)
1247*4882a593Smuzhiyun         DO_SWAP(SDeviceKeyStateNotifyEvent, deviceKeyStateNotify);
1248*4882a593Smuzhiyun     else if (type == DeviceButtonStateNotify)
1249*4882a593Smuzhiyun         DO_SWAP(SDeviceButtonStateNotifyEvent, deviceButtonStateNotify);
1250*4882a593Smuzhiyun     else if (type == DeviceMappingNotify)
1251*4882a593Smuzhiyun         DO_SWAP(SDeviceMappingNotifyEvent, deviceMappingNotify);
1252*4882a593Smuzhiyun     else if (type == ChangeDeviceNotify)
1253*4882a593Smuzhiyun         DO_SWAP(SChangeDeviceNotifyEvent, changeDeviceNotify);
1254*4882a593Smuzhiyun     else if (type == DevicePresenceNotify)
1255*4882a593Smuzhiyun         DO_SWAP(SDevicePresenceNotifyEvent, devicePresenceNotify);
1256*4882a593Smuzhiyun     else if (type == DevicePropertyNotify)
1257*4882a593Smuzhiyun         DO_SWAP(SDevicePropertyNotifyEvent, devicePropertyNotify);
1258*4882a593Smuzhiyun     else {
1259*4882a593Smuzhiyun         FatalError("XInputExtension: Impossible event!\n");
1260*4882a593Smuzhiyun     }
1261*4882a593Smuzhiyun }
1262*4882a593Smuzhiyun 
1263*4882a593Smuzhiyun /**********************************************************************
1264*4882a593Smuzhiyun  *
1265*4882a593Smuzhiyun  * IExtensionInit - initialize the input extension.
1266*4882a593Smuzhiyun  *
1267*4882a593Smuzhiyun  * Called from InitExtensions in main() or from QueryExtension() if the
1268*4882a593Smuzhiyun  * extension is dynamically loaded.
1269*4882a593Smuzhiyun  *
1270*4882a593Smuzhiyun  * This extension has several events and errors.
1271*4882a593Smuzhiyun  *
1272*4882a593Smuzhiyun  * XI is mandatory nowadays, so if we fail to init XI, we die.
1273*4882a593Smuzhiyun  */
1274*4882a593Smuzhiyun 
1275*4882a593Smuzhiyun void
XInputExtensionInit(void)1276*4882a593Smuzhiyun XInputExtensionInit(void)
1277*4882a593Smuzhiyun {
1278*4882a593Smuzhiyun     ExtensionEntry *extEntry;
1279*4882a593Smuzhiyun 
1280*4882a593Smuzhiyun     XExtensionVersion thisversion = { XI_Present,
1281*4882a593Smuzhiyun         SERVER_XI_MAJOR_VERSION,
1282*4882a593Smuzhiyun         SERVER_XI_MINOR_VERSION,
1283*4882a593Smuzhiyun     };
1284*4882a593Smuzhiyun 
1285*4882a593Smuzhiyun     if (!dixRegisterPrivateKey
1286*4882a593Smuzhiyun         (&XIClientPrivateKeyRec, PRIVATE_CLIENT, sizeof(XIClientRec)))
1287*4882a593Smuzhiyun         FatalError("Cannot request private for XI.\n");
1288*4882a593Smuzhiyun 
1289*4882a593Smuzhiyun     if (!XIBarrierInit())
1290*4882a593Smuzhiyun         FatalError("Could not initialize barriers.\n");
1291*4882a593Smuzhiyun 
1292*4882a593Smuzhiyun     extEntry = AddExtension(INAME, IEVENTS, IERRORS, ProcIDispatch,
1293*4882a593Smuzhiyun                             SProcIDispatch, IResetProc, StandardMinorOpcode);
1294*4882a593Smuzhiyun     if (extEntry) {
1295*4882a593Smuzhiyun         IReqCode = extEntry->base;
1296*4882a593Smuzhiyun         IEventBase = extEntry->eventBase;
1297*4882a593Smuzhiyun         XIVersion = thisversion;
1298*4882a593Smuzhiyun         MakeDeviceTypeAtoms();
1299*4882a593Smuzhiyun         RT_INPUTCLIENT = CreateNewResourceType((DeleteType) InputClientGone,
1300*4882a593Smuzhiyun                                                "INPUTCLIENT");
1301*4882a593Smuzhiyun         if (!RT_INPUTCLIENT)
1302*4882a593Smuzhiyun             FatalError("Failed to add resource type for XI.\n");
1303*4882a593Smuzhiyun         FixExtensionEvents(extEntry);
1304*4882a593Smuzhiyun         ReplySwapVector[IReqCode] = (ReplySwapPtr) SReplyIDispatch;
1305*4882a593Smuzhiyun         EventSwapVector[DeviceValuator] = SEventIDispatch;
1306*4882a593Smuzhiyun         EventSwapVector[DeviceKeyPress] = SEventIDispatch;
1307*4882a593Smuzhiyun         EventSwapVector[DeviceKeyRelease] = SEventIDispatch;
1308*4882a593Smuzhiyun         EventSwapVector[DeviceButtonPress] = SEventIDispatch;
1309*4882a593Smuzhiyun         EventSwapVector[DeviceButtonRelease] = SEventIDispatch;
1310*4882a593Smuzhiyun         EventSwapVector[DeviceMotionNotify] = SEventIDispatch;
1311*4882a593Smuzhiyun         EventSwapVector[DeviceFocusIn] = SEventIDispatch;
1312*4882a593Smuzhiyun         EventSwapVector[DeviceFocusOut] = SEventIDispatch;
1313*4882a593Smuzhiyun         EventSwapVector[ProximityIn] = SEventIDispatch;
1314*4882a593Smuzhiyun         EventSwapVector[ProximityOut] = SEventIDispatch;
1315*4882a593Smuzhiyun         EventSwapVector[DeviceStateNotify] = SEventIDispatch;
1316*4882a593Smuzhiyun         EventSwapVector[DeviceKeyStateNotify] = SEventIDispatch;
1317*4882a593Smuzhiyun         EventSwapVector[DeviceButtonStateNotify] = SEventIDispatch;
1318*4882a593Smuzhiyun         EventSwapVector[DeviceMappingNotify] = SEventIDispatch;
1319*4882a593Smuzhiyun         EventSwapVector[ChangeDeviceNotify] = SEventIDispatch;
1320*4882a593Smuzhiyun         EventSwapVector[DevicePresenceNotify] = SEventIDispatch;
1321*4882a593Smuzhiyun 
1322*4882a593Smuzhiyun         GERegisterExtension(IReqCode, XI2EventSwap);
1323*4882a593Smuzhiyun 
1324*4882a593Smuzhiyun         memset(&xi_all_devices, 0, sizeof(xi_all_devices));
1325*4882a593Smuzhiyun         memset(&xi_all_master_devices, 0, sizeof(xi_all_master_devices));
1326*4882a593Smuzhiyun         xi_all_devices.id = XIAllDevices;
1327*4882a593Smuzhiyun         xi_all_devices.name = strdup("XIAllDevices");
1328*4882a593Smuzhiyun         xi_all_master_devices.id = XIAllMasterDevices;
1329*4882a593Smuzhiyun         xi_all_master_devices.name = strdup("XIAllMasterDevices");
1330*4882a593Smuzhiyun 
1331*4882a593Smuzhiyun         inputInfo.all_devices = &xi_all_devices;
1332*4882a593Smuzhiyun         inputInfo.all_master_devices = &xi_all_master_devices;
1333*4882a593Smuzhiyun 
1334*4882a593Smuzhiyun         XIResetProperties();
1335*4882a593Smuzhiyun     }
1336*4882a593Smuzhiyun     else {
1337*4882a593Smuzhiyun         FatalError("IExtensionInit: AddExtensions failed\n");
1338*4882a593Smuzhiyun     }
1339*4882a593Smuzhiyun }
1340