]>
diplodocus.org Git - xorg-xinput/blob - src/xinput.c
5dd276608dec8b212c9d538cc7260807dbbc5342
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 || --name-only || --id-only] [<device name>...]",
79 "[-proximity] <device name>",
84 "<id> [<sendCore (dflt:1)>] [<enable (dflt:1)>]",
88 "<id> [Floating|AttachToMaster (dflt:Floating)] [<returnPointer>] [<returnKeyboard>]",
108 "<device> <output name>",
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> ...]",
154 static const char version_id
[] = VERSION
;
159 XExtensionVersion
*version
;
162 printf("xinput version %s\n", version_id
);
164 display
= XOpenDisplay(NULL
);
166 printf("XI version on server: ");
169 printf("Failed to open display.\n");
171 version
= XGetExtensionVersion(display
, INAME
);
172 if (!version
|| (version
== (XExtensionVersion
*) NoSuchExtension
))
173 printf(" Extension not supported.\n");
175 printf("%d.%d\n", version
->major_version
,
176 version
->minor_version
);
186 xinput_version(Display
*display
)
188 XExtensionVersion
*version
;
189 static int vers
= -1;
194 version
= XGetExtensionVersion(display
, INAME
);
196 if (version
&& (version
!= (XExtensionVersion
*) NoSuchExtension
)) {
197 vers
= version
->major_version
;
202 /* Announce our supported version so the server treats us correctly. */
203 if (vers
>= XI_2_Major
)
205 const char *forced_version
;
215 forced_version
= getenv("XINPUT_XI2_VERSION");
216 if (forced_version
) {
217 if (sscanf(forced_version
, "%d.%d", &maj
, &min
) != 2) {
218 fprintf(stderr
, "Invalid format of XINPUT_XI2_VERSION "
219 "environment variable. Need major.minor\n");
222 printf("Overriding XI2 version to: %d.%d\n", maj
, min
);
225 XIQueryVersion(display
, &maj
, &min
);
233 find_device_info(Display
*display
,
237 XDeviceInfo
*devices
;
238 XDeviceInfo
*found
= NULL
;
241 int len
= strlen(name
);
245 for(loop
=0; loop
<len
; loop
++) {
246 if (!isdigit(name
[loop
])) {
256 devices
= XListInputDevices(display
, &num_devices
);
258 for(loop
=0; loop
<num_devices
; loop
++) {
259 if ((!only_extended
|| (devices
[loop
].use
>= IsXExtensionDevice
)) &&
260 ((!is_id
&& strcmp(devices
[loop
].name
, name
) == 0) ||
261 (is_id
&& devices
[loop
].id
== id
))) {
264 "Warning: There are multiple devices named '%s'.\n"
265 "To ensure the correct one is selected, please use "
266 "the device ID instead.\n\n", name
);
269 found
= &devices
[loop
];
277 Bool
is_pointer(int use
)
279 return use
== XIMasterPointer
|| use
== XISlavePointer
;
282 Bool
is_keyboard(int use
)
284 return use
== XIMasterKeyboard
|| use
== XISlaveKeyboard
;
287 Bool
device_matches(XIDeviceInfo
*info
, char *name
)
289 if (strcmp(info
->name
, name
) == 0) {
293 if (strncmp(name
, "pointer:", strlen("pointer:")) == 0 &&
294 strcmp(info
->name
, name
+ strlen("pointer:")) == 0 &&
295 is_pointer(info
->use
)) {
299 if (strncmp(name
, "keyboard:", strlen("keyboard:")) == 0 &&
300 strcmp(info
->name
, name
+ strlen("keyboard:")) == 0 &&
301 is_keyboard(info
->use
)) {
309 xi2_find_device_info(Display
*display
, char *name
)
312 XIDeviceInfo
*found
= NULL
;
317 for(i
= 0; i
< strlen(name
); i
++) {
318 if (!isdigit(name
[i
])) {
328 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
329 for(i
= 0; i
< ndevices
; i
++)
331 if (is_id
? info
[i
].deviceid
== id
: device_matches (&info
[i
], name
)) {
334 "Warning: There are multiple devices matching '%s'.\n"
335 "To ensure the correct one is selected, please use "
336 "the device ID, or prefix the\ndevice name with "
337 "'pointer:' or 'keyboard:' as appropriate.\n\n", name
);
338 XIFreeDeviceInfo(info
);
353 entry
*pdriver
= drivers
;
355 fprintf(stderr
, "usage :\n");
357 while(pdriver
->func_name
) {
358 fprintf(stderr
, "\txinput %s %s\n", pdriver
->func_name
,
365 main(int argc
, char * argv
[])
368 entry
*driver
= drivers
;
374 while(func
[0] == '-') func
++;
379 if (strcmp("version", func
) == 0) {
380 return print_version();
383 if (strcmp("help", func
) == 0) {
388 display
= XOpenDisplay(NULL
);
390 if (display
== NULL
) {
391 fprintf(stderr
, "Unable to connect to X server\n");
395 if (!XQueryExtension(display
, "XInputExtension", &xi_opcode
, &event
, &error
)) {
396 printf("X Input extension not available.\n");
400 if (!xinput_version(display
)) {
401 fprintf(stderr
, "%s extension not available\n", INAME
);
405 while(driver
->func_name
) {
406 if (strcmp(driver
->func_name
, func
) == 0) {
407 int r
= (*driver
->func
)(display
, argc
-2, argv
+2,
408 driver
->func_name
, driver
->arg_desc
);
409 XSync(display
, False
);
410 XCloseDisplay(display
);
420 XCloseDisplay(display
);
424 /* end of xinput.c */