diff --git a/man/xinput_calibrator.1 b/man/xinput_calibrator.1 index e0d84a6..de6a3d3 100644 --- a/man/xinput_calibrator.1 +++ b/man/xinput_calibrator.1 @@ -51,8 +51,12 @@ This is useful if the calibration values are stored in your xorg.conf, but the d set the misclick threshold (0=off, default: 15 pixels) .PP .TP 8 -.B \-\-no-timeout -turns off the timeout +.B \-\-no\-timeout +turns off the timeout; same as --timeout 0 +.PP +.TP 8 +.B \-\-timeout \fIsec\fP +sets the timeout, in seconds (0=no timeout, default: 15 sec) .PP .TP 8 .B \-\-output\-type \fIauto|xorg.conf.d|hal|xinput\fP diff --git a/src/calibrator.cpp b/src/calibrator.cpp index cdbd461..0934e8a 100644 --- a/src/calibrator.cpp +++ b/src/calibrator.cpp @@ -40,10 +40,10 @@ const char* Calibrator::SYSFS_DEVNAME="device/name"; Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type0, const char* geometry0, - const bool use_timeout0, const char* output_filename0) + const int timeout0, const char* output_filename0) : device_name(device_name0), threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick), - output_type(output_type0), geometry(geometry0), use_timeout(use_timeout0), + output_type(output_type0), geometry(geometry0), timeout(timeout0), output_filename(output_filename0) { old_axys = axys0; diff --git a/src/calibrator.hh b/src/calibrator.hh index a6f9504..8dc7495 100644 --- a/src/calibrator.hh +++ b/src/calibrator.hh @@ -148,7 +148,7 @@ public: const int thr_doubleclick=0, const OutputType output_type=OUTYPE_AUTO, const char* geometry=0, - const bool use_timeout=1, + const int timeout=0, const char* output_filename = 0); virtual ~Calibrator() {} @@ -181,8 +181,8 @@ public: /// returns NULL if it can not be found const char* get_sysfs_name(); - const bool get_use_timeout() const - { return use_timeout; } + const int get_timeout() const + { return timeout; } /// get output filename set at cmdline or NULL const char* get_output_filename() const @@ -237,7 +237,7 @@ protected: // manually specified geometry string const char* geometry; - const bool use_timeout; + const int timeout; // manually specified output filename const char* output_filename; diff --git a/src/calibrator/Evdev.cpp b/src/calibrator/Evdev.cpp index 0889056..06d609e 100644 --- a/src/calibrator/Evdev.cpp +++ b/src/calibrator/Evdev.cpp @@ -47,9 +47,9 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const int thr_doubleclick, const OutputType output_type, const char* geometry, - const bool use_timeout, + const int timeout, const char* output_filename) - : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename) + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, timeout, output_filename) { // init display = XOpenDisplay(NULL); @@ -167,9 +167,9 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const int thr_doubleclick, const OutputType output_type, const char* geometry, - const bool use_timeout, + const int timeout, const char* output_filename) - : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, output_filename) { } + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, timeout, output_filename) { } // Destructor CalibratorEvdev::~CalibratorEvdev () { diff --git a/src/calibrator/Evdev.hpp b/src/calibrator/Evdev.hpp index 9efe7d6..dc92802 100644 --- a/src/calibrator/Evdev.hpp +++ b/src/calibrator/Evdev.hpp @@ -47,7 +47,7 @@ class CalibratorEvdev: public Calibrator const int thr_doubleclick=0, const OutputType output_type=OUTYPE_AUTO, const char* geometry=0, - const bool use_timeout=false, + const int timeout=0, const char* output_filename = 0); public: @@ -58,7 +58,7 @@ class CalibratorEvdev: public Calibrator const int thr_doubleclick=0, const OutputType output_type=OUTYPE_AUTO, const char* geometry=0, - const bool use_timeout=false, + const int timeout=0, const char* output_filename = 0); virtual ~CalibratorEvdev(); diff --git a/src/calibrator/Usbtouchscreen.cpp b/src/calibrator/Usbtouchscreen.cpp index 9bbafe3..1e7d9f2 100644 --- a/src/calibrator/Usbtouchscreen.cpp +++ b/src/calibrator/Usbtouchscreen.cpp @@ -48,8 +48,8 @@ static const char *p_flip_x = "flip_x"; static const char *p_flip_y = "flip_y"; static const char *p_swap_xy = "swap_xy"; -CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const bool use_timeout, const char* output_filename) - : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename) +CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const int timeout, const char* output_filename) + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, timeout, output_filename) { if (strcmp(device_name, "Usbtouchscreen") != 0) throw WrongCalibratorException("Not a usbtouchscreen device"); diff --git a/src/calibrator/Usbtouchscreen.hpp b/src/calibrator/Usbtouchscreen.hpp index 1898bf1..e5b66f1 100644 --- a/src/calibrator/Usbtouchscreen.hpp +++ b/src/calibrator/Usbtouchscreen.hpp @@ -35,7 +35,7 @@ class CalibratorUsbtouchscreen: public Calibrator CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys, const int thr_misclick=0, const int thr_doubleclick=0, const OutputType output_type=OUTYPE_AUTO, const char* geometry=0, - const bool use_timeout=false, const char* output_filename = 0); + const int timeout=0, const char* output_filename = 0); virtual ~CalibratorUsbtouchscreen(); virtual bool finish_data(const XYinfo &new_axys); diff --git a/src/calibrator/XorgPrint.cpp b/src/calibrator/XorgPrint.cpp index 9ae04e5..76de944 100644 --- a/src/calibrator/XorgPrint.cpp +++ b/src/calibrator/XorgPrint.cpp @@ -24,8 +24,8 @@ #include -CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const bool use_timeout, const char* output_filename) - : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename) +CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const int timeout, const char* output_filename) + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, timeout, output_filename) { printf("Calibrating standard Xorg driver \"%s\"\n", device_name); printf("\tcurrent calibration values: min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", diff --git a/src/calibrator/XorgPrint.hpp b/src/calibrator/XorgPrint.hpp index 1083e0d..c9e6969 100644 --- a/src/calibrator/XorgPrint.hpp +++ b/src/calibrator/XorgPrint.hpp @@ -35,7 +35,7 @@ class CalibratorXorgPrint: public Calibrator CalibratorXorgPrint(const char* const device_name, const XYinfo& axys, const int thr_misclick=0, const int thr_doubleclick=0, const OutputType output_type=OUTYPE_AUTO, const char* geometry=0, - const bool use_timeout=false, const char* output_filename = 0); + const int timeout=0, const char* output_filename = 0); virtual bool finish_data(const XYinfo &new_axys); diff --git a/src/gui/gtkmm.cpp b/src/gui/gtkmm.cpp index 9c189d0..29cbe0f 100644 --- a/src/gui/gtkmm.cpp +++ b/src/gui/gtkmm.cpp @@ -49,7 +49,7 @@ CalibrationArea::CalibrationArea(Calibrator* calibrator0) set_display_size(get_width(), get_height()); // Setup timer for animation - if(calibrator->get_use_timeout()){ + if(calibrator->get_timeout() > 0){ sigc::slot slot = sigc::mem_fun(*this, &CalibrationArea::on_timer_signal); Glib::signal_timeout().connect(slot, time_step); } @@ -136,7 +136,11 @@ bool CalibrationArea::on_expose_event(GdkEventExpose *event) cr->arc(X[i], Y[i], cross_circle, 0.0, 2.0 * M_PI); cr->stroke(); } - if(calibrator->get_use_timeout()){ + + int max_time = 15000; + + if(calibrator->get_timeout() > 0) { + max_time = calibrator->get_timeout(); // Draw the clock background cr->arc(display_width/2, display_height/2, clock_radius/2, 0.0, 2.0 * M_PI); cr->set_source_rgb(0.5, 0.5, 0.5); @@ -189,7 +193,8 @@ void CalibrationArea::redraw() bool CalibrationArea::on_timer_signal() { - if (calibrator->get_use_timeout()) { + if (calibrator->get_timeout() > 0) { + int max_time = calibrator->get_timeout(); time_elapsed += time_step; if (time_elapsed > max_time) { exit(0); diff --git a/src/gui/gui_common.cpp b/src/gui/gui_common.cpp index 91ea993..12ed5d6 100644 --- a/src/gui/gui_common.cpp +++ b/src/gui/gui_common.cpp @@ -43,7 +43,7 @@ void get_display_texts(std::list *texts, Calibrator *calibrator) texts->push_back(str); /* 4th line */ str = "(To abort, press any key"; - if(calibrator->get_use_timeout()) + if(calibrator->get_timeout()>0) str += " or wait)"; else str += ")"; diff --git a/src/gui/gui_common.hpp b/src/gui/gui_common.hpp index ca78bef..cc74e2d 100644 --- a/src/gui/gui_common.hpp +++ b/src/gui/gui_common.hpp @@ -29,7 +29,6 @@ // Timeout parameters const int time_step = 100; // in milliseconds -const int max_time = 15000; // in milliseconds, 5000 = 5 sec // Clock appereance const int cross_lines = 25; diff --git a/src/gui/x11.cpp b/src/gui/x11.cpp index c3176a9..e4c77c6 100644 --- a/src/gui/x11.cpp +++ b/src/gui/x11.cpp @@ -268,7 +268,7 @@ void GuiCalibratorX11::redraw() } // Draw the clock background - if(calibrator->get_use_timeout()){ + if(calibrator->get_timeout() > 0) { XSetForeground(display, gc, pixel[DIMGRAY]); XSetLineAttributes(display, gc, 0, LineSolid, CapRound, JoinRound); XFillArc(display, win, gc, (display_width-clock_radius)/2, (display_height - clock_radius)/2, @@ -284,8 +284,9 @@ void GuiCalibratorX11::on_expose_event() void GuiCalibratorX11::on_timer_signal() { // Update clock - if(calibrator->get_use_timeout()) { - + if(calibrator->get_timeout() > 0) { + int max_time = calibrator->get_timeout(); + time_elapsed += time_step; if (time_elapsed > max_time) { exit(0); diff --git a/src/main_common.cpp b/src/main_common.cpp index da8a3a3..2818581 100644 --- a/src/main_common.cpp +++ b/src/main_common.cpp @@ -37,6 +37,8 @@ #include #include +#define DEFAULT_TIMEOUT 15 + // strdup: non-ansi static char* my_strdup(const char* s) { size_t len = strlen(s) + 1; @@ -189,7 +191,7 @@ int Calibrator::find_device(const char* pre_device, bool list_devices, static void usage(char* cmd, unsigned thr_misclick) { - fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device ] [--precalib ] [--misclick ] [--output-type ] [--fake] [--geometry x] [--no-timeout]\n", cmd); + fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device ] [--precalib ] [--misclick ] [--output-type ] [--fake] [--geometry x] [--timeout | --no-timeout]\n", cmd); fprintf(stderr, "\t-h, --help: print this help message\n"); fprintf(stderr, "\t-v, --verbose: print debug messages during the process\n"); fprintf(stderr, "\t--list: list calibratable input devices and quit\n"); @@ -200,6 +202,7 @@ static void usage(char* cmd, unsigned thr_misclick) fprintf(stderr, "\t--output-type : type of config to ouput (auto=automatically detect, default: auto)\n"); fprintf(stderr, "\t--fake: emulate a fake device (for testing purposes)\n"); fprintf(stderr, "\t--geometry: manually provide the geometry (width and height) for the calibration window\n"); + fprintf(stderr, "\t--timeout : set timeout in seconds (0='no timeout', default: %d sec)\n", DEFAULT_TIMEOUT); fprintf(stderr, "\t--no-timeout: turns off the timeout\n"); fprintf(stderr, "\t--output-filename: write calibration data to file (USB: override default /etc/modprobe.conf.local\n"); } @@ -209,7 +212,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) bool list_devices = false; bool fake = false; bool precalib = false; - bool use_timeout = true; + int timeout = DEFAULT_TIMEOUT * 1000; XYinfo pre_axys; const char* pre_device = NULL; const char* geometry = NULL; @@ -309,15 +312,25 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) fake = true; } else - // Disable timeout - if (strcmp("--no-timeout", argv[i]) == 0) { - use_timeout = false; - } else - - // Output file - if (strcmp("--output-filename", argv[i]) == 0) { - output_filename = argv[++i]; - } + // Set timeout + if (strcmp("--no-timeout", argv[i]) == 0) { + timeout = 0; + } else + + if (strcmp("--timeout", argv[i]) == 0) { + if (argc > i+1) + timeout = atoi (argv[++i]) * 1000; + else { + fprintf(stderr, "Error: --timeout needs a number (seconds) as argument. Set to 0 to disable timeout.\n\n"); + usage(argv[0], thr_misclick); + exit(1); + } + } else + + // Output file + if (strcmp("--output-filename", argv[i]) == 0) { + output_filename = argv[++i]; + } // unknown option else { @@ -328,6 +341,8 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) } } + if (verbose) + printf("DEBUG: Timeout: %d ms\n", timeout); /// Choose the device to calibrate XID device_id = (XID) -1; @@ -392,7 +407,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) // try Usbtouchscreen driver return new CalibratorUsbtouchscreen(device_name, device_axys, thr_misclick, thr_doubleclick, output_type, geometry, - use_timeout, output_filename); + timeout, output_filename); } catch(WrongCalibratorException& x) { if (verbose) @@ -403,7 +418,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) // next, try Evdev driver (with XID) return new CalibratorEvdev(device_name, device_axys, device_id, thr_misclick, thr_doubleclick, output_type, geometry, - use_timeout, output_filename); + timeout, output_filename); } catch(WrongCalibratorException& x) { if (verbose) @@ -413,5 +428,5 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) // lastly, presume a standard Xorg driver (evtouch, mutouch, ...) return new CalibratorXorgPrint(device_name, device_axys, thr_misclick, thr_doubleclick, output_type, geometry, - use_timeout, output_filename); + timeout, output_filename); }