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