@@ -47,8 +47,9 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0,
4747 const int thr_doubleclick,
4848 const OutputType output_type,
4949 const char * geometry,
50- const bool use_timeout)
51- : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout)
50+ const bool use_timeout,
51+ const char * output_filename)
52+ : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename)
5253{
5354 // init
5455 display = XOpenDisplay (NULL );
@@ -166,8 +167,9 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0,
166167 const int thr_doubleclick,
167168 const OutputType output_type,
168169 const char * geometry,
169- const bool use_timeout)
170- : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) { }
170+ const bool use_timeout,
171+ const char * output_filename)
172+ : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, output_filename) { }
171173
172174// Destructor
173175CalibratorEvdev::~CalibratorEvdev () {
@@ -515,18 +517,41 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys)
515517 if (not_sysfs_name)
516518 sysfs_name = " !!Name_Of_TouchScreen!!" ;
517519
520+ if (output_filename == NULL || not_sysfs_name)
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+ else
523+ printf (" writing xorg.conf calibration data to '%s'\n " , output_filename);
524+
518525 // xorg.conf.d snippet
519- 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 " );
520- printf (" Section \" InputClass\"\n " );
521- printf (" Identifier \" calibration\"\n " );
522- printf (" MatchProduct \" %s\"\n " , sysfs_name);
523- printf (" Option \" Calibration\" \" %d %d %d %d\"\n " ,
526+ char line[MAX_LINE_LEN];
527+ std::string outstr;
528+
529+ outstr += " Section \" InputClass\"\n " ;
530+ outstr += " Identifier \" calibration\"\n " ;
531+ sprintf (line, " MatchProduct \" %s\"\n " , sysfs_name);
532+ outstr += line;
533+ sprintf (line, " Option \" Calibration\" \" %d %d %d %d\"\n " ,
524534 new_axys.x .min , new_axys.x .max , new_axys.y .min , new_axys.y .max );
525- printf (" Option \" SwapAxes\" \" %d\"\n " , new_axys.swap_xy );
526- printf (" EndSection\n " );
535+ outstr += line;
536+ sprintf (line, " Option \" SwapAxes\" \" %d\"\n " , new_axys.swap_xy );
537+ outstr += line;
538+ outstr += " EndSection\n " ;
527539
540+ // console out
541+ printf (" %s" , outstr.c_str ());
528542 if (not_sysfs_name)
529543 printf (" \n Change '%s' to your device's name in the snippet above.\n " , sysfs_name);
544+ // file out
545+ else if (output_filename != NULL ) {
546+ FILE* fid = fopen (output_filename, " w" );
547+ if (fid == NULL ) {
548+ fprintf (stderr, " Error: Can't open '%s' for writing. Make sure you have the necessary rights\n " , output_filename);
549+ fprintf (stderr, " New calibration data NOT saved\n " );
550+ return false ;
551+ }
552+ fprintf (fid, " %s" , outstr.c_str ());
553+ fclose (fid);
554+ }
530555
531556 return true ;
532557}
@@ -538,26 +563,71 @@ bool CalibratorEvdev::output_hal(const XYinfo new_axys)
538563 if (not_sysfs_name)
539564 sysfs_name = " !!Name_Of_TouchScreen!!" ;
540565
541- // HAL policy output
542- printf (" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n \
543- <match key=\" info.product\" contains=\" %s\" >\n \
544- <merge key=\" input.x11_options.calibration\" type=\" string\" >%d %d %d %d</merge>\n "
545- , sysfs_name, new_axys.x .min , new_axys.x .max , new_axys.y .min , new_axys.y .max );
546- printf (" <merge key=\" input.x11_options.swapaxes\" type=\" string\" >%d</merge>\n " , new_axys.swap_xy );
547- printf (" </match>\n " );
566+ if (output_filename == NULL || not_sysfs_name)
567+ printf (" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n " );
568+ else
569+ printf (" writing HAL calibration data to '%s'\n " , output_filename);
548570
571+ // HAL policy output
572+ char line[MAX_LINE_LEN];
573+ std::string outstr;
574+
575+ sprintf (line, " <match key=\" info.product\" contains=\" %s\" >\n " , sysfs_name);
576+ outstr += line;
577+ sprintf (line, " <merge key=\" input.x11_options.calibration\" type=\" string\" >%d %d %d %d</merge>\n " ,
578+ new_axys.x .min , new_axys.x .max , new_axys.y .min , new_axys.y .max );
579+ outstr += line;
580+ sprintf (line, " <merge key=\" input.x11_options.swapaxes\" type=\" string\" >%d</merge>\n " ,
581+ new_axys.swap_xy );
582+ outstr += " </match>\n " ;
583+ // console out
584+ printf (" %s" , outstr.c_str ());
549585 if (not_sysfs_name)
550586 printf (" \n Change '%s' to your device's name in the config above.\n " , sysfs_name);
587+ // file out
588+ else if (output_filename != NULL ) {
589+ FILE* fid = fopen (output_filename, " w" );
590+ if (fid == NULL ) {
591+ fprintf (stderr, " Error: Can't open '%s' for writing. Make sure you have the necessary rights\n " , output_filename);
592+ fprintf (stderr, " New calibration data NOT saved\n " );
593+ return false ;
594+ }
595+ fprintf (fid, " %s" , outstr.c_str ());
596+ fclose (fid);
597+ }
551598
552599 return true ;
553600}
554601
555602bool CalibratorEvdev::output_xinput (const XYinfo new_axys)
556603{
604+ if (output_filename == NULL )
605+ printf (" Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session\n " );
606+ else
607+ printf (" writing calibration script to '%s'\n " , output_filename);
608+
557609 // create startup script
558- printf (" Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session\n " );
559- 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 );
560- printf (" xinput set-int-prop \" %s\" \" Evdev Axes Swap\" 8 %d\n " , device_name, new_axys.swap_xy );
610+ char line[MAX_LINE_LEN];
611+ std::string outstr;
612+
613+ 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 );
614+ outstr += line;
615+ sprintf (line, " xinput set-int-prop \" %s\" \" Evdev Axes Swap\" 8 %d\n " , device_name, new_axys.swap_xy );
616+ outstr += line;
617+
618+ // console out
619+ printf (" %s" , outstr.c_str ());
620+ // file out
621+ if (output_filename != NULL ) {
622+ FILE* fid = fopen (output_filename, " w" );
623+ if (fid == NULL ) {
624+ fprintf (stderr, " Error: Can't open '%s' for writing. Make sure you have the necessary rights\n " , output_filename);
625+ fprintf (stderr, " New calibration data NOT saved\n " );
626+ return false ;
627+ }
628+ fprintf (fid, " %s" , outstr.c_str ());
629+ fclose (fid);
630+ }
561631
562632 return true ;
563633}
0 commit comments