]>
diplodocus.org Git - xorg-xinput/blob - src/test_xi2.c
ecaf0dc00b7aaddbaa570aa95c03acccee72c79e
2 * Copyright © 2009 Red Hat, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
29 #define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
31 static Window
create_win(Display
*dpy
)
33 Window win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 0, 0, 200,
34 200, 0, 0, WhitePixel(dpy
, 0));
42 test_xi2(Display
*display
,
49 XIDeviceEventMask mask
;
52 list(display
, argc
, argv
, name
, desc
);
53 win
= create_win(display
);
55 /* Select for motion events */
56 mask
.deviceid
= AllDevices
;
58 mask
.mask
= calloc(1, sizeof(char));
59 mask
.mask
[0] = XI_ButtonPressMask
| XI_ButtonReleaseMask
| XI_MotionMask
|
60 XI_KeyPressMask
| XI_KeyReleaseMask
;
61 XISelectEvent(display
, win
, &mask
, 1);
67 XNextEvent(display
, (XEvent
*)&ev
);
68 if (ev
.type
== GenericEvent
)
70 XIDeviceEvent
*event
= (XIDeviceEvent
*)&ev
;
73 printf("EVENT type %d\n", event
->evtype
);
74 printf(" device: %d (%d)\n", event
->deviceid
, event
->sourceid
);
75 printf(" detail: %d\n", event
->detail
);
77 for (i
= 0; i
< event
->buttons
->mask_len
* 8; i
++)
78 if (BitIsOn(event
->buttons
->mask
, i
))
82 printf(" modifiers: locked 0x%x latched 0x%x base 0x%x\n",
83 event
->mods
->locked
, event
->mods
->latched
,
85 printf(" group: locked 0x%x latched 0x%x base 0x%x\n",
86 event
->group
->locked
, event
->group
->latched
,
88 printf(" valuators:");
90 val
= event
->valuators
->values
;
91 for (i
= 0; i
< event
->valuators
->mask_len
* 8; i
++)
92 if (BitIsOn(event
->valuators
->mask
, i
))
93 printf(" %.2f", *val
++);
96 printf(" windows: root 0x%lx event 0x%lx child 0x%ld\n",
97 event
->root
, event
->event
, event
->child
);
100 XIFreeEventData(&ev
);