1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
|
/************************************************************
Copyright 1989, 1998 The Open Group
Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of The Open Group shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from The Open Group.
Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Hewlett-Packard not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
********************************************************/
/***********************************************************************
*
* Input Extension library internal functions.
*
*/
#define NEED_EVENTS
#define NEED_REPLIES
#include <stdio.h>
#include <X11/extensions/XI.h>
#include <X11/extensions/XIproto.h>
#include <X11/Xlibint.h>
#include <X11/extensions/XInput.h>
#include <X11/extensions/extutil.h>
#include <X11/extensions/geproto.h>
#include <X11/extensions/ge.h>
#include <X11/extensions/Xge.h>
#include "XIint.h"
#define ENQUEUE_EVENT True
#define DONT_ENQUEUE False
extern void _xibaddevice(
Display * /* dpy */,
int * /* error */
);
extern void _xibadclass(
Display * /* dpy */,
int * /* error */
);
extern void _xibadevent(
Display * /* dpy */,
int * /* error */
);
extern void _xibadmode(
Display * /* dpy */,
int * /* error */
);
extern void _xidevicebusy(
Display * /* dpy */,
int * /* error */
);
extern int _XiGetDevicePresenceNotifyEvent(
Display * /* dpy */
);
static XExtensionInfo *xinput_info;
static /* const */ char *xinput_extension_name = INAME;
static int XInputClose(
Display * /* dpy */,
XExtCodes * /* codes */
);
static char *XInputError(
Display * /* dpy */,
int /* code */,
XExtCodes * /* codes */,
char * /* buf */,
int /* n */
);
static Bool XInputWireToEvent(
Display * /* dpy */,
XEvent * /* re */,
xEvent * /* event */
);
static /* const */ XEvent emptyevent;
typedef struct _XInputData
{
XEvent data;
XExtensionVersion *vers;
} XInputData;
static /* const */ XExtensionHooks xinput_extension_hooks = {
NULL, /* create_gc */
NULL, /* copy_gc */
NULL, /* flush_gc */
NULL, /* free_gc */
NULL, /* create_font */
NULL, /* free_font */
XInputClose, /* close_display */
XInputWireToEvent, /* wire_to_event */
_XiEventToWire, /* event_to_wire */
NULL, /* error */
XInputError, /* error_string */
};
static char *XInputErrorList[] = {
"BadDevice, invalid or uninitialized input device", /* BadDevice */
"BadEvent, invalid event type", /* BadEvent */
"BadMode, invalid mode parameter", /* BadMode */
"DeviceBusy, device is busy", /* DeviceBusy */
"BadClass, invalid event class", /* BadClass */
};
_X_HIDDEN
XEXT_GENERATE_FIND_DISPLAY(XInput_find_display, xinput_info,
xinput_extension_name, &xinput_extension_hooks,
IEVENTS, NULL)
static XEXT_GENERATE_ERROR_STRING(XInputError, xinput_extension_name,
IERRORS, XInputErrorList)
/*******************************************************************
*
* Input extension versions.
*
*/
static XExtensionVersion versions[] = { {XI_Absent, 0, 0},
{XI_Present, XI_Initial_Release_Major, XI_Initial_Release_Minor},
{XI_Present, XI_Add_XDeviceBell_Major, XI_Add_XDeviceBell_Minor},
{XI_Present, XI_Add_XSetDeviceValuators_Major,
XI_Add_XSetDeviceValuators_Minor},
{XI_Present, XI_Add_XChangeDeviceControl_Major,
XI_Add_XChangeDeviceControl_Minor},
{XI_Present, XI_Add_DevicePresenceNotify_Major,
XI_Add_DevicePresenceNotify_Minor},
{XI_Present, XI_Add_DeviceProperties_Major,
XI_Add_DeviceProperties_Minor},
{XI_Present, XI_2_Major, XI_2_Minor}
};
/***********************************************************************
*
* Return errors reported by this extension.
*
*/
void
_xibaddevice(
Display *dpy,
int *error)
{
XExtDisplayInfo *info = XInput_find_display(dpy);
*error = info->codes->first_error + XI_BadDevice;
}
void
_xibadclass(
Display *dpy,
int *error)
{
XExtDisplayInfo *info = XInput_find_display(dpy);
*error = info->codes->first_error + XI_BadClass;
}
void
_xibadevent(
Display *dpy,
int *error)
{
XExtDisplayInfo *info = XInput_find_display(dpy);
*error = info->codes->first_error + XI_BadEvent;
}
void
_xibadmode(
Display *dpy,
int *error)
{
XExtDisplayInfo *info = XInput_find_display(dpy);
*error = info->codes->first_error + XI_BadMode;
}
void
_xidevicebusy(
Display *dpy,
int *error)
{
XExtDisplayInfo *info = XInput_find_display(dpy);
*error = info->codes->first_error + XI_DeviceBusy;
}
static int XInputCheckExtension(Display *dpy, XExtDisplayInfo *info)
{
XextCheckExtension (dpy, info, xinput_extension_name, 0);
return 1;
}
/***********************************************************************
*
* Check to see if the input extension is installed in the server.
* Also check to see if the version is >= the requested version.
*
*/
_X_HIDDEN int
_XiCheckExtInit(
register Display *dpy,
register int version_index,
XExtDisplayInfo *info)
{
XExtensionVersion *ext;
if (!XInputCheckExtension(dpy, info)) {
UnlockDisplay(dpy);
return (-1);
}
if (info->data == NULL) {
info->data = (XPointer) Xmalloc(sizeof(XInputData));
if (!info->data) {
UnlockDisplay(dpy);
return (-1);
}
((XInputData *) info->data)->vers =
_XiGetExtensionVersion(dpy, "XInputExtension", info);
}
if (versions[version_index].major_version > Dont_Check) {
ext = ((XInputData *) info->data)->vers;
if ((ext->major_version < versions[version_index].major_version) ||
((ext->major_version == versions[version_index].major_version) &&
(ext->minor_version < versions[version_index].minor_version))) {
UnlockDisplay(dpy);
return (-1);
}
}
return (0);
}
/***********************************************************************
*
* Close display routine.
*
*/
static int
XInputClose(
Display *dpy,
XExtCodes *codes)
{
XExtDisplayInfo *info = XInput_find_display(dpy);
if (info->data != NULL) {
XFree((char *)((XInputData *) info->data)->vers);
XFree((char *)info->data);
}
return XextRemoveDisplay(xinput_info, dpy);
}
static int
Ones(Mask mask)
{
register Mask y;
y = (mask >> 1) & 033333333333;
y = mask - y - ((y >> 1) & 033333333333);
return (((y + (y >> 3)) & 030707070707) % 077);
}
int
_XiGetDevicePresenceNotifyEvent(Display * dpy)
{
XExtDisplayInfo *info = XInput_find_display(dpy);
return info->codes->first_event + XI_DevicePresenceNotify;
}
/***********************************************************************
*
* Handle Input extension events.
* Reformat a wire event into an XEvent structure of the right type.
*
*/
static Bool
XInputWireToEvent(
Display *dpy,
XEvent *re,
xEvent *event)
{
unsigned int type, reltype;
unsigned int i, j;
XExtDisplayInfo *info = XInput_find_display(dpy);
XEvent *save = (XEvent *) info->data;
type = event->u.u.type & 0x7f;
reltype = (type - info->codes->first_event);
if (type == GenericEvent ||
(reltype != XI_DeviceValuator &&
reltype != XI_DeviceKeystateNotify &&
reltype != XI_DeviceButtonstateNotify)) {
*save = emptyevent;
save->type = type;
((XAnyEvent *) save)->serial = _XSetLastRequestRead(dpy,
(xGenericReply *)
event);
((XAnyEvent *) save)->send_event = ((event->u.u.type & 0x80) != 0);
((XAnyEvent *) save)->display = dpy;
}
/* Process traditional events */
if (type != GenericEvent)
{
switch (reltype) {
case XI_DeviceMotionNotify:
{
register XDeviceMotionEvent *ev = (XDeviceMotionEvent *) save;
deviceKeyButtonPointer *ev2 = (deviceKeyButtonPointer *) event;
ev->root = ev2->root;
ev->window = ev2->event;
ev->subwindow = ev2->child;
ev->time = ev2->time;
ev->x_root = ev2->root_x;
ev->y_root = ev2->root_y;
ev->x = ev2->event_x;
ev->y = ev2->event_y;
ev->state = ev2->state;
ev->same_screen = ev2->same_screen;
ev->is_hint = ev2->detail;
ev->deviceid = ev2->deviceid & DEVICE_BITS;
return (DONT_ENQUEUE);
}
break;
case XI_DeviceKeyPress:
case XI_DeviceKeyRelease:
{
register XDeviceKeyEvent *ev = (XDeviceKeyEvent *) save;
deviceKeyButtonPointer *ev2 = (deviceKeyButtonPointer *) event;
ev->root = ev2->root;
ev->window = ev2->event;
ev->subwindow = ev2->child;
ev->time = ev2->time;
ev->x_root = ev2->root_x;
ev->y_root = ev2->root_y;
ev->x = ev2->event_x;
ev->y = ev2->event_y;
ev->state = ev2->state;
ev->same_screen = ev2->same_screen;
ev->keycode = ev2->detail;
ev->deviceid = ev2->deviceid & DEVICE_BITS;
if (ev2->deviceid & MORE_EVENTS)
return (DONT_ENQUEUE);
else {
*re = *save;
return (ENQUEUE_EVENT);
}
}
break;
case XI_DeviceButtonPress:
case XI_DeviceButtonRelease:
{
register XDeviceButtonEvent *ev = (XDeviceButtonEvent *) save;
deviceKeyButtonPointer *ev2 = (deviceKeyButtonPointer *) event;
ev->root = ev2->root;
ev->window = ev2->event;
ev->subwindow = ev2->child;
ev->time = ev2->time;
ev->x_root = ev2->root_x;
ev->y_root = ev2->root_y;
ev->x = ev2->event_x;
ev->y = ev2->event_y;
ev->state = ev2->state;
ev->same_screen = ev2->same_screen;
ev->button = ev2->detail;
ev->deviceid = ev2->deviceid & DEVICE_BITS;
if (ev2->deviceid & MORE_EVENTS)
return (DONT_ENQUEUE);
else {
*re = *save;
return (ENQUEUE_EVENT);
}
}
break;
case XI_ProximityIn:
case XI_ProximityOut:
{
register XProximityNotifyEvent *ev = (XProximityNotifyEvent *) save;
deviceKeyButtonPointer *ev2 = (deviceKeyButtonPointer *) event;
ev->root = ev2->root;
ev->window = ev2->event;
ev->subwindow = ev2->child;
ev->time = ev2->time;
ev->x_root = ev2->root_x;
ev->y_root = ev2->root_y;
ev->x = ev2->event_x;
ev->y = ev2->event_y;
ev->state = ev2->state;
ev->same_screen = ev2->same_screen;
ev->deviceid = ev2->deviceid & DEVICE_BITS;
if (ev2->deviceid & MORE_EVENTS)
return (DONT_ENQUEUE);
else {
*re = *save;
return (ENQUEUE_EVENT);
}
}
break;
case XI_DeviceValuator:
{
deviceValuator *xev = (deviceValuator *) event;
int save_type = save->type - info->codes->first_event;
if (save_type == XI_DeviceKeyPress || save_type == XI_DeviceKeyRelease) {
XDeviceKeyEvent *kev = (XDeviceKeyEvent *) save;
kev->device_state = xev->device_state;
kev->axes_count = xev->num_valuators;
kev->first_axis = xev->first_valuator;
i = xev->num_valuators;
if (i > 6)
i = 6;
switch (i) {
case 6:
kev->axis_data[5] = xev->valuator5;
case 5:
kev->axis_data[4] = xev->valuator4;
case 4:
kev->axis_data[3] = xev->valuator3;
case 3:
kev->axis_data[2] = xev->valuator2;
case 2:
kev->axis_data[1] = xev->valuator1;
case 1:
kev->axis_data[0] = xev->valuator0;
}
} else if (save_type == XI_DeviceButtonPress ||
save_type == XI_DeviceButtonRelease) {
XDeviceButtonEvent *bev = (XDeviceButtonEvent *) save;
bev->device_state = xev->device_state;
bev->axes_count = xev->num_valuators;
bev->first_axis = xev->first_valuator;
i = xev->num_valuators;
if (i > 6)
i = 6;
switch (i) {
case 6:
bev->axis_data[5] = xev->valuator5;
case 5:
bev->axis_data[4] = xev->valuator4;
case 4:
bev->axis_data[3] = xev->valuator3;
case 3:
bev->axis_data[2] = xev->valuator2;
case 2:
bev->axis_data[1] = xev->valuator1;
case 1:
bev->axis_data[0] = xev->valuator0;
}
} else if (save_type == XI_DeviceMotionNotify) {
XDeviceMotionEvent *mev = (XDeviceMotionEvent *) save;
mev->device_state = xev->device_state;
mev->axes_count = xev->num_valuators;
mev->first_axis = xev->first_valuator;
i = xev->num_valuators;
if (i > 6)
i = 6;
switch (i) {
case 6:
mev->axis_data[5] = xev->valuator5;
case 5:
mev->axis_data[4] = xev->valuator4;
case 4:
mev->axis_data[3] = xev->valuator3;
case 3:
mev->axis_data[2] = xev->valuator2;
case 2:
mev->axis_data[1] = xev->valuator1;
case 1:
mev->axis_data[0] = xev->valuator0;
}
} else if (save_type == XI_ProximityIn || save_type == XI_ProximityOut) {
XProximityNotifyEvent *pev = (XProximityNotifyEvent *) save;
pev->device_state = xev->device_state;
pev->axes_count = xev->num_valuators;
pev->first_axis = xev->first_valuator;
i = xev->num_valuators;
if (i > 6)
i = 6;
switch (i) {
case 6:
pev->axis_data[5] = xev->valuator5;
case 5:
pev->axis_data[4] = xev->valuator4;
case 4:
pev->axis_data[3] = xev->valuator3;
case 3:
pev->axis_data[2] = xev->valuator2;
case 2:
pev->axis_data[1] = xev->valuator1;
case 1:
pev->axis_data[0] = xev->valuator0;
}
} else if (save_type == XI_DeviceStateNotify) {
XDeviceStateNotifyEvent *sev = (XDeviceStateNotifyEvent *) save;
XInputClass *any = (XInputClass *) & sev->data[0];
XValuatorStatus *v;
for (i = 0; i < sev->num_classes; i++)
if (any->class != ValuatorClass)
any = (XInputClass *) ((char *)any + any->length);
v = (XValuatorStatus *) any;
i = v->num_valuators;
j = xev->num_valuators;
if (j > 3)
j = 3;
switch (j) {
case 3:
v->valuators[i + 2] = xev->valuator2;
case 2:
v->valuators[i + 1] = xev->valuator1;
case 1:
v->valuators[i + 0] = xev->valuator0;
}
v->num_valuators += j;
}
*re = *save;
return (ENQUEUE_EVENT);
}
break;
case XI_DeviceFocusIn:
case XI_DeviceFocusOut:
{
register XDeviceFocusChangeEvent *ev = (XDeviceFocusChangeEvent *) re;
deviceFocus *fev = (deviceFocus *) event;
*ev = *((XDeviceFocusChangeEvent *) save);
ev->window = fev->window;
ev->time = fev->time;
ev->mode = fev->mode;
ev->detail = fev->detail;
ev->deviceid = fev->deviceid & DEVICE_BITS;
return (ENQUEUE_EVENT);
}
break;
case XI_DeviceStateNotify:
{
XDeviceStateNotifyEvent *stev = (XDeviceStateNotifyEvent *) save;
deviceStateNotify *sev = (deviceStateNotify *) event;
char *data;
stev->window = None;
stev->deviceid = sev->deviceid & DEVICE_BITS;
stev->time = sev->time;
stev->num_classes = Ones((Mask) sev->classes_reported & InputClassBits);
data = (char *)&stev->data[0];
if (sev->classes_reported & (1 << KeyClass)) {
register XKeyStatus *kstev = (XKeyStatus *) data;
kstev->class = KeyClass;
kstev->length = sizeof(XKeyStatus);
kstev->num_keys = sev->num_keys;
memcpy((char *)&kstev->keys[0], (char *)&sev->keys[0], 4);
data += sizeof(XKeyStatus);
}
if (sev->classes_reported & (1 << ButtonClass)) {
register XButtonStatus *bev = (XButtonStatus *) data;
bev->class = ButtonClass;
bev->length = sizeof(XButtonStatus);
bev->num_buttons = sev->num_buttons;
memcpy((char *)bev->buttons, (char *)sev->buttons, 4);
data += sizeof(XButtonStatus);
}
if (sev->classes_reported & (1 << ValuatorClass)) {
register XValuatorStatus *vev = (XValuatorStatus *) data;
vev->class = ValuatorClass;
vev->length = sizeof(XValuatorStatus);
vev->num_valuators = sev->num_valuators;
vev->mode = sev->classes_reported >> ModeBitsShift;
j = sev->num_valuators;
if (j > 3)
j = 3;
switch (j) {
case 3:
vev->valuators[2] = sev->valuator2;
case 2:
vev->valuators[1] = sev->valuator1;
case 1:
vev->valuators[0] = sev->valuator0;
}
data += sizeof(XValuatorStatus);
}
if (sev->deviceid & MORE_EVENTS)
return (DONT_ENQUEUE);
else {
*re = *save;
stev = (XDeviceStateNotifyEvent *) re;
return (ENQUEUE_EVENT);
}
}
break;
case XI_DeviceKeystateNotify:
{
int i;
XInputClass *anyclass;
register XKeyStatus *kv;
deviceKeyStateNotify *ksev = (deviceKeyStateNotify *) event;
XDeviceStateNotifyEvent *kstev = (XDeviceStateNotifyEvent *) save;
anyclass = (XInputClass *) & kstev->data[0];
for (i = 0; i < kstev->num_classes; i++)
if (anyclass->class == KeyClass)
break;
else
anyclass = (XInputClass *) ((char *)anyclass +
anyclass->length);
kv = (XKeyStatus *) anyclass;
kv->num_keys = 256;
memcpy((char *)&kv->keys[4], (char *)ksev->keys, 28);
if (ksev->deviceid & MORE_EVENTS)
return (DONT_ENQUEUE);
else {
*re = *save;
kstev = (XDeviceStateNotifyEvent *) re;
return (ENQUEUE_EVENT);
}
}
break;
case XI_DeviceButtonstateNotify:
{
int i;
XInputClass *anyclass;
register XButtonStatus *bv;
deviceButtonStateNotify *bsev = (deviceButtonStateNotify *) event;
XDeviceStateNotifyEvent *bstev = (XDeviceStateNotifyEvent *) save;
anyclass = (XInputClass *) & bstev->data[0];
for (i = 0; i < bstev->num_classes; i++)
if (anyclass->class == ButtonClass)
break;
else
anyclass = (XInputClass *) ((char *)anyclass +
anyclass->length);
bv = (XButtonStatus *) anyclass;
bv->num_buttons = 256;
memcpy((char *)&bv->buttons[4], (char *)bsev->buttons, 28);
if (bsev->deviceid & MORE_EVENTS)
return (DONT_ENQUEUE);
else {
*re = *save;
bstev = (XDeviceStateNotifyEvent *) re;
return (ENQUEUE_EVENT);
}
}
break;
case XI_DeviceMappingNotify:
{
register XDeviceMappingEvent *ev = (XDeviceMappingEvent *) re;
deviceMappingNotify *ev2 = (deviceMappingNotify *) event;
*ev = *((XDeviceMappingEvent *) save);
ev->window = 0;
ev->first_keycode = ev2->firstKeyCode;
ev->request = ev2->request;
ev->count = ev2->count;
ev->time = ev2->time;
ev->deviceid = ev2->deviceid & DEVICE_BITS;
return (ENQUEUE_EVENT);
}
break;
case XI_ChangeDeviceNotify:
{
register XChangeDeviceNotifyEvent *ev = (XChangeDeviceNotifyEvent *) re;
changeDeviceNotify *ev2 = (changeDeviceNotify *) event;
*ev = *((XChangeDeviceNotifyEvent *) save);
ev->window = 0;
ev->request = ev2->request;
ev->time = ev2->time;
ev->deviceid = ev2->deviceid & DEVICE_BITS;
return (ENQUEUE_EVENT);
}
break;
case XI_DevicePresenceNotify:
{
XDevicePresenceNotifyEvent *ev = (XDevicePresenceNotifyEvent *) re;
devicePresenceNotify *ev2 = (devicePresenceNotify *) event;
*ev = *(XDevicePresenceNotifyEvent *) save;
ev->window = 0;
ev->time = ev2->time;
ev->devchange = ev2->devchange;
ev->deviceid = ev2->deviceid;
ev->control = ev2->control;
return (ENQUEUE_EVENT);
}
break;
case XI_DevicePropertyNotify:
{
XDevicePropertyNotifyEvent* ev = (XDevicePropertyNotifyEvent*)re;
devicePropertyNotify *ev2 = (devicePropertyNotify*)event;
*ev = *(XDevicePropertyNotifyEvent*)save;
ev->time = ev2->time;
ev->deviceid = ev2->deviceid;
ev->atom = ev2->atom;
ev->state = ev2->state;
return ENQUEUE_EVENT;
}
break;
default:
printf("XInputWireToEvent: UNKNOWN WIRE EVENT! type=%d\n", type);
break;
}
} else /* if type == GenericEvent */
{
#if 0
xGenericEvent* ge = (xGenericEvent*)event;
if (ge->extension == info->codes->major_opcode)
{
switch(ge->evtype)
{
case XI_HierarchyChangedNotify:
{
XDeviceHierarchyChangedEvent* dhc_event =
(XDeviceHierarchyChangedEvent*)save;
XIDeviceHierarchyEvent* dhc_wire =
(XIDeviceHierarchyEvent*)event;
dhc_event->extension = dhc_wire->extension;
dhc_event->evtype = dhc_wire->evtype;
dhc_event->time = dhc_wire->time;
*re = *save;
return ENQUEUE_EVENT;
}
case XI_ClassesChangedNotify:
{
XDeviceClassesChangedEvent* dcc_event =
(XDeviceClassesChangedEvent*)save;
XIDeviceChangedEvent* dcc_wire =
(XIDeviceChangedEvent*)event;
int size;
XAnyClassPtr Any;
xAnyClassPtr any;
dcc_event->extension = dcc_wire->extension;
dcc_event->evtype = dcc_wire->evtype;
dcc_event->time = dcc_wire->time;
dcc_event->deviceid = dcc_wire->deviceid;
dcc_event->slaveid = dcc_wire->new_slave;
dcc_event->num_classes = dcc_wire->num_classes;
any = (xAnyClassPtr)&dcc_wire[1];
size = SizeClassInfo(&any, dcc_wire->num_classes);
dcc_event->inputclassinfo = Xmalloc(size);
if (!dcc_event)
{
printf("Allocation error.\n");
return DONT_ENQUEUE;
}
any = (xAnyClassPtr)&dcc_wire[1];
Any = (XAnyClassPtr)dcc_event->inputclassinfo;
ParseClassInfo(&any, &Any, dcc_wire->num_classes);
*re = *save;
return ENQUEUE_EVENT;
}
default:
printf("XInputWireToEvent: Unknown generic event. type %d\n", ge->evtype);
}
}
#endif
}
return (DONT_ENQUEUE);
}
|