void fetchWacomToolId(qint64 &serialId, qint64 &deviceId, QTabletDeviceData *tablet) { XDevice *dev = static_cast<XDevice*>(tablet->device); Atom prop = None, type; int format; unsigned char* data; unsigned long nitems, bytes_after; prop = XInternAtom(KIS_X11->display, WACOM_PROP_SERIALIDS, True); if (!prop) { // property doesn't exist return; } XGetDeviceProperty(KIS_X11->display, dev, prop, 0, 1000, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &data); if (nitems < 5 || format != 32) { // property offset doesn't exist return; } long *l = (long*)data; serialId = l[3]; // serial id of the stylus in proximity deviceId = l[4]; // device if of the stylus in proximity }
static gboolean device_has_property (XDevice *device, const char *property_name) { GdkDisplay *display; Atom realtype, prop; int realformat; unsigned long nitems, bytes_after; unsigned char *data; display = gdk_display_get_default (); prop = XInternAtom (GDK_DISPLAY_XDISPLAY (display), property_name, True); if (!prop) return FALSE; gdk_x11_display_error_trap_push (display); if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (display), device, prop, 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { gdk_x11_display_error_trap_pop_ignored (display); XFree (data); return TRUE; } gdk_x11_display_error_trap_pop_ignored (display); return FALSE; }
void synaptics_disable_3fingers_tap(Grabber* self, XDevice* dev) { Atom prop, type; double val; int format; unsigned long nitems, bytes_after; unsigned char* data = NULL; prop = XInternAtom(self->dpy, SYNAPTICS_PROP_TAP_ACTION, True); /* get current configuration */ XGetDeviceProperty(self->dpy, dev, prop, 0, 1000, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &data); char* b = (char*) data; int offset = 6; // the position of 3TAP_FINGER inside config /* change configuration if needed */ if (b[offset] != 0) { b[offset] = 0;//rint(val); XChangeDeviceProperty(self->dpy, dev, prop, type, format, PropModeReplace, data, nitems); XFlush(self->dpy); } }
int check_device(XDeviceInfo *info) { XDevice *device; Atom type; int format; unsigned long nitems, nbytes; unsigned char *retval; if (verbose) printf("Checking device %lu: %s...", info->id, info->name); device = XOpenDevice(display, info->id); XGetDeviceProperty(display, device, prop_calibration, 0, 4, False, XA_INTEGER, &type, &format, &nitems, &nbytes, &retval); XCloseDevice(display, device); if (nitems != 4) { if (verbose) printf("can't be calibrated\n"); return False; } if (verbose) printf("can be calibrated\n"); return True; }
XDevice* device_is_touchpad (XDeviceInfo deviceinfo) { XDevice *device; Atom realtype, prop; int realformat; unsigned long nitems, bytes_after; unsigned char *data; if (deviceinfo.type != XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), XI_TOUCHPAD, False)) return NULL; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Off", False); if (!prop) return NULL; gdk_error_trap_push (); device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), deviceinfo.id); if (gdk_error_trap_pop () || (device == NULL)) return NULL; gdk_error_trap_push (); if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop, 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { gdk_error_trap_pop (); XFree (data); return device; } gdk_error_trap_pop (); XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device); return NULL; }
gboolean device_is_touchpad (XDevice *xdevice) { Atom realtype, prop; int realformat; unsigned long nitems, bytes_after; unsigned char *data; /* we don't check on the type being XI_TOUCHPAD here, * but having a "Synaptics Off" property should be enough */ prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Off", False); if (!prop) return FALSE; gdk_error_trap_push (); if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { gdk_error_trap_pop_ignored (); XFree (data); return TRUE; } gdk_error_trap_pop_ignored (); return FALSE; }
int uncalibrate(XDevice *device) { Atom type; int format; unsigned long nitems, nbytes; long values[4] = { 0, 32767, 0, 32767 }; /* uncalibrated */ Bool swap = 0; unsigned char *retval; /* Save old values */ XGetDeviceProperty(display, device, prop_calibration, 0, 4, False, XA_INTEGER, &type, &format, &nitems, &nbytes, &retval); if (type != XA_INTEGER) { fprintf(stderr, "Device property \"%s\": invalid type %s\n", WS_PROP_CALIBRATION, XGetAtomName(display, type)); return -1; } if (nitems != 4 && nitems != 0) { fprintf(stderr, "Device property \"%s\": " "invalid number of items %ld\n", WS_PROP_CALIBRATION, nitems); return -1; } old_calib.minx = *(long *)retval; old_calib.maxx = *((long *)retval + 1); old_calib.miny = *((long *)retval + 2); old_calib.maxy = *((long *)retval + 3); XFree(retval); XGetDeviceProperty(display, device, prop_swap, 0, 1, False, XA_INTEGER, &type, &format, &nitems, &nbytes, &retval); old_swap = *(Bool *)retval; XFree(retval); /* Force uncalibrated state */ XChangeDeviceProperty(display, device, prop_calibration, XA_INTEGER, 32, PropModeReplace, (unsigned char *)values, 4); XChangeDeviceProperty(display, device, prop_swap, XA_INTEGER, 8, PropModeReplace, (unsigned char *)&swap, 1); return 0; }
gboolean device_set_property (XDevice *xdevice, const char *device_name, PropertyHelper *property) { int rc, i; Atom prop; Atom realtype; int realformat; unsigned long nitems, bytes_after; unsigned char *data; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), property->name, False); if (!prop) return FALSE; gdk_error_trap_push (); rc = XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, 0, property->nitems, False, AnyPropertyType, &realtype, &realformat, &nitems, &bytes_after, &data); if (rc != Success || realtype != property->type || realformat != property->format || nitems < property->nitems) { gdk_error_trap_pop_ignored (); g_warning ("Error reading property \"%s\" for \"%s\"", property->name, device_name); return FALSE; } for (i = 0; i < nitems; i++) { switch (property->format) { case 8: data[i] = property->data.c[i]; break; case 32: ((long*)data)[i] = property->data.i[i]; break; } } XChangeDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), xdevice, prop, realtype, realformat, PropModeReplace, data, nitems); XFree (data); if (gdk_error_trap_pop ()) { g_warning ("Error in setting \"%s\" for \"%s\"", property->name, device_name); return FALSE; } return TRUE; }
static gboolean find_synaptics (void) { gboolean ret = FALSE; #ifdef HAVE_XINPUT int numdevices, i; XDeviceInfo *devicelist; Atom realtype, prop; int realformat; unsigned long nitems, bytes_after; unsigned char *data; XExtensionVersion *version; /* Input device properties require version 1.5 or higher */ version = XGetExtensionVersion (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "XInputExtension"); if (!version->present || (version->major_version * 1000 + version->minor_version) < 1005) { XFree (version); return False; } prop = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Off", True); if (!prop) return False; devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); for (i = 0; i < numdevices; i++) { if (devicelist[i].use != IsXExtensionPointer) continue; gdk_error_trap_push(); XDevice *device = XOpenDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), devicelist[i].id); if (gdk_error_trap_pop ()) continue; gdk_error_trap_push (); if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { XFree (data); ret = TRUE; } gdk_error_trap_pop (); XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); if (ret) break; } XFree (version); XFreeDeviceList (devicelist); #endif return ret; }
void QTabletDeviceData::SavedAxesData::tryFetchAxesMapping(XDevice *dev) { Atom propertyType; int propertyFormat; unsigned long nitems; unsigned long bytes_after; unsigned char *prop; int result = XGetDeviceProperty(KIS_X11->display, dev, KIS_ATOM(AxisLabels), 0, 16, false, AnyPropertyType, &propertyType, &propertyFormat, &nitems, &bytes_after, &prop); if (result == Success && propertyType > 0) { if (KisTabletDebugger::instance()->initializationDebugEnabled()) { dbgTablet << "# Building tablet axes remapping table:"; } QVector<AxesIndexes> axesMap(nitems, Unused); for (unsigned int axisIndex = 0; axisIndex < nitems; axisIndex++) { Atom currentAxisName = ((Atom*)prop)[axisIndex]; AxesIndexes mappedIndex = Unused; if (currentAxisName == KIS_ATOM(AbsX)) { mappedIndex = XCoord; } else if (currentAxisName == KIS_ATOM(AbsY)) { mappedIndex = YCoord; } else if (currentAxisName == KIS_ATOM(AbsPressure)) { mappedIndex = Pressure; } else if (currentAxisName == KIS_ATOM(AbsTiltX)) { mappedIndex = XTilt; } else if (currentAxisName == KIS_ATOM(AbsTiltY)) { mappedIndex = YTilt; } axesMap[axisIndex] = mappedIndex; if (KisTabletDebugger::instance()->initializationDebugEnabled()) { dbgTablet << XGetAtomName(KIS_X11->display, currentAxisName) << axisIndex << "->" << mappedIndex; } } this->setAxesMap(axesMap); } }
static void synaptics_check_capabilities (GtkBuilder *dialog) { #ifdef HAVE_XINPUT int numdevices, i; XDeviceInfo *devicelist; Atom realtype, prop; int realformat; unsigned long nitems, bytes_after; unsigned char *data; prop = XInternAtom (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), "Synaptics Capabilities", True); if (!prop) return; devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), &numdevices); for (i = 0; i < numdevices; i++) { if (devicelist[i].use != IsXExtensionPointer) continue; gdk_error_trap_push (); XDevice *device = XOpenDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), devicelist[i].id); if (gdk_error_trap_pop ()) continue; gdk_error_trap_push (); if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device, prop, 0, 2, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { /* Property data is booleans for has_left, has_middle, * has_right, has_double, has_triple */ if (!data[0]) { gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (WID ("tap_to_click_toggle")), TRUE); gtk_widget_set_sensitive (WID ("tap_to_click_toggle"), FALSE); } if (!data[3]) gtk_widget_set_sensitive (WID ("scroll_twofinger_radio"), FALSE); XFree (data); } gdk_error_trap_pop (); XCloseDevice (GDK_DISPLAY_XDISPLAY(gdk_display_get_default()), device); } XFreeDeviceList (devicelist); #endif }
static void store_current_touchpad_state(void) { Atom real_type; int real_format; unsigned long nitems, bytes_after; unsigned char *data; if ((XGetDeviceProperty(display, dev, touchpad_off_prop, 0, 1, False, XA_INTEGER, &real_type, &real_format, &nitems, &bytes_after, &data) == Success) && (real_type != None)) { previous_state = data[0]; } }
static void synaptics_check_capabilities (GtkBuilder *dialog) { int numdevices, i; XDeviceInfo *devicelist; Atom realtype, prop; int realformat; unsigned long nitems, bytes_after; unsigned char *data; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Capabilities", True); if (!prop) return; devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &numdevices); for (i = 0; i < numdevices; i++) { if (devicelist[i].use != IsXExtensionPointer) continue; gdk_error_trap_push (); XDevice *device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), devicelist[i].id); if (gdk_error_trap_pop ()) continue; gdk_error_trap_push (); if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop, 0, 2, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { /* Property data is booleans for has_left, has_middle, has_right, has_double, has_triple. * Newer drivers (X.org/kerrnel) will also include has_pressure and has_width. */ if (!data[0]) { gtk_widget_set_sensitive (WID ("tap_to_click_toggle"), FALSE); } /* Disable two finger scrolling unless the hardware supports * double touch */ if (!(data[3])) gtk_widget_set_sensitive (WID ("two_finger_scroll_toggle"), FALSE); XFree (data); } gdk_error_trap_pop_ignored (); XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device); } XFreeDeviceList (devicelist); }
static int do_set_prop_xi1(Display *dpy, Atom type, int format, int argc, char **argv, char *n, char *desc) { XDeviceInfo *info; XDevice *dev; Atom prop; Atom old_type; char *name; int i; Atom float_atom; int old_format, nelements = 0; unsigned long act_nitems, bytes_after; char *endptr; union { unsigned char *c; short *s; long *l; Atom *a; } data; if (argc < 3) { fprintf(stderr, "Usage: xinput %s %s\n", n, desc); return EXIT_FAILURE; } info = find_device_info(dpy, argv[0], False); if (!info) { fprintf(stderr, "unable to find device %s\n", argv[0]); return EXIT_FAILURE; } dev = XOpenDevice(dpy, info->id); if (!dev) { fprintf(stderr, "unable to open device %s\n", argv[0]); return EXIT_FAILURE; } name = argv[1]; prop = parse_atom(dpy, name); if (prop == None) { fprintf(stderr, "invalid property %s\n", name); return EXIT_FAILURE; } float_atom = XInternAtom(dpy, "FLOAT", False); nelements = argc - 2; if (type == None || format == 0) { if (XGetDeviceProperty(dpy, dev, prop, 0, 0, False, AnyPropertyType, &old_type, &old_format, &act_nitems, &bytes_after, &data.c) != Success) { fprintf(stderr, "failed to get property type and format for %s\n", name); return EXIT_FAILURE; } else { if (type == None) type = old_type; if (format == 0) format = old_format; } XFree(data.c); } if (type == None) { fprintf(stderr, "property %s doesn't exist, you need to specify " "its type and format\n", name); return EXIT_FAILURE; } data.c = calloc(nelements, sizeof(long)); for (i = 0; i < nelements; i++) { if (type == XA_INTEGER) { switch (format) { case 8: data.c[i] = atoi(argv[2 + i]); break; case 16: data.s[i] = atoi(argv[2 + i]); break; case 32: data.l[i] = atoi(argv[2 + i]); break; default: fprintf(stderr, "unexpected size for property %s", name); return EXIT_FAILURE; } } else if (type == float_atom) { if (format != 32) { fprintf(stderr, "unexpected format %d for property %s\n", format, name); return EXIT_FAILURE; } *(float *)(data.l + i) = strtod(argv[2 + i], &endptr); if (endptr == argv[2 + i]) { fprintf(stderr, "argument %s could not be parsed\n", argv[2 + i]); return EXIT_FAILURE; } } else if (type == XA_ATOM) { if (format != 32) { fprintf(stderr, "unexpected format %d for property %s\n", format, name); return EXIT_FAILURE; } data.a[i] = parse_atom(dpy, argv[2 + i]); } else { fprintf(stderr, "unexpected type for property %s\n", name); return EXIT_FAILURE; } } XChangeDeviceProperty(dpy, dev, prop, type, format, PropModeReplace, data.c, nelements); free(data.c); XCloseDevice(dpy, dev); return EXIT_SUCCESS; }
static void synaptics_check_capabilities_x11 (CcMousePropertiesPrivate *d) { int numdevices, i; XDeviceInfo *devicelist; Atom realtype, prop_capabilities, prop_scroll_methods, prop_tapping_enabled; int realformat; unsigned long nitems, bytes_after; unsigned char *data; gboolean tap_to_click, two_finger_scroll; prop_capabilities = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Synaptics Capabilities", False); prop_scroll_methods = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "libinput Scroll Methods Available", False); prop_tapping_enabled = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "libinput Tapping Enabled", False); if (!prop_capabilities || !prop_scroll_methods || !prop_tapping_enabled) return; tap_to_click = FALSE; two_finger_scroll = FALSE; devicelist = XListInputDevices (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), &numdevices); for (i = 0; i < numdevices; i++) { if (devicelist[i].use != IsXExtensionPointer) continue; gdk_error_trap_push (); XDevice *device = XOpenDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), devicelist[i].id); if (gdk_error_trap_pop ()) continue; gdk_error_trap_push (); /* xorg-x11-drv-synaptics */ if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop_capabilities, 0, 2, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { /* Property data is booleans for has_left, has_middle, has_right, has_double, has_triple. * Newer drivers (X.org/kerrnel) will also include has_pressure and has_width. */ /* Set tap_to_click_toggle sensitive only if the device has hardware buttons */ if (data[0]) tap_to_click = TRUE; /* Set two_finger_scroll_toggle sensitive if the hardware supports double touch */ if (data[3]) two_finger_scroll = TRUE; XFree (data); } /* xorg-x11-drv-libinput */ if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop_scroll_methods, 0, 2, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { /* Property data is booleans for two-finger, edge, on-button scroll available. */ if (data[0] && data[1]) two_finger_scroll = TRUE; XFree (data); } if ((XGetDeviceProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device, prop_tapping_enabled, 0, 1, False, XA_INTEGER, &realtype, &realformat, &nitems, &bytes_after, &data) == Success) && (realtype != None)) { /* Property data is boolean for tapping enabled. */ tap_to_click = TRUE; XFree (data); } gdk_error_trap_pop_ignored (); XCloseDevice (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device); } XFreeDeviceList (devicelist); gtk_widget_set_sensitive (WID ("tap_to_click_toggle"), tap_to_click); gtk_widget_set_sensitive (WID ("two_finger_scroll_toggle"), two_finger_scroll); }
static void print_property(Display *dpy, XDevice* dev, Atom property) { Atom act_type; char *name; int act_format; unsigned long nitems, bytes_after; unsigned char *data, *ptr; int j, done = False, size; name = XGetAtomName(dpy, property); printf("\t%s (%ld):\t", name, property); if (XGetDeviceProperty(dpy, dev, property, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) == Success) { Atom float_atom = XInternAtom(dpy, "FLOAT", True); ptr = data; if (nitems == 0) printf("<no items>"); switch(act_format) { case 8: size = sizeof(char); break; case 16: size = sizeof(short); break; case 32: size = sizeof(long); break; } for (j = 0; j < nitems; j++) { switch(act_type) { case XA_INTEGER: switch(act_format) { case 8: printf("%d", *((char*)ptr)); break; case 16: printf("%d", *((short*)ptr)); break; case 32: printf("%ld", *((long*)ptr)); break; } break; case XA_STRING: if (act_format != 8) { printf("Unknown string format.\n"); done = True; break; } printf("\"%s\"", ptr); j += strlen((char*)ptr); /* The loop's j++ jumps over the terminating 0 */ ptr += strlen((char*)ptr); /* ptr += size below jumps over the terminating 0 */ break; case XA_ATOM: { Atom a = *(Atom*)ptr; printf("\"%s\" (%d)", (a) ? XGetAtomName(dpy, a) : "None", (int)a); break; } default: if (float_atom != None && act_type == float_atom) { printf("%f", *((float*)ptr)); break; } printf("\t... of unknown type %s\n", XGetAtomName(dpy, act_type)); done = True; break; } ptr += size; if (done == True) break; if (j < nitems - 1) printf(", "); } printf("\n"); XFree(data); } else printf("\tFetch failure\n"); }
// Constructor CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& axys0, XID device_id, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const bool use_valuator, const bool use_timeout, const char* output_filename) : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename) { // init display = XOpenDisplay(NULL); if (display == NULL) { throw WrongCalibratorException("Evdev: Unable to connect to X server"); } // normaly, we already have the device id if (device_id == (XID)-1) { devInfo = xinput_find_device_info(display, device_name, False); if (!devInfo) { XCloseDisplay(display); throw WrongCalibratorException("Evdev: Unable to find device"); } device_id = devInfo->id; } dev = XOpenDevice(display, device_id); if (!dev) { XCloseDisplay(display); throw WrongCalibratorException("Evdev: Unable to open device"); } #ifndef HAVE_XI_PROP throw WrongCalibratorException("Evdev: you need at least libXi 1.2 and inputproto 1.5 for dynamic recalibration of evdev."); #else // XGetDeviceProperty vars Atom property; Atom act_type; int act_format; unsigned long nitems, bytes_after; unsigned char *data, *ptr; // get "Evdev Axis Calibration" property property = xinput_parse_atom(display, "Evdev Axis Calibration"); if (XGetDeviceProperty(display, dev, property, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) != Success) { XCloseDevice(display, dev); XCloseDisplay(display); throw WrongCalibratorException("Evdev: \"Evdev Axis Calibration\" property missing, not a (valid) evdev device"); } else { if (act_format != 32 || act_type != XA_INTEGER) { XCloseDevice(display, dev); XCloseDisplay(display); throw WrongCalibratorException("Evdev: invalid \"Evdev Axis Calibration\" property format"); } else if (use_valuator) { int ndevices = 0, i, j; XIDeviceInfo *info = XIQueryDevice(display, device_id, &ndevices); if (ndevices != 1) { XCloseDevice(display, dev); XCloseDisplay(display); throw WrongCalibratorException("Evdev: unknown Xinput device ID???"); } for (i = 0; i < ndevices; i++) { XIDeviceInfo *dev = &info[i]; for (j = 0; j < dev->num_classes; j++) { switch(dev->classes[i]->type) { case XIValuatorClass: { XIValuatorClassInfo *v = (XIValuatorClassInfo*)dev->classes[i]; /* Valuator 0 = X, Valuator 1 = Y, others are ignored */ switch (v->number) { case 0: old_axys.x.min = v->min; old_axys.x.max = v->max; old_axys.x.invert = false; break; case 1: old_axys.y.min = v->min; old_axys.y.max = v->max; old_axys.y.invert = false; break; default: break; } break; } default: break; } } } XIFreeDeviceInfo(info); if (verbose) printf("DEBUG: Evdev Axis Calibration set to axis valuators\n"); (void) set_calibration(old_axys); } else if (nitems == 0) { if (verbose) printf("DEBUG: Evdev Axis Calibration not set, setting to axis valuators to be sure.\n"); // No axis calibration set, set it to the default one // QUIRK: when my machine resumes from a sleep, // the calibration property is no longer exported through xinput, but still active // not setting the values here would result in a wrong first calibration (void) set_calibration(old_axys); } else if (nitems > 0) { ptr = data; old_axys.x.min = *((long*)ptr); ptr += sizeof(long); old_axys.x.max = *((long*)ptr); ptr += sizeof(long); old_axys.y.min = *((long*)ptr); ptr += sizeof(long); old_axys.y.max = *((long*)ptr); ptr += sizeof(long); } XFree(data); } // get "Evdev Axes Swap" property property = xinput_parse_atom(display, "Evdev Axes Swap"); if (XGetDeviceProperty(display, dev, property, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) == Success) { if (act_format == 8 && act_type == XA_INTEGER && nitems == 1) { old_axys.swap_xy = *((char*)data); if (verbose) printf("DEBUG: Read axes swap value of %i.\n", old_axys.swap_xy); } } // get "Evdev Axes Inversion" property property = xinput_parse_atom(display, "Evdev Axis Inversion"); if (XGetDeviceProperty(display, dev, property, 0, 1000, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data) == Success) { if (act_format == 8 && act_type == XA_INTEGER && nitems == 2) { old_axys.x.invert = *((char*)data++); old_axys.y.invert = *((char*)data); if (verbose) printf("DEBUG: Read InvertX=%i, InvertY=%i.\n", old_axys.x.invert, old_axys.y.invert); } } printf("Calibrating EVDEV driver for \"%s\" id=%i\n", device_name, (int)device_id); printf("\tcurrent calibration values (from XInput): min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", old_axys.x.min, old_axys.x.max, old_axys.y.min, old_axys.y.max); #endif // HAVE_XI_PROP }
// Set Integer property on X bool CalibratorEvdev::xinput_do_set_int_prop( const char * name, Display *display, int format, int argc, const int *argv ) { #ifndef HAVE_XI_PROP return false; #else Atom prop; Atom old_type; int i; int old_format; unsigned long act_nitems, bytes_after; union { unsigned char *c; short *s; long *l; Atom *a; } data; if (argc < 1) { fprintf(stderr, "Wrong usage of xinput_do_set_prop, need at least 1 arguments\n"); return false; } prop = xinput_parse_atom(display, name); if (prop == None) { fprintf(stderr, "invalid property %s\n", name); return false; } if ( format == 0) { if (XGetDeviceProperty(display, dev, prop, 0, 0, False, AnyPropertyType, &old_type, &old_format, &act_nitems, &bytes_after, &data.c) != Success) { fprintf(stderr, "failed to get property type and format for %s\n", name); return false; } else { format = old_format; } XFree(data.c); } data.c = (unsigned char*)calloc(argc, sizeof(long)); for (i = 0; i < argc; i++) { switch (format) { case 8: data.c[i] = argv[i]; case 16: data.s[i] = argv[i]; break; case 32: data.l[i] = argv[i]; break; default: fprintf(stderr, "unexpected size for property %s\n", name); return false; } } XChangeDeviceProperty(display, dev, prop, XA_INTEGER, format, PropModeReplace, data.c, argc); free(data.c); return true; #endif // HAVE_XI_PROP }
static void dp_set_variables(Display *dpy, XDevice* dev, int argc, char *argv[], int first_cmd) { int i; double val; struct Parameter *par; Atom prop, type, float_type; int format; unsigned char* data; unsigned long nitems, bytes_after; union flong *f; long *n; char *b; float_type = XInternAtom(dpy, XATOM_FLOAT, True); if (!float_type) fprintf(stderr, "Float properties not available.\n"); for (i = first_cmd; i < argc; i++) { val = parse_cmd(argv[i], &par); if (!par) continue; prop = XInternAtom(dpy, par->prop_name, True); if (!prop) { fprintf(stderr, "Property for '%s' not available. Skipping.\n", par->name); continue; } XGetDeviceProperty(dpy, dev, prop, 0, 1000, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &data); switch(par->prop_format) { case 8: if (format != par->prop_format || type != XA_INTEGER) { fprintf(stderr, " %-23s = format mismatch (%d)\n", par->name, format); break; } b = (char*)data; b[par->prop_offset] = rint(val); break; case 32: if (format != par->prop_format || type != XA_INTEGER) { fprintf(stderr, " %-23s = format mismatch (%d)\n", par->name, format); break; } n = (long*)data; n[par->prop_offset] = rint(val); break; case 0: /* float */ if (!float_type) continue; if (format != 32 || type != float_type) { fprintf(stderr, " %-23s = format mismatch (%d)\n", par->name, format); break; } f = (union flong*)data; f[par->prop_offset].f = val; break; } XChangeDeviceProperty(dpy, dev, prop, type, format, PropModeReplace, data, nitems); XFlush(dpy); } }
/* FIXME: horribly inefficient. */ static void dp_show_settings(Display *dpy, XDevice *dev) { int j; Atom a, type, float_type; int format; unsigned long nitems, bytes_after; unsigned char* data; int len; union flong *f; long *i; char *b; float_type = XInternAtom(dpy, XATOM_FLOAT, True); if (!float_type) fprintf(stderr, "Float properties not available.\n"); printf("Parameter settings:\n"); for (j = 0; params[j].name; j++) { struct Parameter *par = ¶ms[j]; a = XInternAtom(dpy, par->prop_name, True); if (!a) continue; len = 1 + ((par->prop_offset * (par->prop_format ? par->prop_format : 32)/8))/4; XGetDeviceProperty(dpy, dev, a, 0, len, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &data); switch(par->prop_format) { case 8: if (format != par->prop_format || type != XA_INTEGER) { fprintf(stderr, " %-23s = format mismatch (%d)\n", par->name, format); break; } b = (char*)data; printf(" %-23s = %d\n", par->name, b[par->prop_offset]); break; case 32: if (format != par->prop_format || type != XA_INTEGER) { fprintf(stderr, " %-23s = format mismatch (%d)\n", par->name, format); break; } i = (long*)data; printf(" %-23s = %ld\n", par->name, i[par->prop_offset]); break; case 0: /* Float */ if (!float_type) continue; if (format != 32 || type != float_type) { fprintf(stderr, " %-23s = format mismatch (%d)\n", par->name, format); break; } f = (union flong*)data; printf(" %-23s = %g\n", par->name, f[par->prop_offset].f); break; } XFree(data); } }