A generic touchscreen calibration program for X.Org
Revisión | e4ffde5ab28397c3154a60d930bb15bed5cda2a3 (tree) |
---|---|
Tiempo | 2011-04-20 19:24:48 |
Autor | Antoine Hue <antoine@peti...> |
Commiter | Tias Guns |
Managing correctly X/Y swap and X or Y inversion: - detect swap and inversion modification - take into account for inversion in calibration computation since Evdev is doing inversion after calibration. - Mainly tested for Evdev based driver. To be tested for USB.
Sorting outputs to stdout in such a way to only get calibration commands at output => scriptable.
@@ -1,6 +1,7 @@ | ||
1 | 1 | /* |
2 | 2 | * Copyright (c) 2009 Tias Guns |
3 | 3 | * Copyright (c) 2009 Soren Hauberg |
4 | + * Copyright (c) 2011 Antoine Hue | |
4 | 5 | * |
5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | 7 | * of this software and associated documentation files (the "Software"), to deal |
@@ -26,46 +27,37 @@ | ||
26 | 27 | #include <iostream> |
27 | 28 | #include <fstream> |
28 | 29 | #include <cstring> |
30 | +#include <stdarg.h> | |
29 | 31 | |
30 | 32 | #include "calibrator.hh" |
31 | 33 | |
32 | -Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0, | |
33 | - const bool verbose0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type0, const char* geometry0) | |
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), geometry(geometry0) | |
35 | -{ | |
36 | -} | |
34 | +// static instance | |
35 | +bool Calibrator::verbose = false; | |
37 | 36 | |
38 | -void Calibrator::set_threshold_doubleclick(int t) | |
39 | -{ | |
40 | - threshold_doubleclick = t; | |
41 | -} | |
42 | - | |
43 | -void Calibrator::set_threshold_misclick(int t) | |
44 | -{ | |
45 | - threshold_misclick = t; | |
46 | -} | |
47 | - | |
48 | -int Calibrator::get_numclicks() | |
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) | |
39 | +: device_name(device_name0), | |
40 | + threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick), | |
41 | + output_type(output_type0), geometry(geometry0) | |
49 | 42 | { |
50 | - return num_clicks; | |
51 | -} | |
43 | + old_axys = axys0; | |
52 | 44 | |
53 | -const char* Calibrator::get_geometry() | |
54 | -{ | |
55 | - return geometry; | |
45 | + clicked.num = 0; | |
46 | + //clicked.x(NUM_POINTS); | |
47 | + //clicked.y(NUM_POINTS); | |
56 | 48 | } |
57 | 49 | |
58 | 50 | bool Calibrator::add_click(int x, int y) |
59 | 51 | { |
60 | 52 | // Double-click detection |
61 | - if (threshold_doubleclick > 0 && num_clicks > 0) { | |
62 | - int i = num_clicks-1; | |
53 | + if (threshold_doubleclick > 0 && clicked.num > 0) { | |
54 | + int i = clicked.num - 1; | |
63 | 55 | while (i >= 0) { |
64 | - if (abs(x - clicked_x[i]) <= threshold_doubleclick | |
65 | - && abs(y - clicked_y[i]) <= threshold_doubleclick) { | |
56 | + if (abs(x - clicked.x[i]) <= threshold_doubleclick | |
57 | + && abs(y - clicked.y[i]) <= threshold_doubleclick) { | |
66 | 58 | if (verbose) { |
67 | - printf("DEBUG: Not adding click %i (X=%i, Y=%i): within %i pixels of previous click\n", | |
68 | - num_clicks, x, y, threshold_doubleclick); | |
59 | + trace ( "Not adding click %i (X=%i, Y=%i): within %i pixels of previous click\n", | |
60 | + clicked.num, x, y, threshold_doubleclick); | |
69 | 61 | } |
70 | 62 | return false; |
71 | 63 | } |
@@ -74,52 +66,61 @@ bool Calibrator::add_click(int x, int y) | ||
74 | 66 | } |
75 | 67 | |
76 | 68 | // Mis-click detection |
77 | - if (threshold_misclick > 0 && num_clicks > 0) { | |
69 | + if (threshold_misclick > 0 && clicked.num > 0) { | |
78 | 70 | bool misclick = true; |
79 | 71 | |
80 | - if (num_clicks == 1) { | |
81 | - // check that along one axis of first point | |
82 | - if (along_axis(x,clicked_x[0],clicked_y[0]) || | |
83 | - along_axis(y,clicked_x[0],clicked_y[0])) | |
84 | - misclick = false; | |
85 | - } else if (num_clicks == 2) { | |
86 | - // check that along other axis of first point than second point | |
87 | - if ((along_axis(y,clicked_x[0],clicked_y[0]) && | |
88 | - along_axis(clicked_x[1],clicked_x[0],clicked_y[0])) || | |
89 | - (along_axis(x,clicked_x[0],clicked_y[0]) && | |
90 | - along_axis(clicked_y[1],clicked_x[0],clicked_y[0]))) | |
91 | - misclick = false; | |
92 | - } else if (num_clicks == 3) { | |
93 | - // check that along both axis of second and third point | |
94 | - if ((along_axis(x,clicked_x[1],clicked_y[1]) && | |
95 | - along_axis(y,clicked_x[2],clicked_y[2])) || | |
96 | - (along_axis(y,clicked_x[1],clicked_y[1]) && | |
97 | - along_axis(x,clicked_x[2],clicked_y[2]))) | |
98 | - misclick = false; | |
72 | + switch (clicked.num) { | |
73 | + case 1: | |
74 | + // check that along one axis of first point | |
75 | + if (along_axis(x,clicked.x[UL],clicked.y[UL]) || | |
76 | + along_axis(y,clicked.x[UL],clicked.y[UL])) | |
77 | + { | |
78 | + misclick = false; | |
79 | + } else { | |
80 | + trace ( "Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 0 (X=%i, Y=%i) (threshold=%i)\n", | |
81 | + clicked.num, x, y, clicked.x[UL], clicked.y[UL], threshold_misclick); | |
82 | + } | |
83 | + break; | |
84 | + | |
85 | + case 2: | |
86 | + // check that along other axis of first point than second point | |
87 | + if ((along_axis( y, clicked.x[UL], clicked.y[UL]) | |
88 | + && along_axis( clicked.x[UR], clicked.x[UL], clicked.y[UL])) | |
89 | + || (along_axis( x, clicked.x[UL], clicked.y[UL]) | |
90 | + && along_axis( clicked.y[UR], clicked.x[UL], clicked.y[UL]))) | |
91 | + { | |
92 | + misclick = false; | |
93 | + } else { | |
94 | + trace ( "Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 0 (X=%i, Y=%i) or click 1 (X=%i, Y=%i) (threshold=%i)\n", | |
95 | + clicked.num, x, y, clicked.x[UL], clicked.y[UL], clicked.x[UR], clicked.y[UR], threshold_misclick); | |
96 | + } | |
97 | + break; | |
98 | + | |
99 | + case 3: | |
100 | + // check that along both axis of second and third point | |
101 | + if ( ( along_axis( x, clicked.x[UR], clicked.y[UR]) | |
102 | + && along_axis( y, clicked.x[LL], clicked.y[LL]) ) | |
103 | + ||( along_axis( y, clicked.x[UR], clicked.y[UR]) | |
104 | + && along_axis( x, clicked.x[LL], clicked.y[LL]) ) ) | |
105 | + { | |
106 | + misclick = false; | |
107 | + } else { | |
108 | + trace ( "Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 1 (X=%i, Y=%i) or click 2 (X=%i, Y=%i) (threshold=%i)\n", | |
109 | + clicked.num, x, y, clicked.x[UR], clicked.y[UR], clicked.x[LL], clicked.y[LL], threshold_misclick); | |
110 | + } | |
99 | 111 | } |
100 | 112 | |
101 | 113 | if (misclick) { |
102 | - if (verbose) { | |
103 | - if (num_clicks == 1) | |
104 | - printf("DEBUG: Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 0 (X=%i, Y=%i) (threshold=%i)\n", num_clicks, x, y, clicked_x[0], clicked_y[0], threshold_misclick); | |
105 | - else if (num_clicks == 2) | |
106 | - printf("DEBUG: Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 0 (X=%i, Y=%i) or click 1 (X=%i, Y=%i) (threshold=%i)\n", num_clicks, x, y, clicked_x[0], clicked_y[0], clicked_x[1], clicked_y[1], threshold_misclick); | |
107 | - else if (num_clicks == 3) | |
108 | - printf("DEBUG: Mis-click detected, click %i (X=%i, Y=%i) not aligned with click 1 (X=%i, Y=%i) or click 2 (X=%i, Y=%i) (threshold=%i)\n", num_clicks, x, y, clicked_x[1], clicked_y[1], clicked_x[2], clicked_y[2], threshold_misclick); | |
109 | - } | |
110 | - | |
111 | 114 | reset(); |
112 | 115 | return false; |
113 | 116 | } |
114 | 117 | } |
115 | 118 | |
116 | - clicked_x[num_clicks] = x; | |
117 | - clicked_y[num_clicks] = y; | |
118 | - num_clicks++; | |
119 | - | |
120 | - if (verbose) | |
121 | - printf("DEBUG: Adding click %i (X=%i, Y=%i)\n", num_clicks-1, x, y); | |
119 | + clicked.x.push_back(x); | |
120 | + clicked.y.push_back(y); | |
121 | + clicked.num++; | |
122 | 122 | |
123 | + trace("Adding click %i (X=%i, Y=%i)\n", clicked.num-1, x, y); | |
123 | 124 | return true; |
124 | 125 | } |
125 | 126 |
@@ -129,47 +130,86 @@ inline bool Calibrator::along_axis(int xy, int x0, int y0) | ||
129 | 130 | (abs(xy - y0) <= threshold_misclick)); |
130 | 131 | } |
131 | 132 | |
133 | +/// Compute calibration on 1 axis | |
134 | +/// (all +0.5 for float to int rounding) | |
135 | +void Calibrator::process_axys( int screen_dim, const AxisInfo &previous, std::vector<int> &clicked, AxisInfo &updated ) | |
136 | +{ | |
137 | + // These are scaled using the values of old_axys | |
138 | + const float old_scale = (previous.max - previous.min)/(float)screen_dim; | |
139 | + | |
140 | + // Sort to get lowest two and highest two whatever is the orientation | |
141 | + std::sort( clicked.begin(), clicked.end()); | |
142 | + // If inverted, must undo inversion since calibration is before in evdev driver. | |
143 | + if ( previous.invert ) { | |
144 | + updated.min = ( (2*screen_dim - clicked[2] - clicked[3]) * old_scale/2 ) + previous.min + 0.5; | |
145 | + updated.max = ( (2*screen_dim - clicked[0] - clicked[1]) * old_scale/2 ) + previous.min + 0.5; | |
146 | + } else { | |
147 | + updated.min = ( (clicked[0] + clicked[1]) * old_scale/2 ) + previous.min + 0.5; | |
148 | + updated.max = ( (clicked[2] + clicked[3]) * old_scale/2 ) + previous.min + 0.5; | |
149 | + } | |
150 | + | |
151 | + // Add/subtract the offset that comes from not having the points in the | |
152 | + // corners (using the new scale, assumed better than previous) | |
153 | + const int new_delta = (updated.max - updated.min) / (float)(num_blocks - 2) + 0.5; | |
154 | + updated.min -= new_delta; | |
155 | + updated.max += new_delta; | |
156 | +} | |
157 | + | |
158 | +// Compute calibration and correct orientation from captured coordinates | |
132 | 159 | bool Calibrator::finish(int width, int height) |
133 | 160 | { |
134 | - if (get_numclicks() != 4) { | |
161 | + if (get_numclicks() != NUM_POINTS) { | |
135 | 162 | return false; |
136 | 163 | } |
137 | 164 | |
138 | - // Should x and y be swapped? | |
139 | - const bool swap_xy = (abs (clicked_x [UL] - clicked_x [UR]) < abs (clicked_y [UL] - clicked_y [UR])); | |
140 | - if (swap_xy) { | |
141 | - std::swap(clicked_x[LL], clicked_x[UR]); | |
142 | - std::swap(clicked_y[LL], clicked_y[UR]); | |
165 | + trace ( "Screen size=%dx%d\n", width, height ); | |
166 | + trace ( "Expected screen coordinates, x.min=%d, x.max=%d, y.min=%d, y.max=%d\n", | |
167 | + width/num_blocks, width-width/num_blocks, | |
168 | + height/num_blocks, height - height/num_blocks); | |
169 | + | |
170 | + // Evdev v2.3.2 order to compute coordinates from peripheral to screen: | |
171 | + // - swap xy axis | |
172 | + // - calibration (offset and scale) | |
173 | + // - invert x, invert y axis | |
174 | + | |
175 | + trace ( "Previous orientation: swap_xy=%d, invert_x=%d, invert_y=%d\n", old_axys.swap_xy, old_axys.x.invert, old_axys.y.invert ); | |
176 | + | |
177 | + // Compute orientation modifications from existing (if orientation is already corrected, no change) | |
178 | + // Start reverse order vs. evdev: from screen to peripheral | |
179 | + | |
180 | + // Check if axes are inverted ? | |
181 | + bool invert_x = false, invert_y = false; | |
182 | + if ( clicked.x[UL] > clicked.x[LR] ) { | |
183 | + invert_x = true; | |
143 | 184 | } |
144 | 185 | |
145 | - // Compute min/max coordinates. | |
146 | - XYinfo axys; | |
147 | - // These are scaled using the values of old_axys | |
148 | - const float scale_x = (old_axys.x_max - old_axys.x_min)/(float)width; | |
149 | - axys.x_min = ((clicked_x[UL] + clicked_x[LL]) * scale_x/2) + old_axys.x_min; | |
150 | - axys.x_max = ((clicked_x[UR] + clicked_x[LR]) * scale_x/2) + old_axys.x_min; | |
151 | - const float scale_y = (old_axys.y_max - old_axys.y_min)/(float)height; | |
152 | - axys.y_min = ((clicked_y[UL] + clicked_y[UR]) * scale_y/2) + old_axys.y_min; | |
153 | - axys.y_max = ((clicked_y[LL] + clicked_y[LR]) * scale_y/2) + old_axys.y_min; | |
186 | + if ( clicked.y[UL] > clicked.y[LR] ) { | |
187 | + invert_y = true; | |
188 | + } | |
154 | 189 | |
155 | - // Add/subtract the offset that comes from not having the points in the | |
156 | - // corners (using the same coordinate system they are currently in) | |
157 | - const int delta_x = (axys.x_max - axys.x_min) / (float)(num_blocks - 2); | |
158 | - axys.x_min -= delta_x; | |
159 | - axys.x_max += delta_x; | |
160 | - const int delta_y = (axys.y_max - axys.y_min) / (float)(num_blocks - 2); | |
161 | - axys.y_min -= delta_y; | |
162 | - axys.y_max += delta_y; | |
190 | + XYinfo new_axys; // new axys origin and scaling | |
163 | 191 | |
192 | + // Should x and y be swapped | |
193 | + const bool swap_xy = (abs (clicked.x [UL] - clicked.x [UR]) < abs (clicked.y [UL] - clicked.y [UR])); | |
194 | + trace ( "Orientation modifications: swap_xy=%d, invert_x=%d, invert_y=%d\n", swap_xy, invert_x, invert_y); | |
164 | 195 | |
165 | - // If x and y has to be swapped we also have to swap the parameters | |
196 | + /// Compute calibration | |
166 | 197 | if (swap_xy) { |
167 | - std::swap(axys.x_min, axys.y_max); | |
168 | - std::swap(axys.y_min, axys.x_max); | |
198 | + process_axys( height, old_axys.x, clicked.y, new_axys.x ); | |
199 | + process_axys( width, old_axys.y, clicked.x, new_axys.y ); | |
200 | + } else { | |
201 | + process_axys( width, old_axys.x, clicked.x, new_axys.x ); | |
202 | + process_axys( height, old_axys.y, clicked.y, new_axys.y ); | |
169 | 203 | } |
170 | 204 | |
205 | + new_axys.swap_xy = old_axys.swap_xy ^ swap_xy; | |
206 | + new_axys.x.invert = old_axys.x.invert ^ invert_x; | |
207 | + new_axys.y.invert = old_axys.y.invert ^ invert_y; | |
208 | + | |
209 | + trace ( "New orientation: swap_xy=%d, invert_x=%d, invert_y=%d\n", new_axys.swap_xy, new_axys.x.invert, new_axys.y.invert ); | |
210 | + | |
171 | 211 | // finish the data, driver/calibrator specific |
172 | - return finish_data(axys, swap_xy); | |
212 | + return finish_data(new_axys); | |
173 | 213 | } |
174 | 214 | |
175 | 215 | const char* Calibrator::get_sysfs_name() |
@@ -202,8 +242,7 @@ bool Calibrator::is_sysfs_name(const char* name) { | ||
202 | 242 | std::string devname; |
203 | 243 | std::getline(ifile, devname); |
204 | 244 | if (devname == name) { |
205 | - if (verbose) | |
206 | - printf("DEBUG: Found that '%s' is a sysfs name.\n", name); | |
245 | + trace("Found that '%s' is a sysfs name.\n", name); | |
207 | 246 | return true; |
208 | 247 | } |
209 | 248 | } |
@@ -213,9 +252,8 @@ bool Calibrator::is_sysfs_name(const char* name) { | ||
213 | 252 | } |
214 | 253 | (void) closedir(dp); |
215 | 254 | |
216 | - if (verbose) | |
217 | - printf("DEBUG: Name '%s' does not match any in '%s/event*/%s'\n", | |
218 | - name, SYSFS_INPUT, SYSFS_DEVNAME); | |
255 | + trace ("Name '%s' does not match any in '%s/event*/%s'\n", | |
256 | + name, SYSFS_INPUT, SYSFS_DEVNAME); | |
219 | 257 | return false; |
220 | 258 | } |
221 | 259 |
@@ -227,7 +265,7 @@ bool Calibrator::has_xorgconfd_support(Display* dpy) { | ||
227 | 265 | display = XOpenDisplay(NULL); |
228 | 266 | |
229 | 267 | if (display == NULL) { |
230 | - fprintf(stderr, "Unable to connect to X server\n"); | |
268 | + error ( "Unable to connect to X server\n"); | |
231 | 269 | exit(1); |
232 | 270 | } |
233 | 271 |
@@ -241,3 +279,46 @@ bool Calibrator::has_xorgconfd_support(Display* dpy) { | ||
241 | 279 | |
242 | 280 | return has_support; |
243 | 281 | } |
282 | + | |
283 | +/// Write calibration output (to stdout) | |
284 | +void Calibrator::output ( const char *format, ... ) | |
285 | +{ | |
286 | + va_list vl; | |
287 | + va_start ( vl, format ); | |
288 | + vprintf ( format, vl ); | |
289 | + va_end ( vl ); | |
290 | +} | |
291 | + | |
292 | +/// Dump debug information if verbose activated | |
293 | +void Calibrator::trace ( const char *format, ...) | |
294 | +{ | |
295 | + if ( verbose == true ) { | |
296 | + printf ( "DEBUG: "); | |
297 | + va_list vl; | |
298 | + va_start ( vl, format ); | |
299 | + vprintf ( format, vl ); | |
300 | + va_end ( vl ); | |
301 | + } | |
302 | +} | |
303 | + | |
304 | +/// Information to user, if verbose mode activated | |
305 | +void Calibrator::info ( const char *format, ... ) | |
306 | +{ | |
307 | + if ( verbose == true ) { | |
308 | + printf ( "INFO: "); | |
309 | + va_list vl; | |
310 | + va_start ( vl, format ); | |
311 | + vprintf ( format, vl ); | |
312 | + va_end ( vl ); | |
313 | + } | |
314 | +} | |
315 | + | |
316 | +/// Error (non fatal) | |
317 | +void Calibrator::error ( const char *format, ...) | |
318 | +{ | |
319 | + fprintf ( stderr, "ERROR: "); | |
320 | + va_list vl; | |
321 | + va_start ( vl, format ); | |
322 | + vprintf ( format, vl ); | |
323 | + va_end ( vl ); | |
324 | +} |
@@ -1,6 +1,7 @@ | ||
1 | 1 | /* |
2 | 2 | * Copyright (c) 2009 Tias Guns |
3 | 3 | * Copyright (c) 2009 Soren Hauberg |
4 | + * Copyright (c) 2011 Antoine Hue | |
4 | 5 | * |
5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | 7 | * of this software and associated documentation files (the "Software"), to deal |
@@ -26,6 +27,7 @@ | ||
26 | 27 | |
27 | 28 | #include <stdexcept> |
28 | 29 | #include <X11/Xlib.h> |
30 | +#include <vector> | |
29 | 31 | |
30 | 32 | /* |
31 | 33 | * Number of blocks. We partition the screen into 'num_blocks' x 'num_blocks' |
@@ -55,15 +57,23 @@ | ||
55 | 57 | */ |
56 | 58 | const int num_blocks = 8; |
57 | 59 | |
60 | +struct AxisInfo { | |
61 | + int min, max; | |
62 | + bool invert; | |
63 | + AxisInfo() : min(-1), max(-1), invert(false) { } | |
64 | +}; | |
65 | + | |
58 | 66 | /// struct to hold min/max info of the X and Y axis |
59 | 67 | struct XYinfo { |
60 | - int x_min; | |
61 | - int x_max; | |
62 | - int y_min; | |
63 | - int y_max; | |
64 | - XYinfo() : x_min(-1), x_max(-1), y_min(-1), y_max(-1) {} | |
65 | - XYinfo(int xmi, int xma, int ymi, int yma) : | |
66 | - x_min(xmi), x_max(xma), y_min(ymi), y_max(yma) {} | |
68 | + /// Axis swapped | |
69 | + bool swap_xy; | |
70 | + /// X, Y axis | |
71 | + AxisInfo x, y; | |
72 | + | |
73 | + XYinfo() : swap_xy(false) {} | |
74 | + | |
75 | + XYinfo(int xmi, int xma, int ymi, int yma, bool swap_xy_ = false): | |
76 | + swap_xy(swap_xy_) { x.min = xmi; x.max = xma; y.min = ymi; y.max = yma;} | |
67 | 77 | }; |
68 | 78 | |
69 | 79 | /// Names of the points |
@@ -102,7 +112,6 @@ public: | ||
102 | 112 | /// if the touchscreen is not of the type it supports |
103 | 113 | Calibrator(const char* const device_name, |
104 | 114 | const XYinfo& axys, |
105 | - const bool verbose, | |
106 | 115 | const int thr_misclick=0, |
107 | 116 | const int thr_doubleclick=0, |
108 | 117 | const OutputType output_type=OUTYPE_AUTO, |
@@ -111,21 +120,24 @@ public: | ||
111 | 120 | ~Calibrator() {} |
112 | 121 | |
113 | 122 | /// set the doubleclick treshold |
114 | - void set_threshold_doubleclick(int t); | |
123 | + void set_threshold_doubleclick(int t) | |
124 | + { threshold_doubleclick = t; } | |
115 | 125 | |
116 | 126 | /// set the misclick treshold |
117 | - void set_threshold_misclick(int t); | |
127 | + void set_threshold_misclick(int t) | |
128 | + { threshold_misclick = t; } | |
118 | 129 | |
119 | 130 | /// get the number of clicks already registered |
120 | - int get_numclicks(); | |
131 | + int get_numclicks() const | |
132 | + { return clicked.num; } | |
121 | 133 | |
122 | 134 | /// return geometry string or NULL |
123 | - const char* get_geometry(); | |
135 | + const char* get_geometry() const | |
136 | + { return geometry; } | |
124 | 137 | |
125 | 138 | /// reset clicks |
126 | - void reset() { | |
127 | - num_clicks = 0; | |
128 | - } | |
139 | + void reset() | |
140 | + { clicked.num = 0; clicked.x.clear(); clicked.y.clear();} | |
129 | 141 | |
130 | 142 | /// add a click with the given coordinates |
131 | 143 | bool add_click(int x, int y); |
@@ -136,22 +148,54 @@ public: | ||
136 | 148 | const char* get_sysfs_name(); |
137 | 149 | |
138 | 150 | protected: |
139 | - // check whether the coordinates are along the respective axis | |
151 | + /// check whether the coordinates are along the respective axis | |
140 | 152 | bool along_axis(int xy, int x0, int y0); |
141 | 153 | |
142 | - // overloaded function that applies the new calibration | |
143 | - virtual bool finish_data(const XYinfo new_axys, int swap_xy) =0; | |
154 | + /// Apply new calibration, implementation dependent | |
155 | + ///\param[in] swap_xy if true, X and Y axes are swapped | |
156 | + ///\param[in] invert_x if true, X axis is inverted | |
157 | + ///\param[in] invert_y if true, Y axis is inverted | |
158 | + virtual bool finish_data(const XYinfo new_axys ) =0; | |
159 | + | |
160 | + /// Compute calibration on 1 axis | |
161 | + void process_axys( int screen_dim, const AxisInfo &previous, std::vector<int> &clicked, AxisInfo &updated ); | |
162 | + | |
163 | + /// Check whether the given name is a sysfs device name | |
164 | + bool is_sysfs_name(const char* name); | |
165 | + | |
166 | + /// Check whether the X server has xorg.conf.d support | |
167 | + bool has_xorgconfd_support(Display* display=NULL); | |
168 | + | |
169 | + /// Write output calibration (to stdout) | |
170 | + void output ( const char *format, ... ); | |
171 | + | |
172 | + /// Write information to user, if verbose mode activated | |
173 | + static void info ( const char *format, ... ); | |
174 | + | |
175 | + /// Trace debug information if verbose activated | |
176 | + static void trace ( const char *format, ...); | |
177 | + | |
178 | + /// Write error (non fatal) | |
179 | + static void error ( const char *format, ...); | |
180 | + | |
181 | + static int find_device(const char* pre_device, bool list_devices, | |
182 | + XID& device_id, const char*& device_name, XYinfo& device_axys); | |
183 | +protected: | |
184 | + // be verbose or not | |
185 | + static bool verbose; | |
144 | 186 | |
145 | 187 | // name of the device (driver) |
146 | 188 | const char* const device_name; |
147 | - // original axys values | |
189 | + /// Original values | |
148 | 190 | XYinfo old_axys; |
149 | - // be verbose or not | |
150 | - bool verbose; | |
151 | - // nr of clicks registered | |
152 | - int num_clicks; | |
153 | - // click coordinates | |
154 | - int clicked_x[NUM_POINTS], clicked_y[NUM_POINTS]; | |
191 | + | |
192 | + /// Clicked values (screen coordinates) | |
193 | + struct { | |
194 | + /// actual number of clicks registered | |
195 | + int num; | |
196 | + /// click coordinates | |
197 | + std::vector<int> x, y; | |
198 | + } clicked; | |
155 | 199 | |
156 | 200 | // Threshold to keep the same point from being clicked twice. |
157 | 201 | // Set to zero if you don't want this check |
@@ -162,17 +206,11 @@ protected: | ||
162 | 206 | // Set to zero if you don't want this check |
163 | 207 | int threshold_misclick; |
164 | 208 | |
165 | - // Type of output | |
209 | + /// Format or type of output calibration | |
166 | 210 | OutputType output_type; |
167 | 211 | |
168 | - // manually specified geometry string | |
212 | + /// manually specified geometry string for the calibration pattern | |
169 | 213 | const char* geometry; |
170 | - | |
171 | - // Check whether the given name is a sysfs device name | |
172 | - bool is_sysfs_name(const char* name); | |
173 | - | |
174 | - // Check whether the X server has xorg.conf.d support | |
175 | - bool has_xorgconfd_support(Display* display=NULL); | |
176 | 214 | }; |
177 | 215 | |
178 | 216 | #endif |
@@ -1,6 +1,7 @@ | ||
1 | 1 | /* |
2 | 2 | * Copyright (c) 2009 Tias Guns |
3 | 3 | * Copyright 2007 Peter Hutterer (xinput_ methods from xinput) |
4 | + * Copyright (c) 2011 Antoine Hue (invertX/Y) | |
4 | 5 | * |
5 | 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | 7 | * of this software and associated documentation files (the "Software"), to deal |
@@ -25,7 +26,6 @@ | ||
25 | 26 | |
26 | 27 | #include <X11/Xlib.h> |
27 | 28 | #include <X11/Xatom.h> |
28 | -//#include <X11/Xutil.h> | |
29 | 29 | #include <ctype.h> |
30 | 30 | #include <cstdio> |
31 | 31 | #include <cstring> |
@@ -38,8 +38,15 @@ | ||
38 | 38 | #define EXIT_FAILURE 0 |
39 | 39 | #endif |
40 | 40 | |
41 | -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, const char* geometry) | |
42 | - : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type, geometry), old_swap_xy(0) | |
41 | +// Constructor | |
42 | +CalibratorEvdev::CalibratorEvdev(const char* const device_name0, | |
43 | + const XYinfo& axys0, | |
44 | + XID device_id, | |
45 | + const int thr_misclick, | |
46 | + const int thr_doubleclick, | |
47 | + const OutputType output_type, | |
48 | + const char* geometry) | |
49 | + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) | |
43 | 50 | { |
44 | 51 | // init |
45 | 52 | display = XOpenDisplay(NULL); |
@@ -49,12 +56,12 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& a | ||
49 | 56 | |
50 | 57 | // normaly, we already have the device id |
51 | 58 | if (device_id == (XID)-1) { |
52 | - info = xinput_find_device_info(display, device_name, False); | |
53 | - if (!info) { | |
59 | + devInfo = xinput_find_device_info(display, device_name, False); | |
60 | + if (!devInfo) { | |
54 | 61 | XCloseDisplay(display); |
55 | 62 | throw WrongCalibratorException("Evdev: Unable to find device"); |
56 | 63 | } |
57 | - device_id = info->id; | |
64 | + device_id = devInfo->id; | |
58 | 65 | } |
59 | 66 | |
60 | 67 | dev = XOpenDevice(display, device_id); |
@@ -92,31 +99,29 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& a | ||
92 | 99 | |
93 | 100 | } else if (nitems == 0) { |
94 | 101 | if (verbose) |
95 | - printf("DEBUG: Evdev Axis Calibration not set, setting to axis valuators to be sure.\n"); | |
102 | + trace ( "Evdev Axis Calibration not set, setting to axis valuators to be sure.\n"); | |
96 | 103 | |
97 | 104 | // No axis calibration set, set it to the default one |
98 | 105 | // QUIRK: when my machine resumes from a sleep, |
99 | - // the calibration property is no longer exported thourgh xinput, but still active | |
106 | + // the calibration property is no longer exported through xinput, but still active | |
100 | 107 | // not setting the values here would result in a wrong first calibration |
101 | 108 | bool ok = set_calibration(old_axys); |
102 | 109 | |
103 | - if (verbose) { | |
104 | - if (ok) | |
105 | - printf("DEBUG: Successfully applied axis calibration.\n"); | |
106 | - else | |
107 | - printf("DEBUG: Failed to apply axis calibration.\n"); | |
108 | - } | |
110 | + if (ok) | |
111 | + trace("Successfully applied axis calibration.\n"); | |
112 | + else | |
113 | + trace("Failed to apply axis calibration.\n"); | |
109 | 114 | |
110 | 115 | } else if (nitems > 0) { |
111 | 116 | ptr = data; |
112 | 117 | |
113 | - old_axys.x_min = *((long*)ptr); | |
118 | + old_axys.x.min = *((long*)ptr); | |
114 | 119 | ptr += sizeof(long); |
115 | - old_axys.x_max = *((long*)ptr); | |
120 | + old_axys.x.max = *((long*)ptr); | |
116 | 121 | ptr += sizeof(long); |
117 | - old_axys.y_min = *((long*)ptr); | |
122 | + old_axys.y.min = *((long*)ptr); | |
118 | 123 | ptr += sizeof(long); |
119 | - old_axys.y_max = *((long*)ptr); | |
124 | + old_axys.y.max = *((long*)ptr); | |
120 | 125 | ptr += sizeof(long); |
121 | 126 | } |
122 | 127 |
@@ -130,87 +135,86 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& a | ||
130 | 135 | &nitems, &bytes_after, &data) == Success) |
131 | 136 | { |
132 | 137 | if (act_format == 8 && act_type == XA_INTEGER && nitems == 1) { |
133 | - old_swap_xy = *((char*)data); | |
138 | + old_axys.swap_xy = *((char*)data); | |
134 | 139 | |
135 | - if (verbose) | |
136 | - printf("DEBUG: Read axes swap value of %i.\n", old_swap_xy); | |
140 | + trace("Read axes swap value of %i.\n", old_axys.swap_xy); | |
141 | + } | |
142 | + } | |
143 | + | |
144 | + // get "Evdev Axes Inversion" property | |
145 | + property = xinput_parse_atom(display, "Evdev Axis Inversion"); | |
146 | + if (XGetDeviceProperty(display, dev, property, 0, 1000, False, | |
147 | + AnyPropertyType, &act_type, &act_format, | |
148 | + &nitems, &bytes_after, &data) == Success) { | |
149 | + if (act_format == 8 && act_type == XA_INTEGER && nitems == 2) { | |
150 | + old_axys.x.invert = *((char*)data++); | |
151 | + old_axys.y.invert = *((char*)data); | |
152 | + | |
153 | + trace("Read InvertX=%i, InvertY=%i.\n", old_axys.x.invert, old_axys.y.invert); | |
137 | 154 | } |
138 | 155 | } |
156 | + | |
139 | 157 | // TODO? evdev < 2.3.2 with swap_xy had a bug which calibrated before swapping (eg X calib on Y axis) |
140 | 158 | // see http://cgit.freedesktop.org/xorg/driver/xf86-input-evdev/commit/?h=evdev-2.3-branch&id=3772676fd65065b43a94234127537ab5030b09f8 |
141 | 159 | |
142 | - printf("Calibrating EVDEV driver for \"%s\" id=%i\n", device_name, (int)device_id); | |
143 | - printf("\tcurrent calibration values (from XInput): min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", | |
144 | - old_axys.x_min, old_axys.x_max, old_axys.y_min, old_axys.y_max); | |
160 | + trace("Calibrating EVDEV driver for \"%s\" id=%i\n", device_name, (int)device_id); | |
161 | + trace("\tcurrent calibration values (from XInput): min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", | |
162 | + old_axys.x.min, old_axys.x.max, old_axys.y.min, old_axys.y.max); | |
145 | 163 | #endif // HAVE_XI_PROP |
146 | 164 | |
147 | 165 | } |
148 | 166 | |
167 | +// Destructor | |
149 | 168 | CalibratorEvdev::~CalibratorEvdev () { |
150 | 169 | XCloseDevice(display, dev); |
151 | 170 | XCloseDisplay(display); |
152 | 171 | } |
153 | 172 | |
154 | -bool CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy) | |
173 | +// Activate calibrated data or write it | |
174 | +bool CalibratorEvdev::finish_data(const XYinfo new_axys) | |
155 | 175 | { |
156 | 176 | bool success = true; |
157 | 177 | |
158 | 178 | // swap x and y axis, indicated by swap_xy |
159 | 179 | // new value is old value (could have been 0 or 1) swapped: |
160 | - int new_swap_xy = 1 - old_swap_xy; | |
180 | + int new_swap_xy = (new_axys.swap_xy)?1:0; | |
181 | + int new_invert_x = (new_axys.x.invert)?1:0; | |
182 | + int new_invert_y = (new_axys.y.invert)?1:0; | |
161 | 183 | |
162 | - printf("\nDoing dynamic recalibration:\n"); | |
163 | - // Evdev Axes Swap | |
164 | - if (swap_xy) { | |
165 | - printf("\tSwapping X and Y axis...\n"); | |
166 | - bool ok = set_swapxy(new_swap_xy); | |
167 | - success &= ok; | |
184 | + trace("--- Doing dynamic recalibration:\n"); | |
168 | 185 | |
169 | - if (verbose) { | |
170 | - if (ok) | |
171 | - printf("DEBUG: Successfully swapped X and Y axis.\n"); | |
172 | - else | |
173 | - printf("DEBUG: Failed to swap X and Y axis.\n"); | |
174 | - } | |
175 | - } | |
186 | + // Evdev Axes Swap | |
187 | + success &= set_swapxy(new_swap_xy); | |
188 | + success &= set_invert_xy(true, new_invert_x, new_invert_y); | |
176 | 189 | |
177 | 190 | // Evdev Axis Calibration |
178 | - printf("\tSetting new calibration data: %d, %d, %d, %d\n", new_axys.x_min, new_axys.x_max, new_axys.y_min, new_axys.y_max); | |
179 | - bool ok = set_calibration(new_axys); | |
180 | - success &= ok; | |
181 | - | |
182 | - if (verbose) { | |
183 | - if (ok) | |
184 | - printf("DEBUG: Successfully applied axis calibration.\n"); | |
185 | - else | |
186 | - printf("DEBUG: Failed to apply axis calibration.\n"); | |
187 | - } | |
191 | + trace("\tSetting new calibration data: %d, %d, %d, %d\n", new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
192 | + success &= set_calibration(new_axys); | |
193 | + | |
188 | 194 | // close |
189 | 195 | XSync(display, False); |
190 | 196 | |
191 | - | |
192 | - | |
193 | - printf("\n\n--> Making the calibration permanent <--\n"); | |
197 | + trace("\t--> Making the calibration permanent <--\n"); | |
194 | 198 | switch (output_type) { |
195 | 199 | case OUTYPE_AUTO: |
196 | 200 | // xorg.conf.d or alternatively xinput commands |
197 | 201 | if (has_xorgconfd_support()) { |
198 | - success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
202 | + success &= output_xorgconfd(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
199 | 203 | } else { |
200 | - success &= output_xinput(new_axys, swap_xy, new_swap_xy); | |
204 | + success &= output_xinput(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
201 | 205 | } |
202 | 206 | break; |
203 | 207 | case OUTYPE_XORGCONFD: |
204 | - success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
208 | + success &= output_xorgconfd(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
205 | 209 | break; |
206 | 210 | case OUTYPE_HAL: |
207 | - success &= output_hal(new_axys, swap_xy, new_swap_xy); | |
211 | + success &= output_hal(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
208 | 212 | break; |
209 | 213 | case OUTYPE_XINPUT: |
210 | - success &= output_xinput(new_axys, swap_xy, new_swap_xy); | |
214 | + success &= output_xinput(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
211 | 215 | break; |
212 | 216 | default: |
213 | - fprintf(stderr, "ERROR: Evdev Calibrator does not support the supplied --output-type\n"); | |
217 | + error ( "ERROR: Evdev Calibrator does not support the supplied --output-type\n"); | |
214 | 218 | success = false; |
215 | 219 | } |
216 | 220 |
@@ -220,49 +224,77 @@ bool CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy) | ||
220 | 224 | bool CalibratorEvdev::set_swapxy(const int swap_xy) |
221 | 225 | { |
222 | 226 | // xinput set-int-prop "divername" "Evdev Axes Swap" 8 0 |
223 | - char* arr_cmd[3]; | |
227 | + const char* arr_cmd[3]; | |
224 | 228 | //arr_cmd[0] = ""; |
225 | - char str_prop[50]; | |
226 | - sprintf(str_prop, "Evdev Axes Swap"); | |
227 | - arr_cmd[1] = str_prop; | |
229 | + arr_cmd[1] = "Evdev Axes Swap"; | |
228 | 230 | char str_swap_xy[20]; |
229 | - sprintf(str_swap_xy, "%d", swap_xy); | |
231 | + snprintf(str_swap_xy, 20, "%d", swap_xy); | |
230 | 232 | arr_cmd[2] = str_swap_xy; |
231 | 233 | |
232 | 234 | int ret = xinput_do_set_prop(display, XA_INTEGER, 8, 3, arr_cmd); |
235 | + | |
236 | + if (ret == EXIT_SUCCESS) | |
237 | + trace("Successfully set swapped X and Y axes = %d.\n", swap_xy); | |
238 | + else | |
239 | + trace("Failed to set swap X and Y axes.\n"); | |
240 | + | |
241 | + return (ret == EXIT_SUCCESS); | |
242 | +} | |
243 | + | |
244 | +bool CalibratorEvdev::set_invert_xy(bool axisX, const int invert_x, const int invert_y) | |
245 | +{ | |
246 | + // xinput set-int-prop "divername" "Evdev Axes Swap" 8 0 | |
247 | + const char* arr_cmd[3]; | |
248 | + //arr_cmd[0] = ""; | |
249 | + arr_cmd[1] = "Evdev Axis Inversion"; | |
250 | + char str_val[20]; | |
251 | + snprintf(str_val, 20, "%d %d", invert_x, invert_y); | |
252 | + arr_cmd[2] = str_val; | |
253 | + | |
254 | + int ret = xinput_do_set_prop(display, XA_INTEGER, 8, 3, arr_cmd); | |
255 | + | |
256 | + if (ret == EXIT_SUCCESS) | |
257 | + trace("Successfully set invert axis X=%d, Y=%d.\n", invert_x, invert_y); | |
258 | + else | |
259 | + trace("Failed to set axis inversion.\n"); | |
260 | + | |
233 | 261 | return (ret == EXIT_SUCCESS); |
234 | 262 | } |
235 | 263 | |
236 | 264 | bool CalibratorEvdev::set_calibration(const XYinfo new_axys) |
237 | 265 | { |
238 | 266 | // xinput set-int-prop 4 223 32 5 500 8 300 |
239 | - char* arr_cmd[6]; | |
267 | + const char* arr_cmd[6]; | |
240 | 268 | //arr_cmd[0] = ""; |
241 | - char str_prop[50]; | |
242 | - sprintf(str_prop, "Evdev Axis Calibration"); | |
243 | - arr_cmd[1] = str_prop; | |
269 | + arr_cmd[1] = "Evdev Axis Calibration"; | |
244 | 270 | char str_min_x[20]; |
245 | - sprintf(str_min_x, "%d", new_axys.x_min); | |
271 | + sprintf(str_min_x, "%d", new_axys.x.min); | |
246 | 272 | arr_cmd[2] = str_min_x; |
247 | 273 | char str_max_x[20]; |
248 | - sprintf(str_max_x, "%d", new_axys.x_max); | |
274 | + sprintf(str_max_x, "%d", new_axys.x.max); | |
249 | 275 | arr_cmd[3] = str_max_x; |
250 | 276 | char str_min_y[20]; |
251 | - sprintf(str_min_y, "%d", new_axys.y_min); | |
277 | + sprintf(str_min_y, "%d", new_axys.y.min); | |
252 | 278 | arr_cmd[4] = str_min_y; |
253 | 279 | char str_max_y[20]; |
254 | - sprintf(str_max_y, "%d", new_axys.y_max); | |
280 | + sprintf(str_max_y, "%d", new_axys.y.max); | |
255 | 281 | arr_cmd[5] = str_max_y; |
256 | 282 | |
257 | 283 | int ret = xinput_do_set_prop(display, XA_INTEGER, 32, 6, arr_cmd); |
284 | + | |
285 | + if (ret == EXIT_SUCCESS) | |
286 | + trace("Successfully applied axis calibration.\n"); | |
287 | + else | |
288 | + trace("Failed to apply axis calibration.\n"); | |
289 | + | |
258 | 290 | return (ret == EXIT_SUCCESS); |
259 | 291 | } |
260 | 292 | |
261 | -Atom CalibratorEvdev::xinput_parse_atom(Display *display, const char *name) { | |
293 | +Atom CalibratorEvdev::xinput_parse_atom(Display *display, const char *name) | |
294 | +{ | |
262 | 295 | Bool is_atom = True; |
263 | - int i; | |
264 | 296 | |
265 | - for (i = 0; name[i] != '\0'; i++) { | |
297 | + for (int i = 0; name[i] != '\0'; i++) { | |
266 | 298 | if (!isdigit(name[i])) { |
267 | 299 | is_atom = False; |
268 | 300 | break; |
@@ -280,13 +312,12 @@ Display *display, const char *name, Bool only_extended) | ||
280 | 312 | { |
281 | 313 | XDeviceInfo *devices; |
282 | 314 | XDeviceInfo *found = NULL; |
283 | - int loop; | |
284 | 315 | int num_devices; |
285 | 316 | int len = strlen(name); |
286 | 317 | Bool is_id = True; |
287 | 318 | XID id = (XID)-1; |
288 | 319 | |
289 | - for (loop=0; loop<len; loop++) { | |
320 | + for (int loop=0; loop<len; loop++) { | |
290 | 321 | if (!isdigit(name[loop])) { |
291 | 322 | is_id = False; |
292 | 323 | break; |
@@ -299,15 +330,14 @@ Display *display, const char *name, Bool only_extended) | ||
299 | 330 | |
300 | 331 | devices = XListInputDevices(display, &num_devices); |
301 | 332 | |
302 | - for (loop=0; loop<num_devices; loop++) { | |
333 | + for (int loop = 0; loop < num_devices; loop++) { | |
303 | 334 | if ((!only_extended || (devices[loop].use >= IsXExtensionDevice)) && |
304 | 335 | ((!is_id && strcmp(devices[loop].name, name) == 0) || |
305 | 336 | (is_id && devices[loop].id == id))) { |
306 | 337 | if (found) { |
307 | - fprintf(stderr, | |
308 | - "Warning: There are multiple devices named \"%s\".\n" | |
309 | - "To ensure the correct one is selected, please use " | |
310 | - "the device ID instead.\n\n", name); | |
338 | + error ( "Warning: There are multiple devices named \"%s\".\n" | |
339 | + "To ensure the correct one is selected, please use " | |
340 | + "the device ID instead.\n\n", name); | |
311 | 341 | return NULL; |
312 | 342 | } else { |
313 | 343 | found = &devices[loop]; |
@@ -318,8 +348,7 @@ Display *display, const char *name, Bool only_extended) | ||
318 | 348 | return found; |
319 | 349 | } |
320 | 350 | |
321 | -int CalibratorEvdev::xinput_do_set_prop( | |
322 | -Display *display, Atom type, int format, int argc, char **argv) | |
351 | +int CalibratorEvdev::xinput_do_set_prop(Display *display, Atom type, int format, int argc, const char **argv) | |
323 | 352 | { |
324 | 353 | #ifndef HAVE_XI_PROP |
325 | 354 | return EXIT_FAILURE; |
@@ -327,7 +356,7 @@ Display *display, Atom type, int format, int argc, char **argv) | ||
327 | 356 | |
328 | 357 | Atom prop; |
329 | 358 | Atom old_type; |
330 | - char *name; | |
359 | + const char *name; | |
331 | 360 | int i; |
332 | 361 | Atom float_atom; |
333 | 362 | int old_format, nelements = 0; |
@@ -342,7 +371,7 @@ Display *display, Atom type, int format, int argc, char **argv) | ||
342 | 371 | |
343 | 372 | if (argc < 3) |
344 | 373 | { |
345 | - fprintf(stderr, "Wrong usage of xinput_do_set_prop, need at least 3 arguments\n"); | |
374 | + error ( "Wrong usage of xinput_do_set_prop, need at least 3 arguments\n"); | |
346 | 375 | return EXIT_FAILURE; |
347 | 376 | } |
348 | 377 |
@@ -351,7 +380,7 @@ Display *display, Atom type, int format, int argc, char **argv) | ||
351 | 380 | prop = xinput_parse_atom(display, name); |
352 | 381 | |
353 | 382 | if (prop == None) { |
354 | - fprintf(stderr, "invalid property %s\n", name); | |
383 | + error ( "invalid property %s\n", name); | |
355 | 384 | return EXIT_FAILURE; |
356 | 385 | } |
357 | 386 |
@@ -362,7 +391,7 @@ Display *display, Atom type, int format, int argc, char **argv) | ||
362 | 391 | if (XGetDeviceProperty(display, dev, prop, 0, 0, False, AnyPropertyType, |
363 | 392 | &old_type, &old_format, &act_nitems, |
364 | 393 | &bytes_after, &data.c) != Success) { |
365 | - fprintf(stderr, "failed to get property type and format for %s\n", | |
394 | + error ( "failed to get property type and format for %s\n", | |
366 | 395 | name); |
367 | 396 | return EXIT_FAILURE; |
368 | 397 | } else { |
@@ -376,7 +405,7 @@ Display *display, Atom type, int format, int argc, char **argv) | ||
376 | 405 | } |
377 | 406 | |
378 | 407 | if (type == None) { |
379 | - fprintf(stderr, "property %s doesn't exist, you need to specify " | |
408 | + error ( "property %s doesn't exist, you need to specify " | |
380 | 409 | "its type and format\n", name); |
381 | 410 | return EXIT_FAILURE; |
382 | 411 | } |
@@ -398,29 +427,29 @@ Display *display, Atom type, int format, int argc, char **argv) | ||
398 | 427 | data.l[i] = atoi(argv[2 + i]); |
399 | 428 | break; |
400 | 429 | default: |
401 | - fprintf(stderr, "unexpected size for property %s", name); | |
430 | + error ( "unexpected size for property %s", name); | |
402 | 431 | return EXIT_FAILURE; |
403 | 432 | } |
404 | 433 | } else if (type == float_atom) { |
405 | 434 | if (format != 32) { |
406 | - fprintf(stderr, "unexpected format %d for property %s\n", | |
435 | + error ( "unexpected format %d for property %s\n", | |
407 | 436 | format, name); |
408 | 437 | return EXIT_FAILURE; |
409 | 438 | } |
410 | 439 | *(float *)(data.l + i) = strtod(argv[2 + i], &endptr); |
411 | 440 | if (endptr == argv[2 + i]) { |
412 | - fprintf(stderr, "argument %s could not be parsed\n", argv[2 + i]); | |
441 | + error ( "argument %s could not be parsed\n", argv[2 + i]); | |
413 | 442 | return EXIT_FAILURE; |
414 | 443 | } |
415 | 444 | } else if (type == XA_ATOM) { |
416 | 445 | if (format != 32) { |
417 | - fprintf(stderr, "unexpected format %d for property %s\n", | |
446 | + error ( "unexpected format %d for property %s\n", | |
418 | 447 | format, name); |
419 | 448 | return EXIT_FAILURE; |
420 | 449 | } |
421 | 450 | data.a[i] = xinput_parse_atom(display, argv[2 + i]); |
422 | 451 | } else { |
423 | - fprintf(stderr, "unexpected type for property %s\n", name); | |
452 | + error ( "unexpected type for property %s\n", name); | |
424 | 453 | return EXIT_FAILURE; |
425 | 454 | } |
426 | 455 | } |
@@ -433,7 +462,7 @@ Display *display, Atom type, int format, int argc, char **argv) | ||
433 | 462 | |
434 | 463 | } |
435 | 464 | |
436 | -bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys, int swap_xy, int new_swap_xy) | |
465 | +bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y) | |
437 | 466 | { |
438 | 467 | const char* sysfs_name = get_sysfs_name(); |
439 | 468 | bool not_sysfs_name = (sysfs_name == NULL); |
@@ -441,23 +470,24 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys, int swap_xy, int n | ||
441 | 470 | sysfs_name = "!!Name_Of_TouchScreen!!"; |
442 | 471 | |
443 | 472 | // xorg.conf.d snippet |
444 | - printf(" copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf'\n"); | |
445 | - printf("Section \"InputClass\"\n"); | |
446 | - printf(" Identifier \"calibration\"\n"); | |
447 | - printf(" MatchProduct \"%s\"\n", sysfs_name); | |
448 | - printf(" Option \"Calibration\" \"%d %d %d %d\"\n", | |
449 | - new_axys.x_min, new_axys.x_max, new_axys.y_min, new_axys.y_max); | |
450 | - if (swap_xy != 0) | |
451 | - printf(" Option \"SwapAxes\" \"%d\"\n", new_swap_xy); | |
452 | - printf("EndSection\n"); | |
473 | + info (" copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf'\n"); | |
474 | + output("Section \"InputClass\"\n"); | |
475 | + output(" Identifier \"calibration\"\n"); | |
476 | + output(" MatchProduct \"%s\"\n", sysfs_name); | |
477 | + output(" Option \"Calibration\" \"%d %d %d %d\"\n", | |
478 | + new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
479 | + output (" Option \"SwapAxes\" \"%d\"\n", new_swap_xy); | |
480 | + output (" Option \"InvertX\" \"%d\"\n", new_invert_x); | |
481 | + output (" Option \"InvertY\" \"%d\"\n", new_invert_y); | |
482 | + output("EndSection\n"); | |
453 | 483 | |
454 | 484 | if (not_sysfs_name) |
455 | - printf("\nChange '%s' to your device's name in the snippet above.\n", sysfs_name); | |
485 | + info ("\nChange '%s' to your device's name in the snippet above.\n", sysfs_name); | |
456 | 486 | |
457 | 487 | return true; |
458 | 488 | } |
459 | 489 | |
460 | -bool CalibratorEvdev::output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy) | |
490 | +bool CalibratorEvdev::output_hal(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y) | |
461 | 491 | { |
462 | 492 | const char* sysfs_name = get_sysfs_name(); |
463 | 493 | bool not_sysfs_name = (sysfs_name == NULL); |
@@ -465,27 +495,28 @@ bool CalibratorEvdev::output_hal(const XYinfo new_axys, int swap_xy, int new_swa | ||
465 | 495 | sysfs_name = "!!Name_Of_TouchScreen!!"; |
466 | 496 | |
467 | 497 | // HAL policy output |
468 | - printf(" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n\ | |
469 | -<match key=\"info.product\" contains=\"%s\">\n\ | |
470 | - <merge key=\"input.x11_options.calibration\" type=\"string\">%d %d %d %d</merge>\n" | |
471 | - , sysfs_name, new_axys.x_min, new_axys.x_max, new_axys.y_min, new_axys.y_max); | |
472 | - if (swap_xy != 0) | |
473 | - printf(" <merge key=\"input.x11_options.swapaxes\" type=\"string\">%d</merge>\n", new_swap_xy); | |
474 | - printf("</match>\n"); | |
498 | + info (" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n"); | |
499 | + output ( "<match key=\"info.product\" contains=\"%s\">\n\ | |
500 | + <merge key=\"input.x11_options.calibration\" type=\"string\">%d %d %d %d</merge>\n", | |
501 | + sysfs_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
502 | + output(" <merge key=\"input.x11_options.swapaxes\" type=\"string\">%d</merge>\n", new_swap_xy); | |
503 | + output(" <merge key=\"input.x11_options.invertx\" type=\"string\">%d</merge>\n", new_invert_x); | |
504 | + output(" <merge key=\"input.x11_options.inverty\" type=\"string\">%d</merge>\n", new_invert_y); | |
505 | + output("</match>\n"); | |
475 | 506 | |
476 | 507 | if (not_sysfs_name) |
477 | - printf("\nChange '%s' to your device's name in the config above.\n", sysfs_name); | |
508 | + info ("\nChange '%s' to your device's name in the config above.\n", sysfs_name); | |
478 | 509 | |
479 | 510 | return true; |
480 | 511 | } |
481 | 512 | |
482 | -bool CalibratorEvdev::output_xinput(const XYinfo new_axys, int swap_xy, int new_swap_xy) | |
513 | +bool CalibratorEvdev::output_xinput(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y) | |
483 | 514 | { |
484 | 515 | // create startup script |
485 | - printf(" Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session\n"); | |
486 | - 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); | |
487 | - if (swap_xy) | |
488 | - printf(" xinput set-int-prop \"%s\" \"Evdev Axes Swap\" 8 %d\n", device_name, new_swap_xy); | |
516 | + info (" Install the 'xinput' tool and copy the command(s) below in a script that starts with your X session\n"); | |
517 | + output (" xinput set-prop \"%s\" \"Evdev Axis Calibration\" %d %d %d %d\n", device_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
489 | 518 | |
519 | + output (" xinput set-prop \"%s\" \"Evdev Axes Swap\" %d\n", device_name, new_swap_xy); | |
520 | + output (" xinput set-prop \"%s\" \"Evdev Axis Inversion\" %d %d\n", device_name, new_invert_x, new_invert_y); | |
490 | 521 | return true; |
491 | 522 | } |
@@ -35,29 +35,29 @@ class CalibratorEvdev: public Calibrator | ||
35 | 35 | { |
36 | 36 | private: |
37 | 37 | Display *display; |
38 | - XDeviceInfo *info; | |
38 | + XDeviceInfo *devInfo; | |
39 | 39 | XDevice *dev; |
40 | 40 | |
41 | - int old_swap_xy; | |
42 | 41 | public: |
43 | - CalibratorEvdev(const char* const device_name, const XYinfo& axys, const bool verbose, | |
42 | + CalibratorEvdev(const char* const device_name, const XYinfo& axys, | |
44 | 43 | XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0, |
45 | 44 | const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); |
46 | 45 | ~CalibratorEvdev(); |
47 | 46 | |
48 | - virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
47 | + virtual bool finish_data(const XYinfo new_axys); | |
49 | 48 | |
50 | 49 | bool set_swapxy(const int swap_xy); |
50 | + bool set_invert_xy(bool axisX, const int invert_x, const int invert_y ); | |
51 | 51 | bool set_calibration(const XYinfo new_axys); |
52 | 52 | |
53 | 53 | // xinput_ functions (from the xinput project) |
54 | 54 | Atom xinput_parse_atom(Display *display, const char* name); |
55 | 55 | XDeviceInfo* xinput_find_device_info(Display *display, const char* name, Bool only_extended); |
56 | - int xinput_do_set_prop(Display *display, Atom type, int format, int argc, char* argv[]); | |
56 | + int xinput_do_set_prop(Display *display, Atom type, int format, int argc, const char** argv); | |
57 | 57 | protected: |
58 | - bool output_xorgconfd(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
59 | - bool output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
60 | - bool output_xinput(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
58 | + bool output_xorgconfd(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y); | |
59 | + bool output_hal(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y); | |
60 | + bool output_xinput(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y); | |
61 | 61 | }; |
62 | 62 | |
63 | 63 | #endif |
@@ -1,5 +1,6 @@ | ||
1 | 1 | /* |
2 | 2 | * Copyright (c) 2009 Soren Hauberg |
3 | + * Copyright (c) 2011 Antoine Hue | |
3 | 4 | * |
4 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | 6 | * of this software and associated documentation files (the "Software"), to deal |
@@ -48,67 +49,67 @@ static const char *p_flip_x = "flip_x"; | ||
48 | 49 | static const char *p_flip_y = "flip_y"; |
49 | 50 | static const char *p_swap_xy = "swap_xy"; |
50 | 51 | |
51 | -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, const char* geometry) | |
52 | - : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type, geometry) | |
52 | +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) | |
53 | + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) | |
53 | 54 | { |
54 | 55 | if (strcmp(device_name, "Usbtouchscreen") != 0) |
55 | 56 | throw WrongCalibratorException("Not a usbtouchscreen device"); |
56 | 57 | |
57 | 58 | // Reset the currently running kernel |
58 | 59 | read_bool_parameter(p_transform_xy, val_transform_xy); |
59 | - read_bool_parameter(p_flip_x, val_flip_x); | |
60 | - read_bool_parameter(p_flip_y, val_flip_y); | |
61 | - read_bool_parameter(p_swap_xy, val_swap_xy); | |
60 | + read_bool_parameter(p_flip_x, old_axys.x.invert); | |
61 | + read_bool_parameter(p_flip_y, old_axys.y.invert); | |
62 | + read_bool_parameter(p_swap_xy, old_axys.swap_xy); | |
62 | 63 | |
64 | +#if 0 // do not modify current | |
63 | 65 | write_bool_parameter(p_transform_xy, false); |
64 | 66 | write_bool_parameter(p_flip_x, false); |
65 | 67 | write_bool_parameter(p_flip_y, false); |
66 | 68 | write_bool_parameter(p_swap_xy, false); |
67 | - | |
68 | - printf("Calibrating Usbtouchscreen, through the kernel module\n"); | |
69 | +#endif | |
70 | + info ("Calibrating Usbtouchscreen, through the kernel module\n"); | |
69 | 71 | } |
70 | 72 | |
71 | 73 | CalibratorUsbtouchscreen::~CalibratorUsbtouchscreen() |
72 | 74 | { |
75 | +#if 0 // do not modify current | |
73 | 76 | // Dirty exit, so we restore the parameters of the running kernel |
74 | 77 | write_bool_parameter (p_transform_xy, val_transform_xy); |
75 | 78 | write_bool_parameter (p_flip_x, val_flip_x); |
76 | 79 | write_bool_parameter (p_flip_y, val_flip_y); |
77 | 80 | write_bool_parameter (p_swap_xy, val_swap_xy); |
81 | +#endif | |
78 | 82 | } |
79 | 83 | |
80 | -bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy) | |
84 | +bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys) | |
81 | 85 | { |
82 | 86 | if (output_type != OUTYPE_AUTO) { |
83 | - fprintf(stderr, "ERROR: Usbtouchscreen Calibrator does not support the supplied --output-type\n"); | |
87 | + error ("Usbtouchscreen Calibrator does not support the supplied --output-type\n"); | |
84 | 88 | return false; |
85 | 89 | } |
86 | 90 | |
87 | 91 | // New ranges |
88 | - const int range_x = (new_axys.x_max - new_axys.x_min); | |
89 | - const int range_y = (new_axys.y_max - new_axys.y_min); | |
90 | - // Should x and y be flipped ? | |
91 | - const bool flip_x = (new_axys.x_min > new_axys.x_max); | |
92 | - const bool flip_y = (new_axys.y_min > new_axys.y_max); | |
92 | + const int range_x = (new_axys.x.max - new_axys.x.min); | |
93 | + const int range_y = (new_axys.y.max - new_axys.y.min); | |
93 | 94 | |
94 | 95 | // Send the estimated parameters to the currently running kernel |
95 | 96 | write_int_parameter(p_range_x, range_x); |
96 | 97 | write_int_parameter(p_range_y, range_y); |
97 | - write_int_parameter(p_min_x, new_axys.x_min); | |
98 | - write_int_parameter(p_max_x, new_axys.x_max); | |
99 | - write_int_parameter(p_min_y, new_axys.y_min); | |
100 | - write_int_parameter(p_max_y, new_axys.y_max); | |
98 | + write_int_parameter(p_min_x, new_axys.x.min); | |
99 | + write_int_parameter(p_max_x, new_axys.x.max); | |
100 | + write_int_parameter(p_min_y, new_axys.y.min); | |
101 | + write_int_parameter(p_max_y, new_axys.y.max); | |
101 | 102 | write_bool_parameter(p_transform_xy, true); |
102 | - write_bool_parameter(p_flip_x, flip_x); | |
103 | - write_bool_parameter(p_flip_y, flip_y); | |
104 | - write_bool_parameter(p_swap_xy, swap_xy); | |
103 | + write_bool_parameter(p_flip_x, new_axys.x.invert); | |
104 | + write_bool_parameter(p_flip_y, new_axys.y.invert); | |
105 | + write_bool_parameter(p_swap_xy, new_axys.swap_xy); | |
105 | 106 | |
106 | 107 | // Read, then write calibration parameters to modprobe_conf_local, |
107 | 108 | // to keep the for the next boot |
108 | 109 | FILE *fid = fopen(modprobe_conf_local, "r"); |
109 | 110 | if (fid == NULL) { |
110 | - fprintf(stderr, "Error: Can't open '%s' for reading. Make sure you have the necessary rights\n", modprobe_conf_local); | |
111 | - fprintf(stderr, "New calibration data NOT saved\n"); | |
111 | + error ( "Can't open '%s' for reading. Make sure you have the necessary rights\n", modprobe_conf_local); | |
112 | + error ( "\tNew calibration data NOT saved\n"); | |
112 | 113 | return false; |
113 | 114 | } |
114 | 115 |
@@ -129,16 +130,16 @@ bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy) | ||
129 | 130 | char *new_opt = new char[opt_len]; |
130 | 131 | sprintf(new_opt, "%s %s=%d %s=%d %s=%d %s=%d %s=%d %s=%d %s=%c %s=%c %s=%c %s=%c\n", |
131 | 132 | opt, p_range_x, range_x, p_range_y, range_y, |
132 | - p_min_x, new_axys.x_min, p_min_y, new_axys.y_min, | |
133 | - p_max_x, new_axys.x_max, p_max_y, new_axys.y_max, | |
134 | - p_transform_xy, yesno(true), p_flip_x, yesno(flip_x), | |
135 | - p_flip_y, yesno(flip_y), p_swap_xy, yesno(swap_xy)); | |
133 | + p_min_x, new_axys.x.min, p_min_y, new_axys.y.min, | |
134 | + p_max_x, new_axys.x.max, p_max_y, new_axys.y.max, | |
135 | + p_transform_xy, yesno(true), p_flip_x, yesno(new_axys.x.invert), | |
136 | + p_flip_y, yesno(new_axys.y.invert), p_swap_xy, yesno(new_axys.swap_xy)); | |
136 | 137 | new_contents += new_opt; |
137 | 138 | |
138 | 139 | fid = fopen(modprobe_conf_local, "w"); |
139 | 140 | if (fid == NULL) { |
140 | - fprintf(stderr, "Error: Can't open '%s' for writing. Make sure you have the necessary rights\n", modprobe_conf_local); | |
141 | - fprintf(stderr, "New calibration data NOT saved\n"); | |
141 | + error ( "Can't open '%s' for writing. Make sure you have the necessary rights\n", modprobe_conf_local); | |
142 | + error ( "\tNew calibration data NOT saved\n"); | |
142 | 143 | return false; |
143 | 144 | } |
144 | 145 | fprintf(fid, "%s", new_contents.c_str ()); |
@@ -154,7 +155,7 @@ void CalibratorUsbtouchscreen::read_int_parameter(const char *param, int &value) | ||
154 | 155 | sprintf(filename, "%s/%s", module_prefix, param); |
155 | 156 | FILE *fid = fopen(filename, "r"); |
156 | 157 | if (fid == NULL) { |
157 | - fprintf(stderr, "Could not read parameter '%s'\n", param); | |
158 | + error ( "Could not read parameter '%s'\n", param); | |
158 | 159 | return; |
159 | 160 | } |
160 | 161 |
@@ -169,7 +170,7 @@ void CalibratorUsbtouchscreen::read_int_parameter(const char *param, int &value) | ||
169 | 170 | sprintf(filename, "%s/%s", module_prefix, param); |
170 | 171 | FILE *fid = fopen(filename, "r"); |
171 | 172 | if (fid == NULL) { |
172 | - fprintf(stderr, "Could not read parameter '%s'\n", param); | |
173 | + error ( "Could not read parameter '%s'\n", param); | |
173 | 174 | return; |
174 | 175 | } |
175 | 176 |
@@ -186,7 +187,7 @@ void CalibratorUsbtouchscreen::read_int_parameter(const char *param, int &value) | ||
186 | 187 | sprintf(filename, "%s/%s", module_prefix, param); |
187 | 188 | FILE *fid = fopen(filename, "w"); |
188 | 189 | if (fid == NULL) { |
189 | - fprintf(stderr, "Could not save parameter '%s'\n", param); | |
190 | + error ( "Could not save parameter '%s'\n", param); | |
190 | 191 | return; |
191 | 192 | } |
192 | 193 |
@@ -200,7 +201,7 @@ void CalibratorUsbtouchscreen::write_bool_parameter(const char *param, const boo | ||
200 | 201 | sprintf(filename, "%s/%s", module_prefix, param); |
201 | 202 | FILE *fid = fopen(filename, "w"); |
202 | 203 | if (fid == NULL) { |
203 | - fprintf(stderr, "Could not save parameter '%s'\n", param); | |
204 | + error ("Could not save parameter '%s'\n", param); | |
204 | 205 | return; |
205 | 206 | } |
206 | 207 |
@@ -33,19 +33,19 @@ class CalibratorUsbtouchscreen: public Calibrator | ||
33 | 33 | { |
34 | 34 | public: |
35 | 35 | CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys, |
36 | - const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, | |
36 | + const int thr_misclick=0, const int thr_doubleclick=0, | |
37 | 37 | const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); |
38 | 38 | ~CalibratorUsbtouchscreen(); |
39 | 39 | |
40 | - virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
40 | + virtual bool finish_data(const XYinfo new_axys); | |
41 | 41 | |
42 | 42 | protected: |
43 | 43 | // Globals for kernel parameters from startup. |
44 | 44 | // We revert to these if the program aborts |
45 | - bool val_transform_xy, val_flip_x, val_flip_y, val_swap_xy; | |
45 | + bool val_transform_xy; | |
46 | 46 | |
47 | 47 | // Helper functions |
48 | - char yesno(const bool value) | |
48 | + inline char yesno(const bool value) | |
49 | 49 | { |
50 | 50 | if (value) |
51 | 51 | return 'Y'; |
@@ -1,5 +1,6 @@ | ||
1 | 1 | /* |
2 | 2 | * Copyright (c) 2009 Tias Guns |
3 | + * Copyright (c) 2011 Antoine Hue | |
3 | 4 | * |
4 | 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | 6 | * of this software and associated documentation files (the "Software"), to deal |
@@ -24,48 +25,50 @@ | ||
24 | 25 | |
25 | 26 | #include <cstdio> |
26 | 27 | |
27 | -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, const char* geometry) | |
28 | - : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type, geometry) | |
28 | +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) | |
29 | + : Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry) | |
29 | 30 | { |
30 | - printf("Calibrating standard Xorg driver \"%s\"\n", device_name); | |
31 | - printf("\tcurrent calibration values: min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", | |
32 | - old_axys.x_min, old_axys.x_max, old_axys.y_min, old_axys.y_max); | |
33 | - printf("\tIf these values are estimated wrong, either supply it manually with the --precalib option, or run the 'get_precalib.sh' script to automatically get it (through HAL).\n"); | |
31 | + trace("Calibrating standard Xorg driver \"%s\"\n", device_name); | |
32 | + trace("\tcurrent calibration values: min_x=%d, max_x=%d and min_y=%d, max_y=%d\n", | |
33 | + old_axys.x.min, old_axys.x.max, old_axys.y.min, old_axys.y.max); | |
34 | + trace("\tIf these values are estimated wrong, either supply it manually with the --precalib option, or run the 'get_precalib.sh' script to automatically get it (through HAL).\n"); | |
34 | 35 | } |
35 | 36 | |
36 | -bool CalibratorXorgPrint::finish_data(const XYinfo new_axys, int swap_xy) | |
37 | +bool CalibratorXorgPrint::finish_data(const XYinfo new_axys) | |
37 | 38 | { |
38 | 39 | bool success = true; |
39 | 40 | |
40 | - // we suppose the previous 'swap_xy' value was 0 | |
41 | + // we suppose the previous 'swap_xy', 'invert_x', 'invert_y' value was 0 | |
41 | 42 | // (unfortunately there is no way to verify this (yet)) |
42 | - int new_swap_xy = swap_xy; | |
43 | + int new_swap_xy = (new_axys.swap_xy)? 1: 0; | |
44 | + int new_invert_x = (new_axys.x.invert)? 1: 0; | |
45 | + int new_invert_y = (new_axys.y.invert)? 1: 0; | |
43 | 46 | |
44 | - printf("\n\n--> Making the calibration permanent <--\n"); | |
47 | + info ("\t--> Making the calibration permanent <--\n"); | |
45 | 48 | switch (output_type) { |
46 | 49 | case OUTYPE_AUTO: |
47 | 50 | // xorg.conf.d or alternatively hal config |
48 | 51 | if (has_xorgconfd_support()) { |
49 | - success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
52 | + success &= output_xorgconfd(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
50 | 53 | } else { |
51 | - success &= output_hal(new_axys, swap_xy, new_swap_xy); | |
54 | + success &= output_hal(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
52 | 55 | } |
53 | 56 | break; |
54 | 57 | case OUTYPE_XORGCONFD: |
55 | - success &= output_xorgconfd(new_axys, swap_xy, new_swap_xy); | |
58 | + success &= output_xorgconfd(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
56 | 59 | break; |
57 | 60 | case OUTYPE_HAL: |
58 | - success &= output_hal(new_axys, swap_xy, new_swap_xy); | |
61 | + success &= output_hal(new_axys, new_swap_xy, new_invert_x, new_invert_y); | |
59 | 62 | break; |
60 | 63 | default: |
61 | - fprintf(stderr, "ERROR: XorgPrint Calibrator does not support the supplied --output-type\n"); | |
64 | + error ( "XorgPrint Calibrator does not support the supplied --output-type\n"); | |
62 | 65 | success = false; |
63 | 66 | } |
64 | 67 | |
65 | 68 | return success; |
66 | 69 | } |
67 | 70 | |
68 | -bool CalibratorXorgPrint::output_xorgconfd(const XYinfo new_axys, int swap_xy, int new_swap_xy) | |
71 | +bool CalibratorXorgPrint::output_xorgconfd(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y) | |
69 | 72 | { |
70 | 73 | const char* sysfs_name = get_sysfs_name(); |
71 | 74 | bool not_sysfs_name = (sysfs_name == NULL); |
@@ -73,25 +76,26 @@ bool CalibratorXorgPrint::output_xorgconfd(const XYinfo new_axys, int swap_xy, i | ||
73 | 76 | sysfs_name = "!!Name_Of_TouchScreen!!"; |
74 | 77 | |
75 | 78 | // xorg.conf.d snippet |
76 | - printf(" copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf'\n"); | |
77 | - printf("Section \"InputClass\"\n"); | |
78 | - printf(" Identifier \"calibration\"\n"); | |
79 | - printf(" MatchProduct \"%s\"\n", sysfs_name); | |
80 | - printf(" Option \"MinX\" \"%d\"\n", new_axys.x_min); | |
81 | - printf(" Option \"MaxX\" \"%d\"\n", new_axys.x_max); | |
82 | - printf(" Option \"MinY\" \"%d\"\n", new_axys.y_min); | |
83 | - printf(" Option \"MaxY\" \"%d\"\n", new_axys.y_max); | |
84 | - if (swap_xy != 0) | |
85 | - printf(" Option \"SwapXY\" \"%d\" # unless it was already set to 1\n", new_swap_xy); | |
86 | - printf("EndSection\n"); | |
79 | + info (" copy the snippet below into '/etc/X11/xorg.conf.d/99-calibration.conf'\n"); | |
80 | + output("Section \"InputClass\"\n"); | |
81 | + output(" Identifier \"calibration\"\n"); | |
82 | + output(" MatchProduct \"%s\"\n", sysfs_name); | |
83 | + output(" Option \"MinX\" \"%d\"\n", new_axys.x.min); | |
84 | + output(" Option \"MaxX\" \"%d\"\n", new_axys.x.max); | |
85 | + output(" Option \"MinY\" \"%d\"\n", new_axys.y.min); | |
86 | + output(" Option \"MaxY\" \"%d\"\n", new_axys.y.max); | |
87 | + output(" Option \"SwapXY\" \"%d\" # unless it was already set\n", new_swap_xy); | |
88 | + output(" Option \"InvertX\" \"%d\" # unless it was already set\n", new_invert_x); | |
89 | + output(" Option \"InvertY\" \"%d\" # unless it was already set\n", new_invert_y); | |
90 | + output("EndSection\n"); | |
87 | 91 | |
88 | 92 | if (not_sysfs_name) |
89 | - printf("\nChange '%s' to your device's name in the config above.\n", sysfs_name); | |
93 | + trace("Change '%s' to your device's name in the config above.\n", sysfs_name); | |
90 | 94 | |
91 | 95 | return true; |
92 | 96 | } |
93 | 97 | |
94 | -bool CalibratorXorgPrint::output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy) | |
98 | +bool CalibratorXorgPrint::output_hal(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y) | |
95 | 99 | { |
96 | 100 | const char* sysfs_name = get_sysfs_name(); |
97 | 101 | bool not_sysfs_name = (sysfs_name == NULL); |
@@ -99,19 +103,21 @@ bool CalibratorXorgPrint::output_hal(const XYinfo new_axys, int swap_xy, int new | ||
99 | 103 | sysfs_name = "!!Name_Of_TouchScreen!!"; |
100 | 104 | |
101 | 105 | // HAL policy output |
102 | - printf(" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n\ | |
103 | -<match key=\"info.product\" contains=\"%s\">\n\ | |
104 | - <merge key=\"input.x11_options.minx\" type=\"string\">%d</merge>\n\ | |
105 | - <merge key=\"input.x11_options.maxx\" type=\"string\">%d</merge>\n\ | |
106 | - <merge key=\"input.x11_options.miny\" type=\"string\">%d</merge>\n\ | |
107 | - <merge key=\"input.x11_options.maxy\" type=\"string\">%d</merge>\n" | |
108 | - , sysfs_name, new_axys.x_min, new_axys.x_max, new_axys.y_min, new_axys.y_max); | |
109 | - if (swap_xy != 0) | |
110 | - printf(" <merge key=\"input.x11_options.swapxy\" type=\"string\">%d</merge>\n", new_swap_xy); | |
111 | - printf("</match>\n"); | |
106 | + info (" copy the policy below into '/etc/hal/fdi/policy/touchscreen.fdi'\n"); | |
107 | + output ( "<match key=\"info.product\" contains=\"%s\">\n\ | |
108 | + <merge key=\"input.x11_options.minx\" type=\"string\">%d</merge>\n\ | |
109 | + <merge key=\"input.x11_options.maxx\" type=\"string\">%d</merge>\n\ | |
110 | + <merge key=\"input.x11_options.miny\" type=\"string\">%d</merge>\n\ | |
111 | + <merge key=\"input.x11_options.maxy\" type=\"string\">%d</merge>\n" | |
112 | + , sysfs_name, new_axys.x.min, new_axys.x.max, new_axys.y.min, new_axys.y.max); | |
113 | + | |
114 | + output(" <merge key=\"input.x11_options.swapxy\" type=\"string\">%d</merge>\n", new_swap_xy); | |
115 | + output(" <merge key=\"input.x11_options.invertx\" type=\"string\">%d</merge>\n", new_invert_x); | |
116 | + output(" <merge key=\"input.x11_options.inverty\" type=\"string\">%d</merge>\n", new_invert_y); | |
117 | + output("</match>\n"); | |
112 | 118 | |
113 | 119 | if (not_sysfs_name) |
114 | - printf("\nChange '%s' to your device's name in the config above.\n", sysfs_name); | |
120 | + info("\nChange '%s' to your device's name in the config above.\n", sysfs_name); | |
115 | 121 | |
116 | 122 | return true; |
117 | 123 | } |
@@ -33,13 +33,14 @@ class CalibratorXorgPrint: public Calibrator | ||
33 | 33 | { |
34 | 34 | public: |
35 | 35 | CalibratorXorgPrint(const char* const device_name, const XYinfo& axys, |
36 | - const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, | |
36 | + const int thr_misclick=0, const int thr_doubleclick=0, | |
37 | 37 | const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); |
38 | 38 | |
39 | - virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
39 | + virtual bool finish_data(const XYinfo new_axys); | |
40 | + | |
40 | 41 | protected: |
41 | - bool output_xorgconfd(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
42 | - bool output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
42 | + bool output_xorgconfd(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y); | |
43 | + bool output_hal(const XYinfo new_axys, int new_swap_xy, int new_invert_x, int new_invert_y); | |
43 | 44 | }; |
44 | 45 | |
45 | 46 | #endif |
@@ -54,7 +54,7 @@ static char* my_strdup(const char* s) { | ||
54 | 54 | * retuns number of devices found, |
55 | 55 | * the data of the device is returned in the last 3 function parameters |
56 | 56 | */ |
57 | -static int find_device(const char* pre_device, bool verbose, bool list_devices, | |
57 | +int Calibrator::find_device(const char* pre_device, bool list_devices, | |
58 | 58 | XID& device_id, const char*& device_name, XYinfo& device_axys) |
59 | 59 | { |
60 | 60 | bool pre_device_is_id = true; |
@@ -62,13 +62,13 @@ static int find_device(const char* pre_device, bool verbose, bool list_devices, | ||
62 | 62 | |
63 | 63 | Display* display = XOpenDisplay(NULL); |
64 | 64 | if (display == NULL) { |
65 | - fprintf(stderr, "Unable to connect to X server\n"); | |
65 | + error ( "Unable to connect to X server\n"); | |
66 | 66 | exit(1); |
67 | 67 | } |
68 | 68 | |
69 | - int xi_opcode, event, error; | |
70 | - if (!XQueryExtension(display, "XInputExtension", &xi_opcode, &event, &error)) { | |
71 | - fprintf(stderr, "X Input extension not available.\n"); | |
69 | + int xi_opcode, event, err; | |
70 | + if (!XQueryExtension(display, "XInputExtension", &xi_opcode, &event, &err)) { | |
71 | + error ( "X Input extension not available.\n"); | |
72 | 72 | exit(1); |
73 | 73 | } |
74 | 74 |
@@ -77,7 +77,7 @@ static int find_device(const char* pre_device, bool verbose, bool list_devices, | ||
77 | 77 | XExtensionVersion *version = XGetExtensionVersion(display, INAME); |
78 | 78 | |
79 | 79 | if (version && (version != (XExtensionVersion*) NoSuchExtension)) { |
80 | - printf("DEBUG: %s version is %i.%i\n", | |
80 | + trace ("%s version is %i.%i\n", | |
81 | 81 | INAME, version->major_version, version->minor_version); |
82 | 82 | XFree(version); |
83 | 83 | } |
@@ -94,9 +94,7 @@ static int find_device(const char* pre_device, bool verbose, bool list_devices, | ||
94 | 94 | } |
95 | 95 | } |
96 | 96 | |
97 | - | |
98 | - if (verbose) | |
99 | - printf("DEBUG: Skipping virtual master devices and devices without axis valuators.\n"); | |
97 | + trace ("Skipping virtual master devices and devices without axis valuators.\n"); | |
100 | 98 | int ndevices; |
101 | 99 | XDeviceInfoPtr list, slist; |
102 | 100 | slist=list=(XDeviceInfoPtr) XListInputDevices (display, &ndevices); |
@@ -126,27 +124,25 @@ static int find_device(const char* pre_device, bool verbose, bool list_devices, | ||
126 | 124 | XAxisInfoPtr ax = (XAxisInfoPtr) V->axes; |
127 | 125 | |
128 | 126 | if (V->mode != Absolute) { |
129 | - if (verbose) | |
130 | - printf("DEBUG: Skipping device '%s' id=%i, does not report Absolute events.\n", | |
127 | + trace ( "Skipping device '%s' id=%i, does not report Absolute events.\n", | |
131 | 128 | list->name, (int)list->id); |
132 | 129 | } else if (V->num_axes < 2 || |
133 | 130 | (ax[0].min_value == -1 && ax[0].max_value == -1) || |
134 | 131 | (ax[1].min_value == -1 && ax[1].max_value == -1)) { |
135 | - if (verbose) | |
136 | - printf("DEBUG: Skipping device '%s' id=%i, does not have two calibratable axes.\n", | |
132 | + trace ( "Skipping device '%s' id=%i, does not have two calibratable axes.\n", | |
137 | 133 | list->name, (int)list->id); |
138 | 134 | } else { |
139 | 135 | /* a calibratable device (has 2 axis valuators) */ |
140 | 136 | found++; |
141 | 137 | device_id = list->id; |
142 | 138 | device_name = my_strdup(list->name); |
143 | - device_axys.x_min = ax[0].min_value; | |
144 | - device_axys.x_max = ax[0].max_value; | |
145 | - device_axys.y_min = ax[1].min_value; | |
146 | - device_axys.y_max = ax[1].max_value; | |
139 | + device_axys.x.min = ax[0].min_value; | |
140 | + device_axys.x.max = ax[0].max_value; | |
141 | + device_axys.y.min = ax[1].min_value; | |
142 | + device_axys.y.max = ax[1].max_value; | |
147 | 143 | |
148 | 144 | if (list_devices) |
149 | - printf("Device \"%s\" id=%i\n", device_name, (int)device_id); | |
145 | + info ("Device \"%s\" id=%i\n", device_name, (int)device_id); | |
150 | 146 | } |
151 | 147 | |
152 | 148 | } |
@@ -183,7 +179,6 @@ static void usage(char* cmd, unsigned thr_misclick) | ||
183 | 179 | |
184 | 180 | Calibrator* Calibrator::make_calibrator(int argc, char** argv) |
185 | 181 | { |
186 | - bool verbose = false; | |
187 | 182 | bool list_devices = false; |
188 | 183 | bool fake = false; |
189 | 184 | bool precalib = false; |
@@ -200,7 +195,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
200 | 195 | // Display help ? |
201 | 196 | if (strcmp("-h", argv[i]) == 0 || |
202 | 197 | strcmp("--help", argv[i]) == 0) { |
203 | - fprintf(stderr, "xinput_calibrator, v%s\n\n", VERSION); | |
198 | + error ( "xinput_calibrator, v%s\n\n", VERSION); | |
204 | 199 | usage(argv[0], thr_misclick); |
205 | 200 | exit(0); |
206 | 201 | } else |
@@ -221,7 +216,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
221 | 216 | if (argc > i+1) |
222 | 217 | pre_device = argv[++i]; |
223 | 218 | else { |
224 | - fprintf(stderr, "Error: --device needs a device name or id as argument; use --list to list the calibratable input devices.\n\n"); | |
219 | + error( "--device needs a device name or id as argument; use --list to list the calibratable input devices.\n\n"); | |
225 | 220 | usage(argv[0], thr_misclick); |
226 | 221 | exit(1); |
227 | 222 | } |
@@ -231,13 +226,13 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
231 | 226 | if (strcmp("--precalib", argv[i]) == 0) { |
232 | 227 | precalib = true; |
233 | 228 | if (argc > i+1) |
234 | - pre_axys.x_min = atoi(argv[++i]); | |
229 | + pre_axys.x.min = atoi(argv[++i]); | |
235 | 230 | if (argc > i+1) |
236 | - pre_axys.x_max = atoi(argv[++i]); | |
231 | + pre_axys.x.max = atoi(argv[++i]); | |
237 | 232 | if (argc > i+1) |
238 | - pre_axys.y_min = atoi(argv[++i]); | |
233 | + pre_axys.y.min = atoi(argv[++i]); | |
239 | 234 | if (argc > i+1) |
240 | - pre_axys.y_max = atoi(argv[++i]); | |
235 | + pre_axys.y.max = atoi(argv[++i]); | |
241 | 236 | } else |
242 | 237 | |
243 | 238 | // Get mis-click threshold ? |
@@ -245,7 +240,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
245 | 240 | if (argc > i+1) |
246 | 241 | thr_misclick = atoi(argv[++i]); |
247 | 242 | else { |
248 | - fprintf(stderr, "Error: --misclick needs a number (the pixel threshold) as argument. Set to 0 to disable mis-click detection.\n\n"); | |
243 | + error ( "--misclick needs a number (the pixel threshold) as argument. Set to 0 to disable mis-click detection.\n\n"); | |
249 | 244 | usage(argv[0], thr_misclick); |
250 | 245 | exit(1); |
251 | 246 | } |
@@ -264,12 +259,12 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
264 | 259 | else if (strcmp("xinput", argv[i]) == 0) |
265 | 260 | output_type = OUTYPE_XINPUT; |
266 | 261 | else { |
267 | - fprintf(stderr, "Error: --output-type needs one of auto|xorg.conf.d|hal|xinput.\n\n"); | |
262 | + error ( "--output-type needs one of auto|xorg.conf.d|hal|xinput.\n\n"); | |
268 | 263 | usage(argv[0], thr_misclick); |
269 | 264 | exit(1); |
270 | 265 | } |
271 | 266 | } else { |
272 | - fprintf(stderr, "Error: --output-type needs one argument.\n\n"); | |
267 | + error ( "--output-type needs one argument.\n\n"); | |
273 | 268 | usage(argv[0], thr_misclick); |
274 | 269 | exit(1); |
275 | 270 | } |
@@ -304,18 +299,16 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
304 | 299 | device_name = "Fake_device"; |
305 | 300 | device_axys = XYinfo(0,1000,0,1000); |
306 | 301 | |
307 | - if (verbose) { | |
308 | - printf("DEBUG: Faking device: %s\n", device_name); | |
309 | - } | |
302 | + trace ("Faking device: %s\n", device_name); | |
310 | 303 | } else { |
311 | 304 | // Find the right device |
312 | - int nr_found = find_device(pre_device, verbose, list_devices, device_id, device_name, device_axys); | |
305 | + int nr_found = find_device(pre_device, list_devices, device_id, device_name, device_axys); | |
313 | 306 | |
314 | 307 | if (list_devices) { |
315 | 308 | // printed the list in find_device |
316 | 309 | if (nr_found == 0) |
317 | 310 | printf("No calibratable devices found.\n"); |
318 | - exit(0); | |
311 | + exit(2); | |
319 | 312 | } |
320 | 313 | |
321 | 314 | if (nr_found == 0) { |
@@ -326,30 +319,26 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
326 | 319 | exit(1); |
327 | 320 | |
328 | 321 | } else if (nr_found > 1) { |
329 | - printf ("Warning: multiple calibratable devices found, calibrating last one (%s)\n\tuse --device to select another one.\n", device_name); | |
322 | + info ("Warning: multiple calibratable devices found, calibrating last one (%s)\n\tuse --device to select another one.\n", device_name); | |
330 | 323 | } |
331 | 324 | |
332 | - if (verbose) { | |
333 | - printf("DEBUG: Selected device: %s\n", device_name); | |
334 | - } | |
325 | + trace ("Selected device: %s\n", device_name); | |
335 | 326 | } |
336 | 327 | |
337 | 328 | // override min/max XY from command line ? |
338 | 329 | if (precalib) { |
339 | - if (pre_axys.x_min != -1) | |
340 | - device_axys.x_min = pre_axys.x_min; | |
341 | - if (pre_axys.x_max != -1) | |
342 | - device_axys.x_max = pre_axys.x_max; | |
343 | - if (pre_axys.y_min != -1) | |
344 | - device_axys.y_min = pre_axys.y_min; | |
345 | - if (pre_axys.y_max != -1) | |
346 | - device_axys.y_max = pre_axys.y_max; | |
347 | - | |
348 | - if (verbose) { | |
349 | - printf("DEBUG: Setting precalibration: %i, %i, %i, %i\n", | |
350 | - device_axys.x_min, device_axys.x_max, | |
351 | - device_axys.y_min, device_axys.y_max); | |
352 | - } | |
330 | + if (pre_axys.x.min != -1) | |
331 | + device_axys.x.min = pre_axys.x.min; | |
332 | + if (pre_axys.x.max != -1) | |
333 | + device_axys.x.max = pre_axys.x.max; | |
334 | + if (pre_axys.y.min != -1) | |
335 | + device_axys.y.min = pre_axys.y.min; | |
336 | + if (pre_axys.y.max != -1) | |
337 | + device_axys.y.max = pre_axys.y.max; | |
338 | + | |
339 | + trace ( "Setting precalibration: %i, %i, %i, %i\n", | |
340 | + device_axys.x.min, device_axys.x.max, | |
341 | + device_axys.y.min, device_axys.y.max); | |
353 | 342 | } |
354 | 343 | |
355 | 344 |
@@ -357,24 +346,22 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv) | ||
357 | 346 | try { |
358 | 347 | // try Usbtouchscreen driver |
359 | 348 | return new CalibratorUsbtouchscreen(device_name, device_axys, |
360 | - verbose, thr_misclick, thr_doubleclick, output_type, geometry); | |
349 | + thr_misclick, thr_doubleclick, output_type, geometry); | |
361 | 350 | |
362 | 351 | } catch(WrongCalibratorException& x) { |
363 | - if (verbose) | |
364 | - printf("DEBUG: Not usbtouchscreen calibrator: %s\n", x.what()); | |
352 | + trace("Not usbtouchscreen calibrator: %s\n", x.what()); | |
365 | 353 | } |
366 | 354 | |
367 | 355 | try { |
368 | 356 | // next, try Evdev driver (with XID) |
369 | - return new CalibratorEvdev(device_name, device_axys, verbose, device_id, | |
357 | + return new CalibratorEvdev(device_name, device_axys, device_id, | |
370 | 358 | thr_misclick, thr_doubleclick, output_type, geometry); |
371 | 359 | |
372 | 360 | } catch(WrongCalibratorException& x) { |
373 | - if (verbose) | |
374 | - printf("DEBUG: Not evdev calibrator: %s\n", x.what()); | |
361 | + trace ("Not evdev calibrator: %s\n", x.what()); | |
375 | 362 | } |
376 | 363 | |
377 | 364 | // lastly, presume a standard Xorg driver (evtouch, mutouch, ...) |
378 | 365 | return new CalibratorXorgPrint(device_name, device_axys, |
379 | - verbose, thr_misclick, thr_doubleclick, output_type, geometry); | |
366 | + thr_misclick, thr_doubleclick, output_type, geometry); | |
380 | 367 | } |