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.
26 #include <X11/extensions/XIproto.h> /* for XI_Device***ChangedNotify */
29 print_info(XDeviceInfo
*info
, Bool shortformat
)
41 printf("\"%s\"\tid=%ld\t[", info
->name
, info
->id
);
50 case IsXExtensionDevice
:
51 printf("XExtensionDevice");
53 case IsXExtensionKeyboard
:
54 printf("XExtensionKeyboard");
56 case IsXExtensionPointer
:
57 printf("XExtensionPointer");
60 printf("Unknown class");
68 if (info
->num_classes
> 0) {
69 any
= (XAnyClassPtr
) (info
->inputclassinfo
);
70 for (i
=0; i
<info
->num_classes
; i
++) {
73 k
= (XKeyInfoPtr
) any
;
74 printf("\tNum_keys is %d\n", k
->num_keys
);
75 printf("\tMin_keycode is %d\n", k
->min_keycode
);
76 printf("\tMax_keycode is %d\n", k
->max_keycode
);
80 b
= (XButtonInfoPtr
) any
;
81 printf("\tNum_buttons is %d\n", b
->num_buttons
);
85 v
= (XValuatorInfoPtr
) any
;
86 a
= (XAxisInfoPtr
) ((char *) v
+
87 sizeof (XValuatorInfo
));
88 printf("\tNum_axes is %d\n", v
->num_axes
);
89 printf("\tMode is %s\n", (v
->mode
== Absolute
) ? "Absolute" : "Relative");
90 printf("\tMotion_buffer is %ld\n", v
->motion_buffer
);
91 for (j
=0; j
<v
->num_axes
; j
++, a
++) {
92 printf("\tAxis %d :\n", j
);
93 printf("\t\tMin_value is %d\n", a
->min_value
);
94 printf("\t\tMax_value is %d\n", a
->max_value
);
95 printf ("\t\tResolution is %d\n", a
->resolution
);
100 att
= (XAttachInfoPtr
)any
;
101 printf("\tAttached to %d\n", att
->attached
);
105 printf ("unknown class\n");
107 any
= (XAnyClassPtr
) ((char *) any
+ any
->length
);
113 list(Display
*display
,
121 int shortformat
= False
;
124 shortformat
= (argc
== 1 && strcmp(argv
[0], "--short") == 0);
125 daemon
= (argc
== 1 && strcmp(argv
[0], "--loop") == 0);
127 if (argc
== 0 || shortformat
|| daemon
) {
134 XiSelectEvent(display
, DefaultRootWindow(display
), NULL
,
135 XI_DeviceHierarchyChangedMask
|
136 XI_DeviceClassesChangedMask
);
141 info
= XListInputDevices(display
, &num_devices
);
142 for(loop
=0; loop
<num_devices
; loop
++) {
143 print_info(info
+loop
, shortformat
);
147 /* just wait for the next generic event to come along */
148 while (daemon
&& !XNextEvent(display
, &ev
))
150 if (ev
.type
== GenericEvent
)
152 XGenericEvent
* gev
= (XGenericEvent
*)&ev
;
153 /* we just assume that extension is IReqCode, pretty save
154 since we don't register for other events. */
155 if (gev
->evtype
== XI_DeviceHierarchyChangedNotify
)
157 printf("Hierarchy change.\n");
158 } else if (gev
->evtype
== XI_DeviceClassesChangedNotify
)
160 printf("Device classes changed.\n");
161 free(((XDeviceClassesChangedEvent
*)&ev
)->inputclassinfo
);
169 int ret
= EXIT_SUCCESS
;
171 for(loop
=0; loop
<argc
; loop
++) {
172 info
= find_device_info(display
, argv
[loop
], False
);
175 fprintf(stderr
, "unable to find device %s\n", argv
[loop
]);
178 print_info(info
, shortformat
);