• 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ón0428975e1c9152891aa4269afdc02cea8d916247 (tree)
Tiempo2013-01-23 02:34:11
AutorAndreas Müller <schnitzeltony@goog...>
CommiterAndreas Müller

Log Message

CalibratorEvdev: do write calibration results if --output-filename was set

Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com>

Cambiar Resumen

Diferencia incremental

--- a/src/calibrator/Evdev.cpp
+++ b/src/calibrator/Evdev.cpp
@@ -39,6 +39,9 @@
3939 #define EXIT_FAILURE 0
4040 #endif
4141
42+// XXX: we currently don't handle lines that are longer than this
43+#define MAX_LINE_LEN 1024
44+
4245 // Constructor
4346 CalibratorEvdev::CalibratorEvdev(const char* const device_name0,
4447 const XYinfo& axys0,
@@ -517,18 +520,41 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys)
517520 if (not_sysfs_name)
518521 sysfs_name = "!!Name_Of_TouchScreen!!";
519522
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+
520528 // 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",
526537 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";
529542
543+ // console out
544+ printf("%s", outstr.c_str());
530545 if (not_sysfs_name)
531546 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+ }
532558
533559 return true;
534560 }
@@ -540,26 +566,71 @@ bool CalibratorEvdev::output_hal(const XYinfo new_axys)
540566 if (not_sysfs_name)
541567 sysfs_name = "!!Name_Of_TouchScreen!!";
542568
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);
550573
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());
551588 if (not_sysfs_name)
552589 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+ }
553601
554602 return true;
555603 }
556604
557605 bool CalibratorEvdev::output_xinput(const XYinfo new_axys)
558606 {
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+
559612 // 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+ }
563634
564635 return true;
565636 }