]>
diplodocus.org Git - xorg-xinput/blob - src/list.c
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.
26 #include <X11/extensions/XIproto.h> /* for XI_Device***ChangedNotify */
29 print_info(Display
* dpy
, XDeviceInfo
*info
, Bool shortformat
)
38 printf("\"%s\"\tid=%ld\t[", info
->name
, info
->id
);
47 case IsXExtensionDevice
:
48 printf("XExtensionDevice");
50 case IsXExtensionKeyboard
:
51 printf("XExtensionKeyboard");
53 case IsXExtensionPointer
:
54 printf("XExtensionPointer");
57 printf("Unknown class");
65 if(info
->type
!= None
)
66 printf("\tType is %s\n", XGetAtomName(dpy
, info
->type
));
68 if (info
->num_classes
> 0) {
69 any
= (XAnyClassPtr
) (info
->inputclassinfo
);
70 for (i
=0; i
<info
->num_classes
; i
++) {
73 k
= (XKeyInfoPtr
) any
;
74 printf("\tNum_keys is %d\n", k
->num_keys
);
75 printf("\tMin_keycode is %d\n", k
->min_keycode
);
76 printf("\tMax_keycode is %d\n", k
->max_keycode
);
80 b
= (XButtonInfoPtr
) any
;
81 printf("\tNum_buttons is %d\n", b
->num_buttons
);
85 v
= (XValuatorInfoPtr
) any
;
86 a
= (XAxisInfoPtr
) ((char *) v
+
87 sizeof (XValuatorInfo
));
88 printf("\tNum_axes is %d\n", v
->num_axes
);
89 printf("\tMode is %s\n", (v
->mode
== Absolute
) ? "Absolute" : "Relative");
90 printf("\tMotion_buffer is %ld\n", v
->motion_buffer
);
91 for (j
=0; j
<v
->num_axes
; j
++, a
++) {
92 printf("\tAxis %d :\n", j
);
93 printf("\t\tMin_value is %d\n", a
->min_value
);
94 printf("\t\tMax_value is %d\n", a
->max_value
);
95 printf ("\t\tResolution is %d\n", a
->resolution
);
99 printf ("unknown class\n");
101 any
= (XAnyClassPtr
) ((char *) any
+ any
->length
);
106 static int list_xi1(Display
*display
,
114 int shortformat
= False
;
117 shortformat
= (argc
== 1 && strcmp(argv
[0], "--short") == 0);
118 daemon
= (argc
== 1 && strcmp(argv
[0], "--loop") == 0);
120 if (argc
== 0 || shortformat
|| daemon
) {
124 info
= XListInputDevices(display
, &num_devices
);
125 for(loop
=0; loop
<num_devices
; loop
++) {
126 print_info(display
, info
+loop
, shortformat
);
130 int ret
= EXIT_SUCCESS
;
132 for(loop
=0; loop
<argc
; loop
++) {
133 info
= find_device_info(display
, argv
[loop
], False
);
136 fprintf(stderr
, "unable to find device %s\n", argv
[loop
]);
139 print_info(display
, info
, shortformat
);
148 /* also used from test_xi2.c */
150 print_classes_xi2(Display
* display
, XIAnyClassInfo
**classes
,
155 printf("\tReporting %d classes:\n", num_classes
);
156 for (i
= 0; i
< num_classes
; i
++)
158 printf("\t\tClass originated from: %d\n", classes
[i
]->sourceid
);
159 switch(classes
[i
]->type
)
163 XIButtonClassInfo
*b
= (XIButtonClassInfo
*)classes
[i
];
165 printf("\t\tButtons supported: %d\n", b
->num_buttons
);
166 printf("\t\tButton labels:");
167 for (j
= 0; j
< b
->num_buttons
; j
++)
169 name
= (b
->labels
[j
]) ? XGetAtomName(display
, b
->labels
[j
]) : NULL
;
170 printf(" %s", (name
) ? name
: "None");
174 printf("\t\tButton state:");
175 for (j
= 0; j
< b
->state
.mask_len
* 8; j
++)
176 if (XIMaskIsSet(b
->state
.mask
, j
))
184 XIKeyClassInfo
*k
= (XIKeyClassInfo
*)classes
[i
];
185 printf("\t\tKeycodes supported: %d\n", k
->num_keycodes
);
188 case XIValuatorClass
:
190 XIValuatorClassInfo
*v
= (XIValuatorClassInfo
*)classes
[i
];
191 char *name
= v
->label
? XGetAtomName(display
, v
->label
) : NULL
;
193 printf("\t\tDetail for Valuator %d:\n", v
->number
);
194 printf("\t\t Label: %s\n", (name
) ? name
: "None");
195 printf("\t\t Range: %f - %f\n", v
->min
, v
->max
);
196 printf("\t\t Resolution: %d units/m\n", v
->resolution
);
197 printf("\t\t Mode: %s\n", v
->mode
== Absolute
? "absolute" :
199 if (v
->mode
== Absolute
)
200 printf("\t\t Current value: %f\n", v
->value
);
211 print_info_xi2(Display
* display
, XIDeviceInfo
*dev
, Bool shortformat
)
213 printf("%-40s\tid=%d\t[", dev
->name
, dev
->deviceid
);
216 case XIMasterPointer
:
217 printf("master pointer (%d)]\n", dev
->attachment
);
219 case XIMasterKeyboard
:
220 printf("master keyboard (%d)]\n", dev
->attachment
);
223 printf("slave pointer (%d)]\n", dev
->attachment
);
225 case XISlaveKeyboard
:
226 printf("slave keyboard (%d)]\n", dev
->attachment
);
228 case XIFloatingSlave
:
229 printf("floating slave]\n");
237 printf("\tThis device is disabled\n");
239 print_classes_xi2(display
, dev
->classes
, dev
->num_classes
);
244 list_xi2(Display
*display
,
250 int major
= XI_2_Major
,
253 int i
, j
, shortformat
;
254 XIDeviceInfo
*info
, *dev
;
256 shortformat
= (argc
== 1 && strcmp(argv
[0], "--short") == 0);
258 if (XIQueryVersion(display
, &major
, &minor
) != Success
||
259 (major
* 1000 + minor
) < (XI_2_Major
* 1000 + XI_2_Minor
))
261 fprintf(stderr
, "XI2 not supported.\n");
265 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
267 for(i
= 0; i
< ndevices
; i
++)
270 if (dev
->use
== XIMasterPointer
|| dev
->use
== XIMasterKeyboard
)
272 if (dev
->use
== XIMasterPointer
)
277 print_info_xi2(display
, dev
, shortformat
);
278 for (j
= 0; j
< ndevices
; j
++)
280 XIDeviceInfo
* sd
= &info
[j
];
282 if ((sd
->use
== XISlavePointer
|| sd
->use
== XISlaveKeyboard
) &&
283 (sd
->attachment
== dev
->deviceid
))
285 printf("%s ↳ ", dev
->use
== XIMasterPointer
? "⎜" : " ");
286 print_info_xi2(display
, sd
, shortformat
);
292 for (i
= 0; i
< ndevices
; i
++)
295 if (dev
->use
== XIFloatingSlave
)
298 print_info_xi2(display
, dev
, shortformat
);
303 XIFreeDeviceInfo(info
);
309 list(Display
*display
,
316 if (xinput_version(display
) == XI_2_Major
)
317 return list_xi2(display
, argc
, argv
, name
, desc
);
319 return list_xi1(display
, argc
, argv
, name
, desc
);