]>
diplodocus.org Git - xorg-xinput/blob - src/test.c
a81d34a4e0e1cd07c9c193e4bc2e628c57f11f13
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 Frederic Lepied not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Frederic Lepied makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * FREDERIC LEPIED DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL FREDERIC LEPIED 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.
26 static const char rcs_id
[] = "$Id: test.c,v 1.3 1997/06/09 16:06:31 fred Exp $";
28 #define INVALID_EVENT_TYPE -1
30 static int motion_type
= INVALID_EVENT_TYPE
;
31 static int button_press_type
= INVALID_EVENT_TYPE
;
32 static int button_release_type
= INVALID_EVENT_TYPE
;
33 static int key_press_type
= INVALID_EVENT_TYPE
;
34 static int key_release_type
= INVALID_EVENT_TYPE
;
35 static int proximity_in_type
= INVALID_EVENT_TYPE
;
36 static int proximity_out_type
= INVALID_EVENT_TYPE
;
39 register_events(Display
*dpy
,
42 Bool handle_proximity
)
44 int number
= 0; /* number of events registered */
45 XEventClass event_list
[7];
53 screen
= DefaultScreen(dpy
);
54 root_win
= RootWindow(dpy
, screen
);
56 device
= XOpenDevice(dpy
, info
->id
);
59 fprintf(stderr
, "unable to open device %s\n", dev_name
);
63 if (device
->num_classes
> 0) {
64 for (ip
= device
->classes
, i
=0; i
<info
->num_classes
; ip
++, i
++) {
65 switch (ip
->input_class
) {
67 DeviceKeyPress(device
, key_press_type
, event_list
[number
]); number
++;
68 DeviceKeyRelease(device
, key_release_type
, event_list
[number
]); number
++;
72 DeviceButtonPress(device
, button_press_type
, event_list
[number
]); number
++;
73 DeviceButtonRelease(device
, button_release_type
, event_list
[number
]); number
++;
77 DeviceMotionNotify(device
, motion_type
, event_list
[number
]); number
++;
78 if (handle_proximity
) {
79 ProximityIn(device
, proximity_in_type
, event_list
[number
]); number
++;
80 ProximityOut(device
, proximity_out_type
, event_list
[number
]); number
++;
85 fprintf(stderr
, "unknown class\n");
90 if (XSelectExtensionEvent(dpy
, root_win
, event_list
, number
)) {
91 fprintf(stderr
, "error selecting extended events\n");
99 print_events(Display
*dpy
)
104 XNextEvent(dpy
, &Event
);
106 if (Event
.type
== motion_type
) {
108 XDeviceMotionEvent
*motion
= (XDeviceMotionEvent
*) &Event
;
112 for(loop
=0; loop
<motion
->axes_count
; loop
++) {
113 printf("a[%d]=%d ", motion
->first_axis
+ loop
, motion
->axis_data
[loop
]);
116 } else if ((Event
.type
== button_press_type
) ||
117 (Event
.type
== button_release_type
)) {
119 XDeviceButtonEvent
*button
= (XDeviceButtonEvent
*) &Event
;
121 printf("button %s %d ", (Event
.type
== button_release_type
) ? "release" : "press ",
124 for(loop
=0; loop
<button
->axes_count
; loop
++) {
125 printf("a[%d]=%d ", button
->first_axis
+ loop
, button
->axis_data
[loop
]);
128 } else if ((Event
.type
== key_press_type
) ||
129 (Event
.type
== key_release_type
)) {
131 XDeviceKeyEvent
*key
= (XDeviceKeyEvent
*) &Event
;
133 printf("key %s %d ", (Event
.type
== key_release_type
) ? "release" : "press ",
136 for(loop
=0; loop
<key
->axes_count
; loop
++) {
137 printf("a[%d]=%d ", key
->first_axis
+ loop
, key
->axis_data
[loop
]);
140 } else if ((Event
.type
== proximity_out_type
) ||
141 (Event
.type
== proximity_in_type
)) {
143 XProximityNotifyEvent
*prox
= (XProximityNotifyEvent
*) &Event
;
145 printf("proximity %s ", (Event
.type
== proximity_in_type
) ? "in " : "out");
147 for(loop
=0; loop
<prox
->axes_count
; loop
++) {
148 printf("a[%d]=%d ", prox
->first_axis
+ loop
, prox
->axis_data
[loop
]);
153 printf("what's that %d\n", Event
.type
);
159 test(Display
*display
,
167 if (argc
!= 1 && argc
!= 2) {
168 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
171 Bool handle_proximity
= False
;
175 if (strcmp("-proximity", argv
[0]) != 0) {
176 fprintf(stderr
, "usage: xinput %s %s\n", name
, desc
);
179 handle_proximity
= 1;
183 info
= find_device_info(display
, argv
[idx
], True
);
186 fprintf(stderr
, "unable to find device %s\n", argv
[idx
]);
189 if (register_events(display
, info
, argv
[idx
], handle_proximity
)) {
190 print_events(display
);
193 fprintf(stderr
, "no event registered...\n");