2 * Copyright 1996 by Frederic Lepied, France. <Frederic.Lepied@sugix.frmug.org>
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of the authors not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. The authors make no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
27 #define INVALID_EVENT_TYPE -1
29 static int motion_type = INVALID_EVENT_TYPE;
30 static int button_press_type = INVALID_EVENT_TYPE;
31 static int button_release_type = INVALID_EVENT_TYPE;
32 static int key_press_type = INVALID_EVENT_TYPE;
33 static int key_release_type = INVALID_EVENT_TYPE;
34 static int proximity_in_type = INVALID_EVENT_TYPE;
35 static int proximity_out_type = INVALID_EVENT_TYPE;
38 register_events(Display *dpy,
41 Bool handle_proximity)
43 int number = 0; /* number of events registered */
44 XEventClass event_list[7];
51 screen = DefaultScreen(dpy);
52 root_win = RootWindow(dpy, screen);
54 device = XOpenDevice(dpy, info->id);
57 fprintf(stderr, "unable to open device '%s'\n", dev_name);
61 if (device->num_classes > 0) {
62 for (ip = device->classes, i=0; i<info->num_classes; ip++, i++) {
63 switch (ip->input_class) {
65 DeviceKeyPress(device, key_press_type, event_list[number]); number++;
66 DeviceKeyRelease(device, key_release_type, event_list[number]); number++;
70 DeviceButtonPress(device, button_press_type, event_list[number]); number++;
71 DeviceButtonRelease(device, button_release_type, event_list[number]); number++;
75 DeviceMotionNotify(device, motion_type, event_list[number]); number++;
76 if (handle_proximity) {
77 ProximityIn(device, proximity_in_type, event_list[number]); number++;
78 ProximityOut(device, proximity_out_type, event_list[number]); number++;
83 fprintf(stderr, "unknown class\n");
88 if (XSelectExtensionEvent(dpy, root_win, event_list, number)) {
89 fprintf(stderr, "error selecting extended events\n");
97 print_events(Display *dpy)
102 XNextEvent(dpy, &Event);
104 if (Event.type == motion_type) {
106 XDeviceMotionEvent *motion = (XDeviceMotionEvent *) &Event;
110 for(loop=0; loop<motion->axes_count; loop++) {
111 printf("a[%d]=%d ", motion->first_axis + loop, motion->axis_data[loop]);
114 } else if ((Event.type == button_press_type) ||
115 (Event.type == button_release_type)) {
117 XDeviceButtonEvent *button = (XDeviceButtonEvent *) &Event;
119 printf("button %s %d ", (Event.type == button_release_type) ? "release" : "press ",
122 for(loop=0; loop<button->axes_count; loop++) {
123 printf("a[%d]=%d ", button->first_axis + loop, button->axis_data[loop]);
126 } else if ((Event.type == key_press_type) ||
127 (Event.type == key_release_type)) {
129 XDeviceKeyEvent *key = (XDeviceKeyEvent *) &Event;
131 printf("key %s %d ", (Event.type == key_release_type) ? "release" : "press ",
134 for(loop=0; loop<key->axes_count; loop++) {
135 printf("a[%d]=%d ", key->first_axis + loop, key->axis_data[loop]);
138 } else if ((Event.type == proximity_out_type) ||
139 (Event.type == proximity_in_type)) {
141 XProximityNotifyEvent *prox = (XProximityNotifyEvent *) &Event;
143 printf("proximity %s ", (Event.type == proximity_in_type) ? "in " : "out");
145 for(loop=0; loop<prox->axes_count; loop++) {
146 printf("a[%d]=%d ", prox->first_axis + loop, prox->axis_data[loop]);
151 printf("what's that %d\n", Event.type);
157 test(Display *display,
165 if (argc != 1 && argc != 2) {
166 fprintf(stderr, "usage: xinput %s %s\n", name, desc);
169 Bool handle_proximity = False;
173 if (strcmp("-proximity", argv[0]) != 0) {
174 fprintf(stderr, "usage: xinput %s %s\n", name, desc);
177 handle_proximity = 1;
181 info = find_device_info(display, argv[idx], True);
184 fprintf(stderr, "unable to find device '%s'\n", argv[idx]);
187 if (register_events(display, info, argv[idx], handle_proximity)) {
188 print_events(display);
191 fprintf(stderr, "no event registered...\n");