A generic touchscreen calibration program for X.Org
Revision | 9b8708970b199397b9af49ce5f2e4efeed6365dd (tree) |
---|---|
Zeit | 2010-09-13 00:11:46 |
Autor | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
add --output-type option to select output type (default: auto, automatically selects best option)
@@ -30,8 +30,8 @@ | ||
30 | 30 | #include "calibrator.hh" |
31 | 31 | |
32 | 32 | Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0, |
33 | - const bool verbose0, const int thr_misclick, const int thr_doubleclick) | |
34 | - : device_name(device_name0), old_axys(axys0), verbose(verbose0), num_clicks(0), threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick) | |
33 | + const bool verbose0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type0) | |
34 | + : device_name(device_name0), old_axys(axys0), verbose(verbose0), num_clicks(0), threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick), output_type(output_type0) | |
35 | 35 | { |
36 | 36 | } |
37 | 37 |
@@ -34,7 +34,7 @@ public: | ||
34 | 34 | * if the touchscreen is not of the type it supports |
35 | 35 | */ |
36 | 36 | Calibrator(const char* const device_name, const XYinfo& axys, |
37 | - const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0); | |
37 | + const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, const OutputType output_type=OUTYPE_AUTO); | |
38 | 38 | ~Calibrator() {} |
39 | 39 | |
40 | 40 | // set the doubleclick treshold |
@@ -82,6 +82,9 @@ protected: | ||
82 | 82 | // Set to zero if you don't want this check |
83 | 83 | int threshold_misclick; |
84 | 84 | |
85 | + // Type of output | |
86 | + OutputType output_type; | |
87 | + | |
85 | 88 | // Check whether the given name is a sysfs device name |
86 | 89 | bool is_sysfs_name(const char* name); |
87 | 90 |
@@ -48,7 +48,8 @@ private: | ||
48 | 48 | int old_swap_xy; |
49 | 49 | public: |
50 | 50 | CalibratorEvdev(const char* const device_name, const XYinfo& axys, const bool verbose, |
51 | - XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0); | |
51 | + XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0, | |
52 | + const OutputType output_type=OUTYPE_AUTO); | |
52 | 53 | ~CalibratorEvdev(); |
53 | 54 | |
54 | 55 | virtual bool finish_data(const XYinfo new_axys, int swap_xy); |
@@ -65,8 +66,8 @@ protected: | ||
65 | 66 | bool output_xinput(const XYinfo new_axys, int swap_xy, int new_swap_xy); |
66 | 67 | }; |
67 | 68 | |
68 | -CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& axys0, const bool verbose0, XID device_id, const int thr_misclick, const int thr_doubleclick) | |
69 | - : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick), old_swap_xy(0) | |
69 | +CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& axys0, const bool verbose0, XID device_id, const int thr_misclick, const int thr_doubleclick, const OutputType output_type) | |
70 | + : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type), old_swap_xy(0) | |
70 | 71 | { |
71 | 72 | // init |
72 | 73 | display = XOpenDisplay(NULL); |
@@ -218,11 +219,24 @@ bool CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy) | ||
218 | 219 | |
219 | 220 | |
220 | 221 | printf("\n\n--> Making the calibration permanent <--\n"); |
221 | - // xorg.conf.d or alternatively xinput commands | |
222 | - if (has_xorgconfd_support()) { | |
223 | - success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
224 | - } else { | |
225 | - success &= output_xinput(new_axys, swap_xy, new_swap_xy); | |
222 | + switch (output_type) { | |
223 | + case OUTYPE_AUTO: | |
224 | + // xorg.conf.d or alternatively xinput commands | |
225 | + if (has_xorgconfd_support()) { | |
226 | + success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
227 | + } else { | |
228 | + success &= output_xinput(new_axys, swap_xy, new_swap_xy); | |
229 | + } | |
230 | + break; | |
231 | + case OUTYPE_XORGCONFD: | |
232 | + success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
233 | + break; | |
234 | + case OUTYPE_XINPUT: | |
235 | + success &= output_xinput(new_axys, swap_xy, new_swap_xy); | |
236 | + break; | |
237 | + default: | |
238 | + fprintf(stderr, "ERROR: Evdev Calibrator does not support the supplied --output-type\n"); | |
239 | + success = false; | |
226 | 240 | } |
227 | 241 | |
228 | 242 | return success; |
@@ -52,7 +52,8 @@ class CalibratorUsbtouchscreen: public Calibrator | ||
52 | 52 | { |
53 | 53 | public: |
54 | 54 | CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys, |
55 | - const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0); | |
55 | + const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, | |
56 | + const OutputType output_type=OUTYPE_AUTO); | |
56 | 57 | ~CalibratorUsbtouchscreen(); |
57 | 58 | |
58 | 59 | virtual bool finish_data(const XYinfo new_axys, int swap_xy); |
@@ -133,8 +134,8 @@ protected: | ||
133 | 134 | } |
134 | 135 | }; |
135 | 136 | |
136 | -CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick) | |
137 | - : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick) | |
137 | +CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type) | |
138 | + : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type) | |
138 | 139 | { |
139 | 140 | if (strcmp(device_name, "Usbtouchscreen") != 0) |
140 | 141 | throw WrongCalibratorException("Not a usbtouchscreen device"); |
@@ -164,6 +165,11 @@ CalibratorUsbtouchscreen::~CalibratorUsbtouchscreen() | ||
164 | 165 | |
165 | 166 | bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy) |
166 | 167 | { |
168 | + if (output_type != OUTYPE_AUTO) { | |
169 | + fprintf(stderr, "ERROR: Usbtouchscreen Calibrator does not support the supplied --output-type\n"); | |
170 | + return false; | |
171 | + } | |
172 | + | |
167 | 173 | // New ranges |
168 | 174 | const int range_x = (new_axys.x_max - new_axys.x_min); |
169 | 175 | const int range_y = (new_axys.y_max - new_axys.y_min); |
@@ -28,7 +28,8 @@ class CalibratorXorgPrint: public Calibrator | ||
28 | 28 | { |
29 | 29 | public: |
30 | 30 | CalibratorXorgPrint(const char* const device_name, const XYinfo& axys, |
31 | - const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0); | |
31 | + const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, | |
32 | + const OutputType output_type=OUTYPE_AUTO); | |
32 | 33 | |
33 | 34 | virtual bool finish_data(const XYinfo new_axys, int swap_xy); |
34 | 35 | protected: |
@@ -36,8 +37,8 @@ protected: | ||
36 | 37 | bool output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy); |
37 | 38 | }; |
38 | 39 | |
39 | -CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick) | |
40 | - : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick) | |
40 | +CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const bool verbose0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type) | |
41 | + : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type) | |
41 | 42 | { |
42 | 43 | printf("Calibrating standard Xorg driver \"%s\"\n", device_name); |
43 | 44 | printf("\tcurrent calibration values: min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", |
@@ -54,11 +55,24 @@ bool CalibratorXorgPrint::finish_data(const XYinfo new_axys, int swap_xy) | ||
54 | 55 | int new_swap_xy = swap_xy; |
55 | 56 | |
56 | 57 | printf("\n\n--> Making the calibration permanent <--\n"); |
57 | - // xorg.conf.d or alternatively hal config | |
58 | - if (has_xorgconfd_support()) { | |
59 | - success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
60 | - } else { | |
61 | - success &= output_hal(new_axys, swap_xy, new_swap_xy); | |
58 | + switch (output_type) { | |
59 | + case OUTYPE_AUTO: | |
60 | + // xorg.conf.d or alternatively hal config | |
61 | + if (has_xorgconfd_support()) { | |
62 | + success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
63 | + } else { | |
64 | + success &= output_hal(new_axys, swap_xy, new_swap_xy); | |
65 | + } | |
66 | + break; | |
67 | + case OUTYPE_XORGCONFD: | |
68 | + success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
69 | + break; | |
70 | + case OUTYPE_HAL: | |
71 | + success &= output_hal(new_axys, swap_xy, new_swap_xy); | |
72 | + break; | |
73 | + default: | |
74 | + fprintf(stderr, "ERROR: XorgPrint Calibrator does not support the supplied --output-type\n"); | |
75 | + success = false; | |
62 | 76 | } |
63 | 77 | |
64 | 78 | return success; |
@@ -64,6 +64,14 @@ enum { | ||
64 | 64 | LR = 3 // Lower-right |
65 | 65 | }; |
66 | 66 | |
67 | +// Output types | |
68 | +enum OutputType { | |
69 | + OUTYPE_AUTO, | |
70 | + OUTYPE_XORGCONFD, | |
71 | + OUTYPE_HAL, | |
72 | + OUTYPE_XINPUT | |
73 | +}; | |
74 | + | |
67 | 75 | // struct to hold min/max info of the X and Y axis |
68 | 76 | struct XYinfo { |
69 | 77 | int x_min; |
@@ -222,7 +230,7 @@ int find_device(const char* pre_device, bool verbose, bool list_devices, | ||
222 | 230 | |
223 | 231 | static void usage(char* cmd, unsigned thr_misclick) |
224 | 232 | { |
225 | - fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device <device name or id>] [--precalib <minx> <maxx> <miny> <maxy>] [--misclick <nr of pixels>] [--fake]\n", cmd); | |
233 | + 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]\n", cmd); | |
226 | 234 | fprintf(stderr, "\t-h, --help: print this help message\n"); |
227 | 235 | fprintf(stderr, "\t-v, --verbose: print debug messages during the process\n"); |
228 | 236 | fprintf(stderr, "\t--list: list calibratable input devices and quit\n"); |
@@ -230,6 +238,7 @@ static void usage(char* cmd, unsigned thr_misclick) | ||
230 | 238 | fprintf(stderr, "\t--precalib: manually provide the current calibration setting (eg. the values in xorg.conf)\n"); |
231 | 239 | fprintf(stderr, "\t--misclick: set the misclick threshold (0=off, default: %i pixels)\n", |
232 | 240 | thr_misclick); |
241 | + fprintf(stderr, "\t--output-type <auto|xorg.conf.d|hal|xinput>: type of config to ouput (auto=automatically detect, default: auto)\n"); | |
233 | 242 | fprintf(stderr, "\t--fake: emulate a fake device (for testing purposes)\n"); |
234 | 243 | } |
235 | 244 |
@@ -244,6 +253,7 @@ Calibrator* main_common(int argc, char** argv) | ||
244 | 253 | const char* pre_device = NULL; |
245 | 254 | unsigned thr_misclick = 15; |
246 | 255 | unsigned thr_doubleclick = 7; |
256 | + OutputType output_type = OUTYPE_AUTO; | |
247 | 257 | |
248 | 258 | // parse input |
249 | 259 | if (argc > 1) { |
@@ -302,6 +312,30 @@ Calibrator* main_common(int argc, char** argv) | ||
302 | 312 | } |
303 | 313 | } else |
304 | 314 | |
315 | + // Get output type ? | |
316 | + if (strcmp("--output-type", argv[i]) == 0) { | |
317 | + if (argc > i+1) { | |
318 | + i++; // eat it or exit | |
319 | + if (strcmp("auto", argv[i]) == 0) | |
320 | + output_type = OUTYPE_AUTO; | |
321 | + else if (strcmp("xorg.conf.d", argv[i]) == 0) | |
322 | + output_type = OUTYPE_XORGCONFD; | |
323 | + else if (strcmp("hal", argv[i]) == 0) | |
324 | + output_type = OUTYPE_HAL; | |
325 | + else if (strcmp("xinput", argv[i]) == 0) | |
326 | + output_type = OUTYPE_XINPUT; | |
327 | + else { | |
328 | + fprintf(stderr, "Error: --output-type needs one of auto|xorg.conf.d|hal|xinput.\n\n"); | |
329 | + usage(argv[0], thr_misclick); | |
330 | + exit(1); | |
331 | + } | |
332 | + } else { | |
333 | + fprintf(stderr, "Error: --output-type needs one argument.\n\n"); | |
334 | + usage(argv[0], thr_misclick); | |
335 | + exit(1); | |
336 | + } | |
337 | + } else | |
338 | + | |
305 | 339 | // Fake calibratable device ? |
306 | 340 | if (strcmp("--fake", argv[i]) == 0) { |
307 | 341 | fake = true; |
@@ -379,7 +413,7 @@ Calibrator* main_common(int argc, char** argv) | ||
379 | 413 | try { |
380 | 414 | // try Usbtouchscreen driver |
381 | 415 | return new CalibratorUsbtouchscreen(device_name, device_axys, |
382 | - verbose, thr_misclick, thr_doubleclick); | |
416 | + verbose, thr_misclick, thr_doubleclick, output_type); | |
383 | 417 | |
384 | 418 | } catch(WrongCalibratorException& x) { |
385 | 419 | if (verbose) |
@@ -389,7 +423,7 @@ Calibrator* main_common(int argc, char** argv) | ||
389 | 423 | try { |
390 | 424 | // next, try Evdev driver (with XID) |
391 | 425 | return new CalibratorEvdev(device_name, device_axys, verbose, device_id, |
392 | - thr_misclick, thr_doubleclick); | |
426 | + thr_misclick, thr_doubleclick, output_type); | |
393 | 427 | |
394 | 428 | } catch(WrongCalibratorException& x) { |
395 | 429 | if (verbose) |
@@ -398,5 +432,5 @@ Calibrator* main_common(int argc, char** argv) | ||
398 | 432 | |
399 | 433 | // lastly, presume a standard Xorg driver (evtouch, mutouch, ...) |
400 | 434 | return new CalibratorXorgPrint(device_name, device_axys, |
401 | - verbose, thr_misclick, thr_doubleclick); | |
435 | + verbose, thr_misclick, thr_doubleclick, output_type); | |
402 | 436 | } |