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];
235 Bool is_pointer(int use)
237 return use == XIMasterPointer || use == XISlavePointer;
240 Bool is_keyboard(int use)
242 return use == XIMasterKeyboard || use == XISlaveKeyboard;
245 Bool device_matches(XIDeviceInfo *info, char *name)
247 if (strcmp(info->name, name) == 0) {
251 if (strncmp(name, "pointer:", strlen("pointer:")) == 0 &&
252 strcmp(info->name, name + strlen("pointer:")) == 0 &&
253 is_pointer(info->use)) {
257 if (strncmp(name, "keyboard:", strlen("keyboard:")) == 0 &&
258 strcmp(info->name, name + strlen("keyboard:")) == 0 &&
259 is_keyboard(info->use)) {
267 xi2_find_device_info(Display *display, char *name)
270 XIDeviceInfo *found = NULL;
275 for(i = 0; i < strlen(name); i++) {
276 if (!isdigit(name[i])) {
286 info = XIQueryDevice(display, XIAllDevices, &ndevices);
287 for(i = 0; i < ndevices; i++)
289 if (is_id ? info[i].deviceid == id : device_matches (&info[i], name)) {
292 "Warning: There are multiple devices matching '%s'.\n"
293 "To ensure the correct one is selected, please use "
294 "the device ID, or prefix the\ndevice name with "
295 "'pointer:' or 'keyboard:' as appropriate.\n\n", name);
296 XIFreeDeviceInfo(info);
311 entry *pdriver = drivers;
313 fprintf(stderr, "usage :\n");
315 while(pdriver->func_name) {
316 fprintf(stderr, "\txinput %s %s\n", pdriver->func_name,
323 main(int argc, char * argv[])
326 entry *driver = drivers;
336 while((*func) == '-') func++;
338 if (strcmp("version", func) == 0) {
339 return print_version(argv[0]);
342 display = XOpenDisplay(NULL);
344 if (display == NULL) {
345 fprintf(stderr, "Unable to connect to X server\n");
349 if (!XQueryExtension(display, "XInputExtension", &xi_opcode, &event, &error)) {
350 printf("X Input extension not available.\n");
354 if (!xinput_version(display)) {
355 fprintf(stderr, "%s extension not available\n", INAME);
359 while(driver->func_name) {
360 if (strcmp(driver->func_name, func) == 0) {
361 int r = (*driver->func)(display, argc-2, argv+2,
362 driver->func_name, driver->arg_desc);
363 XSync(display, False);
364 XCloseDisplay(display);
375 /* end of xinput.c */