• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A generic touchscreen calibration program for X.Org


Commit MetaInfo

Revisiónc87e35513e89ae0018bc8088df4cabb3d2fe0bc6 (tree)
Tiempo2011-04-20 19:24:48
AutorAntoine Hue <antoine@peti...>
CommiterTias Guns

Log Message

Fixing xinput_do_set_prop into cleaner xinput_do_set_int_prop Also fixing property issue on invert axes

Cambiar Resumen

Diferencia incremental

--- a/src/calibrator/Evdev.cpp
+++ b/src/calibrator/Evdev.cpp
@@ -105,12 +105,7 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0,
105105 // QUIRK: when my machine resumes from a sleep,
106106 // the calibration property is no longer exported through xinput, but still active
107107 // 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);
114109
115110 } else if (nitems > 0) {
116111 ptr = data;
@@ -223,71 +218,52 @@ bool CalibratorEvdev::finish_data(const XYinfo new_axys)
223218
224219 bool CalibratorEvdev::set_swapxy(const int swap_xy)
225220 {
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;
233223
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);
235225
236- if (ret == EXIT_SUCCESS)
226+ if (ret == true)
237227 trace("Successfully set swapped X and Y axes = %d.\n", swap_xy);
238228 else
239229 trace("Failed to set swap X and Y axes.\n");
240230
241- return (ret == EXIT_SUCCESS);
231+ return ret;
242232 }
243233
244234 bool CalibratorEvdev::set_invert_xy(bool axisX, const int invert_x, const int invert_y)
245235 {
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;
253239
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);
255241
256- if (ret == EXIT_SUCCESS)
242+ if (ret == true)
257243 trace("Successfully set invert axis X=%d, Y=%d.\n", invert_x, invert_y);
258244 else
259245 trace("Failed to set axis inversion.\n");
260246
261- return (ret == EXIT_SUCCESS);
247+ return ret;
262248 }
263249
264250 bool CalibratorEvdev::set_calibration(const XYinfo new_axys)
265251 {
266252 // 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)
286262 trace("Successfully applied axis calibration.\n");
287263 else
288264 trace("Failed to apply axis calibration.\n");
289265
290- return (ret == EXIT_SUCCESS);
266+ return ret;
291267 }
292268
293269 Atom CalibratorEvdev::xinput_parse_atom(Display *display, const char *name)
@@ -317,7 +293,7 @@ Display *display, const char *name, Bool only_extended)
317293 Bool is_id = True;
318294 XID id = (XID)-1;
319295
320- for (int loop=0; loop<len; loop++) {
296+ for (int loop = 0; loop < len; loop++) {
321297 if (!isdigit(name[loop])) {
322298 is_id = False;
323299 break;
@@ -348,20 +324,23 @@ Display *display, const char *name, Bool only_extended)
348324 return found;
349325 }
350326
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 )
352333 {
353334 #ifndef HAVE_XI_PROP
354- return EXIT_FAILURE;
335+ return false;
355336 #else
356337
357338 Atom prop;
358339 Atom old_type;
359- const char *name;
360340 int i;
361- Atom float_atom;
362- int old_format, nelements = 0;
341+ int old_format;
363342 unsigned long act_nitems, bytes_after;
364- char *endptr;
343+
365344 union {
366345 unsigned char *c;
367346 short *s;
@@ -369,95 +348,56 @@ int CalibratorEvdev::xinput_do_set_prop(Display *display, Atom type, int format,
369348 Atom *a;
370349 } data;
371350
372- if (argc < 3)
351+ if (argc < 1)
373352 {
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;
376355 }
377356
378- name = argv[1];
379-
380357 prop = xinput_parse_atom(display, name);
381358
382359 if (prop == None) {
383360 error ( "invalid property %s\n", name);
384- return EXIT_FAILURE;
361+ return false;
385362 }
386363
387- float_atom = XInternAtom(display, "FLOAT", False);
388-
389- nelements = argc - 2;
390- if (type == None || format == 0) {
364+ if ( format == 0) {
391365 if (XGetDeviceProperty(display, dev, prop, 0, 0, False, AnyPropertyType,
392366 &old_type, &old_format, &act_nitems,
393367 &bytes_after, &data.c) != Success) {
394368 error ( "failed to get property type and format for %s\n",
395369 name);
396- return EXIT_FAILURE;
370+ return false;
397371 } else {
398- if (type == None)
399- type = old_type;
400- if (format == 0)
401- format = old_format;
372+ format = old_format;
402373 }
403374
404375 XFree(data.c);
405376 }
406377
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));
412379
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;
414390
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+ }
455395 }
456396
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);
459399 free(data.c);
460- return EXIT_SUCCESS;
400+ return true;
461401 #endif // HAVE_XI_PROP
462402
463403 }
--- a/src/calibrator/Evdev.hpp
+++ b/src/calibrator/Evdev.hpp
@@ -53,7 +53,11 @@ public:
5353 // xinput_ functions (from the xinput project)
5454 Atom xinput_parse_atom(Display *display, const char* name);
5555 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);
5761 protected:
5862 bool output_xorgconfd(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y);
5963 bool output_hal(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y);