]> diplodocus.org Git - xorg-xinput/blob - src/test_xi2.c
ecaf0dc00b7aaddbaa570aa95c03acccee72c79e
[xorg-xinput] / src / test_xi2.c
1 /*
2 * Copyright © 2009 Red Hat, Inc.
3 *
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:
10 *
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
13 * Software.
14 *
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.
22 *
23 */
24
25
26 #include "xinput.h"
27
28
29 #define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
30
31 static Window create_win(Display *dpy)
32 {
33 Window win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200,
34 200, 0, 0, WhitePixel(dpy, 0));
35
36 XMapWindow(dpy, win);
37 XFlush(dpy);
38 return win;
39 }
40
41 int
42 test_xi2(Display *display,
43 int argc,
44 char *argv[],
45 char *name,
46 char *desc)
47 {
48 int i;
49 XIDeviceEventMask mask;
50 Window win;
51
52 list(display, argc, argv, name, desc);
53 win = create_win(display);
54
55 /* Select for motion events */
56 mask.deviceid = AllDevices;
57 mask.mask_len = 1;
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);
62 free(mask.mask);
63
64 while(1)
65 {
66 XIEvent ev;
67 XNextEvent(display, (XEvent*)&ev);
68 if (ev.type == GenericEvent)
69 {
70 XIDeviceEvent *event = (XIDeviceEvent*)&ev;
71 double *val;
72
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);
76 printf(" buttons:");
77 for (i = 0; i < event->buttons->mask_len * 8; i++)
78 if (BitIsOn(event->buttons->mask, i))
79 printf(" %d", i);
80 printf("\n");
81
82 printf(" modifiers: locked 0x%x latched 0x%x base 0x%x\n",
83 event->mods->locked, event->mods->latched,
84 event->mods->base);
85 printf(" group: locked 0x%x latched 0x%x base 0x%x\n",
86 event->group->locked, event->group->latched,
87 event->group->base);
88 printf(" valuators:");
89
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++);
94 printf("\n");
95
96 printf(" windows: root 0x%lx event 0x%lx child 0x%ld\n",
97 event->root, event->event, event->child);
98 }
99
100 XIFreeEventData(&ev);
101 }
102
103 return EXIT_SUCCESS;
104 }