]> diplodocus.org Git - xorg-xinput/blob - src/list.c
Let autoconf substitute the VERSION.
[xorg-xinput] / src / list.c
1 /*
2 * Copyright 1996 by Frederic Lepied, France. <Frederic.Lepied@sugix.frmug.org>
3 *
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.
13 *
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.
21 *
22 */
23
24 #include "xinput.h"
25
26 static void
27 print_info(XDeviceInfo *info)
28 {
29 int i,j;
30 XAnyClassPtr any;
31 XKeyInfoPtr k;
32 XButtonInfoPtr b;
33 XValuatorInfoPtr v;
34 XAxisInfoPtr a;
35
36 printf("\"%s\"\tid=%ld\t[", info->name, info->id);
37
38 switch (info->use) {
39 case IsXPointer:
40 printf("XPointer");
41 break;
42 case IsXKeyboard:
43 printf("XKeyboard");
44 break;
45 case IsXExtensionDevice:
46 printf("XExtensionDevice");
47 break;
48 case IsXExtensionKeyboard:
49 printf("XExtensionKeyboard");
50 break;
51 case IsXExtensionPointer:
52 printf("XExtensionPointer");
53 break;
54 default:
55 printf("Unknown class");
56 break;
57 }
58 printf("]\n");
59
60 if (info->num_classes > 0) {
61 any = (XAnyClassPtr) (info->inputclassinfo);
62 for (i=0; i<info->num_classes; i++) {
63 switch (any->class) {
64 case KeyClass:
65 k = (XKeyInfoPtr) any;
66 printf("\tNum_keys is %d\n", k->num_keys);
67 printf("\tMin_keycode is %d\n", k->min_keycode);
68 printf("\tMax_keycode is %d\n", k->max_keycode);
69 break;
70
71 case ButtonClass:
72 b = (XButtonInfoPtr) any;
73 printf("\tNum_buttons is %d\n", b->num_buttons);
74 break;
75
76 case ValuatorClass:
77 v = (XValuatorInfoPtr) any;
78 a = (XAxisInfoPtr) ((char *) v +
79 sizeof (XValuatorInfo));
80 printf("\tNum_axes is %d\n", v->num_axes);
81 printf("\tMode is %s\n", (v->mode == Absolute) ? "Absolute" : "Relative");
82 printf("\tMotion_buffer is %ld\n", v->motion_buffer);
83 for (j=0; j<v->num_axes; j++, a++) {
84 printf("\tAxis %d :\n", j);
85 printf("\t\tMin_value is %d\n", a->min_value);
86 printf("\t\tMax_value is %d\n", a->max_value);
87 printf ("\t\tResolution is %d\n", a->resolution);
88 }
89 break;
90
91 default:
92 printf ("unknown class\n");
93 }
94 any = (XAnyClassPtr) ((char *) any + any->length);
95 }
96 }
97 }
98
99 int
100 list(Display *display,
101 int argc,
102 char *argv[],
103 char *name,
104 char *desc)
105 {
106 XDeviceInfo *info;
107 int loop;
108
109 if (argc == 0) {
110 int num_devices;
111
112 info = XListInputDevices(display, &num_devices);
113
114 for(loop=0; loop<num_devices; loop++) {
115 print_info(info+loop);
116 }
117 } else {
118 int ret = EXIT_SUCCESS;
119
120 for(loop=0; loop<argc; loop++) {
121 info = find_device_info(display, argv[0], False);
122
123 if (!info) {
124 fprintf(stderr, "unable to find device %s\n", argv[0]);
125 ret = EXIT_FAILURE;
126 } else {
127 print_info(info);
128 }
129 }
130 return ret;
131 }
132 return EXIT_SUCCESS;
133 }
134
135 /* end of list.c */