]>
diplodocus.org Git - xorg-xinput/blob - src/xinput.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.
28 typedef int (*prog
)(Display
* display
, int argc
, char *argv
[],
29 char *prog_name
, char *prog_desc
);
38 static entry drivers
[] =
45 "<device name> <threshold> <num> <denom>",
48 {"set-integer-feedback",
49 "<device name> <feedback id> <value>",
57 "<device name> <map button 1> [<map button 2> [...]]",
61 "<device name> [<x index> <y index>]",
65 "<device name> ABSOLUTE|RELATIVE",
69 "[--loop || --short || <device name>...]",
77 "[-proximity] <device name>",
86 "<id> [sendCore (dflt:1)] [enable (dflt:1)]",
90 "<id> [returnMode (dflt:Floating)] [returnPointer] [returnKeyboard]",
111 "<device> [<device> ...]",
115 "<device> <property> <format (8, 16, 32)> <val> [<val> ...]",
119 "<device> <property> <val> [<val> ...]",
123 "<device> <property> <val> [<val> ...]",
131 "<device> <property>",
135 "<device> <property> <val> [<val> ...]",
143 xinput_version(Display
*display
)
145 XExtensionVersion
*version
;
146 static int vers
= -1;
151 version
= XGetExtensionVersion(display
, INAME
);
153 if (version
&& (version
!= (XExtensionVersion
*) NoSuchExtension
)) {
154 vers
= version
->major_version
;
162 find_device_info(Display
*display
,
166 XDeviceInfo
*devices
;
167 XDeviceInfo
*found
= NULL
;
170 int len
= strlen(name
);
174 for(loop
=0; loop
<len
; loop
++) {
175 if (!isdigit(name
[loop
])) {
185 devices
= XListInputDevices(display
, &num_devices
);
187 for(loop
=0; loop
<num_devices
; loop
++) {
188 if ((!only_extended
|| (devices
[loop
].use
>= IsXExtensionDevice
)) &&
189 ((!is_id
&& strcmp(devices
[loop
].name
, name
) == 0) ||
190 (is_id
&& devices
[loop
].id
== id
))) {
193 "Warning: There are multiple devices named \"%s\".\n"
194 "To ensure the correct one is selected, please use "
195 "the device ID instead.\n\n", name
);
198 found
= &devices
[loop
];
207 xi2_find_device_info(Display
*display
, char *name
)
214 for(i
= 0; i
< strlen(name
); i
++) {
215 if (!isdigit(name
[i
])) {
225 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
226 for(i
= 0; i
< ndevices
; i
++)
228 if ((is_id
&& info
[i
].deviceid
== id
) ||
229 (!is_id
&& strcmp(info
[i
].name
, name
) == 0))
235 XIFreeDeviceInfo(info
);
243 entry
*pdriver
= drivers
;
245 fprintf(stderr
, "usage :\n");
247 while(pdriver
->func_name
) {
248 fprintf(stderr
, "\txinput %s %s\n", pdriver
->func_name
,
255 main(int argc
, char * argv
[])
258 entry
*driver
= drivers
;
266 display
= XOpenDisplay(NULL
);
268 if (display
== NULL
) {
269 fprintf(stderr
, "Unable to connect to X server\n");
274 while((*func
) == '-') func
++;
276 if (!xinput_version(display
)) {
277 fprintf(stderr
, "%s extension not available\n", INAME
);
281 while(driver
->func_name
) {
282 if (strcmp(driver
->func_name
, func
) == 0) {
283 int r
= (*driver
->func
)(display
, argc
-2, argv
+2,
284 driver
->func_name
, driver
->arg_desc
);
285 XSync(display
, False
);
286 XCloseDisplay(display
);
297 /* end of xinput.c */