]>
diplodocus.org Git - xorg-xinput/blob - src/xinput.c
da54b480a7ccc14c4d28feaf0c576bf34386f0d1
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.
29 #if NeedFunctionPrototypes
30 Display
* display
, int argc
, char *argv
[],
31 char *prog_name
, char *prog_desc
42 static entry drivers
[] =
49 "<device name> <threshold> <num> <denom>",
52 {"set-integer-feedback",
53 "<device name> <feedback id> <value>",
61 "<device name> <map button 1> [<map button 2> [...]]",
65 "<device name> [<x index> <y index>]",
69 "<device name> ABSOLUTE|RELATIVE",
73 "[--loop || --short || <device name>...]",
81 "[-proximity] <device name>",
90 "<id> [sendCore (dflt:1)] [enable (dflt:1)]",
94 "<id> [returnMode (dflt:Floating)] [returnPointer] [returnKeyboard]",
115 "<device> [<device> ...]",
119 "<device> <property> <format (8, 16, 32)> <val> [<val> ...]",
123 "<device> <property> <val> [<val> ...]",
127 "<device> <property> <val> [<val> ...]",
135 "<device> <property>",
139 "<device> <property> <val> [<val> ...]",
147 xinput_version(Display
*display
)
149 XExtensionVersion
*version
;
150 static int vers
= -1;
155 version
= XGetExtensionVersion(display
, INAME
);
157 if (version
&& (version
!= (XExtensionVersion
*) NoSuchExtension
)) {
158 vers
= version
->major_version
;
166 find_device_info(Display
*display
,
170 XDeviceInfo
*devices
;
171 XDeviceInfo
*found
= NULL
;
174 int len
= strlen(name
);
178 for(loop
=0; loop
<len
; loop
++) {
179 if (!isdigit(name
[loop
])) {
189 devices
= XListInputDevices(display
, &num_devices
);
191 for(loop
=0; loop
<num_devices
; loop
++) {
192 if ((!only_extended
|| (devices
[loop
].use
>= IsXExtensionDevice
)) &&
193 ((!is_id
&& strcmp(devices
[loop
].name
, name
) == 0) ||
194 (is_id
&& devices
[loop
].id
== id
))) {
197 "Warning: There are multiple devices named \"%s\".\n"
198 "To ensure the correct one is selected, please use "
199 "the device ID instead.\n\n", name
);
202 found
= &devices
[loop
];
211 xi2_find_device_id(Display
*display
, char *name
)
218 for(i
= 0; i
< strlen(name
); i
++) {
219 if (!isdigit(name
[i
])) {
229 info
= XIQueryDevice(display
, AllDevices
, &ndevices
);
230 for(i
= 0; i
< ndevices
; i
++)
232 if ((is_id
&& info
[i
].deviceid
== id
) ||
233 (!is_id
&& strcmp(info
[i
].name
, name
) == 0))
235 id
= info
[i
].deviceid
;
240 XIFreeDeviceInfo(info
);
249 entry
*pdriver
= drivers
;
251 fprintf(stderr
, "usage :\n");
253 while(pdriver
->func_name
) {
254 fprintf(stderr
, "\txinput %s %s\n", pdriver
->func_name
,
261 main(int argc
, char * argv
[])
264 entry
*driver
= drivers
;
272 display
= XOpenDisplay(NULL
);
274 if (display
== NULL
) {
275 fprintf(stderr
, "Unable to connect to X server\n");
280 while((*func
) == '-') func
++;
282 if (!xinput_version(display
)) {
283 fprintf(stderr
, "%s extension not available\n", INAME
);
287 while(driver
->func_name
) {
288 if (strcmp(driver
->func_name
, func
) == 0) {
289 int r
= (*driver
->func
)(display
, argc
-2, argv
+2,
290 driver
->func_name
, driver
->arg_desc
);
291 XSync(display
, False
);
302 /* end of xinput.c */