~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to Xi/extinit.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: extinit.c,v 1.4 2001/02/09 02:04:34 xorgcvs Exp $ */
 
2
 
 
3
/************************************************************
 
4
 
 
5
Copyright 1989, 1998  The Open Group
 
6
 
 
7
Permission to use, copy, modify, distribute, and sell this software and its
 
8
documentation for any purpose is hereby granted without fee, provided that
 
9
the above copyright notice appear in all copies and that both that
 
10
copyright notice and this permission notice appear in supporting
 
11
documentation.
 
12
 
 
13
The above copyright notice and this permission notice shall be included in
 
14
all copies or substantial portions of the Software.
 
15
 
 
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
22
 
 
23
Except as contained in this notice, the name of The Open Group shall not be
 
24
used in advertising or otherwise to promote the sale, use or other dealings
 
25
in this Software without prior written authorization from The Open Group.
 
26
 
 
27
Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
 
28
 
 
29
                        All Rights Reserved
 
30
 
 
31
Permission to use, copy, modify, and distribute this software and its
 
32
documentation for any purpose and without fee is hereby granted,
 
33
provided that the above copyright notice appear in all copies and that
 
34
both that copyright notice and this permission notice appear in
 
35
supporting documentation, and that the name of Hewlett-Packard not be
 
36
used in advertising or publicity pertaining to distribution of the
 
37
software without specific, written prior permission.
 
38
 
 
39
HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 
40
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 
41
HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 
42
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 
43
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 
44
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 
45
SOFTWARE.
 
46
 
 
47
********************************************************/
 
48
/* $XFree86: xc/programs/Xserver/Xi/extinit.c,v 3.6 2001/12/14 19:58:55 dawes Exp $ */
 
49
 
 
50
/********************************************************************
 
51
 *
 
52
 *  Dispatch routines and initialization routines for the X input extension.
 
53
 *
 
54
 */
 
55
 
 
56
#define  NUMTYPES 15
 
57
 
 
58
#define  NEED_EVENTS
 
59
#define  NEED_REPLIES
 
60
#ifdef HAVE_DIX_CONFIG_H
 
61
#include <dix-config.h>
 
62
#endif
 
63
 
 
64
#include <X11/X.h>
 
65
#include <X11/Xproto.h>
 
66
#include "inputstr.h"
 
67
#include "gcstruct.h"                   /* pointer for extnsionst.h*/
 
68
#include "extnsionst.h"                 /* extension entry   */
 
69
#include <X11/extensions/XI.h>
 
70
#include <X11/extensions/XIproto.h>
 
71
 
 
72
#include "dixevents.h"
 
73
#include "exevents.h"
 
74
#include "extinit.h"
 
75
#include "exglobals.h"
 
76
#include "swaprep.h"
 
77
 
 
78
/* modules local to Xi */
 
79
#include "allowev.h"
 
80
#include "chgdctl.h"
 
81
#include "chgfctl.h"
 
82
#include "chgkbd.h"
 
83
#include "chgprop.h"
 
84
#include "chgptr.h"
 
85
#include "closedev.h"
 
86
#include "devbell.h"
 
87
#include "getbmap.h"
 
88
#include "getbmap.h"
 
89
#include "getdctl.h"
 
90
#include "getfctl.h"
 
91
#include "getfocus.h"
 
92
#include "getkmap.h"
 
93
#include "getmmap.h"
 
94
#include "getprop.h"
 
95
#include "getselev.h"
 
96
#include "getvers.h"
 
97
#include "getvers.h"
 
98
#include "grabdev.h"
 
99
#include "grabdevb.h"
 
100
#include "grabdevk.h"
 
101
#include "gtmotion.h"
 
102
#include "listdev.h"
 
103
#include "opendev.h"
 
104
#include "queryst.h"
 
105
#include "selectev.h"
 
106
#include "sendexev.h"
 
107
#include "chgkmap.h"
 
108
#include "setbmap.h"
 
109
#include "setdval.h"
 
110
#include "setfocus.h"
 
111
#include "setmmap.h"
 
112
#include "setmode.h"
 
113
#include "ungrdev.h"
 
114
#include "ungrdevb.h"
 
115
#include "ungrdevk.h"
 
116
 
 
117
static Mask     lastExtEventMask = 1;
 
118
int             ExtEventIndex;
 
119
Mask            ExtValidMasks[EMASKSIZE];
 
120
Mask            ExtExclusiveMasks[EMASKSIZE];
 
121
 
 
122
struct  dev_type
 
123
    {
 
124
    Atom        type;
 
125
    char        *name;
 
126
    }dev_type [] = {{0,XI_KEYBOARD},
 
127
            {0,XI_MOUSE},
 
128
            {0,XI_TABLET},
 
129
            {0,XI_TOUCHSCREEN},
 
130
            {0,XI_TOUCHPAD},
 
131
            {0,XI_BARCODE},
 
132
            {0,XI_BUTTONBOX},
 
133
            {0,XI_KNOB_BOX},
 
134
            {0,XI_ONE_KNOB},
 
135
            {0,XI_NINE_KNOB},
 
136
            {0,XI_TRACKBALL},
 
137
            {0,XI_QUADRATURE},
 
138
            {0,XI_ID_MODULE},
 
139
            {0,XI_SPACEBALL},
 
140
            {0,XI_DATAGLOVE},
 
141
            {0,XI_EYETRACKER},
 
142
            {0,XI_CURSORKEYS},
 
143
            {0,XI_FOOTMOUSE}};
 
144
 
 
145
CARD8  event_base [numInputClasses];
 
146
XExtEventInfo EventInfo[32];
 
147
 
 
148
/*****************************************************************
 
149
 *
 
150
 * Globals referenced elsewhere in the server.
 
151
 *
 
152
 */
 
153
 
 
154
int     IReqCode = 0;
 
155
int     BadDevice = 0;
 
156
int     BadEvent = 1;
 
157
int     BadMode = 2;
 
158
int     DeviceBusy = 3;
 
159
int     BadClass = 4;
 
160
 
 
161
Mask    DevicePointerMotionMask;
 
162
Mask    DevicePointerMotionHintMask;
 
163
Mask    DeviceFocusChangeMask;
 
164
Mask    DeviceStateNotifyMask;
 
165
Mask    ChangeDeviceNotifyMask;
 
166
Mask    DeviceMappingNotifyMask;
 
167
Mask    DeviceOwnerGrabButtonMask;
 
168
Mask    DeviceButtonGrabMask;
 
169
Mask    DeviceButtonMotionMask;
 
170
 
 
171
int     DeviceValuator;
 
172
int     DeviceKeyPress;
 
173
int     DeviceKeyRelease;
 
174
int     DeviceButtonPress;
 
175
int     DeviceButtonRelease;
 
176
int     DeviceMotionNotify;
 
177
int     DeviceFocusIn;
 
178
int     DeviceFocusOut;
 
179
int     ProximityIn;
 
180
int     ProximityOut;
 
181
int     DeviceStateNotify;
 
182
int     DeviceKeyStateNotify;
 
183
int     DeviceButtonStateNotify;
 
184
int     DeviceMappingNotify;
 
185
int     ChangeDeviceNotify;
 
186
 
 
187
int     RT_INPUTCLIENT;
 
188
 
 
189
/*****************************************************************
 
190
 *
 
191
 * Externs defined elsewhere in the X server.
 
192
 *
 
193
 */
 
194
 
 
195
extern  XExtensionVersion       AllExtensionVersions[];
 
196
 
 
197
Mask    PropagateMask[MAX_DEVICES];
 
198
 
 
199
/*****************************************************************
 
200
 *
 
201
 * Declarations of local routines.
 
202
 *
 
203
 */
 
204
 
 
205
static  XExtensionVersion       thisversion = 
 
206
                                        {XI_Present, 
 
207
                                         XI_Add_XChangeDeviceControl_Major, 
 
208
                                         XI_Add_XChangeDeviceControl_Minor};
 
209
 
 
210
/**********************************************************************
 
211
 *
 
212
 * IExtensionInit - initialize the input extension.
 
213
 *
 
214
 * Called from InitExtensions in main() or from QueryExtension() if the
 
215
 * extension is dynamically loaded.
 
216
 *
 
217
 * This extension has several events and errors.
 
218
 *
 
219
 */
 
220
 
 
221
void
 
222
XInputExtensionInit()
 
223
{
 
224
    ExtensionEntry *extEntry;
 
225
 
 
226
    extEntry = AddExtension(INAME, IEVENTS, IERRORS, ProcIDispatch,
 
227
                   SProcIDispatch, IResetProc, StandardMinorOpcode);
 
228
    if (extEntry)
 
229
        {
 
230
        IReqCode = extEntry->base;
 
231
        AllExtensionVersions[IReqCode-128] = thisversion;
 
232
        MakeDeviceTypeAtoms ();
 
233
        RT_INPUTCLIENT = CreateNewResourceType((DeleteType)InputClientGone);
 
234
        FixExtensionEvents (extEntry);
 
235
        ReplySwapVector[IReqCode] = (ReplySwapPtr)SReplyIDispatch;
 
236
        EventSwapVector[DeviceValuator] = SEventIDispatch;
 
237
        EventSwapVector[DeviceKeyPress] = SEventIDispatch;
 
238
        EventSwapVector[DeviceKeyRelease] = SEventIDispatch;
 
239
        EventSwapVector[DeviceButtonPress] = SEventIDispatch;
 
240
        EventSwapVector[DeviceButtonRelease] = SEventIDispatch;
 
241
        EventSwapVector[DeviceMotionNotify] = SEventIDispatch;
 
242
        EventSwapVector[DeviceFocusIn] = SEventIDispatch;
 
243
        EventSwapVector[DeviceFocusOut] = SEventIDispatch;
 
244
        EventSwapVector[ProximityIn] = SEventIDispatch;
 
245
        EventSwapVector[ProximityOut] = SEventIDispatch;
 
246
        EventSwapVector[DeviceStateNotify] = SEventIDispatch;
 
247
        EventSwapVector[DeviceKeyStateNotify] = SEventIDispatch;
 
248
        EventSwapVector[DeviceButtonStateNotify] = SEventIDispatch;
 
249
        EventSwapVector[DeviceMappingNotify] = SEventIDispatch;
 
250
        EventSwapVector[ChangeDeviceNotify] = SEventIDispatch;
 
251
        }
 
252
    else 
 
253
        {
 
254
        FatalError("IExtensionInit: AddExtensions failed\n");
 
255
        }
 
256
    }
 
257
 
 
258
/*************************************************************************
 
259
 *
 
260
 * ProcIDispatch - main dispatch routine for requests to this extension.
 
261
 * This routine is used if server and client have the same byte ordering.
 
262
 *
 
263
 */
 
264
 
 
265
int
 
266
ProcIDispatch (client)
 
267
    register ClientPtr client;
 
268
{
 
269
    REQUEST(xReq);
 
270
    if (stuff->data == X_GetExtensionVersion)
 
271
        return(ProcXGetExtensionVersion(client));
 
272
    if (stuff->data == X_ListInputDevices)
 
273
        return(ProcXListInputDevices(client));
 
274
    else if (stuff->data == X_OpenDevice)
 
275
        return(ProcXOpenDevice(client));
 
276
    else if (stuff->data == X_CloseDevice)
 
277
        return(ProcXCloseDevice(client));
 
278
    else if (stuff->data == X_SetDeviceMode)
 
279
        return(ProcXSetDeviceMode(client));
 
280
    else if (stuff->data == X_SelectExtensionEvent)
 
281
        return(ProcXSelectExtensionEvent(client));
 
282
    else if (stuff->data == X_GetSelectedExtensionEvents)
 
283
        return(ProcXGetSelectedExtensionEvents(client));
 
284
    else if (stuff->data == X_ChangeDeviceDontPropagateList)
 
285
        return(ProcXChangeDeviceDontPropagateList(client));
 
286
    else if (stuff->data == X_GetDeviceDontPropagateList)
 
287
        return(ProcXGetDeviceDontPropagateList(client));
 
288
    else if (stuff->data == X_GetDeviceMotionEvents)
 
289
        return(ProcXGetDeviceMotionEvents(client));
 
290
    else if (stuff->data == X_ChangeKeyboardDevice)
 
291
        return(ProcXChangeKeyboardDevice(client));
 
292
    else if (stuff->data == X_ChangePointerDevice)
 
293
        return(ProcXChangePointerDevice(client));
 
294
    else if (stuff->data == X_GrabDevice)
 
295
        return(ProcXGrabDevice(client));
 
296
    else if (stuff->data == X_UngrabDevice)
 
297
        return(ProcXUngrabDevice(client));
 
298
    else if (stuff->data == X_GrabDeviceKey)
 
299
        return(ProcXGrabDeviceKey(client));
 
300
    else if (stuff->data == X_UngrabDeviceKey)
 
301
        return(ProcXUngrabDeviceKey(client));
 
302
    else if (stuff->data == X_GrabDeviceButton)
 
303
        return(ProcXGrabDeviceButton(client));
 
304
    else if (stuff->data == X_UngrabDeviceButton)
 
305
        return(ProcXUngrabDeviceButton(client));
 
306
    else if (stuff->data == X_AllowDeviceEvents)
 
307
        return(ProcXAllowDeviceEvents(client));
 
308
    else if (stuff->data == X_GetDeviceFocus)
 
309
        return(ProcXGetDeviceFocus(client));
 
310
    else if (stuff->data == X_SetDeviceFocus)
 
311
        return(ProcXSetDeviceFocus(client));
 
312
    else if (stuff->data == X_GetFeedbackControl)
 
313
        return(ProcXGetFeedbackControl(client));
 
314
    else if (stuff->data == X_ChangeFeedbackControl)
 
315
        return(ProcXChangeFeedbackControl(client));
 
316
    else if (stuff->data == X_GetDeviceKeyMapping)
 
317
        return(ProcXGetDeviceKeyMapping(client));
 
318
    else if (stuff->data == X_ChangeDeviceKeyMapping)
 
319
        return(ProcXChangeDeviceKeyMapping(client));
 
320
    else if (stuff->data == X_GetDeviceModifierMapping)
 
321
        return(ProcXGetDeviceModifierMapping(client));
 
322
    else if (stuff->data == X_SetDeviceModifierMapping)
 
323
        return(ProcXSetDeviceModifierMapping(client));
 
324
    else if (stuff->data == X_GetDeviceButtonMapping)
 
325
        return(ProcXGetDeviceButtonMapping(client));
 
326
    else if (stuff->data == X_SetDeviceButtonMapping)
 
327
        return(ProcXSetDeviceButtonMapping(client));
 
328
    else if (stuff->data == X_QueryDeviceState)
 
329
        return(ProcXQueryDeviceState(client));
 
330
    else if (stuff->data == X_SendExtensionEvent)
 
331
        return(ProcXSendExtensionEvent(client));
 
332
    else if (stuff->data == X_DeviceBell)
 
333
        return(ProcXDeviceBell(client));
 
334
    else if (stuff->data == X_SetDeviceValuators)
 
335
        return(ProcXSetDeviceValuators(client));
 
336
    else if (stuff->data == X_GetDeviceControl)
 
337
        return(ProcXGetDeviceControl(client));
 
338
    else if (stuff->data == X_ChangeDeviceControl)
 
339
        return(ProcXChangeDeviceControl(client));
 
340
    else
 
341
        {
 
342
        SendErrorToClient(client, IReqCode, stuff->data, 0, BadRequest);
 
343
        }
 
344
    return(BadRequest);
 
345
    }
 
346
 
 
347
/*******************************************************************************
 
348
 *
 
349
 * SProcXDispatch 
 
350
 *
 
351
 * Main swapped dispatch routine for requests to this extension.
 
352
 * This routine is used if server and client do not have the same byte ordering.
 
353
 *
 
354
 */
 
355
 
 
356
int
 
357
SProcIDispatch(client)
 
358
    register ClientPtr client;
 
359
{
 
360
    REQUEST(xReq);
 
361
    if (stuff->data == X_GetExtensionVersion)
 
362
        return(SProcXGetExtensionVersion(client));
 
363
    if (stuff->data == X_ListInputDevices)
 
364
        return(SProcXListInputDevices(client));
 
365
    else if (stuff->data == X_OpenDevice)
 
366
        return(SProcXOpenDevice(client));
 
367
    else if (stuff->data == X_CloseDevice)
 
368
        return(SProcXCloseDevice(client));
 
369
    else if (stuff->data == X_SetDeviceMode)
 
370
        return(SProcXSetDeviceMode(client));
 
371
    else if (stuff->data == X_SelectExtensionEvent)
 
372
        return(SProcXSelectExtensionEvent(client));
 
373
    else if (stuff->data == X_GetSelectedExtensionEvents)
 
374
        return(SProcXGetSelectedExtensionEvents(client));
 
375
    else if (stuff->data == X_ChangeDeviceDontPropagateList)
 
376
        return(SProcXChangeDeviceDontPropagateList(client));
 
377
    else if (stuff->data == X_GetDeviceDontPropagateList)
 
378
        return(SProcXGetDeviceDontPropagateList(client));
 
379
    else if (stuff->data == X_GetDeviceMotionEvents)
 
380
        return(SProcXGetDeviceMotionEvents(client));
 
381
    else if (stuff->data == X_ChangeKeyboardDevice)
 
382
        return(SProcXChangeKeyboardDevice(client));
 
383
    else if (stuff->data == X_ChangePointerDevice)
 
384
        return(SProcXChangePointerDevice(client));
 
385
    else if (stuff->data == X_GrabDevice)
 
386
        return(SProcXGrabDevice(client));
 
387
    else if (stuff->data == X_UngrabDevice)
 
388
        return(SProcXUngrabDevice(client));
 
389
    else if (stuff->data == X_GrabDeviceKey)
 
390
        return(SProcXGrabDeviceKey(client));
 
391
    else if (stuff->data == X_UngrabDeviceKey)
 
392
        return(SProcXUngrabDeviceKey(client));
 
393
    else if (stuff->data == X_GrabDeviceButton)
 
394
        return(SProcXGrabDeviceButton(client));
 
395
    else if (stuff->data == X_UngrabDeviceButton)
 
396
        return(SProcXUngrabDeviceButton(client));
 
397
    else if (stuff->data == X_AllowDeviceEvents)
 
398
        return(SProcXAllowDeviceEvents(client));
 
399
    else if (stuff->data == X_GetDeviceFocus)
 
400
        return(SProcXGetDeviceFocus(client));
 
401
    else if (stuff->data == X_SetDeviceFocus)
 
402
        return(SProcXSetDeviceFocus(client));
 
403
    else if (stuff->data == X_GetFeedbackControl)
 
404
        return(SProcXGetFeedbackControl(client));
 
405
    else if (stuff->data == X_ChangeFeedbackControl)
 
406
        return(SProcXChangeFeedbackControl(client));
 
407
    else if (stuff->data == X_GetDeviceKeyMapping)
 
408
        return(SProcXGetDeviceKeyMapping(client));
 
409
    else if (stuff->data == X_ChangeDeviceKeyMapping)
 
410
        return(SProcXChangeDeviceKeyMapping(client));
 
411
    else if (stuff->data == X_GetDeviceModifierMapping)
 
412
        return(SProcXGetDeviceModifierMapping(client));
 
413
    else if (stuff->data == X_SetDeviceModifierMapping)
 
414
        return(SProcXSetDeviceModifierMapping(client));
 
415
    else if (stuff->data == X_GetDeviceButtonMapping)
 
416
        return(SProcXGetDeviceButtonMapping(client));
 
417
    else if (stuff->data == X_SetDeviceButtonMapping)
 
418
        return(SProcXSetDeviceButtonMapping(client));
 
419
    else if (stuff->data == X_QueryDeviceState)
 
420
        return(SProcXQueryDeviceState(client));
 
421
    else if (stuff->data == X_SendExtensionEvent)
 
422
        return(SProcXSendExtensionEvent(client));
 
423
    else if (stuff->data == X_DeviceBell)
 
424
        return(SProcXDeviceBell(client));
 
425
    else if (stuff->data == X_SetDeviceValuators)
 
426
        return(SProcXSetDeviceValuators(client));
 
427
    else if (stuff->data == X_GetDeviceControl)
 
428
        return(SProcXGetDeviceControl(client));
 
429
    else if (stuff->data == X_ChangeDeviceControl)
 
430
        return(SProcXChangeDeviceControl(client));
 
431
    else
 
432
        {
 
433
        SendErrorToClient(client, IReqCode, stuff->data, 0, BadRequest);
 
434
        }
 
435
    return(BadRequest);
 
436
    }
 
437
 
 
438
/**********************************************************************
 
439
 *
 
440
 * SReplyIDispatch
 
441
 * Swap any replies defined in this extension.
 
442
 *
 
443
 */
 
444
 
 
445
/* FIXME: this would be more concise and readable in ANSI C */
 
446
#define DISPATCH(code) \
 
447
    if (rep->RepType == X_##code) \
 
448
        SRepX##code (client, len, (x##code##Reply *) rep)
 
449
 
 
450
void
 
451
SReplyIDispatch (client, len, rep)
 
452
    ClientPtr           client;
 
453
    int                 len;
 
454
    xGrabDeviceReply    *rep;           /* All we look at is the type field */
 
455
{                                       /* This is common to all replies    */
 
456
    if (rep->RepType == X_GetExtensionVersion)
 
457
        SRepXGetExtensionVersion (client, len, (xGetExtensionVersionReply *)rep);
 
458
    else if (rep->RepType == X_ListInputDevices)
 
459
        SRepXListInputDevices (client, len, (xListInputDevicesReply *)rep);
 
460
    else if (rep->RepType == X_OpenDevice)
 
461
        SRepXOpenDevice (client, len, (xOpenDeviceReply *)rep);
 
462
    else if (rep->RepType == X_SetDeviceMode)
 
463
        SRepXSetDeviceMode (client, len, (xSetDeviceModeReply *) rep);
 
464
    else if (rep->RepType == X_GetSelectedExtensionEvents)
 
465
        SRepXGetSelectedExtensionEvents (client, len, (xGetSelectedExtensionEventsReply *) rep);
 
466
    else if (rep->RepType == X_GetDeviceDontPropagateList)
 
467
        SRepXGetDeviceDontPropagateList (client, len, (xGetDeviceDontPropagateListReply *)rep);
 
468
    else if (rep->RepType == X_GetDeviceMotionEvents)
 
469
        SRepXGetDeviceMotionEvents (client, len, (xGetDeviceMotionEventsReply *) rep);
 
470
    else if (rep->RepType == X_ChangeKeyboardDevice)
 
471
        SRepXChangeKeyboardDevice (client, len, (xChangeKeyboardDeviceReply *) rep);
 
472
    else if (rep->RepType == X_ChangePointerDevice)
 
473
        SRepXChangePointerDevice (client, len, (xChangePointerDeviceReply *)rep);
 
474
    else if (rep->RepType == X_GrabDevice)
 
475
        SRepXGrabDevice (client, len, (xGrabDeviceReply *)rep);
 
476
    else if (rep->RepType == X_GetDeviceFocus)
 
477
        SRepXGetDeviceFocus (client, len, (xGetDeviceFocusReply *)rep);
 
478
    else if (rep->RepType == X_GetFeedbackControl)
 
479
        SRepXGetFeedbackControl (client, len, (xGetFeedbackControlReply *)rep);
 
480
    else if (rep->RepType == X_GetDeviceKeyMapping)
 
481
        SRepXGetDeviceKeyMapping (client, len, (xGetDeviceKeyMappingReply *)rep);
 
482
    else if (rep->RepType == X_GetDeviceModifierMapping)
 
483
        SRepXGetDeviceModifierMapping (client, len, (xGetDeviceModifierMappingReply *)rep);
 
484
    else if (rep->RepType == X_SetDeviceModifierMapping)
 
485
        SRepXSetDeviceModifierMapping (client, len, (xSetDeviceModifierMappingReply *)rep);
 
486
    else if (rep->RepType == X_GetDeviceButtonMapping)
 
487
        SRepXGetDeviceButtonMapping (client, len, (xGetDeviceButtonMappingReply *)rep);
 
488
    else if (rep->RepType == X_SetDeviceButtonMapping)
 
489
        SRepXSetDeviceButtonMapping (client, len, (xSetDeviceButtonMappingReply *)rep);
 
490
    else if (rep->RepType == X_QueryDeviceState)
 
491
        SRepXQueryDeviceState (client, len, (xQueryDeviceStateReply *)rep);
 
492
    else if (rep->RepType == X_SetDeviceValuators)
 
493
        SRepXSetDeviceValuators (client, len, (xSetDeviceValuatorsReply *)rep);
 
494
    else if (rep->RepType == X_GetDeviceControl)
 
495
        SRepXGetDeviceControl (client, len, (xGetDeviceControlReply *)rep);
 
496
    else if (rep->RepType == X_ChangeDeviceControl)
 
497
        SRepXChangeDeviceControl (client, len, (xChangeDeviceControlReply *)rep);
 
498
    else
 
499
        {
 
500
            FatalError("XINPUT confused sending swapped reply");
 
501
        }
 
502
    }
 
503
 
 
504
/*****************************************************************************
 
505
 *
 
506
 *      SEventIDispatch
 
507
 *
 
508
 *      Swap any events defined in this extension.
 
509
 */
 
510
#define DO_SWAP(func,type) func ((type *)from, (type *)to)
 
511
 
 
512
void
 
513
SEventIDispatch (from, to)
 
514
    xEvent      *from;
 
515
    xEvent      *to;
 
516
{
 
517
    int         type = from->u.u.type & 0177;
 
518
 
 
519
    if (type == DeviceValuator)
 
520
        DO_SWAP(SEventDeviceValuator, deviceValuator);
 
521
    else if (type == DeviceKeyPress)
 
522
        {
 
523
        SKeyButtonPtrEvent (from, to);
 
524
        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
 
525
        }
 
526
    else if (type == DeviceKeyRelease)
 
527
        {
 
528
        SKeyButtonPtrEvent (from, to);
 
529
        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
 
530
        }
 
531
    else if (type == DeviceButtonPress)
 
532
        {
 
533
        SKeyButtonPtrEvent (from, to);
 
534
        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
 
535
        }
 
536
    else if (type == DeviceButtonRelease)
 
537
        {
 
538
        SKeyButtonPtrEvent (from, to);
 
539
        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
 
540
        }
 
541
    else if (type == DeviceMotionNotify)
 
542
        {
 
543
        SKeyButtonPtrEvent (from, to);
 
544
        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
 
545
        }
 
546
    else if (type == DeviceFocusIn)
 
547
        DO_SWAP(SEventFocus, deviceFocus);
 
548
    else if (type == DeviceFocusOut)
 
549
        DO_SWAP(SEventFocus, deviceFocus);
 
550
    else if (type == ProximityIn)
 
551
        {
 
552
        SKeyButtonPtrEvent (from, to);
 
553
        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
 
554
        }
 
555
    else if (type == ProximityOut)
 
556
        { 
 
557
        SKeyButtonPtrEvent (from, to);
 
558
        to->u.keyButtonPointer.pad1 = from->u.keyButtonPointer.pad1;
 
559
        }
 
560
    else if (type == DeviceStateNotify)
 
561
        DO_SWAP(SDeviceStateNotifyEvent, deviceStateNotify);
 
562
    else if (type == DeviceKeyStateNotify)
 
563
        DO_SWAP(SDeviceKeyStateNotifyEvent, deviceKeyStateNotify);
 
564
    else if (type == DeviceButtonStateNotify)
 
565
        DO_SWAP(SDeviceButtonStateNotifyEvent, deviceButtonStateNotify);
 
566
    else if (type == DeviceMappingNotify)
 
567
        DO_SWAP(SDeviceMappingNotifyEvent, deviceMappingNotify);
 
568
    else if (type == ChangeDeviceNotify)
 
569
        DO_SWAP(SChangeDeviceNotifyEvent, changeDeviceNotify);
 
570
    else
 
571
        {
 
572
        FatalError("XInputExtension: Impossible event!\n");
 
573
        }
 
574
    }
 
575
 
 
576
/************************************************************************
 
577
 *
 
578
 * This function swaps the DeviceValuator event.
 
579
 *
 
580
 */
 
581
 
 
582
void
 
583
SEventDeviceValuator (from, to)
 
584
    deviceValuator      *from;
 
585
    deviceValuator      *to;
 
586
    {
 
587
    register char       n;
 
588
    register int        i;
 
589
    INT32 *ip B32;
 
590
 
 
591
    *to = *from;
 
592
    swaps(&to->sequenceNumber,n);
 
593
    swaps(&to->device_state,n);
 
594
    ip = &to->valuator0;
 
595
    for (i=0; i<6; i++)
 
596
        {
 
597
        swapl((ip+i),n);        /* macro - braces are required      */
 
598
        }
 
599
    }
 
600
 
 
601
void
 
602
SEventFocus (from, to)
 
603
    deviceFocus *from;
 
604
    deviceFocus *to;
 
605
{
 
606
    register char       n;
 
607
 
 
608
    *to = *from;
 
609
    swaps(&to->sequenceNumber,n);
 
610
    swapl(&to->time, n);
 
611
    swapl(&to->window, n);
 
612
    }
 
613
 
 
614
void
 
615
SDeviceStateNotifyEvent (from, to)
 
616
    deviceStateNotify   *from;
 
617
    deviceStateNotify   *to;
 
618
{
 
619
    register int        i;
 
620
    register char       n;
 
621
    INT32 *ip B32;
 
622
 
 
623
    *to = *from;
 
624
    swaps(&to->sequenceNumber,n);
 
625
    swapl(&to->time, n);
 
626
    ip = &to->valuator0;
 
627
    for (i=0; i<3; i++)
 
628
        {
 
629
        swapl((ip+i),n);        /* macro - braces are required      */
 
630
        }
 
631
    }
 
632
 
 
633
void
 
634
SDeviceKeyStateNotifyEvent (from, to)
 
635
    deviceKeyStateNotify        *from;
 
636
    deviceKeyStateNotify        *to;
 
637
{
 
638
    register char       n;
 
639
 
 
640
    *to = *from;
 
641
    swaps(&to->sequenceNumber,n);
 
642
    }
 
643
 
 
644
void
 
645
SDeviceButtonStateNotifyEvent (from, to)
 
646
    deviceButtonStateNotify     *from;
 
647
    deviceButtonStateNotify     *to;
 
648
{
 
649
    register char       n;
 
650
 
 
651
    *to = *from;
 
652
    swaps(&to->sequenceNumber,n);
 
653
    }
 
654
 
 
655
void
 
656
SChangeDeviceNotifyEvent (from, to)
 
657
    changeDeviceNotify  *from;
 
658
    changeDeviceNotify  *to;
 
659
{
 
660
    register char       n;
 
661
 
 
662
    *to = *from;
 
663
    swaps(&to->sequenceNumber,n);
 
664
    swapl(&to->time, n);
 
665
    }
 
666
 
 
667
void
 
668
SDeviceMappingNotifyEvent (from, to)
 
669
    deviceMappingNotify *from;
 
670
    deviceMappingNotify *to;
 
671
{
 
672
    register char       n;
 
673
 
 
674
    *to = *from;
 
675
    swaps(&to->sequenceNumber,n);
 
676
    swapl(&to->time, n);
 
677
    }
 
678
 
 
679
/************************************************************************
 
680
 *
 
681
 * This function sets up extension event types and masks.
 
682
 *
 
683
 */
 
684
 
 
685
void
 
686
FixExtensionEvents (extEntry)
 
687
    ExtensionEntry      *extEntry;
 
688
{
 
689
    Mask                mask;
 
690
 
 
691
    DeviceValuator          = extEntry->eventBase;
 
692
    DeviceKeyPress          = DeviceValuator + 1;
 
693
    DeviceKeyRelease        = DeviceKeyPress + 1;
 
694
    DeviceButtonPress       = DeviceKeyRelease + 1;
 
695
    DeviceButtonRelease     = DeviceButtonPress + 1;
 
696
    DeviceMotionNotify      = DeviceButtonRelease + 1;
 
697
    DeviceFocusIn           = DeviceMotionNotify + 1;
 
698
    DeviceFocusOut          = DeviceFocusIn + 1;
 
699
    ProximityIn             = DeviceFocusOut + 1;
 
700
    ProximityOut            = ProximityIn + 1;
 
701
    DeviceStateNotify       = ProximityOut + 1;
 
702
    DeviceMappingNotify     = DeviceStateNotify + 1;
 
703
    ChangeDeviceNotify      = DeviceMappingNotify + 1;
 
704
    DeviceKeyStateNotify    = ChangeDeviceNotify + 1;
 
705
    DeviceButtonStateNotify = DeviceKeyStateNotify + 1;
 
706
 
 
707
    event_base[KeyClass] = DeviceKeyPress;
 
708
    event_base[ButtonClass] = DeviceButtonPress;
 
709
    event_base[ValuatorClass] = DeviceMotionNotify;
 
710
    event_base[ProximityClass] = ProximityIn;
 
711
    event_base[FocusClass] = DeviceFocusIn;
 
712
    event_base[OtherClass] = DeviceStateNotify;
 
713
 
 
714
    BadDevice += extEntry->errorBase;
 
715
    BadEvent += extEntry->errorBase;
 
716
    BadMode += extEntry->errorBase;
 
717
    DeviceBusy += extEntry->errorBase;
 
718
    BadClass += extEntry->errorBase;
 
719
 
 
720
    mask = GetNextExtEventMask ();
 
721
    SetMaskForExtEvent (mask, DeviceKeyPress);
 
722
    AllowPropagateSuppress (mask);
 
723
 
 
724
    mask = GetNextExtEventMask ();
 
725
    SetMaskForExtEvent (mask, DeviceKeyRelease);
 
726
    AllowPropagateSuppress (mask);
 
727
 
 
728
    mask = GetNextExtEventMask ();
 
729
    SetMaskForExtEvent (mask, DeviceButtonPress);
 
730
    AllowPropagateSuppress (mask);
 
731
 
 
732
    mask = GetNextExtEventMask ();
 
733
    SetMaskForExtEvent (mask, DeviceButtonRelease);
 
734
    AllowPropagateSuppress (mask);
 
735
 
 
736
    mask = GetNextExtEventMask ();
 
737
    SetMaskForExtEvent (mask, ProximityIn);
 
738
    SetMaskForExtEvent (mask, ProximityOut);
 
739
    AllowPropagateSuppress (mask);
 
740
 
 
741
    mask = GetNextExtEventMask ();
 
742
    DeviceStateNotifyMask = mask;
 
743
    SetMaskForExtEvent (mask, DeviceStateNotify);
 
744
 
 
745
    mask = GetNextExtEventMask ();
 
746
    DevicePointerMotionMask = mask;
 
747
    SetMaskForExtEvent (mask, DeviceMotionNotify);
 
748
    AllowPropagateSuppress (mask);
 
749
 
 
750
    DevicePointerMotionHintMask = GetNextExtEventMask();
 
751
    SetEventInfo (DevicePointerMotionHintMask, _devicePointerMotionHint);
 
752
    SetEventInfo (GetNextExtEventMask(), _deviceButton1Motion);
 
753
    SetEventInfo (GetNextExtEventMask(), _deviceButton2Motion);
 
754
    SetEventInfo (GetNextExtEventMask(), _deviceButton3Motion);
 
755
    SetEventInfo (GetNextExtEventMask(), _deviceButton4Motion);
 
756
    SetEventInfo (GetNextExtEventMask(), _deviceButton5Motion);
 
757
    DeviceButtonMotionMask = GetNextExtEventMask();
 
758
    SetEventInfo (DeviceButtonMotionMask, _deviceButtonMotion);
 
759
 
 
760
    DeviceFocusChangeMask = GetNextExtEventMask ();
 
761
    SetMaskForExtEvent (DeviceFocusChangeMask, DeviceFocusIn);
 
762
    SetMaskForExtEvent (DeviceFocusChangeMask, DeviceFocusOut);
 
763
 
 
764
    mask = GetNextExtEventMask ();
 
765
    SetMaskForExtEvent (mask, DeviceMappingNotify);
 
766
    DeviceMappingNotifyMask = mask;
 
767
 
 
768
    mask = GetNextExtEventMask ();
 
769
    SetMaskForExtEvent (mask, ChangeDeviceNotify);
 
770
    ChangeDeviceNotifyMask = mask;
 
771
 
 
772
    DeviceButtonGrabMask = GetNextExtEventMask();
 
773
    SetEventInfo (DeviceButtonGrabMask, _deviceButtonGrab);
 
774
    SetExclusiveAccess (DeviceButtonGrabMask);
 
775
 
 
776
    DeviceOwnerGrabButtonMask = GetNextExtEventMask();
 
777
    SetEventInfo (DeviceOwnerGrabButtonMask, _deviceOwnerGrabButton);
 
778
    SetEventInfo (0, _noExtensionEvent);
 
779
    }
 
780
 
 
781
/************************************************************************
 
782
 *
 
783
 * This function restores extension event types and masks to their 
 
784
 * initial state.
 
785
 *
 
786
 */
 
787
 
 
788
void
 
789
RestoreExtensionEvents ()
 
790
{
 
791
    int i;
 
792
 
 
793
    IReqCode = 0;
 
794
 
 
795
    for (i=0; i<ExtEventIndex-1; i++)
 
796
        {
 
797
        if ((EventInfo[i].type >= LASTEvent) && (EventInfo[i].type < 128))
 
798
            SetMaskForEvent(0,EventInfo[i].type);
 
799
        EventInfo[i].mask = 0;
 
800
        EventInfo[i].type = 0;
 
801
        }
 
802
    ExtEventIndex = 0;
 
803
    lastExtEventMask = 1;
 
804
    DeviceValuator = 0;
 
805
    DeviceKeyPress = 1;
 
806
    DeviceKeyRelease = 2;
 
807
    DeviceButtonPress = 3;
 
808
    DeviceButtonRelease = 4;
 
809
    DeviceMotionNotify = 5;
 
810
    DeviceFocusIn = 6;
 
811
    DeviceFocusOut = 7;
 
812
    ProximityIn = 8;
 
813
    ProximityOut = 9;
 
814
    DeviceStateNotify = 10;
 
815
    DeviceMappingNotify = 11;
 
816
    ChangeDeviceNotify = 12;
 
817
    DeviceKeyStateNotify = 13;
 
818
    DeviceButtonStateNotify = 13;
 
819
 
 
820
    BadDevice = 0;
 
821
    BadEvent = 1;
 
822
    BadMode = 2;
 
823
    DeviceBusy = 3;
 
824
    BadClass = 4;
 
825
 
 
826
    }
 
827
 
 
828
/***********************************************************************
 
829
 *
 
830
 * IResetProc.
 
831
 * Remove reply-swapping routine.
 
832
 * Remove event-swapping routine.
 
833
 *
 
834
 */
 
835
 
 
836
void
 
837
IResetProc(unused)
 
838
    ExtensionEntry *unused;
 
839
    {
 
840
 
 
841
    ReplySwapVector[IReqCode] = ReplyNotSwappd;
 
842
    EventSwapVector[DeviceValuator] = NotImplemented;
 
843
    EventSwapVector[DeviceKeyPress] = NotImplemented;
 
844
    EventSwapVector[DeviceKeyRelease] = NotImplemented;
 
845
    EventSwapVector[DeviceButtonPress] = NotImplemented;
 
846
    EventSwapVector[DeviceButtonRelease] = NotImplemented;
 
847
    EventSwapVector[DeviceMotionNotify] = NotImplemented;
 
848
    EventSwapVector[DeviceFocusIn] = NotImplemented;
 
849
    EventSwapVector[DeviceFocusOut] = NotImplemented;
 
850
    EventSwapVector[ProximityIn] = NotImplemented;
 
851
    EventSwapVector[ProximityOut] = NotImplemented;
 
852
    EventSwapVector[DeviceStateNotify] = NotImplemented;
 
853
    EventSwapVector[DeviceKeyStateNotify] = NotImplemented;
 
854
    EventSwapVector[DeviceButtonStateNotify] = NotImplemented;
 
855
    EventSwapVector[DeviceMappingNotify] = NotImplemented;
 
856
    EventSwapVector[ChangeDeviceNotify] = NotImplemented;
 
857
    RestoreExtensionEvents ();
 
858
    }
 
859
 
 
860
/***********************************************************************
 
861
 *
 
862
 * Assign an id and type to an input device.
 
863
 *
 
864
 */
 
865
 
 
866
void
 
867
AssignTypeAndName (dev, type, name)
 
868
    DeviceIntPtr dev;
 
869
    Atom type;
 
870
    char *name;
 
871
{
 
872
    dev->type = type;
 
873
    dev->name = (char *) xalloc(strlen(name)+1);
 
874
    strcpy (dev->name, name);
 
875
    }
 
876
 
 
877
/***********************************************************************
 
878
 *
 
879
 * Make device type atoms.
 
880
 *
 
881
 */
 
882
 
 
883
void
 
884
MakeDeviceTypeAtoms ()
 
885
    {
 
886
    int i;
 
887
 
 
888
    for (i=0; i<NUMTYPES; i++)
 
889
        dev_type[i].type = 
 
890
                MakeAtom (dev_type[i].name, strlen(dev_type[i].name), 1);
 
891
    }
 
892
 
 
893
/**************************************************************************
 
894
 *
 
895
 * Return a DeviceIntPtr corresponding to a specified device id.
 
896
 * This will not return the pointer or keyboard, or devices that are not on.
 
897
 *
 
898
 */
 
899
 
 
900
DeviceIntPtr
 
901
LookupDeviceIntRec (
 
902
    CARD8 id)
 
903
{
 
904
    DeviceIntPtr dev;
 
905
 
 
906
    for (dev=inputInfo.devices; dev; dev=dev->next)
 
907
        {
 
908
        if (dev->id == id)
 
909
            {
 
910
            if (id == inputInfo.pointer->id || id == inputInfo.keyboard->id)
 
911
                return (NULL);
 
912
            return (dev);
 
913
            }
 
914
        }
 
915
    return (NULL);
 
916
    }
 
917
 
 
918
/**************************************************************************
 
919
 *
 
920
 * Allow the specified event to be restricted to being selected by one
 
921
 * client at a time.
 
922
 * The default is to allow more than one client to select the event.
 
923
 *
 
924
 */
 
925
 
 
926
void
 
927
SetExclusiveAccess (mask)
 
928
    Mask mask;
 
929
    {
 
930
    int i;
 
931
 
 
932
    for (i=0; i<MAX_DEVICES; i++)
 
933
        ExtExclusiveMasks[i] |= mask;
 
934
    }
 
935
 
 
936
/**************************************************************************
 
937
 *
 
938
 * Allow the specified event to have its propagation suppressed.
 
939
 * The default is to not allow suppression of propagation.
 
940
 *
 
941
 */
 
942
 
 
943
void
 
944
AllowPropagateSuppress (mask)
 
945
    Mask mask;
 
946
    {
 
947
    int i;
 
948
 
 
949
    for (i=0; i<MAX_DEVICES; i++)
 
950
        PropagateMask[i] |= mask;
 
951
    }
 
952
 
 
953
/**************************************************************************
 
954
 *
 
955
 * Return the next available extension event mask.
 
956
 *
 
957
 */
 
958
 
 
959
Mask 
 
960
GetNextExtEventMask ()
 
961
    {
 
962
    int i;
 
963
    Mask mask = lastExtEventMask;
 
964
 
 
965
    if (lastExtEventMask == 0)
 
966
        {
 
967
        FatalError("GetNextExtEventMask: no more events are available.");
 
968
        }
 
969
    lastExtEventMask <<= 1;
 
970
 
 
971
    for (i=0; i<MAX_DEVICES; i++)
 
972
        ExtValidMasks[i] |= mask;
 
973
    return mask;
 
974
    }
 
975
 
 
976
/**************************************************************************
 
977
 *
 
978
 * Assign the specified mask to the specified event.
 
979
 *
 
980
 */
 
981
 
 
982
void
 
983
SetMaskForExtEvent(mask, event)
 
984
    Mask mask;
 
985
    int event;
 
986
    {
 
987
 
 
988
    EventInfo[ExtEventIndex].mask = mask;
 
989
    EventInfo[ExtEventIndex++].type = event;
 
990
 
 
991
    if ((event < LASTEvent) || (event >= 128))
 
992
        FatalError("MaskForExtensionEvent: bogus event number");
 
993
    SetMaskForEvent(mask,event);
 
994
    }
 
995
 
 
996
/**************************************************************************
 
997
 *
 
998
 * Record an event mask where there is no unique corresponding event type.
 
999
 * We can't call SetMaskForEvent, since that would clobber the existing
 
1000
 * mask for that event.  MotionHint and ButtonMotion are examples.
 
1001
 *
 
1002
 * Since extension event types will never be less than 64, we can use
 
1003
 * 0-63 in the EventInfo array as the "type" to be used to look up this
 
1004
 * mask.  This means that the corresponding macros such as 
 
1005
 * DevicePointerMotionHint must have access to the same constants.
 
1006
 *
 
1007
 */
 
1008
 
 
1009
void
 
1010
SetEventInfo(mask, constant)
 
1011
    Mask mask;
 
1012
    int constant;
 
1013
    {
 
1014
    EventInfo[ExtEventIndex].mask = mask;
 
1015
    EventInfo[ExtEventIndex++].type = constant;
 
1016
    }