static void change_property (ClutterInputDevice *device, const gchar *property, Atom type, int format, void *data, gulong nitems) { MetaBackend *backend = meta_get_backend (); Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); int device_id; Atom property_atom; guchar *data_ret; property_atom = XInternAtom (xdisplay, property, False); device_id = clutter_input_device_get_device_id (device); data_ret = get_property (device, property, type, format, nitems); if (!data_ret) return; XIChangeProperty (xdisplay, device_id, property_atom, type, format, XIPropModeReplace, data, nitems); meta_XFree (data_ret); }
int set_prop(int id, const char* prop, unsigned char* data, int nitems, Atom type, Atom format) { if (!prop) { fprintf(stderr, "[set_prop] Empty property for %d\n", id); return -1; } if (!data || nitems < 1) { fprintf(stderr, "[set_prop] Invalid data or item number for %d\n", id); return -1; } Display* disp = XOpenDisplay(0); if (!disp) { fprintf(stderr, "[set_prop] Open display failed for %d\n", id); return -1; } Atom prop_id = XInternAtom(disp, prop, True); if (prop_id == None) { XCloseDisplay(disp); fprintf(stderr, "[set_prop] Intern atom %s failed\n", prop); return -1; } XIChangeProperty(disp, id, prop_id, type, format, XIPropModeReplace, data, nitems); /* XFree(&prop_id); */ XCloseDisplay(disp); return 0; }
/* * Evdev Middle Button Emulation * 1 boolean value (8 bit, 0 or 1). */ int set_middle_button_emulation(int deviceid, int enabled) { Display *disp = XOpenDisplay(0); if (!disp) { fprintf(stderr, "Args error in set_middle_button_emulation\n"); return -1; } char *prop_name = "Evdev Middle Button Emulation"; Atom prop = XInternAtom( disp, prop_name, True); if (prop == None) { fprintf(stderr, "Get '%s' Atom Failed\n", prop_name); XCloseDisplay(disp); return -1; } unsigned char data = 0; if (enabled == 1) { data = 1; } XIChangeProperty(disp, deviceid, prop, XA_INTEGER, 8, XIPropModeReplace, &data, 1); XCloseDisplay(disp); return 0; }
static int apply_matrix(Display *dpy, int deviceid, Matrix *m) { Atom prop_float, prop_matrix; union { unsigned char *c; float *f; } data; int format_return; Atom type_return; unsigned long nitems; unsigned long bytes_after; int rc; prop_float = XInternAtom(dpy, "FLOAT", False); prop_matrix = XInternAtom(dpy, "Coordinate Transformation Matrix", False); if (!prop_float) { fprintf(stderr, "Float atom not found. This server is too old.\n"); return EXIT_FAILURE; } if (!prop_matrix) { fprintf(stderr, "Coordinate transformation matrix not found. This " "server is too old\n"); return EXIT_FAILURE; } rc = XIGetProperty(dpy, deviceid, prop_matrix, 0, 9, False, prop_float, &type_return, &format_return, &nitems, &bytes_after, &data.c); if (rc != Success || prop_float != type_return || format_return != 32 || nitems != 9 || bytes_after != 0) { fprintf(stderr, "Failed to retrieve current property values\n"); return EXIT_FAILURE; } memcpy(data.f, m->m, sizeof(m->m)); XIChangeProperty(dpy, deviceid, prop_matrix, prop_float, format_return, PropModeReplace, data.c, nitems); XFree(data.c); return EXIT_SUCCESS; }
static int set_prop_float (Display *disp, int deviceid, const char *prop_name, double value) { if (!disp || !prop_name) { fprintf(stderr, "Args error in set_prop_float\n"); return -1; } Atom prop = XInternAtom( disp, prop_name, True); if (prop == None) { fprintf(stderr, "Get '%s' Atom Failed\n", prop_name); return -1; } Atom act_type; int act_format; unsigned long nitems, bytes_after; unsigned char *data; int rc = XIGetProperty(disp, deviceid, prop, 0, 1, False, AnyPropertyType, &act_type, &act_format, &nitems, &bytes_after, &data); if (rc != Success) { fprintf(stderr, "Get '%ld' property failed\n", prop); return -1; } Atom float_atom = XInternAtom(disp, "FLOAT", True); if (float_atom != None && act_type == float_atom && nitems == 1) { *(float*)data = (float)value; XIChangeProperty(disp, deviceid, prop, act_type, act_format, XIPropModeReplace, data, nitems); } XFree(data); return 0; }
gboolean set_device_enabled (int device_id, gboolean enabled) { Atom prop; guchar value; prop = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "Device Enabled", False); if (!prop) return FALSE; gdk_error_trap_push (); value = enabled ? 1 : 0; XIChangeProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), device_id, prop, XA_INTEGER, 8, PropModeReplace, &value, 1); if (gdk_error_trap_pop ()) return FALSE; return TRUE; }
static int do_set_prop_xi2(Display *dpy, Atom type, int format, int argc, char **argv, char *n, char *desc) { XIDeviceInfo *info; 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; int16_t *s; int32_t *l; } data; if (argc < 3) { fprintf(stderr, "Usage: xinput %s %s\n", n, desc); return EXIT_FAILURE; } info = xi2_find_device_info(dpy, argv[0]); if (!info) { fprintf(stderr, "unable to find 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 (XIGetProperty(dpy, info->deviceid, 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(int32_t)); 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.l[i] = parse_atom(dpy, argv[2 + i]); } else { fprintf(stderr, "unexpected type for property %s\n", name); return EXIT_FAILURE; } } XIChangeProperty(dpy, info->deviceid, prop, type, format, PropModeReplace, data.c, nelements); free(data.c); return EXIT_SUCCESS; }