A generic touchscreen calibration program for X.Org
Revisión | c87e35513e89ae0018bc8088df4cabb3d2fe0bc6 (tree) |
---|---|
Tiempo | 2011-04-20 19:24:48 |
Autor | Antoine Hue <antoine@peti...> |
Commiter | Tias Guns |
Fixing xinput_do_set_prop into cleaner xinput_do_set_int_prop Also fixing property issue on invert axes
@@ -105,12 +105,7 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, | ||
105 | 105 | // QUIRK: when my machine resumes from a sleep, |
106 | 106 | // the calibration property is no longer exported through xinput, but still active |
107 | 107 | // not setting the values here would result in a wrong first calibration |
108 | - bool ok = set_calibration(old_axys); | |
109 | - | |
110 | - if (ok) | |
111 | - trace("Successfully applied axis calibration.\n"); | |
112 | - else | |
113 | - trace("Failed to apply axis calibration.\n"); | |
108 | + set_calibration(old_axys); | |
114 | 109 | |
115 | 110 | } else if (nitems > 0) { |
116 | 111 | ptr = data; |
@@ -223,71 +218,52 @@ bool CalibratorEvdev::finish_data(const XYinfo new_axys) | ||
223 | 218 | |
224 | 219 | bool CalibratorEvdev::set_swapxy(const int swap_xy) |
225 | 220 | { |
226 | - // xinput set-int-prop "divername" "Evdev Axes Swap" 8 0 | |
227 | - const char* arr_cmd[3]; | |
228 | - //arr_cmd[0] = ""; | |
229 | - arr_cmd[1] = "Evdev Axes Swap"; | |
230 | - char str_swap_xy[20]; | |
231 | - snprintf(str_swap_xy, 20, "%d", swap_xy); | |
232 | - arr_cmd[2] = str_swap_xy; | |
221 | + int arr_cmd[1]; | |
222 | + arr_cmd[0] = swap_xy; | |
233 | 223 | |
234 | - int ret = xinput_do_set_prop(display, XA_INTEGER, 8, 3, arr_cmd); | |
224 | + bool ret = xinput_do_set_int_prop("Evdev Axes Swap", display, 8, 1, arr_cmd); | |
235 | 225 | |
236 | - if (ret == EXIT_SUCCESS) | |
226 | + if (ret == true) | |
237 | 227 | trace("Successfully set swapped X and Y axes = %d.\n", swap_xy); |
238 | 228 | else |
239 | 229 | trace("Failed to set swap X and Y axes.\n"); |
240 | 230 | |
241 | - return (ret == EXIT_SUCCESS); | |
231 | + return ret; | |
242 | 232 | } |
243 | 233 | |
244 | 234 | bool CalibratorEvdev::set_invert_xy(bool axisX, const int invert_x, const int invert_y) |
245 | 235 | { |
246 | - // xinput set-int-prop "divername" "Evdev Axes Swap" 8 0 | |
247 | - const char* arr_cmd[3]; | |
248 | - //arr_cmd[0] = ""; | |
249 | - arr_cmd[1] = "Evdev Axis Inversion"; | |
250 | - char str_val[20]; | |
251 | - snprintf(str_val, 20, "%d %d", invert_x, invert_y); | |
252 | - arr_cmd[2] = str_val; | |
236 | + int arr_cmd[2]; | |
237 | + arr_cmd[0] = invert_x; | |
238 | + arr_cmd[1] = invert_y; | |
253 | 239 | |
254 | - int ret = xinput_do_set_prop(display, XA_INTEGER, 8, 3, arr_cmd); | |
240 | + int ret = xinput_do_set_int_prop("Evdev Axis Inversion", display, 8, 2, arr_cmd); | |
255 | 241 | |
256 | - if (ret == EXIT_SUCCESS) | |
242 | + if (ret == true) | |
257 | 243 | trace("Successfully set invert axis X=%d, Y=%d.\n", invert_x, invert_y); |
258 | 244 | else |
259 | 245 | trace("Failed to set axis inversion.\n"); |
260 | 246 | |
261 | - return (ret == EXIT_SUCCESS); | |
247 | + return ret; | |
262 | 248 | } |
263 | 249 | |
264 | 250 | bool CalibratorEvdev::set_calibration(const XYinfo new_axys) |
265 | 251 | { |
266 | 252 | // xinput set-int-prop 4 223 32 5 500 8 300 |
267 | - const char* arr_cmd[6]; | |
268 | - //arr_cmd[0] = ""; | |
269 | - arr_cmd[1] = "Evdev Axis Calibration"; | |
270 | - char str_min_x[20]; | |
271 | - sprintf(str_min_x, "%d", new_axys.x.min); | |
272 | - arr_cmd[2] = str_min_x; | |
273 | - char str_max_x[20]; | |
274 | - sprintf(str_max_x, "%d", new_axys.x.max); | |
275 | - arr_cmd[3] = str_max_x; | |
276 | - char str_min_y[20]; | |
277 | - sprintf(str_min_y, "%d", new_axys.y.min); | |
278 | - arr_cmd[4] = str_min_y; | |
279 | - char str_max_y[20]; | |
280 | - sprintf(str_max_y, "%d", new_axys.y.max); | |
281 | - arr_cmd[5] = str_max_y; | |
282 | - | |
283 | - int ret = xinput_do_set_prop(display, XA_INTEGER, 32, 6, arr_cmd); | |
284 | - | |
285 | - if (ret == EXIT_SUCCESS) | |
253 | + int arr_cmd[4]; | |
254 | + arr_cmd[0] = new_axys.x.min; | |
255 | + arr_cmd[1] = new_axys.x.max; | |
256 | + arr_cmd[2] = new_axys.y.min; | |
257 | + arr_cmd[3] = new_axys.y.max; | |
258 | + | |
259 | + int ret = xinput_do_set_int_prop("Evdev Axis Calibration", display, 32, 4, arr_cmd); | |
260 | + | |
261 | + if (ret == true) | |
286 | 262 | trace("Successfully applied axis calibration.\n"); |
287 | 263 | else |
288 | 264 | trace("Failed to apply axis calibration.\n"); |
289 | 265 | |
290 | - return (ret == EXIT_SUCCESS); | |
266 | + return ret; | |
291 | 267 | } |
292 | 268 | |
293 | 269 | Atom CalibratorEvdev::xinput_parse_atom(Display *display, const char *name) |
@@ -317,7 +293,7 @@ Display *display, const char *name, Bool only_extended) | ||
317 | 293 | Bool is_id = True; |
318 | 294 | XID id = (XID)-1; |
319 | 295 | |
320 | - for (int loop=0; loop<len; loop++) { | |
296 | + for (int loop = 0; loop < len; loop++) { | |
321 | 297 | if (!isdigit(name[loop])) { |
322 | 298 | is_id = False; |
323 | 299 | break; |
@@ -348,20 +324,23 @@ Display *display, const char *name, Bool only_extended) | ||
348 | 324 | return found; |
349 | 325 | } |
350 | 326 | |
351 | -int CalibratorEvdev::xinput_do_set_prop(Display *display, Atom type, int format, int argc, const char **argv) | |
327 | +// Set Integer property on X | |
328 | +bool CalibratorEvdev::xinput_do_set_int_prop( const char * name, | |
329 | + Display *display, | |
330 | + int format, | |
331 | + int argc, | |
332 | + const int *argv ) | |
352 | 333 | { |
353 | 334 | #ifndef HAVE_XI_PROP |
354 | - return EXIT_FAILURE; | |
335 | + return false; | |
355 | 336 | #else |
356 | 337 | |
357 | 338 | Atom prop; |
358 | 339 | Atom old_type; |
359 | - const char *name; | |
360 | 340 | int i; |
361 | - Atom float_atom; | |
362 | - int old_format, nelements = 0; | |
341 | + int old_format; | |
363 | 342 | unsigned long act_nitems, bytes_after; |
364 | - char *endptr; | |
343 | + | |
365 | 344 | union { |
366 | 345 | unsigned char *c; |
367 | 346 | short *s; |
@@ -369,95 +348,56 @@ int CalibratorEvdev::xinput_do_set_prop(Display *display, Atom type, int format, | ||
369 | 348 | Atom *a; |
370 | 349 | } data; |
371 | 350 | |
372 | - if (argc < 3) | |
351 | + if (argc < 1) | |
373 | 352 | { |
374 | - error ( "Wrong usage of xinput_do_set_prop, need at least 3 arguments\n"); | |
375 | - return EXIT_FAILURE; | |
353 | + error ( "Wrong usage of xinput_do_set_prop, need at least 1 argument\n"); | |
354 | + return false; | |
376 | 355 | } |
377 | 356 | |
378 | - name = argv[1]; | |
379 | - | |
380 | 357 | prop = xinput_parse_atom(display, name); |
381 | 358 | |
382 | 359 | if (prop == None) { |
383 | 360 | error ( "invalid property %s\n", name); |
384 | - return EXIT_FAILURE; | |
361 | + return false; | |
385 | 362 | } |
386 | 363 | |
387 | - float_atom = XInternAtom(display, "FLOAT", False); | |
388 | - | |
389 | - nelements = argc - 2; | |
390 | - if (type == None || format == 0) { | |
364 | + if ( format == 0) { | |
391 | 365 | if (XGetDeviceProperty(display, dev, prop, 0, 0, False, AnyPropertyType, |
392 | 366 | &old_type, &old_format, &act_nitems, |
393 | 367 | &bytes_after, &data.c) != Success) { |
394 | 368 | error ( "failed to get property type and format for %s\n", |
395 | 369 | name); |
396 | - return EXIT_FAILURE; | |
370 | + return false; | |
397 | 371 | } else { |
398 | - if (type == None) | |
399 | - type = old_type; | |
400 | - if (format == 0) | |
401 | - format = old_format; | |
372 | + format = old_format; | |
402 | 373 | } |
403 | 374 | |
404 | 375 | XFree(data.c); |
405 | 376 | } |
406 | 377 | |
407 | - if (type == None) { | |
408 | - error ( "property %s doesn't exist, you need to specify " | |
409 | - "its type and format\n", name); | |
410 | - return EXIT_FAILURE; | |
411 | - } | |
378 | + data.c = (unsigned char*)calloc(argc, sizeof(long)); | |
412 | 379 | |
413 | - data.c = (unsigned char*)calloc(nelements, sizeof(long)); | |
380 | + for (i = 0; i < argc; i++) { | |
381 | + switch (format) { | |
382 | + case 8: | |
383 | + data.c[i] = argv[i]; | |
384 | + case 16: | |
385 | + data.s[i] = argv[i]; | |
386 | + break; | |
387 | + case 32: | |
388 | + data.l[i] = argv[i]; | |
389 | + break; | |
414 | 390 | |
415 | - for (i = 0; i < nelements; i++) | |
416 | - { | |
417 | - if (type == XA_INTEGER) { | |
418 | - switch (format) | |
419 | - { | |
420 | - case 8: | |
421 | - data.c[i] = atoi(argv[2 + i]); | |
422 | - break; | |
423 | - case 16: | |
424 | - data.s[i] = atoi(argv[2 + i]); | |
425 | - break; | |
426 | - case 32: | |
427 | - data.l[i] = atoi(argv[2 + i]); | |
428 | - break; | |
429 | - default: | |
430 | - error ( "unexpected size for property %s", name); | |
431 | - return EXIT_FAILURE; | |
432 | - } | |
433 | - } else if (type == float_atom) { | |
434 | - if (format != 32) { | |
435 | - error ( "unexpected format %d for property %s\n", | |
436 | - format, name); | |
437 | - return EXIT_FAILURE; | |
438 | - } | |
439 | - *(float *)(data.l + i) = strtod(argv[2 + i], &endptr); | |
440 | - if (endptr == argv[2 + i]) { | |
441 | - error ( "argument %s could not be parsed\n", argv[2 + i]); | |
442 | - return EXIT_FAILURE; | |
443 | - } | |
444 | - } else if (type == XA_ATOM) { | |
445 | - if (format != 32) { | |
446 | - error ( "unexpected format %d for property %s\n", | |
447 | - format, name); | |
448 | - return EXIT_FAILURE; | |
449 | - } | |
450 | - data.a[i] = xinput_parse_atom(display, argv[2 + i]); | |
451 | - } else { | |
452 | - error ( "unexpected type for property %s\n", name); | |
453 | - return EXIT_FAILURE; | |
454 | - } | |
391 | + default: | |
392 | + error ( "unexpected size for property %s", name); | |
393 | + return false; | |
394 | + } | |
455 | 395 | } |
456 | 396 | |
457 | - XChangeDeviceProperty(display, dev, prop, type, format, PropModeReplace, | |
458 | - data.c, nelements); | |
397 | + XChangeDeviceProperty(display, dev, prop, XA_INTEGER, format, PropModeReplace, | |
398 | + data.c, argc); | |
459 | 399 | free(data.c); |
460 | - return EXIT_SUCCESS; | |
400 | + return true; | |
461 | 401 | #endif // HAVE_XI_PROP |
462 | 402 | |
463 | 403 | } |
@@ -53,7 +53,11 @@ public: | ||
53 | 53 | // xinput_ functions (from the xinput project) |
54 | 54 | Atom xinput_parse_atom(Display *display, const char* name); |
55 | 55 | XDeviceInfo* xinput_find_device_info(Display *display, const char* name, Bool only_extended); |
56 | - int xinput_do_set_prop(Display *display, Atom type, int format, int argc, const char** argv); | |
56 | + bool xinput_do_set_int_prop( const char * name, | |
57 | + Display *display, | |
58 | + int format, | |
59 | + int argc, | |
60 | + const int* argv); | |
57 | 61 | protected: |
58 | 62 | bool output_xorgconfd(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y); |
59 | 63 | bool output_hal(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y); |