]>
diplodocus.org Git - xorg-xinput/blob - src/xinput.c
2d9a8931456c8b5d1f8147e9268f2ec68e8c6e85
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> <crtc 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> ...]",
144 static const char version_id
[] = VERSION
;
149 XExtensionVersion
*version
;
152 printf("xinput version %s\n", version_id
);
154 display
= XOpenDisplay(NULL
);
156 printf("XI version on server: ");
159 printf("Failed to open display.\n");
161 version
= XGetExtensionVersion(display
, INAME
);
162 if (!version
|| (version
== (XExtensionVersion
*) NoSuchExtension
))
163 printf(" Extension not supported.\n");
165 printf("%d.%d\n", version
->major_version
,
166 version
->minor_version
);
176 xinput_version(Display
*display
)
178 XExtensionVersion
*version
;
179 static int vers
= -1;
184 version
= XGetExtensionVersion(display
, INAME
);
186 if (version
&& (version
!= (XExtensionVersion
*) NoSuchExtension
)) {
187 vers
= version
->major_version
;
192 /* Announce our supported version so the server treats us correctly. */
193 if (vers
>= XI_2_Major
)
202 XIQueryVersion(display
, &maj
, &min
);
210 find_device_info(Display
*display
,
214 XDeviceInfo
*devices
;
215 XDeviceInfo
*found
= NULL
;
218 int len
= strlen(name
);
222 for(loop
=0; loop
<len
; loop
++) {
223 if (!isdigit(name
[loop
])) {
233 devices
= XListInputDevices(display
, &num_devices
);
235 for(loop
=0; loop
<num_devices
; loop
++) {
236 if ((!only_extended
|| (devices
[loop
].use
>= IsXExtensionDevice
)) &&
237 ((!is_id
&& strcmp(devices
[loop
].name
, name
) == 0) ||
238 (is_id
&& devices
[loop
].id
== id
))) {
241 "Warning: There are multiple devices named \"%s\".\n"
242 "To ensure the correct one is selected, please use "
243 "the device ID instead.\n\n", name
);
246 found
= &devices
[loop
];
254 Bool
is_pointer(int use
)
256 return use
== XIMasterPointer
|| use
== XISlavePointer
;
259 Bool
is_keyboard(int use
)
261 return use
== XIMasterKeyboard
|| use
== XISlaveKeyboard
;
264 Bool
device_matches(XIDeviceInfo
*info
, char *name
)
266 if (strcmp(info
->name
, name
) == 0) {
270 if (strncmp(name
, "pointer:", strlen("pointer:")) == 0 &&
271 strcmp(info
->name
, name
+ strlen("pointer:")) == 0 &&
272 is_pointer(info
->use
)) {
276 if (strncmp(name
, "keyboard:", strlen("keyboard:")) == 0 &&
277 strcmp(info
->name
, name
+ strlen("keyboard:")) == 0 &&
278 is_keyboard(info
->use
)) {
286 xi2_find_device_info(Display
*display
, char *name
)
289 XIDeviceInfo
*found
= NULL
;
294 for(i
= 0; i
< strlen(name
); i
++) {
295 if (!isdigit(name
[i
])) {
305 info
= XIQueryDevice(display
, XIAllDevices
, &ndevices
);
306 for(i
= 0; i
< ndevices
; i
++)
308 if (is_id
? info
[i
].deviceid
== id
: device_matches (&info
[i
], name
)) {
311 "Warning: There are multiple devices matching '%s'.\n"
312 "To ensure the correct one is selected, please use "
313 "the device ID, or prefix the\ndevice name with "
314 "'pointer:' or 'keyboard:' as appropriate.\n\n", name
);
315 XIFreeDeviceInfo(info
);
330 entry
*pdriver
= drivers
;
332 fprintf(stderr
, "usage :\n");
334 while(pdriver
->func_name
) {
335 fprintf(stderr
, "\txinput %s %s\n", pdriver
->func_name
,
342 main(int argc
, char * argv
[])
345 entry
*driver
= drivers
;
351 while(func
[0] == '-') func
++;
356 if (strcmp("version", func
) == 0) {
357 return print_version(argv
[0]);
360 if (strcmp("help", func
) == 0) {
365 display
= XOpenDisplay(NULL
);
367 if (display
== NULL
) {
368 fprintf(stderr
, "Unable to connect to X server\n");
372 if (!XQueryExtension(display
, "XInputExtension", &xi_opcode
, &event
, &error
)) {
373 printf("X Input extension not available.\n");
377 if (!xinput_version(display
)) {
378 fprintf(stderr
, "%s extension not available\n", INAME
);
382 while(driver
->func_name
) {
383 if (strcmp(driver
->func_name
, func
) == 0) {
384 int r
= (*driver
->func
)(display
, argc
-2, argv
+2,
385 driver
->func_name
, driver
->arg_desc
);
386 XSync(display
, False
);
387 XCloseDisplay(display
);
398 /* end of xinput.c */