]>
diplodocus.org Git - xorg-xinput/blob - src/list.c
ca3c6bfaa3364f94ed3864efcaa864cb183ae1b4
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.
36 print_info(Display
* dpy
, XDeviceInfo
*info
, enum print_format format
)
45 if (format
== FORMAT_NAME
)
47 printf("%s\n", info
->name
);
49 } else if (format
== FORMAT_ID
)
51 printf("%ld\n", info
->id
);
55 printf("\"%s\"\tid=%ld\t[", info
->name
, info
->id
);
64 case IsXExtensionDevice
:
65 printf("XExtensionDevice");
67 case IsXExtensionKeyboard
:
68 printf("XExtensionKeyboard");
70 case IsXExtensionPointer
:
71 printf("XExtensionPointer");
74 printf("Unknown class");
79 if (format
== FORMAT_SHORT
)
82 if(info
->type
!= None
)
83 printf("\tType is %s\n", XGetAtomName(dpy
, info
->type
));
85 if (info
->num_classes
> 0) {
86 any
= (XAnyClassPtr
) (info
->inputclassinfo
);
87 for (i
=0; i
<info
->num_classes
; i
++) {
90 k
= (XKeyInfoPtr
) any
;
91 printf("\tNum_keys is %d\n", k
->num_keys
);
92 printf("\tMin_keycode is %d\n", k
->min_keycode
);
93 printf("\tMax_keycode is %d\n", k
->max_keycode
);
97 b
= (XButtonInfoPtr
) any
;
98 printf("\tNum_buttons is %d\n", b
->num_buttons
);
102 v
= (XValuatorInfoPtr
) any
;
103 a
= (XAxisInfoPtr
) ((char *) v
+
104 sizeof (XValuatorInfo
));
105 printf("\tNum_axes is %d\n", v
->num_axes
);
106 printf("\tMode is %s\n", (v
->mode
== Absolute
) ? "Absolute" : "Relative");
107 printf("\tMotion_buffer is %ld\n", v
->motion_buffer
);
108 for (j
=0; j
<v
->num_axes
; j
++, a
++) {
109 printf("\tAxis %d :\n", j
);
110 printf("\t\tMin_value is %d\n", a
->min_value
);
111 printf("\t\tMax_value is %d\n", a
->max_value
);
112 printf ("\t\tResolution is %d\n", a
->resolution
);
116 printf ("unknown class\n");
118 any
= (XAnyClassPtr
) ((char *) any
+ any
->length
);
123 static int list_xi1(Display
*display
,
124 enum print_format format
)
130 info
= XListInputDevices(display
, &num_devices
);
131 for(loop
=0; loop
<num_devices
; loop
++) {
132 print_info(display
, info
+loop
, format
);
138 /* also used from test_xi2.c */
140 print_classes_xi2(Display
* display
, XIAnyClassInfo
**classes
,
145 printf("\tReporting %d classes:\n", num_classes
);
146 for (i
= 0; i
< num_classes
; i
++)
148 printf("\t\tClass originated from: %d\n", classes
[i
]->sourceid
);
149 switch(classes
[i
]->type
)
153 XIButtonClassInfo
*b
= (XIButtonClassInfo
*)classes
[i
];
155 printf("\t\tButtons supported: %d\n", b
->num_buttons
);
156 printf("\t\tButton labels:");
157 for (j
= 0; j
< b
->num_buttons
; j
++)
159 name
= (b
->labels
[j
]) ? XGetAtomName(display
, b
->labels
[j
]) : NULL
;
160 printf(" %s", (name
) ? name
: "None");
164 printf("\t\tButton state:");
165 for (j
= 0; j
< b
->state
.mask_len
* 8; j
++)
166 if (XIMaskIsSet(b
->state
.mask
, j
))
174 XIKeyClassInfo
*k
= (XIKeyClassInfo
*)classes
[i
];
175 printf("\t\tKeycodes supported: %d\n", k
->num_keycodes
);
178 case XIValuatorClass
:
180 XIValuatorClassInfo
*v
= (XIValuatorClassInfo
*)classes
[i
];
181 char *name
= v
->label
? XGetAtomName(display
, v
->label
) : NULL
;
183 /* XXX: Bug in X servers 1.7..1.8.1, mode was |
184 OutOfProximity. Remove this once 1.9 is out. */
185 v
->mode
&= DeviceMode
;
187 printf("\t\tDetail for Valuator %d:\n", v
->number
);
188 printf("\t\t Label: %s\n", (name
) ? name
: "None");
189 printf("\t\t Range: %f - %f\n", v
->min
, v
->max
);
190 printf("\t\t Resolution: %d units/m\n", v
->resolution
);
191 printf("\t\t Mode: %s\n", v
->mode
== Absolute
? "absolute" :
193 if (v
->mode
== Absolute
)
194 printf("\t\t Current value: %f\n", v
->value
);
205 print_info_xi2(Display
* display
, XIDeviceInfo
*dev
, enum print_format format
)
207 if (format
== FORMAT_NAME
)
209 printf("%s\n", dev
->name
);
211 } else if (format
== FORMAT_ID
)
213 printf("%d\n", dev
->deviceid
);
217 printf("%-40s\tid=%d\t[", dev
->name
, dev
->deviceid
);
220 case XIMasterPointer
:
221 printf("master pointer (%d)]\n", dev
->attachment
);
223 case XIMasterKeyboard
:
224 printf("master keyboard (%d)]\n", dev
->attachment
);
227 printf("slave pointer (%d)]\n", dev
->attachment
);
229 case XISlaveKeyboard
:
230 printf("slave keyboard (%d)]\n", dev
->attachment
);
232 case XIFloatingSlave
:
233 printf("floating slave]\n");
237 if (format
== FORMAT_SHORT
)
241 printf("\tThis device is disabled\n");
243 print_classes_xi2(display
, dev
->classes
, dev
->num_classes
);
248 list_xi2(Display
*display
,
249 enum print_format format
)
251 int major
= XI_2_Major
,
255 XIDeviceInfo
*info
, *dev
;
257 if (XIQueryVersion(display
, &major
, &minor
) != Success
||
258 (major
* 1000 + minor
) < (XI_2_Major
* 1000 + XI_2_Minor
))
260 fprintf(stderr
, "XI2 not supported.\n");
264 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
266 for(i
= 0; i
< ndevices
; i
++)
269 if (dev
->use
== XIMasterPointer
|| dev
->use
== XIMasterKeyboard
)
271 if (format
== FORMAT_SHORT
|| format
== FORMAT_LONG
)
273 if (dev
->use
== XIMasterPointer
)
279 print_info_xi2(display
, dev
, format
);
280 for (j
= 0; j
< ndevices
; j
++)
282 XIDeviceInfo
* sd
= &info
[j
];
284 if ((sd
->use
== XISlavePointer
|| sd
->use
== XISlaveKeyboard
) &&
285 (sd
->attachment
== dev
->deviceid
))
287 if (format
== FORMAT_SHORT
|| format
== FORMAT_LONG
)
288 printf("%s ↳ ", dev
->use
== XIMasterPointer
? "⎜" : " ");
289 print_info_xi2(display
, sd
, format
);
295 for (i
= 0; i
< ndevices
; i
++)
298 if (dev
->use
== XIFloatingSlave
)
301 print_info_xi2(display
, dev
, format
);
306 XIFreeDeviceInfo(info
);
312 list(Display
*display
,
318 enum print_format format
= FORMAT_SHORT
;
323 if (strcmp(argv
[0], "--short") == 0)
324 format
= FORMAT_SHORT
;
325 else if (strcmp(argv
[0], "--long") == 0)
326 format
= FORMAT_LONG
;
327 else if (strcmp(argv
[0], "--name-only") == 0)
328 format
= FORMAT_NAME
;
329 else if (strcmp(argv
[0], "--id-only") == 0)
337 if (xinput_version(display
) == XI_2_Major
)
339 XIDeviceInfo
*info
= xi2_find_device_info(display
, argv
[arg_dev
]);
342 fprintf(stderr
, "unable to find device %s\n", argv
[arg_dev
]);
345 print_info_xi2(display
, info
, format
);
351 XDeviceInfo
*info
= find_device_info(display
, argv
[arg_dev
], False
);
354 fprintf(stderr
, "unable to find device %s\n", argv
[arg_dev
]);
357 print_info(display
, info
, format
);
363 if (xinput_version(display
) == XI_2_Major
)
364 return list_xi2(display
, format
);
366 return list_xi1(display
, format
);