]>
diplodocus.org Git - xorg-xinput/blob - src/list.c
46b8bd8446e8aeb8c0ccf43af45304ef7b955c8a
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 printf("\tType is %s\n", XGetAtomName(dpy
, info
->type
));
86 if (info
->num_classes
> 0) {
87 any
= (XAnyClassPtr
) (info
->inputclassinfo
);
88 for (i
=0; i
<info
->num_classes
; i
++) {
91 k
= (XKeyInfoPtr
) any
;
92 printf("\tNum_keys is %d\n", k
->num_keys
);
93 printf("\tMin_keycode is %d\n", k
->min_keycode
);
94 printf("\tMax_keycode is %d\n", k
->max_keycode
);
98 b
= (XButtonInfoPtr
) any
;
99 printf("\tNum_buttons is %d\n", b
->num_buttons
);
103 v
= (XValuatorInfoPtr
) any
;
104 a
= (XAxisInfoPtr
) ((char *) v
+
105 sizeof (XValuatorInfo
));
106 printf("\tNum_axes is %d\n", v
->num_axes
);
107 printf("\tMode is %s\n", (v
->mode
== Absolute
) ? "Absolute" : "Relative");
108 printf("\tMotion_buffer is %ld\n", v
->motion_buffer
);
109 for (j
=0; j
<v
->num_axes
; j
++, a
++) {
110 printf("\tAxis %d :\n", j
);
111 printf("\t\tMin_value is %d\n", a
->min_value
);
112 printf("\t\tMax_value is %d\n", a
->max_value
);
113 printf ("\t\tResolution is %d\n", a
->resolution
);
117 printf ("unknown class\n");
119 any
= (XAnyClassPtr
) ((char *) any
+ any
->length
);
124 static int list_xi1(Display
*display
,
125 enum print_format format
)
131 info
= XListInputDevices(display
, &num_devices
);
132 for(loop
=0; loop
<num_devices
; loop
++) {
133 print_info(display
, info
+loop
, format
);
139 /* also used from test_xi2.c */
141 print_classes_xi2(Display
* display
, XIAnyClassInfo
**classes
,
146 printf("\tReporting %d classes:\n", num_classes
);
147 for (i
= 0; i
< num_classes
; i
++)
149 printf("\t\tClass originated from: %d. Type: ", classes
[i
]->sourceid
);
150 switch(classes
[i
]->type
)
154 XIButtonClassInfo
*b
= (XIButtonClassInfo
*)classes
[i
];
156 printf("XIButtonClass\n");
157 printf("\t\tButtons supported: %d\n", b
->num_buttons
);
158 printf("\t\tButton labels:");
159 for (j
= 0; j
< b
->num_buttons
; j
++)
161 name
= (b
->labels
[j
]) ? XGetAtomName(display
, b
->labels
[j
]) : NULL
;
162 printf(" %s", (name
) ? name
: "None");
166 printf("\t\tButton state:");
167 for (j
= 0; j
< b
->state
.mask_len
* 8; j
++)
168 if (XIMaskIsSet(b
->state
.mask
, j
))
176 XIKeyClassInfo
*k
= (XIKeyClassInfo
*)classes
[i
];
177 printf("XIKeyClass\n");
178 printf("\t\tKeycodes supported: %d\n", k
->num_keycodes
);
181 case XIValuatorClass
:
183 XIValuatorClassInfo
*v
= (XIValuatorClassInfo
*)classes
[i
];
184 char *name
= v
->label
? XGetAtomName(display
, v
->label
) : NULL
;
186 /* Bug in X servers 1.7..1.8.1, mode was | OutOfProximity */
187 v
->mode
&= DeviceMode
;
189 printf("XIValuatorClass\n");
190 printf("\t\tDetail for Valuator %d:\n", v
->number
);
191 printf("\t\t Label: %s\n", (name
) ? name
: "None");
192 printf("\t\t Range: %f - %f\n", v
->min
, v
->max
);
193 printf("\t\t Resolution: %d units/m\n", v
->resolution
);
194 printf("\t\t Mode: %s\n", v
->mode
== Absolute
? "absolute" :
196 if (v
->mode
== Absolute
)
197 printf("\t\t Current value: %f\n", v
->value
);
208 print_info_xi2(Display
* display
, XIDeviceInfo
*dev
, enum print_format format
)
210 if (format
== FORMAT_NAME
)
212 printf("%s\n", dev
->name
);
214 } else if (format
== FORMAT_ID
)
216 printf("%d\n", dev
->deviceid
);
220 printf("%-40s\tid=%d\t[", dev
->name
, dev
->deviceid
);
223 case XIMasterPointer
:
224 printf("master pointer (%d)]\n", dev
->attachment
);
226 case XIMasterKeyboard
:
227 printf("master keyboard (%d)]\n", dev
->attachment
);
230 printf("slave pointer (%d)]\n", dev
->attachment
);
232 case XISlaveKeyboard
:
233 printf("slave keyboard (%d)]\n", dev
->attachment
);
235 case XIFloatingSlave
:
236 printf("floating slave]\n");
240 if (format
== FORMAT_SHORT
)
244 printf("\tThis device is disabled\n");
246 print_classes_xi2(display
, dev
->classes
, dev
->num_classes
);
251 list_xi2(Display
*display
,
252 enum print_format format
)
258 XIDeviceInfo
*info
, *dev
;
260 if (XIQueryVersion(display
, &major
, &minor
) != Success
||
261 (major
* 1000 + minor
) < 2000)
263 fprintf(stderr
, "XI2 not supported.\n");
267 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
269 for(i
= 0; i
< ndevices
; i
++)
272 if (dev
->use
== XIMasterPointer
|| dev
->use
== XIMasterKeyboard
)
274 if (format
== FORMAT_SHORT
|| format
== FORMAT_LONG
)
276 if (dev
->use
== XIMasterPointer
)
282 print_info_xi2(display
, dev
, format
);
283 for (j
= 0; j
< ndevices
; j
++)
285 XIDeviceInfo
* sd
= &info
[j
];
287 if ((sd
->use
== XISlavePointer
|| sd
->use
== XISlaveKeyboard
) &&
288 (sd
->attachment
== dev
->deviceid
))
290 if (format
== FORMAT_SHORT
|| format
== FORMAT_LONG
)
291 printf("%s ↳ ", dev
->use
== XIMasterPointer
? "⎜" : " ");
292 print_info_xi2(display
, sd
, format
);
298 for (i
= 0; i
< ndevices
; i
++)
301 if (dev
->use
== XIFloatingSlave
)
304 print_info_xi2(display
, dev
, format
);
309 XIFreeDeviceInfo(info
);
315 list(Display
*display
,
321 enum print_format format
= FORMAT_NONE
;
326 if (strcmp(argv
[0], "--short") == 0)
327 format
= FORMAT_SHORT
;
328 else if (strcmp(argv
[0], "--long") == 0)
329 format
= FORMAT_LONG
;
330 else if (strcmp(argv
[0], "--name-only") == 0)
331 format
= FORMAT_NAME
;
332 else if (strcmp(argv
[0], "--id-only") == 0)
340 if (format
== FORMAT_NONE
)
341 format
= FORMAT_LONG
;
343 if (xinput_version(display
) == XI_2_Major
)
345 XIDeviceInfo
*info
= xi2_find_device_info(display
, argv
[arg_dev
]);
348 fprintf(stderr
, "unable to find device %s\n", argv
[arg_dev
]);
351 print_info_xi2(display
, info
, format
);
357 XDeviceInfo
*info
= find_device_info(display
, argv
[arg_dev
], False
);
360 fprintf(stderr
, "unable to find device %s\n", argv
[arg_dev
]);
363 print_info(display
, info
, format
);
368 if (format
== FORMAT_NONE
)
369 format
= FORMAT_SHORT
;
371 if (xinput_version(display
) == XI_2_Major
)
372 return list_xi2(display
, format
);
374 return list_xi1(display
, format
);