static XDevice * dp_get_device(Display * dpy) { XDevice *dev = NULL; XDeviceInfo *info = NULL; int ndevices = 0; Atom touchpad_type = 0; Atom synaptics_property = 0; Atom *properties = NULL; int nprops = 0; int error = 0; touchpad_type = XInternAtom(dpy, XI_TOUCHPAD, True); synaptics_property = XInternAtom(dpy, SYNAPTICS_PROP_EDGES, True); info = XListInputDevices(dpy, &ndevices); while (ndevices--) { if (info[ndevices].type == touchpad_type) { dev = XOpenDevice(dpy, info[ndevices].id); if (!dev) { fprintf(stderr, "Failed to open device '%s'.\n", info[ndevices].name); error = 1; goto unwind; } properties = XListDeviceProperties(dpy, dev, &nprops); if (!properties || !nprops) { fprintf(stderr, "No properties on device '%s'.\n", info[ndevices].name); error = 1; goto unwind; } while (nprops--) { if (properties[nprops] == synaptics_property) break; } if (!nprops) { fprintf(stderr, "No synaptics properties on device '%s'.\n", info[ndevices].name); error = 1; goto unwind; } break; /* Yay, device is suitable */ } } unwind: XFree(properties); XFreeDeviceList(info); if (!dev) fprintf(stderr, "Unable to find a synaptics device.\n"); else if (error && dev) { XCloseDevice(dpy, dev); dev = NULL; } return dev; }
static int list_props_xi1(Display *dpy, int argc, char** argv, char* name, char *desc) { XDeviceInfo *info; XDevice *dev; int i; int nprops; Atom *props; if (argc == 0) { fprintf(stderr, "Usage: xinput %s %s\n", name, desc); return EXIT_FAILURE; } for (i = 0; i < argc; i++) { info = find_device_info(dpy, argv[i], False); if (!info) { fprintf(stderr, "unable to find device %s\n", argv[i]); continue; } dev = XOpenDevice(dpy, info->id); if (!dev) { fprintf(stderr, "unable to open device '%s'\n", info->name); continue; } props = XListDeviceProperties(dpy, dev, &nprops); if (!nprops) { printf("Device '%s' does not report any properties.\n", info->name); continue; } printf("Device '%s':\n", info->name); while(nprops--) { print_property(dpy, dev, props[nprops]); } XFree(props); XCloseDevice(dpy, dev); } return EXIT_SUCCESS; }