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