]> diplodocus.org Git - xorg-xinput/blob - src/list.c
85b766da7eac3c4fd3f43f461eb61b794c6c824c
[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 XAttachInfoPtr att;
37
38 printf("\"%s\"\tid=%ld\t[", info->name, info->id);
39
40 switch (info->use) {
41 case IsXPointer:
42 printf("XPointer");
43 break;
44 case IsXKeyboard:
45 printf("XKeyboard");
46 break;
47 case IsXExtensionDevice:
48 printf("XExtensionDevice");
49 break;
50 case IsXExtensionKeyboard:
51 printf("XExtensionKeyboard");
52 break;
53 case IsXExtensionPointer:
54 printf("XExtensionPointer");
55 break;
56 default:
57 printf("Unknown class");
58 break;
59 }
60 printf("]\n");
61
62 if (shortformat)
63 return;
64
65 if (info->num_classes > 0) {
66 any = (XAnyClassPtr) (info->inputclassinfo);
67 for (i=0; i<info->num_classes; i++) {
68 switch (any->class) {
69 case KeyClass:
70 k = (XKeyInfoPtr) any;
71 printf("\tNum_keys is %d\n", k->num_keys);
72 printf("\tMin_keycode is %d\n", k->min_keycode);
73 printf("\tMax_keycode is %d\n", k->max_keycode);
74 break;
75
76 case ButtonClass:
77 b = (XButtonInfoPtr) any;
78 printf("\tNum_buttons is %d\n", b->num_buttons);
79 break;
80
81 case ValuatorClass:
82 v = (XValuatorInfoPtr) any;
83 a = (XAxisInfoPtr) ((char *) v +
84 sizeof (XValuatorInfo));
85 printf("\tNum_axes is %d\n", v->num_axes);
86 printf("\tMode is %s\n", (v->mode == Absolute) ? "Absolute" : "Relative");
87 printf("\tMotion_buffer is %ld\n", v->motion_buffer);
88 for (j=0; j<v->num_axes; j++, a++) {
89 printf("\tAxis %d :\n", j);
90 printf("\t\tMin_value is %d\n", a->min_value);
91 printf("\t\tMax_value is %d\n", a->max_value);
92 printf ("\t\tResolution is %d\n", a->resolution);
93 }
94 break;
95 case AttachClass:
96 att = (XAttachInfoPtr)any;
97 printf("\tAttached to %d\n", att->attached);
98 break;
99
100 default:
101 printf ("unknown class\n");
102 }
103 any = (XAnyClassPtr) ((char *) any + any->length);
104 }
105 }
106 }
107
108 int
109 list(Display *display,
110 int argc,
111 char *argv[],
112 char *name,
113 char *desc)
114 {
115 XDeviceInfo *info;
116 int loop;
117 int shortformat = False;
118 int daemon = False;
119
120 shortformat = (argc == 1 && strcmp(argv[0], "--short") == 0);
121 daemon = (argc == 1 && strcmp(argv[0], "--loop") == 0);
122
123 if (argc == 0 || shortformat || daemon) {
124 int num_devices;
125 XEvent ev;
126 int daemon = argc;
127
128 if (daemon)
129 {
130 XiSelectEvent(display, DefaultRootWindow(display),
131 XI_DeviceHierarchyChangedMask);
132 }
133
134 do {
135 info = XListInputDevices(display, &num_devices);
136 for(loop=0; loop<num_devices; loop++) {
137 print_info(info+loop, shortformat);
138 }
139
140 /* just wait for the next generic event to come along */
141 while (daemon && !XNextEvent(display, &ev))
142 {
143 if (ev.type == GenericEvent)
144 break;
145 }
146 } while(daemon);
147 } else {
148 int ret = EXIT_SUCCESS;
149
150 for(loop=0; loop<argc; loop++) {
151 info = find_device_info(display, argv[0], False);
152
153 if (!info) {
154 fprintf(stderr, "unable to find device %s\n", argv[0]);
155 ret = EXIT_FAILURE;
156 } else {
157 print_info(info, shortformat);
158 }
159 }
160 return ret;
161 }
162 return EXIT_SUCCESS;
163 }
164
165 /* end of list.c */