]>
diplodocus.org Git - xorg-xinput/blob - src/xinput.c
3c8b23ca17413152a474547dd50d1e4ab284afb7
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>",
88 "<id> [<sendCore (dflt:1)>] [<enable (dflt:1)>]",
92 "<id> [Floating|AttachToMaster (dflt:Floating)] [<returnPointer>] [<returnKeyboard>]",
113 "<device> [<device> ...]",
117 "<device> <property> <format (8, 16, 32)> <val> [<val> ...]",
121 "<device> <property> <val> [<val> ...]",
125 "<device> <property> <val> [<val> ...]",
133 "<device> <property>",
137 "<device> [--type=atom|float|int] [--format=8|16|32] <property> <val> [<val> ...]",
145 xinput_version(Display
*display
)
147 XExtensionVersion
*version
;
148 static int vers
= -1;
153 version
= XGetExtensionVersion(display
, INAME
);
155 if (version
&& (version
!= (XExtensionVersion
*) NoSuchExtension
)) {
156 vers
= version
->major_version
;
164 find_device_info(Display
*display
,
168 XDeviceInfo
*devices
;
169 XDeviceInfo
*found
= NULL
;
172 int len
= strlen(name
);
176 for(loop
=0; loop
<len
; loop
++) {
177 if (!isdigit(name
[loop
])) {
187 devices
= XListInputDevices(display
, &num_devices
);
189 for(loop
=0; loop
<num_devices
; loop
++) {
190 if ((!only_extended
|| (devices
[loop
].use
>= IsXExtensionDevice
)) &&
191 ((!is_id
&& strcmp(devices
[loop
].name
, name
) == 0) ||
192 (is_id
&& devices
[loop
].id
== id
))) {
195 "Warning: There are multiple devices named \"%s\".\n"
196 "To ensure the correct one is selected, please use "
197 "the device ID instead.\n\n", name
);
200 found
= &devices
[loop
];
209 xi2_find_device_info(Display
*display
, char *name
)
216 for(i
= 0; i
< strlen(name
); i
++) {
217 if (!isdigit(name
[i
])) {
227 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
228 for(i
= 0; i
< ndevices
; i
++)
230 if ((is_id
&& info
[i
].deviceid
== id
) ||
231 (!is_id
&& strcmp(info
[i
].name
, name
) == 0))
237 XIFreeDeviceInfo(info
);
245 entry
*pdriver
= drivers
;
247 fprintf(stderr
, "usage :\n");
249 while(pdriver
->func_name
) {
250 fprintf(stderr
, "\txinput %s %s\n", pdriver
->func_name
,
257 main(int argc
, char * argv
[])
260 entry
*driver
= drivers
;
269 display
= XOpenDisplay(NULL
);
271 if (display
== NULL
) {
272 fprintf(stderr
, "Unable to connect to X server\n");
276 if (!XQueryExtension(display
, "XInputExtension", &xi_opcode
, &event
, &error
)) {
277 printf("X Input extension not available.\n");
282 while((*func
) == '-') func
++;
284 if (!xinput_version(display
)) {
285 fprintf(stderr
, "%s extension not available\n", INAME
);
289 while(driver
->func_name
) {
290 if (strcmp(driver
->func_name
, func
) == 0) {
291 int r
= (*driver
->func
)(display
, argc
-2, argv
+2,
292 driver
->func_name
, driver
->arg_desc
);
293 XSync(display
, False
);
294 XCloseDisplay(display
);
305 /* end of xinput.c */