]>
diplodocus.org Git - xorg-xinput/blob - src/list.c
0e6f9bea01246afcf1d5f7dee46e136855b8fb84
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.
35 print_info(Display
* dpy
, XDeviceInfo
*info
, enum print_format format
)
44 if (format
== FORMAT_NAME
)
46 printf("%s\n", info
->name
);
50 printf("\"%s\"\tid=%ld\t[", info
->name
, info
->id
);
59 case IsXExtensionDevice
:
60 printf("XExtensionDevice");
62 case IsXExtensionKeyboard
:
63 printf("XExtensionKeyboard");
65 case IsXExtensionPointer
:
66 printf("XExtensionPointer");
69 printf("Unknown class");
74 if (format
== FORMAT_SHORT
)
77 if(info
->type
!= None
)
78 printf("\tType is %s\n", XGetAtomName(dpy
, info
->type
));
80 if (info
->num_classes
> 0) {
81 any
= (XAnyClassPtr
) (info
->inputclassinfo
);
82 for (i
=0; i
<info
->num_classes
; i
++) {
85 k
= (XKeyInfoPtr
) any
;
86 printf("\tNum_keys is %d\n", k
->num_keys
);
87 printf("\tMin_keycode is %d\n", k
->min_keycode
);
88 printf("\tMax_keycode is %d\n", k
->max_keycode
);
92 b
= (XButtonInfoPtr
) any
;
93 printf("\tNum_buttons is %d\n", b
->num_buttons
);
97 v
= (XValuatorInfoPtr
) any
;
98 a
= (XAxisInfoPtr
) ((char *) v
+
99 sizeof (XValuatorInfo
));
100 printf("\tNum_axes is %d\n", v
->num_axes
);
101 printf("\tMode is %s\n", (v
->mode
== Absolute
) ? "Absolute" : "Relative");
102 printf("\tMotion_buffer is %ld\n", v
->motion_buffer
);
103 for (j
=0; j
<v
->num_axes
; j
++, a
++) {
104 printf("\tAxis %d :\n", j
);
105 printf("\t\tMin_value is %d\n", a
->min_value
);
106 printf("\t\tMax_value is %d\n", a
->max_value
);
107 printf ("\t\tResolution is %d\n", a
->resolution
);
111 printf ("unknown class\n");
113 any
= (XAnyClassPtr
) ((char *) any
+ any
->length
);
118 static int list_xi1(Display
*display
,
119 enum print_format format
)
125 info
= XListInputDevices(display
, &num_devices
);
126 for(loop
=0; loop
<num_devices
; loop
++) {
127 print_info(display
, info
+loop
, format
);
133 /* also used from test_xi2.c */
135 print_classes_xi2(Display
* display
, XIAnyClassInfo
**classes
,
140 printf("\tReporting %d classes:\n", num_classes
);
141 for (i
= 0; i
< num_classes
; i
++)
143 printf("\t\tClass originated from: %d\n", classes
[i
]->sourceid
);
144 switch(classes
[i
]->type
)
148 XIButtonClassInfo
*b
= (XIButtonClassInfo
*)classes
[i
];
150 printf("\t\tButtons supported: %d\n", b
->num_buttons
);
151 printf("\t\tButton labels:");
152 for (j
= 0; j
< b
->num_buttons
; j
++)
154 name
= (b
->labels
[j
]) ? XGetAtomName(display
, b
->labels
[j
]) : NULL
;
155 printf(" %s", (name
) ? name
: "None");
159 printf("\t\tButton state:");
160 for (j
= 0; j
< b
->state
.mask_len
* 8; j
++)
161 if (XIMaskIsSet(b
->state
.mask
, j
))
169 XIKeyClassInfo
*k
= (XIKeyClassInfo
*)classes
[i
];
170 printf("\t\tKeycodes supported: %d\n", k
->num_keycodes
);
173 case XIValuatorClass
:
175 XIValuatorClassInfo
*v
= (XIValuatorClassInfo
*)classes
[i
];
176 char *name
= v
->label
? XGetAtomName(display
, v
->label
) : NULL
;
178 /* XXX: Bug in X servers 1.7..1.8.1, mode was |
179 OutOfProximity. Remove this once 1.9 is out. */
180 v
->mode
&= DeviceMode
;
182 printf("\t\tDetail for Valuator %d:\n", v
->number
);
183 printf("\t\t Label: %s\n", (name
) ? name
: "None");
184 printf("\t\t Range: %f - %f\n", v
->min
, v
->max
);
185 printf("\t\t Resolution: %d units/m\n", v
->resolution
);
186 printf("\t\t Mode: %s\n", v
->mode
== Absolute
? "absolute" :
188 if (v
->mode
== Absolute
)
189 printf("\t\t Current value: %f\n", v
->value
);
200 print_info_xi2(Display
* display
, XIDeviceInfo
*dev
, enum print_format format
)
202 if (format
== FORMAT_NAME
)
204 printf("%s\n", dev
->name
);
208 printf("%-40s\tid=%d\t[", dev
->name
, dev
->deviceid
);
211 case XIMasterPointer
:
212 printf("master pointer (%d)]\n", dev
->attachment
);
214 case XIMasterKeyboard
:
215 printf("master keyboard (%d)]\n", dev
->attachment
);
218 printf("slave pointer (%d)]\n", dev
->attachment
);
220 case XISlaveKeyboard
:
221 printf("slave keyboard (%d)]\n", dev
->attachment
);
223 case XIFloatingSlave
:
224 printf("floating slave]\n");
228 if (format
== FORMAT_SHORT
)
232 printf("\tThis device is disabled\n");
234 print_classes_xi2(display
, dev
->classes
, dev
->num_classes
);
239 list_xi2(Display
*display
,
240 enum print_format format
)
242 int major
= XI_2_Major
,
246 XIDeviceInfo
*info
, *dev
;
248 if (XIQueryVersion(display
, &major
, &minor
) != Success
||
249 (major
* 1000 + minor
) < (XI_2_Major
* 1000 + XI_2_Minor
))
251 fprintf(stderr
, "XI2 not supported.\n");
255 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
257 for(i
= 0; i
< ndevices
; i
++)
260 if (dev
->use
== XIMasterPointer
|| dev
->use
== XIMasterKeyboard
)
262 if (format
== FORMAT_SHORT
|| format
== FORMAT_LONG
)
264 if (dev
->use
== XIMasterPointer
)
270 print_info_xi2(display
, dev
, format
);
271 for (j
= 0; j
< ndevices
; j
++)
273 XIDeviceInfo
* sd
= &info
[j
];
275 if ((sd
->use
== XISlavePointer
|| sd
->use
== XISlaveKeyboard
) &&
276 (sd
->attachment
== dev
->deviceid
))
278 if (format
== FORMAT_SHORT
|| format
== FORMAT_LONG
)
279 printf("%s ↳ ", dev
->use
== XIMasterPointer
? "⎜" : " ");
280 print_info_xi2(display
, sd
, format
);
286 for (i
= 0; i
< ndevices
; i
++)
289 if (dev
->use
== XIFloatingSlave
)
292 print_info_xi2(display
, dev
, format
);
297 XIFreeDeviceInfo(info
);
303 list(Display
*display
,
309 enum print_format format
= FORMAT_SHORT
;
314 if (strcmp(argv
[0], "--short") == 0)
315 format
= FORMAT_SHORT
;
316 else if (strcmp(argv
[0], "--long") == 0)
317 format
= FORMAT_LONG
;
318 else if (strcmp(argv
[0], "--name-only") == 0)
319 format
= FORMAT_NAME
;
326 if (xinput_version(display
) == XI_2_Major
)
328 XIDeviceInfo
*info
= xi2_find_device_info(display
, argv
[arg_dev
]);
331 fprintf(stderr
, "unable to find device %s\n", argv
[arg_dev
]);
334 print_info_xi2(display
, info
, format
);
340 XDeviceInfo
*info
= find_device_info(display
, argv
[arg_dev
], False
);
343 fprintf(stderr
, "unable to find device %s\n", argv
[arg_dev
]);
346 print_info(display
, info
, format
);
352 if (xinput_version(display
) == XI_2_Major
)
353 return list_xi2(display
, format
);
355 return list_xi1(display
, format
);