A generic touchscreen calibration program for X.Org
修订版 | bb9537380e4000f8b371a9d23051d1682a31cc44 (tree) |
---|---|
时间 | 2013-01-04 06:32:01 |
作者 | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
Merge pull request #44 from felipelerena/master
no-timeout parameter
@@ -35,10 +35,12 @@ | ||
35 | 35 | bool Calibrator::verbose = false; |
36 | 36 | |
37 | 37 | Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0, |
38 | - const int thr_misclick, const int thr_doubleclick, const OutputType output_type0, const char* geometry0) | |
38 | + const int thr_misclick, const int thr_doubleclick, | |
39 | + const OutputType output_type0, const char* geometry0, | |
40 | + const bool use_timeout0) | |
39 | 41 | : device_name(device_name0), |
40 | 42 | threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick), |
41 | - output_type(output_type0), geometry(geometry0) | |
43 | + output_type(output_type0), geometry(geometry0), use_timeout(use_timeout0) | |
42 | 44 | { |
43 | 45 | old_axys = axys0; |
44 | 46 |
@@ -144,7 +144,8 @@ public: | ||
144 | 144 | const int thr_misclick=0, |
145 | 145 | const int thr_doubleclick=0, |
146 | 146 | const OutputType output_type=OUTYPE_AUTO, |
147 | - const char* geometry=0); | |
147 | + const char* geometry=0, | |
148 | + const bool use_timeout=1); | |
148 | 149 | |
149 | 150 | ~Calibrator() {} |
150 | 151 |
@@ -176,6 +177,9 @@ public: | ||
176 | 177 | /// returns NULL if it can not be found |
177 | 178 | const char* get_sysfs_name(); |
178 | 179 | |
180 | + const bool get_use_timeout() const | |
181 | + { return use_timeout; } | |
182 | + | |
179 | 183 | protected: |
180 | 184 | /// check whether the coordinates are along the respective axis |
181 | 185 | bool along_axis(int xy, int x0, int y0); |
@@ -224,6 +228,8 @@ protected: | ||
224 | 228 | |
225 | 229 | // manually specified geometry string |
226 | 230 | const char* geometry; |
231 | + | |
232 | + const bool use_timeout; | |
227 | 233 | }; |
228 | 234 | |
229 | 235 | // Interfance for a CalibratorTester |
@@ -46,8 +46,9 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, | ||
46 | 46 | const int thr_misclick, |
47 | 47 | const int thr_doubleclick, |
48 | 48 | const OutputType output_type, |
49 | - const char* geometry) | |
50 | - : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) | |
49 | + const char* geometry, | |
50 | + const bool use_timeout) | |
51 | + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout) | |
51 | 52 | { |
52 | 53 | // init |
53 | 54 | display = XOpenDisplay(NULL); |
@@ -164,7 +165,8 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, | ||
164 | 165 | const int thr_misclick, |
165 | 166 | const int thr_doubleclick, |
166 | 167 | const OutputType output_type, |
167 | - const char* geometry) | |
168 | + const char* geometry, | |
169 | + const bool use_timeout) | |
168 | 170 | : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) { } |
169 | 171 | |
170 | 172 | // Destructor |
@@ -46,7 +46,8 @@ protected: | ||
46 | 46 | const int thr_misclick=0, |
47 | 47 | const int thr_doubleclick=0, |
48 | 48 | const OutputType output_type=OUTYPE_AUTO, |
49 | - const char* geometry=0); | |
49 | + const char* geometry=0, | |
50 | + const bool use_timeout=false); | |
50 | 51 | |
51 | 52 | public: |
52 | 53 | CalibratorEvdev(const char* const device_name, |
@@ -55,7 +56,8 @@ public: | ||
55 | 56 | const int thr_misclick=0, |
56 | 57 | const int thr_doubleclick=0, |
57 | 58 | const OutputType output_type=OUTYPE_AUTO, |
58 | - const char* geometry=0); | |
59 | + const char* geometry=0, | |
60 | + const bool use_timeout=false); | |
59 | 61 | ~CalibratorEvdev(); |
60 | 62 | |
61 | 63 | /// calculate and apply the calibration |
@@ -48,8 +48,8 @@ static const char *p_flip_x = "flip_x"; | ||
48 | 48 | static const char *p_flip_y = "flip_y"; |
49 | 49 | static const char *p_swap_xy = "swap_xy"; |
50 | 50 | |
51 | -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) | |
52 | - : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) | |
51 | +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) | |
52 | + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout) | |
53 | 53 | { |
54 | 54 | if (strcmp(device_name, "Usbtouchscreen") != 0) |
55 | 55 | throw WrongCalibratorException("Not a usbtouchscreen device"); |
@@ -34,7 +34,8 @@ class CalibratorUsbtouchscreen: public Calibrator | ||
34 | 34 | public: |
35 | 35 | CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys, |
36 | 36 | const int thr_misclick=0, const int thr_doubleclick=0, |
37 | - const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
37 | + const OutputType output_type=OUTYPE_AUTO, const char* geometry=0, | |
38 | + const bool use_timeout=false); | |
38 | 39 | ~CalibratorUsbtouchscreen(); |
39 | 40 | |
40 | 41 | virtual bool finish_data(const XYinfo new_axys); |
@@ -24,8 +24,8 @@ | ||
24 | 24 | |
25 | 25 | #include <cstdio> |
26 | 26 | |
27 | -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) | |
28 | - : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) | |
27 | +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) | |
28 | + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout) | |
29 | 29 | { |
30 | 30 | printf("Calibrating standard Xorg driver \"%s\"\n", device_name); |
31 | 31 | printf("\tcurrent calibration values: min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", |
@@ -34,7 +34,8 @@ class CalibratorXorgPrint: public Calibrator | ||
34 | 34 | public: |
35 | 35 | CalibratorXorgPrint(const char* const device_name, const XYinfo& axys, |
36 | 36 | const int thr_misclick=0, const int thr_doubleclick=0, |
37 | - const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
37 | + const OutputType output_type=OUTYPE_AUTO, const char* geometry=0, | |
38 | + const bool use_timeout=false); | |
38 | 39 | |
39 | 40 | virtual bool finish_data(const XYinfo new_axys); |
40 | 41 |
@@ -66,8 +66,10 @@ CalibrationArea::CalibrationArea(Calibrator* calibrator0) | ||
66 | 66 | set_display_size(get_width(), get_height()); |
67 | 67 | |
68 | 68 | // Setup timer for animation |
69 | - sigc::slot<bool> slot = sigc::mem_fun(*this, &CalibrationArea::on_timer_signal); | |
70 | - Glib::signal_timeout().connect(slot, time_step); | |
69 | + if(calibrator->get_use_timeout()){ | |
70 | + sigc::slot<bool> slot = sigc::mem_fun(*this, &CalibrationArea::on_timer_signal); | |
71 | + Glib::signal_timeout().connect(slot, time_step); | |
72 | + } | |
71 | 73 | } |
72 | 74 | |
73 | 75 | void CalibrationArea::set_display_size(int width, int height) { |
@@ -149,12 +151,13 @@ bool CalibrationArea::on_expose_event(GdkEventExpose *event) | ||
149 | 151 | cr->arc(X[i], Y[i], cross_circle, 0.0, 2.0 * M_PI); |
150 | 152 | cr->stroke(); |
151 | 153 | } |
152 | - | |
153 | - // Draw the clock background | |
154 | - cr->arc(display_width/2, display_height/2, clock_radius/2, 0.0, 2.0 * M_PI); | |
155 | - cr->set_source_rgb(0.5, 0.5, 0.5); | |
156 | - cr->fill_preserve(); | |
157 | - cr->stroke(); | |
154 | + if(calibrator->get_use_timeout()){ | |
155 | + // Draw the clock background | |
156 | + cr->arc(display_width/2, display_height/2, clock_radius/2, 0.0, 2.0 * M_PI); | |
157 | + cr->set_source_rgb(0.5, 0.5, 0.5); | |
158 | + cr->fill_preserve(); | |
159 | + cr->stroke(); | |
160 | + } | |
158 | 161 | |
159 | 162 | cr->set_line_width(clock_line_width); |
160 | 163 | cr->arc(display_width/2, display_height/2, (clock_radius - clock_line_width)/2, |
@@ -168,7 +168,7 @@ int Calibrator::find_device(const char* pre_device, bool list_devices, | ||
168 | 168 | |
169 | 169 | static void usage(char* cmd, unsigned thr_misclick) |
170 | 170 | { |
171 | - fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device <device name or id>] [--precalib <minx> <maxx> <miny> <maxy>] [--misclick <nr of pixels>] [--output-type <auto|xorg.conf.d|hal|xinput>] [--fake] [--geometry <w>x<h>]\n", cmd); | |
171 | + fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device <device name or id>] [--precalib <minx> <maxx> <miny> <maxy>] [--misclick <nr of pixels>] [--output-type <auto|xorg.conf.d|hal|xinput>] [--fake] [--geometry <w>x<h>] [--no-timeout]\n", cmd); | |
172 | 172 | fprintf(stderr, "\t-h, --help: print this help message\n"); |
173 | 173 | fprintf(stderr, "\t-v, --verbose: print debug messages during the process\n"); |
174 | 174 | fprintf(stderr, "\t--list: list calibratable input devices and quit\n"); |
@@ -179,6 +179,7 @@ static void usage(char* cmd, unsigned thr_misclick) | ||
179 | 179 | fprintf(stderr, "\t--output-type <auto|xorg.conf.d|hal|xinput>: type of config to ouput (auto=automatically detect, default: auto)\n"); |
180 | 180 | fprintf(stderr, "\t--fake: emulate a fake device (for testing purposes)\n"); |
181 | 181 | fprintf(stderr, "\t--geometry: manually provide the geometry (width and height) for the calibration window\n"); |
182 | + fprintf(stderr, "\t--no-timeout: turns off the timeout if parameter pressent\n"); | |
182 | 183 | } |
183 | 184 | |
184 | 185 | Calibrator* Calibrator::make_calibrator(int argc, char** argv) |
@@ -186,6 +187,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
186 | 187 | bool list_devices = false; |
187 | 188 | bool fake = false; |
188 | 189 | bool precalib = false; |
190 | + bool use_timeout = true; | |
189 | 191 | XYinfo pre_axys; |
190 | 192 | const char* pre_device = NULL; |
191 | 193 | const char* geometry = NULL; |
@@ -282,7 +284,12 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
282 | 284 | // Fake calibratable device ? |
283 | 285 | if (strcmp("--fake", argv[i]) == 0) { |
284 | 286 | fake = true; |
285 | - } | |
287 | + } else | |
288 | + | |
289 | + // Disable timeout | |
290 | + if (strcmp("--no-timeout", argv[i]) == 0) { | |
291 | + use_timeout = false; | |
292 | + } | |
286 | 293 | |
287 | 294 | // unknown option |
288 | 295 | else { |
@@ -356,7 +363,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
356 | 363 | try { |
357 | 364 | // try Usbtouchscreen driver |
358 | 365 | return new CalibratorUsbtouchscreen(device_name, device_axys, |
359 | - thr_misclick, thr_doubleclick, output_type, geometry); | |
366 | + thr_misclick, thr_doubleclick, output_type, geometry, use_timeout); | |
360 | 367 | |
361 | 368 | } catch(WrongCalibratorException& x) { |
362 | 369 | if (verbose) |
@@ -366,7 +373,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
366 | 373 | try { |
367 | 374 | // next, try Evdev driver (with XID) |
368 | 375 | return new CalibratorEvdev(device_name, device_axys, device_id, |
369 | - thr_misclick, thr_doubleclick, output_type, geometry); | |
376 | + thr_misclick, thr_doubleclick, output_type, geometry, use_timeout); | |
370 | 377 | |
371 | 378 | } catch(WrongCalibratorException& x) { |
372 | 379 | if (verbose) |
@@ -375,5 +382,5 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
375 | 382 | |
376 | 383 | // lastly, presume a standard Xorg driver (evtouch, mutouch, ...) |
377 | 384 | return new CalibratorXorgPrint(device_name, device_axys, |
378 | - thr_misclick, thr_doubleclick, output_type, geometry); | |
385 | + thr_misclick, thr_doubleclick, output_type, geometry, use_timeout); | |
379 | 386 | } |