]>
diplodocus.org Git - xorg-xinput/blob - src/list.c
3fa123bdb37a8646e2990d647e5a70274ec28a7a
2 * Copyright 1996 by Frederic Lepied, France. <Frederic.Lepied@sugix.frmug.org>
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.
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.
37 print_info(Display
* dpy
, XDeviceInfo
*info
, enum print_format format
)
46 if (format
== FORMAT_NAME
)
48 printf("%s\n", info
->name
);
50 } else if (format
== FORMAT_ID
)
52 printf("%ld\n", info
->id
);
56 printf("\"%s\"\tid=%ld\t[", info
->name
, info
->id
);
65 case IsXExtensionDevice
:
66 printf("XExtensionDevice");
68 case IsXExtensionKeyboard
:
69 printf("XExtensionKeyboard");
71 case IsXExtensionPointer
:
72 printf("XExtensionPointer");
75 printf("Unknown class");
80 if (format
== FORMAT_SHORT
)
83 if (info
->type
!= None
) {
84 char *type
= XGetAtomName(dpy
, info
->type
);
85 printf("\tType is %s\n", type
);
89 if (info
->num_classes
> 0) {
90 any
= (XAnyClassPtr
) (info
->inputclassinfo
);
91 for (i
=0; i
<info
->num_classes
; i
++) {
94 k
= (XKeyInfoPtr
) any
;
95 printf("\tNum_keys is %d\n", k
->num_keys
);
96 printf("\tMin_keycode is %d\n", k
->min_keycode
);
97 printf("\tMax_keycode is %d\n", k
->max_keycode
);
101 b
= (XButtonInfoPtr
) any
;
102 printf("\tNum_buttons is %d\n", b
->num_buttons
);
106 v
= (XValuatorInfoPtr
) any
;
107 a
= (XAxisInfoPtr
) ((char *) v
+
108 sizeof (XValuatorInfo
));
109 printf("\tNum_axes is %d\n", v
->num_axes
);
110 printf("\tMode is %s\n", (v
->mode
== Absolute
) ? "Absolute" : "Relative");
111 printf("\tMotion_buffer is %ld\n", v
->motion_buffer
);
112 for (j
=0; j
<v
->num_axes
; j
++, a
++) {
113 printf("\tAxis %d :\n", j
);
114 printf("\t\tMin_value is %d\n", a
->min_value
);
115 printf("\t\tMax_value is %d\n", a
->max_value
);
116 printf ("\t\tResolution is %d\n", a
->resolution
);
120 printf ("unknown class\n");
122 any
= (XAnyClassPtr
) ((char *) any
+ any
->length
);
127 static int list_xi1(Display
*display
,
128 enum print_format format
)
134 info
= XListInputDevices(display
, &num_devices
);
135 for(loop
=0; loop
<num_devices
; loop
++) {
136 print_info(display
, info
+loop
, format
);
142 /* also used from test_xi2.c */
144 print_classes_xi2(Display
* display
, XIAnyClassInfo
**classes
,
149 printf("\tReporting %d classes:\n", num_classes
);
150 for (i
= 0; i
< num_classes
; i
++)
152 printf("\t\tClass originated from: %d. Type: ", classes
[i
]->sourceid
);
153 switch(classes
[i
]->type
)
157 XIButtonClassInfo
*b
= (XIButtonClassInfo
*)classes
[i
];
159 printf("XIButtonClass\n");
160 printf("\t\tButtons supported: %d\n", b
->num_buttons
);
161 printf("\t\tButton labels:");
162 for (j
= 0; j
< b
->num_buttons
; j
++)
164 name
= (b
->labels
[j
]) ? XGetAtomName(display
, b
->labels
[j
]) : NULL
;
166 printf(" \"%s\"", name
);
172 printf("\t\tButton state:");
173 for (j
= 0; j
< b
->state
.mask_len
* 8; j
++)
174 if (XIMaskIsSet(b
->state
.mask
, j
))
182 XIKeyClassInfo
*k
= (XIKeyClassInfo
*)classes
[i
];
183 printf("XIKeyClass\n");
184 printf("\t\tKeycodes supported: %d\n", k
->num_keycodes
);
187 case XIValuatorClass
:
189 XIValuatorClassInfo
*v
= (XIValuatorClassInfo
*)classes
[i
];
190 char *name
= v
->label
? XGetAtomName(display
, v
->label
) : NULL
;
192 /* Bug in X servers 1.7..1.8.1, mode was | OutOfProximity */
193 v
->mode
&= DeviceMode
;
195 printf("XIValuatorClass\n");
196 printf("\t\tDetail for Valuator %d:\n", v
->number
);
197 printf("\t\t Label: %s\n", (name
) ? name
: "None");
198 printf("\t\t Range: %f - %f\n", v
->min
, v
->max
);
199 printf("\t\t Resolution: %d units/m\n", v
->resolution
);
200 printf("\t\t Mode: %s\n", v
->mode
== Absolute
? "absolute" :
202 if (v
->mode
== Absolute
)
203 printf("\t\t Current value: %f\n", v
->value
);
210 XIScrollClassInfo
*s
= (XIScrollClassInfo
*)classes
[i
];
212 printf("XIScrollClass\n");
213 printf("\t\tScroll info for Valuator %d\n", s
->number
);
214 printf("\t\t type: %d (%s)\n", s
->scroll_type
,
215 (s
->scroll_type
== XIScrollTypeHorizontal
) ? "horizontal" :
216 (s
->scroll_type
== XIScrollTypeVertical
) ? "vertical" : "unknown");
217 printf("\t\t increment: %f\n", s
->increment
);
218 printf("\t\t flags: 0x%x", s
->flags
);
221 if (s
->flags
& XIScrollFlagNoEmulation
)
222 printf(" no-emulation ");
223 if (s
->flags
& XIScrollFlagPreferred
)
224 printf(" preferred ");
234 XITouchClassInfo
*t
= (XITouchClassInfo
*)classes
[i
];
236 printf("XITouchClass\n");
237 printf("\t\tTouch mode: %s\n",
238 (t
->mode
== XIDirectTouch
) ? "direct" : "dependent");
239 printf("\t\tMax number of touches: %d\n", t
->num_touches
);
249 print_info_xi2(Display
* display
, XIDeviceInfo
*dev
, enum print_format format
)
251 if (format
== FORMAT_NAME
)
253 printf("%s\n", dev
->name
);
255 } else if (format
== FORMAT_ID
)
257 printf("%d\n", dev
->deviceid
);
261 printf("%-40s\tid=%d\t[", dev
->name
, dev
->deviceid
);
264 case XIMasterPointer
:
265 printf("master pointer (%d)]\n", dev
->attachment
);
267 case XIMasterKeyboard
:
268 printf("master keyboard (%d)]\n", dev
->attachment
);
271 printf("slave pointer (%d)]\n", dev
->attachment
);
273 case XISlaveKeyboard
:
274 printf("slave keyboard (%d)]\n", dev
->attachment
);
276 case XIFloatingSlave
:
277 printf("floating slave]\n");
281 if (format
== FORMAT_SHORT
)
285 printf("\tThis device is disabled\n");
287 print_classes_xi2(display
, dev
->classes
, dev
->num_classes
);
292 list_xi2(Display
*display
,
293 enum print_format format
)
297 XIDeviceInfo
*info
, *dev
;
299 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
301 for(i
= 0; i
< ndevices
; i
++)
304 if (dev
->use
== XIMasterPointer
|| dev
->use
== XIMasterKeyboard
)
306 if (format
== FORMAT_SHORT
|| format
== FORMAT_LONG
)
308 if (dev
->use
== XIMasterPointer
)
314 print_info_xi2(display
, dev
, format
);
315 for (j
= 0; j
< ndevices
; j
++)
317 XIDeviceInfo
* sd
= &info
[j
];
319 if ((sd
->use
== XISlavePointer
|| sd
->use
== XISlaveKeyboard
) &&
320 (sd
->attachment
== dev
->deviceid
))
322 if (format
== FORMAT_SHORT
|| format
== FORMAT_LONG
)
323 printf("%s ↳ ", dev
->use
== XIMasterPointer
? "⎜" : " ");
324 print_info_xi2(display
, sd
, format
);
330 for (i
= 0; i
< ndevices
; i
++)
333 if (dev
->use
== XIFloatingSlave
)
336 print_info_xi2(display
, dev
, format
);
341 XIFreeDeviceInfo(info
);
347 list(Display
*display
,
353 enum print_format format
= FORMAT_NONE
;
358 if (strcmp(argv
[0], "--short") == 0)
359 format
= FORMAT_SHORT
;
360 else if (strcmp(argv
[0], "--long") == 0)
361 format
= FORMAT_LONG
;
362 else if (strcmp(argv
[0], "--name-only") == 0)
363 format
= FORMAT_NAME
;
364 else if (strcmp(argv
[0], "--id-only") == 0)
372 if (format
== FORMAT_NONE
)
373 format
= FORMAT_LONG
;
375 if (xinput_version(display
) == XI_2_Major
)
377 XIDeviceInfo
*info
= xi2_find_device_info(display
, argv
[arg_dev
]);
380 fprintf(stderr
, "unable to find device %s\n", argv
[arg_dev
]);
383 print_info_xi2(display
, info
, format
);
389 XDeviceInfo
*info
= find_device_info(display
, argv
[arg_dev
], False
);
392 fprintf(stderr
, "unable to find device %s\n", argv
[arg_dev
]);
395 print_info(display
, info
, format
);
400 if (format
== FORMAT_NONE
)
401 format
= FORMAT_SHORT
;
403 if (xinput_version(display
) == XI_2_Major
)
404 return list_xi2(display
, format
);
406 return list_xi1(display
, format
);