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 #include <X11/extensions/XIproto.h> /* for XI_Device***ChangedNotify */
29 print_info(XDeviceInfo
*info
, Bool shortformat
)
39 printf("\"%s\"\tid=%ld\t[", info
->name
, info
->id
);
48 case IsXExtensionDevice
:
49 printf("XExtensionDevice");
51 case IsXExtensionKeyboard
:
52 printf("XExtensionKeyboard");
54 case IsXExtensionPointer
:
55 printf("XExtensionPointer");
58 printf("Unknown class");
66 if (info
->num_classes
> 0) {
67 any
= (XAnyClassPtr
) (info
->inputclassinfo
);
68 for (i
=0; i
<info
->num_classes
; i
++) {
71 k
= (XKeyInfoPtr
) any
;
72 printf("\tNum_keys is %d\n", k
->num_keys
);
73 printf("\tMin_keycode is %d\n", k
->min_keycode
);
74 printf("\tMax_keycode is %d\n", k
->max_keycode
);
78 b
= (XButtonInfoPtr
) any
;
79 printf("\tNum_buttons is %d\n", b
->num_buttons
);
83 v
= (XValuatorInfoPtr
) any
;
84 a
= (XAxisInfoPtr
) ((char *) v
+
85 sizeof (XValuatorInfo
));
86 printf("\tNum_axes is %d\n", v
->num_axes
);
87 printf("\tMode is %s\n", (v
->mode
== Absolute
) ? "Absolute" : "Relative");
88 printf("\tMotion_buffer is %ld\n", v
->motion_buffer
);
89 for (j
=0; j
<v
->num_axes
; j
++, a
++) {
90 printf("\tAxis %d :\n", j
);
91 printf("\t\tMin_value is %d\n", a
->min_value
);
92 printf("\t\tMax_value is %d\n", a
->max_value
);
93 printf ("\t\tResolution is %d\n", a
->resolution
);
97 att
= (XAttachInfoPtr
)any
;
98 printf("\tAttached to %d\n", att
->attached
);
102 printf ("unknown class\n");
104 any
= (XAnyClassPtr
) ((char *) any
+ any
->length
);
110 list(Display
*display
,
118 int shortformat
= False
;
121 shortformat
= (argc
== 1 && strcmp(argv
[0], "--short") == 0);
122 daemon
= (argc
== 1 && strcmp(argv
[0], "--loop") == 0);
124 if (argc
== 0 || shortformat
|| daemon
) {
130 XiSelectEvent(display
, DefaultRootWindow(display
),
131 XI_DeviceHierarchyChangedMask
|
132 XI_DeviceClassesChangedMask
);
136 info
= XListInputDevices(display
, &num_devices
);
137 for(loop
=0; loop
<num_devices
; loop
++) {
138 print_info(info
+loop
, shortformat
);
141 /* just wait for the next generic event to come along */
142 while (daemon
&& !XNextEvent(display
, &ev
))
144 if (ev
.type
== GenericEvent
)
146 XGenericEvent
* gev
= (XGenericEvent
*)&ev
;
147 /* we just assume that extension is IReqCode, pretty save
148 since we don't register for other events. */
149 if (gev
->evtype
== XI_DeviceHierarchyChangedNotify
)
151 printf("Hierarchy change.\n");
152 } else if (gev
->evtype
== XI_DeviceClassesChangedNotify
)
154 printf("Device classes changed.\n");
155 free(((XDeviceClassesChangedEvent
*)&ev
)->inputclassinfo
);
162 int ret
= EXIT_SUCCESS
;
164 for(loop
=0; loop
<argc
; loop
++) {
165 info
= find_device_info(display
, argv
[0], False
);
168 fprintf(stderr
, "unable to find device %s\n", argv
[0]);
171 print_info(info
, shortformat
);