A generic touchscreen calibration program for X.Org
Revisión | 0428975e1c9152891aa4269afdc02cea8d916247 (tree) |
---|---|
Tiempo | 2013-01-23 02:34:11 |
Autor | Andreas Müller <schnitzeltony@goog...> |
Commiter | Andreas Müller |
CalibratorEvdev: do write calibration results if --output-filename was set
Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com>
@@ -39,6 +39,9 @@ | ||
39 | 39 | #define EXIT_FAILURE 0 |
40 | 40 | #endif |
41 | 41 | |
42 | +// XXX: we currently don't handle lines that are longer than this | |
43 | +#define MAX_LINE_LEN 1024 | |
44 | + | |
42 | 45 | // Constructor |
43 | 46 | CalibratorEvdev::CalibratorEvdev(const char* const device_name0, |
44 | 47 | const XYinfo& axys0, |
@@ -517,18 +520,41 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys) | ||
517 | 520 | if (not_sysfs_name) |
518 | 521 | sysfs_name = "!!Name_Of_TouchScreen!!"; |
519 | 522 | |
523 | + if(output_filename == NULL || not_sysfs_name) | |
524 | + printf(" copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf' (/usr/share/X11/xorg.conf.d/ in some distro's)\n"); | |
525 | + else | |
526 | + printf(" writing xorg.conf calibration data to '%s'\n", output_filename); | |
527 | + | |
520 | 528 | // xorg.conf.d snippet |
521 | - printf(" copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf' (/usr/share/X11/xorg.conf.d/ in some distro's)\n"); | |
522 | - printf("Section \"InputClass\"\n"); | |
523 | - printf(" Identifier \"calibration\"\n"); | |
524 | - printf(" MatchProduct \"%s\"\n", sysfs_name); | |
525 | - printf(" Option \"Calibration\" \"%d %d %d %d\"\n", | |
529 | + char line[MAX_LINE_LEN]; | |
530 | + std::string outstr; | |
531 | + | |
532 | + outstr += "Section \"InputClass\"\n"; | |
533 | + outstr += " Identifier \"calibration\"\n"; | |
534 | + sprintf(line, " MatchProduct \"%s\"\n", sysfs_name); | |
535 | + outstr += line; | |
536 | + sprintf(line, " Option \"Calibration\" \"%d %d %d %d\"\n", | |
526 | 537 | new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); |
527 | - printf(" Option \"SwapAxes\" \"%d\"\n", new_axys.swap_xy); | |
528 | - printf("EndSection\n"); | |
538 | + outstr += line; | |
539 | + sprintf(line, " Option \"SwapAxes\" \"%d\"\n", new_axys.swap_xy); | |
540 | + outstr += line; | |
541 | + outstr += "EndSection\n"; | |
529 | 542 | |
543 | + // console out | |
544 | + printf("%s", outstr.c_str()); | |
530 | 545 | if (not_sysfs_name) |
531 | 546 | printf("\nChange '%s' to your device's name in the snippet above.\n", sysfs_name); |
547 | + // file out | |
548 | + else if(output_filename != NULL) { | |
549 | + FILE* fid = fopen(output_filename, "w"); | |
550 | + if (fid == NULL) { | |
551 | + fprintf(stderr, "Error: Can't open '%s' for writing. Make sure you have the necessary rights\n", output_filename); | |
552 | + fprintf(stderr, "New calibration data NOT saved\n"); | |
553 | + return false; | |
554 | + } | |
555 | + fprintf(fid, "%s", outstr.c_str()); | |
556 | + fclose(fid); | |
557 | + } | |
532 | 558 | |
533 | 559 | return true; |
534 | 560 | } |
@@ -540,26 +566,71 @@ bool CalibratorEvdev::output_hal(const XYinfo new_axys) | ||
540 | 566 | if (not_sysfs_name) |
541 | 567 | sysfs_name = "!!Name_Of_TouchScreen!!"; |
542 | 568 | |
543 | - // HAL policy output | |
544 | - printf(" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n\ | |
545 | -<match key=\"info.product\" contains=\"%s\">\n\ | |
546 | - <merge key=\"input.x11_options.calibration\" type=\"string\">%d %d %d %d</merge>\n" | |
547 | - , sysfs_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
548 | - printf(" <merge key=\"input.x11_options.swapaxes\" type=\"string\">%d</merge>\n", new_axys.swap_xy); | |
549 | - printf("</match>\n"); | |
569 | + if(output_filename == NULL || not_sysfs_name) | |
570 | + printf(" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n"); | |
571 | + else | |
572 | + printf(" writing HAL calibration data to '%s'\n", output_filename); | |
550 | 573 | |
574 | + // HAL policy output | |
575 | + char line[MAX_LINE_LEN]; | |
576 | + std::string outstr; | |
577 | + | |
578 | + sprintf(line, "<match key=\"info.product\" contains=\"%s\">\n", sysfs_name); | |
579 | + outstr += line; | |
580 | + sprintf(line, " <merge key=\"input.x11_options.calibration\" type=\"string\">%d %d %d %d</merge>\n", | |
581 | + new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
582 | + outstr += line; | |
583 | + sprintf(line, " <merge key=\"input.x11_options.swapaxes\" type=\"string\">%d</merge>\n", | |
584 | + new_axys.swap_xy); | |
585 | + outstr += "</match>\n"; | |
586 | + // console out | |
587 | + printf("%s", outstr.c_str()); | |
551 | 588 | if (not_sysfs_name) |
552 | 589 | printf("\nChange '%s' to your device's name in the config above.\n", sysfs_name); |
590 | + // file out | |
591 | + else if(output_filename != NULL) { | |
592 | + FILE* fid = fopen(output_filename, "w"); | |
593 | + if (fid == NULL) { | |
594 | + fprintf(stderr, "Error: Can't open '%s' for writing. Make sure you have the necessary rights\n", output_filename); | |
595 | + fprintf(stderr, "New calibration data NOT saved\n"); | |
596 | + return false; | |
597 | + } | |
598 | + fprintf(fid, "%s", outstr.c_str()); | |
599 | + fclose(fid); | |
600 | + } | |
553 | 601 | |
554 | 602 | return true; |
555 | 603 | } |
556 | 604 | |
557 | 605 | bool CalibratorEvdev::output_xinput(const XYinfo new_axys) |
558 | 606 | { |
607 | + if(output_filename == NULL) | |
608 | + printf(" Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session\n"); | |
609 | + else | |
610 | + printf(" writing calibration script to '%s'\n", output_filename); | |
611 | + | |
559 | 612 | // create startup script |
560 | - printf(" Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session\n"); | |
561 | - printf(" xinput set-int-prop \"%s\" \"Evdev Axis Calibration\" 32 %d %d %d %d\n", device_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
562 | - printf(" xinput set-int-prop \"%s\" \"Evdev Axes Swap\" 8 %d\n", device_name, new_axys.swap_xy); | |
613 | + char line[MAX_LINE_LEN]; | |
614 | + std::string outstr; | |
615 | + | |
616 | + sprintf(line, " xinput set-int-prop \"%s\" \"Evdev Axis Calibration\" 32 %d %d %d %d\n", device_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
617 | + outstr += line; | |
618 | + sprintf(line, " xinput set-int-prop \"%s\" \"Evdev Axes Swap\" 8 %d\n", device_name, new_axys.swap_xy); | |
619 | + outstr += line; | |
620 | + | |
621 | + // console out | |
622 | + printf("%s", outstr.c_str()); | |
623 | + // file out | |
624 | + if(output_filename != NULL) { | |
625 | + FILE* fid = fopen(output_filename, "w"); | |
626 | + if (fid == NULL) { | |
627 | + fprintf(stderr, "Error: Can't open '%s' for writing. Make sure you have the necessary rights\n", output_filename); | |
628 | + fprintf(stderr, "New calibration data NOT saved\n"); | |
629 | + return false; | |
630 | + } | |
631 | + fprintf(fid, "%s", outstr.c_str()); | |
632 | + fclose(fid); | |
633 | + } | |
563 | 634 | |
564 | 635 | return true; |
565 | 636 | } |