]> diplodocus.org Git - xorg-xinput/blob - src/list.c
XSync the display before jumping in the grab code.
[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 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.
13 *
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.
21 *
22 */
23
24 #include "xinput.h"
25 #include <string.h>
26 #include <X11/extensions/XIproto.h> /* for XI_Device***ChangedNotify */
27
28 static void
29 print_info(XDeviceInfo *info, Bool shortformat)
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[", 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 default:
96 printf ("unknown class\n");
97 }
98 any = (XAnyClassPtr) ((char *) any + any->length);
99 }
100 }
101 }
102
103 static int list_xi1(Display *display,
104 int argc,
105 char *argv[],
106 char *name,
107 char *desc)
108 {
109 XDeviceInfo *info;
110 int loop;
111 int shortformat = False;
112 int daemon = False;
113
114 shortformat = (argc == 1 && strcmp(argv[0], "--short") == 0);
115 daemon = (argc == 1 && strcmp(argv[0], "--loop") == 0);
116
117 if (argc == 0 || shortformat || daemon) {
118 int num_devices;
119
120 do {
121 info = XListInputDevices(display, &num_devices);
122 for(loop=0; loop<num_devices; loop++) {
123 print_info(info+loop, shortformat);
124 }
125 } while(daemon);
126 } else {
127 int ret = EXIT_SUCCESS;
128
129 for(loop=0; loop<argc; loop++) {
130 info = find_device_info(display, argv[loop], False);
131
132 if (!info) {
133 fprintf(stderr, "unable to find device %s\n", argv[loop]);
134 ret = EXIT_FAILURE;
135 } else {
136 print_info(info, shortformat);
137 }
138 }
139 return ret;
140 }
141 return EXIT_SUCCESS;
142 }
143
144 #ifdef HAVE_XI2
145 /* also used from test_xi2.c */
146 void
147 print_classes_xi2(Display* display, XIAnyClassInfo **classes,
148 int num_classes)
149 {
150 int i;
151
152 printf("\tReporting %d classes:\n", num_classes);
153 for (i = 0; i < num_classes; i++)
154 {
155 switch(classes[i]->type)
156 {
157 case ButtonClass:
158 {
159 XIButtonClassInfo *b = (XIButtonClassInfo*)classes[i];
160 printf("\t\tButtons supported: %d\n", b->num_buttons);
161
162 }
163 break;
164 case KeyClass:
165 {
166 XIKeyClassInfo *k = (XIKeyClassInfo*)classes[i];
167 printf("\t\tKeycodes supported: %d\n", k->num_keycodes);
168 }
169 break;
170 case ValuatorClass:
171 {
172 XIValuatorClassInfo *v = (XIValuatorClassInfo*)classes[i];
173 printf("\t\tDetail for Valuator %d:\n", v->number);
174 printf("\t\t Name: %s\n", XGetAtomName(display, v->name));
175 printf("\t\t Range: %f - %f\n", v->min, v->max);
176 printf("\t\t Resolution: %d units/m\n", v->resolution);
177 printf("\t\t Mode: %s\n", v->mode == Absolute ? "absolute" :
178 "relative");
179 }
180 break;
181 }
182 }
183
184 printf("\n");
185 }
186
187 static void
188 print_info_xi2(Display* display, XIDeviceInfo *dev, Bool shortformat)
189 {
190 printf("%-40s\tid=%d\t[", dev->name, dev->deviceid);
191 switch(dev->use)
192 {
193 case MasterPointer:
194 printf("master pointer (%d)]\n", dev->attachment);
195 break;
196 case MasterKeyboard:
197 printf("master keyboard (%d)]\n", dev->attachment);
198 break;
199 case SlavePointer:
200 printf("slave pointer (%d)]\n", dev->attachment);
201 break;
202 case SlaveKeyboard:
203 printf("slave keyboard (%d)]\n", dev->attachment);
204 break;
205 case FloatingSlave:
206 printf("floating slave]\n");
207 break;
208 }
209
210 if (shortformat)
211 return;
212
213 if (!dev->enabled)
214 printf("\tThis device is disabled\n");
215
216 print_classes_xi2(display, dev->classes, dev->num_classes);
217 }
218
219
220 int
221 list_xi2(Display *display,
222 int argc,
223 char *argv[],
224 char *name,
225 char *desc)
226 {
227 int major = XI_2_Major,
228 minor = XI_2_Minor;
229 int ndevices;
230 int i, j, shortformat;
231 XIDeviceInfo *info, *dev;
232
233 shortformat = (argc == 1 && strcmp(argv[0], "--short") == 0);
234
235 if (XIQueryVersion(display, &major, &minor) != Success ||
236 (major * 1000 + minor) < (XI_2_Major * 1000 + XI_2_Minor))
237 {
238 fprintf(stderr, "XI2 not supported.\n");
239 return EXIT_FAILURE;
240 }
241
242 info = XIQueryDevice(display, AllDevices, &ndevices);
243 dev = info;
244
245 for(i = 0; i < ndevices; i++)
246 {
247 dev = &info[i];
248 if (dev->use == MasterPointer || dev->use == MasterKeyboard)
249 {
250 if (dev->use == MasterPointer)
251 printf("⎡ ");
252 else
253 printf("⎣ ");
254
255 print_info_xi2(display, dev, shortformat);
256 for (j = 0; j < ndevices; j++)
257 {
258 XIDeviceInfo* sd = &info[j];
259
260 if ((sd->use == SlavePointer || sd->use == SlaveKeyboard) &&
261 (sd->attachment == dev->deviceid))
262 {
263 printf("%s ↳ ", dev->use == MasterPointer ? "⎜" : " ");
264 print_info_xi2(display, sd, shortformat);
265 }
266 }
267 }
268 }
269
270
271 XIFreeDeviceInfo(info);
272 return EXIT_SUCCESS;
273 }
274 #endif
275
276 int
277 list(Display *display,
278 int argc,
279 char *argv[],
280 char *name,
281 char *desc)
282 {
283 #ifdef HAVE_XI2
284 if (xinput_version(display) == XI_2_Major)
285 return list_xi2(display, argc, argv, name, desc);
286 #endif
287 return list_xi1(display, argc, argv, name, desc);
288 }
289
290 /* end of list.c */