]>
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.
30 typedef int (*prog
)(Display
* display
, int argc
, char *argv
[],
31 char *prog_name
, char *prog_desc
);
40 static entry drivers
[] =
47 "<device name> <threshold> <num> <denom>",
50 {"set-integer-feedback",
51 "<device name> <feedback id> <value>",
59 "<device name> <map button 1> [<map button 2> [...]]",
63 "<device name> [<x index> <y index>]",
67 "<device name> ABSOLUTE|RELATIVE",
71 "[--short || --long] [<device name>...]",
79 "[-proximity] <device name>",
84 "<id> [<sendCore (dflt:1)>] [<enable (dflt:1)>]",
88 "<id> [Floating|AttachToMaster (dflt:Floating)] [<returnPointer>] [<returnKeyboard>]",
109 "<device> [<device> ...]",
113 "<device> <property> <format (8, 16, 32)> <val> [<val> ...]",
117 "<device> <property> <val> [<val> ...]",
121 "<device> <property> <val> [<val> ...]",
129 "<device> <property>",
133 "<device> [--type=atom|float|int] [--format=8|16|32] <property> <val> [<val> ...]",
140 static const char version_id
[] = VERSION
;
145 XExtensionVersion
*version
;
148 printf("xinput version %s\n", version_id
);
150 display
= XOpenDisplay(NULL
);
152 printf("XI version on server: ");
155 printf("Failed to open display.\n");
157 version
= XGetExtensionVersion(display
, INAME
);
158 if (!version
|| (version
== (XExtensionVersion
*) NoSuchExtension
))
159 printf(" Extension not supported.\n");
161 printf("%d.%d\n", version
->major_version
,
162 version
->minor_version
);
172 xinput_version(Display
*display
)
174 XExtensionVersion
*version
;
175 static int vers
= -1;
180 version
= XGetExtensionVersion(display
, INAME
);
182 if (version
&& (version
!= (XExtensionVersion
*) NoSuchExtension
)) {
183 vers
= version
->major_version
;
191 find_device_info(Display
*display
,
195 XDeviceInfo
*devices
;
196 XDeviceInfo
*found
= NULL
;
199 int len
= strlen(name
);
203 for(loop
=0; loop
<len
; loop
++) {
204 if (!isdigit(name
[loop
])) {
214 devices
= XListInputDevices(display
, &num_devices
);
216 for(loop
=0; loop
<num_devices
; loop
++) {
217 if ((!only_extended
|| (devices
[loop
].use
>= IsXExtensionDevice
)) &&
218 ((!is_id
&& strcmp(devices
[loop
].name
, name
) == 0) ||
219 (is_id
&& devices
[loop
].id
== id
))) {
222 "Warning: There are multiple devices named \"%s\".\n"
223 "To ensure the correct one is selected, please use "
224 "the device ID instead.\n\n", name
);
227 found
= &devices
[loop
];
236 xi2_find_device_info(Display
*display
, char *name
)
243 for(i
= 0; i
< strlen(name
); i
++) {
244 if (!isdigit(name
[i
])) {
254 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
255 for(i
= 0; i
< ndevices
; i
++)
257 if ((is_id
&& info
[i
].deviceid
== id
) ||
258 (!is_id
&& strcmp(info
[i
].name
, name
) == 0))
264 XIFreeDeviceInfo(info
);
272 entry
*pdriver
= drivers
;
274 fprintf(stderr
, "usage :\n");
276 while(pdriver
->func_name
) {
277 fprintf(stderr
, "\txinput %s %s\n", pdriver
->func_name
,
284 main(int argc
, char * argv
[])
287 entry
*driver
= drivers
;
297 while((*func
) == '-') func
++;
299 if (strcmp("version", func
) == 0) {
300 return print_version(argv
[0]);
303 display
= XOpenDisplay(NULL
);
305 if (display
== NULL
) {
306 fprintf(stderr
, "Unable to connect to X server\n");
310 if (!XQueryExtension(display
, "XInputExtension", &xi_opcode
, &event
, &error
)) {
311 printf("X Input extension not available.\n");
315 if (!xinput_version(display
)) {
316 fprintf(stderr
, "%s extension not available\n", INAME
);
320 while(driver
->func_name
) {
321 if (strcmp(driver
->func_name
, func
) == 0) {
322 int r
= (*driver
->func
)(display
, argc
-2, argv
+2,
323 driver
->func_name
, driver
->arg_desc
);
324 XSync(display
, False
);
325 XCloseDisplay(display
);
336 /* end of xinput.c */