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)
214 XIQueryVersion(display, &maj, &min);
222 find_device_info(Display *display,
226 XDeviceInfo *devices;
227 XDeviceInfo *found = NULL;
230 int len = strlen(name);
234 for(loop=0; loop<len; loop++) {
235 if (!isdigit(name[loop])) {
245 devices = XListInputDevices(display, &num_devices);
247 for(loop=0; loop<num_devices; loop++) {
248 if ((!only_extended || (devices[loop].use >= IsXExtensionDevice)) &&
249 ((!is_id && strcmp(devices[loop].name, name) == 0) ||
250 (is_id && devices[loop].id == id))) {
253 "Warning: There are multiple devices named '%s'.\n"
254 "To ensure the correct one is selected, please use "
255 "the device ID instead.\n\n", name);
258 found = &devices[loop];
266 Bool is_pointer(int use)
268 return use == XIMasterPointer || use == XISlavePointer;
271 Bool is_keyboard(int use)
273 return use == XIMasterKeyboard || use == XISlaveKeyboard;
276 Bool device_matches(XIDeviceInfo *info, char *name)
278 if (strcmp(info->name, name) == 0) {
282 if (strncmp(name, "pointer:", strlen("pointer:")) == 0 &&
283 strcmp(info->name, name + strlen("pointer:")) == 0 &&
284 is_pointer(info->use)) {
288 if (strncmp(name, "keyboard:", strlen("keyboard:")) == 0 &&
289 strcmp(info->name, name + strlen("keyboard:")) == 0 &&
290 is_keyboard(info->use)) {
298 xi2_find_device_info(Display *display, char *name)
301 XIDeviceInfo *found = NULL;
306 for(i = 0; i < strlen(name); i++) {
307 if (!isdigit(name[i])) {
317 info = XIQueryDevice(display, XIAllDevices, &ndevices);
318 for(i = 0; i < ndevices; i++)
320 if (is_id ? info[i].deviceid == id : device_matches (&info[i], name)) {
323 "Warning: There are multiple devices matching '%s'.\n"
324 "To ensure the correct one is selected, please use "
325 "the device ID, or prefix the\ndevice name with "
326 "'pointer:' or 'keyboard:' as appropriate.\n\n", name);
327 XIFreeDeviceInfo(info);
342 entry *pdriver = drivers;
344 fprintf(stderr, "usage :\n");
346 while(pdriver->func_name) {
347 fprintf(stderr, "\txinput %s %s\n", pdriver->func_name,
354 main(int argc, char * argv[])
357 entry *driver = drivers;
363 while(func[0] == '-') func++;
368 if (strcmp("version", func) == 0) {
369 return print_version();
372 if (strcmp("help", func) == 0) {
377 display = XOpenDisplay(NULL);
379 if (display == NULL) {
380 fprintf(stderr, "Unable to connect to X server\n");
384 if (!XQueryExtension(display, "XInputExtension", &xi_opcode, &event, &error)) {
385 printf("X Input extension not available.\n");
389 if (!xinput_version(display)) {
390 fprintf(stderr, "%s extension not available\n", INAME);
394 while(driver->func_name) {
395 if (strcmp(driver->func_name, func) == 0) {
396 int r = (*driver->func)(display, argc-2, argv+2,
397 driver->func_name, driver->arg_desc);
398 XSync(display, False);
399 XCloseDisplay(display);
409 XCloseDisplay(display);
413 /* end of xinput.c */