A generic touchscreen calibration program for X.Org
Revision | d7bc8bbd0f5a825f0e8993f31df812e8640316ed (tree) |
---|---|
Time | 2012-03-09 08:51:58 |
Author | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
new_axys now contains the axys value to write
previously, new_axys.swap_xy meant that the old swap_xy value needed to
be swapped.
Now, new_axys is initialised to old_axys,
such that setting new_axys.do_swap_xy() swaps the axys and hence
new_axys contains the axys values to write.
Similar for invert_x, invert_y
Changes to Usbtouchscreen were not needed as it resets swap/inversion
values to 'false' before doing calibration.
@@ -137,12 +137,18 @@ bool Calibrator::finish(int width, int height) | ||
137 | 137 | return false; |
138 | 138 | } |
139 | 139 | |
140 | - XYinfo new_axys; // new axys origin and scaling | |
140 | + // new axys origin and scaling | |
141 | + // based on old_axys: inversion/swapping is relative to the old axys | |
142 | + XYinfo new_axys(old_axys); | |
141 | 143 | |
142 | 144 | // Should x and y be swapped? |
143 | - new_axys.swap_xy = (abs (clicked.x[UL] - clicked.x[UR]) < abs (clicked.y[UL] - clicked.y[UR])); | |
145 | + bool do_swap_xy = false; | |
146 | + if (abs(clicked.x[UL] - clicked.x[UR]) < abs(clicked.y[UL] - clicked.y[UR])) { | |
147 | + do_swap_xy = true; | |
148 | + new_axys.do_swap_xy(); | |
149 | + } | |
144 | 150 | |
145 | - if (new_axys.swap_xy) { | |
151 | + if (do_swap_xy) { | |
146 | 152 | std::swap(clicked.x[LL], clicked.x[UR]); |
147 | 153 | std::swap(clicked.y[LL], clicked.y[UR]); |
148 | 154 | } |
@@ -167,7 +173,7 @@ bool Calibrator::finish(int width, int height) | ||
167 | 173 | |
168 | 174 | |
169 | 175 | // If x and y has to be swapped we also have to swap the parameters |
170 | - if (new_axys.swap_xy) { | |
176 | + if (do_swap_xy) { | |
171 | 177 | std::swap(new_axys.x.min, new_axys.y.max); |
172 | 178 | std::swap(new_axys.y.min, new_axys.x.max); |
173 | 179 | } |
@@ -154,14 +154,10 @@ bool CalibratorEvdev::finish_data(const XYinfo new_axys) | ||
154 | 154 | { |
155 | 155 | bool success = true; |
156 | 156 | |
157 | - // swap x and y axis, indicated by swap_xy | |
158 | - // new value is old value (could have been 0 or 1) swapped: | |
159 | - int new_swap_xy = 1 - old_axys.swap_xy; | |
160 | - | |
161 | 157 | printf("\nDoing dynamic recalibration:\n"); |
162 | 158 | // Evdev Axes Swap |
163 | - if (new_axys.swap_xy) { | |
164 | - success &= set_swapxy(new_swap_xy); | |
159 | + if (old_axys.swap_xy != new_axys.swap_xy) { | |
160 | + success &= set_swapxy(new_axys.swap_xy); | |
165 | 161 | } |
166 | 162 | |
167 | 163 | // Evdev Axis Calibration |
@@ -177,19 +173,19 @@ bool CalibratorEvdev::finish_data(const XYinfo new_axys) | ||
177 | 173 | case OUTYPE_AUTO: |
178 | 174 | // xorg.conf.d or alternatively xinput commands |
179 | 175 | if (has_xorgconfd_support()) { |
180 | - success &= output_xorgconfd(new_axys, new_swap_xy); | |
176 | + success &= output_xorgconfd(new_axys); | |
181 | 177 | } else { |
182 | - success &= output_xinput(new_axys, new_swap_xy); | |
178 | + success &= output_xinput(new_axys); | |
183 | 179 | } |
184 | 180 | break; |
185 | 181 | case OUTYPE_XORGCONFD: |
186 | - success &= output_xorgconfd(new_axys, new_swap_xy); | |
182 | + success &= output_xorgconfd(new_axys); | |
187 | 183 | break; |
188 | 184 | case OUTYPE_HAL: |
189 | - success &= output_hal(new_axys, new_swap_xy); | |
185 | + success &= output_hal(new_axys); | |
190 | 186 | break; |
191 | 187 | case OUTYPE_XINPUT: |
192 | - success &= output_xinput(new_axys, new_swap_xy); | |
188 | + success &= output_xinput(new_axys); | |
193 | 189 | break; |
194 | 190 | default: |
195 | 191 | fprintf(stderr, "ERROR: Evdev Calibrator does not support the supplied --output-type\n"); |
@@ -430,7 +426,7 @@ int CalibratorEvdev::xinput_do_set_prop(Display *display, Atom type, int format, | ||
430 | 426 | |
431 | 427 | } |
432 | 428 | |
433 | -bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys, int new_swap_xy) | |
429 | +bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys) | |
434 | 430 | { |
435 | 431 | const char* sysfs_name = get_sysfs_name(); |
436 | 432 | bool not_sysfs_name = (sysfs_name == NULL); |
@@ -444,8 +440,7 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys, int new_swap_xy) | ||
444 | 440 | printf(" MatchProduct \"%s\"\n", sysfs_name); |
445 | 441 | printf(" Option \"Calibration\" \"%d %d %d %d\"\n", |
446 | 442 | new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); |
447 | - if (new_axys.swap_xy != 0) | |
448 | - printf(" Option \"SwapAxes\" \"%d\"\n", new_swap_xy); | |
443 | + printf(" Option \"SwapAxes\" \"%d\"\n", new_axys.swap_xy); | |
449 | 444 | printf("EndSection\n"); |
450 | 445 | |
451 | 446 | if (not_sysfs_name) |
@@ -454,7 +449,7 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys, int new_swap_xy) | ||
454 | 449 | return true; |
455 | 450 | } |
456 | 451 | |
457 | -bool CalibratorEvdev::output_hal(const XYinfo new_axys, int new_swap_xy) | |
452 | +bool CalibratorEvdev::output_hal(const XYinfo new_axys) | |
458 | 453 | { |
459 | 454 | const char* sysfs_name = get_sysfs_name(); |
460 | 455 | bool not_sysfs_name = (sysfs_name == NULL); |
@@ -466,8 +461,7 @@ bool CalibratorEvdev::output_hal(const XYinfo new_axys, int new_swap_xy) | ||
466 | 461 | <match key=\"info.product\" contains=\"%s\">\n\ |
467 | 462 | <merge key=\"input.x11_options.calibration\" type=\"string\">%d %d %d %d</merge>\n" |
468 | 463 | , sysfs_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); |
469 | - if (new_axys.swap_xy != 0) | |
470 | - printf(" <merge key=\"input.x11_options.swapaxes\" type=\"string\">%d</merge>\n", new_swap_xy); | |
464 | + printf(" <merge key=\"input.x11_options.swapaxes\" type=\"string\">%d</merge>\n", new_axys.swap_xy); | |
471 | 465 | printf("</match>\n"); |
472 | 466 | |
473 | 467 | if (not_sysfs_name) |
@@ -476,13 +470,12 @@ bool CalibratorEvdev::output_hal(const XYinfo new_axys, int new_swap_xy) | ||
476 | 470 | return true; |
477 | 471 | } |
478 | 472 | |
479 | -bool CalibratorEvdev::output_xinput(const XYinfo new_axys, int new_swap_xy) | |
473 | +bool CalibratorEvdev::output_xinput(const XYinfo new_axys) | |
480 | 474 | { |
481 | 475 | // create startup script |
482 | 476 | printf(" Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session\n"); |
483 | 477 | 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); |
484 | - if (new_axys.swap_xy) | |
485 | - printf(" xinput set-int-prop \"%s\" \"Evdev Axes Swap\" 8 %d\n", device_name, new_swap_xy); | |
478 | + printf(" xinput set-int-prop \"%s\" \"Evdev Axes Swap\" 8 %d\n", device_name, new_axys.swap_xy); | |
486 | 479 | |
487 | 480 | return true; |
488 | 481 | } |
@@ -54,9 +54,9 @@ public: | ||
54 | 54 | XDeviceInfo* xinput_find_device_info(Display *display, const char* name, Bool only_extended); |
55 | 55 | int xinput_do_set_prop(Display *display, Atom type, int format, int argc, const char** argv); |
56 | 56 | protected: |
57 | - bool output_xorgconfd(const XYinfo new_axys, int new_swap_xy); | |
58 | - bool output_hal(const XYinfo new_axys, int new_swap_xy); | |
59 | - bool output_xinput(const XYinfo new_axys, int new_swap_xy); | |
57 | + bool output_xorgconfd(const XYinfo new_axys); | |
58 | + bool output_hal(const XYinfo new_axys); | |
59 | + bool output_xinput(const XYinfo new_axys); | |
60 | 60 | }; |
61 | 61 | |
62 | 62 | #endif |
@@ -37,25 +37,21 @@ bool CalibratorXorgPrint::finish_data(const XYinfo new_axys) | ||
37 | 37 | { |
38 | 38 | bool success = true; |
39 | 39 | |
40 | - // we suppose the previous 'swap_xy' value was 0 | |
41 | - // (unfortunately there is no way to verify this (yet)) | |
42 | - int new_swap_xy = new_axys.swap_xy; | |
43 | - | |
44 | 40 | printf("\n\n--> Making the calibration permanent <--\n"); |
45 | 41 | switch (output_type) { |
46 | 42 | case OUTYPE_AUTO: |
47 | 43 | // xorg.conf.d or alternatively hal config |
48 | 44 | if (has_xorgconfd_support()) { |
49 | - success &= output_xorgconfd(new_axys, new_swap_xy); | |
45 | + success &= output_xorgconfd(new_axys); | |
50 | 46 | } else { |
51 | - success &= output_hal(new_axys, new_swap_xy); | |
47 | + success &= output_hal(new_axys); | |
52 | 48 | } |
53 | 49 | break; |
54 | 50 | case OUTYPE_XORGCONFD: |
55 | - success &= output_xorgconfd(new_axys, new_swap_xy); | |
51 | + success &= output_xorgconfd(new_axys); | |
56 | 52 | break; |
57 | 53 | case OUTYPE_HAL: |
58 | - success &= output_hal(new_axys, new_swap_xy); | |
54 | + success &= output_hal(new_axys); | |
59 | 55 | break; |
60 | 56 | default: |
61 | 57 | fprintf(stderr, "ERROR: XorgPrint Calibrator does not support the supplied --output-type\n"); |
@@ -65,7 +61,7 @@ bool CalibratorXorgPrint::finish_data(const XYinfo new_axys) | ||
65 | 61 | return success; |
66 | 62 | } |
67 | 63 | |
68 | -bool CalibratorXorgPrint::output_xorgconfd(const XYinfo new_axys, int new_swap_xy) | |
64 | +bool CalibratorXorgPrint::output_xorgconfd(const XYinfo new_axys) | |
69 | 65 | { |
70 | 66 | const char* sysfs_name = get_sysfs_name(); |
71 | 67 | bool not_sysfs_name = (sysfs_name == NULL); |
@@ -81,8 +77,7 @@ bool CalibratorXorgPrint::output_xorgconfd(const XYinfo new_axys, int new_swap_x | ||
81 | 77 | printf(" Option \"MaxX\" \"%d\"\n", new_axys.x.max); |
82 | 78 | printf(" Option \"MinY\" \"%d\"\n", new_axys.y.min); |
83 | 79 | printf(" Option \"MaxY\" \"%d\"\n", new_axys.y.max); |
84 | - if (new_axys.swap_xy != 0) | |
85 | - printf(" Option \"SwapXY\" \"%d\" # unless it was already set to 1\n", new_swap_xy); | |
80 | + printf(" Option \"SwapXY\" \"%d\" # unless it was already set to 1\n", new_axys.swap_xy); | |
86 | 81 | printf("EndSection\n"); |
87 | 82 | |
88 | 83 | if (not_sysfs_name) |
@@ -91,7 +86,7 @@ bool CalibratorXorgPrint::output_xorgconfd(const XYinfo new_axys, int new_swap_x | ||
91 | 86 | return true; |
92 | 87 | } |
93 | 88 | |
94 | -bool CalibratorXorgPrint::output_hal(const XYinfo new_axys, int new_swap_xy) | |
89 | +bool CalibratorXorgPrint::output_hal(const XYinfo new_axys) | |
95 | 90 | { |
96 | 91 | const char* sysfs_name = get_sysfs_name(); |
97 | 92 | bool not_sysfs_name = (sysfs_name == NULL); |
@@ -106,8 +101,7 @@ bool CalibratorXorgPrint::output_hal(const XYinfo new_axys, int new_swap_xy) | ||
106 | 101 | <merge key=\"input.x11_options.miny\" type=\"string\">%d</merge>\n\ |
107 | 102 | <merge key=\"input.x11_options.maxy\" type=\"string\">%d</merge>\n" |
108 | 103 | , sysfs_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); |
109 | - if (new_axys.swap_xy != 0) | |
110 | - printf(" <merge key=\"input.x11_options.swapxy\" type=\"string\">%d</merge>\n", new_swap_xy); | |
104 | + printf(" <merge key=\"input.x11_options.swapxy\" type=\"string\">%d</merge>\n", new_axys.swap_xy); | |
111 | 105 | printf("</match>\n"); |
112 | 106 | |
113 | 107 | if (not_sysfs_name) |
@@ -37,9 +37,10 @@ public: | ||
37 | 37 | const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); |
38 | 38 | |
39 | 39 | virtual bool finish_data(const XYinfo new_axys); |
40 | + | |
40 | 41 | protected: |
41 | - bool output_xorgconfd(const XYinfo new_axys, int new_swap_xy); | |
42 | - bool output_hal(const XYinfo new_axys, int new_swap_xy); | |
42 | + bool output_xorgconfd(const XYinfo new_axys); | |
43 | + bool output_hal(const XYinfo new_axys); | |
43 | 44 | }; |
44 | 45 | |
45 | 46 | #endif |