• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A generic touchscreen calibration program for X.Org


Commit MetaInfo

Révisione4ffde5ab28397c3154a60d930bb15bed5cda2a3 (tree)
l'heure2011-04-20 19:24:48
AuteurAntoine Hue <antoine@peti...>
CommiterTias Guns

Message de Log

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.

Change Summary

Modification

--- a/src/calibrator.cpp
+++ b/src/calibrator.cpp
@@ -1,6 +1,7 @@
11 /*
22 * Copyright (c) 2009 Tias Guns
33 * Copyright (c) 2009 Soren Hauberg
4+ * Copyright (c) 2011 Antoine Hue
45 *
56 * Permission is hereby granted, free of charge, to any person obtaining a copy
67 * of this software and associated documentation files (the "Software"), to deal
@@ -26,46 +27,37 @@
2627 #include <iostream>
2728 #include <fstream>
2829 #include <cstring>
30+#include <stdarg.h>
2931
3032 #include "calibrator.hh"
3133
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;
3736
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)
4942 {
50- return num_clicks;
51-}
43+ old_axys = axys0;
5244
53-const char* Calibrator::get_geometry()
54-{
55- return geometry;
45+ clicked.num = 0;
46+ //clicked.x(NUM_POINTS);
47+ //clicked.y(NUM_POINTS);
5648 }
5749
5850 bool Calibrator::add_click(int x, int y)
5951 {
6052 // 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;
6355 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) {
6658 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);
6961 }
7062 return false;
7163 }
@@ -74,52 +66,61 @@ bool Calibrator::add_click(int x, int y)
7466 }
7567
7668 // Mis-click detection
77- if (threshold_misclick > 0 && num_clicks > 0) {
69+ if (threshold_misclick > 0 && clicked.num > 0) {
7870 bool misclick = true;
7971
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+ }
99111 }
100112
101113 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-
111114 reset();
112115 return false;
113116 }
114117 }
115118
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++;
122122
123+ trace("Adding click %i (X=%i, Y=%i)\n", clicked.num-1, x, y);
123124 return true;
124125 }
125126
@@ -129,47 +130,86 @@ inline bool Calibrator::along_axis(int xy, int x0, int y0)
129130 (abs(xy - y0) <= threshold_misclick));
130131 }
131132
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
132159 bool Calibrator::finish(int width, int height)
133160 {
134- if (get_numclicks() != 4) {
161+ if (get_numclicks() != NUM_POINTS) {
135162 return false;
136163 }
137164
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;
143184 }
144185
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+ }
154189
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
163191
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);
164195
165- // If x and y has to be swapped we also have to swap the parameters
196+ /// Compute calibration
166197 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 );
169203 }
170204
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+
171211 // finish the data, driver/calibrator specific
172- return finish_data(axys, swap_xy);
212+ return finish_data(new_axys);
173213 }
174214
175215 const char* Calibrator::get_sysfs_name()
@@ -202,8 +242,7 @@ bool Calibrator::is_sysfs_name(const char* name) {
202242 std::string devname;
203243 std::getline(ifile, devname);
204244 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);
207246 return true;
208247 }
209248 }
@@ -213,9 +252,8 @@ bool Calibrator::is_sysfs_name(const char* name) {
213252 }
214253 (void) closedir(dp);
215254
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);
219257 return false;
220258 }
221259
@@ -227,7 +265,7 @@ bool Calibrator::has_xorgconfd_support(Display* dpy) {
227265 display = XOpenDisplay(NULL);
228266
229267 if (display == NULL) {
230- fprintf(stderr, "Unable to connect to X server\n");
268+ error ( "Unable to connect to X server\n");
231269 exit(1);
232270 }
233271
@@ -241,3 +279,46 @@ bool Calibrator::has_xorgconfd_support(Display* dpy) {
241279
242280 return has_support;
243281 }
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+}
--- a/src/calibrator.hh
+++ b/src/calibrator.hh
@@ -1,6 +1,7 @@
11 /*
22 * Copyright (c) 2009 Tias Guns
33 * Copyright (c) 2009 Soren Hauberg
4+ * Copyright (c) 2011 Antoine Hue
45 *
56 * Permission is hereby granted, free of charge, to any person obtaining a copy
67 * of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,7 @@
2627
2728 #include <stdexcept>
2829 #include <X11/Xlib.h>
30+#include <vector>
2931
3032 /*
3133 * Number of blocks. We partition the screen into 'num_blocks' x 'num_blocks'
@@ -55,15 +57,23 @@
5557 */
5658 const int num_blocks = 8;
5759
60+struct AxisInfo {
61+ int min, max;
62+ bool invert;
63+ AxisInfo() : min(-1), max(-1), invert(false) { }
64+};
65+
5866 /// struct to hold min/max info of the X and Y axis
5967 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;}
6777 };
6878
6979 /// Names of the points
@@ -102,7 +112,6 @@ public:
102112 /// if the touchscreen is not of the type it supports
103113 Calibrator(const char* const device_name,
104114 const XYinfo& axys,
105- const bool verbose,
106115 const int thr_misclick=0,
107116 const int thr_doubleclick=0,
108117 const OutputType output_type=OUTYPE_AUTO,
@@ -111,21 +120,24 @@ public:
111120 ~Calibrator() {}
112121
113122 /// set the doubleclick treshold
114- void set_threshold_doubleclick(int t);
123+ void set_threshold_doubleclick(int t)
124+ { threshold_doubleclick = t; }
115125
116126 /// set the misclick treshold
117- void set_threshold_misclick(int t);
127+ void set_threshold_misclick(int t)
128+ { threshold_misclick = t; }
118129
119130 /// get the number of clicks already registered
120- int get_numclicks();
131+ int get_numclicks() const
132+ { return clicked.num; }
121133
122134 /// return geometry string or NULL
123- const char* get_geometry();
135+ const char* get_geometry() const
136+ { return geometry; }
124137
125138 /// reset clicks
126- void reset() {
127- num_clicks = 0;
128- }
139+ void reset()
140+ { clicked.num = 0; clicked.x.clear(); clicked.y.clear();}
129141
130142 /// add a click with the given coordinates
131143 bool add_click(int x, int y);
@@ -136,22 +148,54 @@ public:
136148 const char* get_sysfs_name();
137149
138150 protected:
139- // check whether the coordinates are along the respective axis
151+ /// check whether the coordinates are along the respective axis
140152 bool along_axis(int xy, int x0, int y0);
141153
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;
144186
145187 // name of the device (driver)
146188 const char* const device_name;
147- // original axys values
189+ /// Original values
148190 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;
155199
156200 // Threshold to keep the same point from being clicked twice.
157201 // Set to zero if you don't want this check
@@ -162,17 +206,11 @@ protected:
162206 // Set to zero if you don't want this check
163207 int threshold_misclick;
164208
165- // Type of output
209+ /// Format or type of output calibration
166210 OutputType output_type;
167211
168- // manually specified geometry string
212+ /// manually specified geometry string for the calibration pattern
169213 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);
176214 };
177215
178216 #endif
--- a/src/calibrator/Evdev.cpp
+++ b/src/calibrator/Evdev.cpp
@@ -1,6 +1,7 @@
11 /*
22 * Copyright (c) 2009 Tias Guns
33 * Copyright 2007 Peter Hutterer (xinput_ methods from xinput)
4+ * Copyright (c) 2011 Antoine Hue (invertX/Y)
45 *
56 * Permission is hereby granted, free of charge, to any person obtaining a copy
67 * of this software and associated documentation files (the "Software"), to deal
@@ -25,7 +26,6 @@
2526
2627 #include <X11/Xlib.h>
2728 #include <X11/Xatom.h>
28-//#include <X11/Xutil.h>
2929 #include <ctype.h>
3030 #include <cstdio>
3131 #include <cstring>
@@ -38,8 +38,15 @@
3838 #define EXIT_FAILURE 0
3939 #endif
4040
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)
4350 {
4451 // init
4552 display = XOpenDisplay(NULL);
@@ -49,12 +56,12 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& a
4956
5057 // normaly, we already have the device id
5158 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) {
5461 XCloseDisplay(display);
5562 throw WrongCalibratorException("Evdev: Unable to find device");
5663 }
57- device_id = info->id;
64+ device_id = devInfo->id;
5865 }
5966
6067 dev = XOpenDevice(display, device_id);
@@ -92,31 +99,29 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& a
9299
93100 } else if (nitems == 0) {
94101 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");
96103
97104 // No axis calibration set, set it to the default one
98105 // 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
100107 // not setting the values here would result in a wrong first calibration
101108 bool ok = set_calibration(old_axys);
102109
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");
109114
110115 } else if (nitems > 0) {
111116 ptr = data;
112117
113- old_axys.x_min = *((long*)ptr);
118+ old_axys.x.min = *((long*)ptr);
114119 ptr += sizeof(long);
115- old_axys.x_max = *((long*)ptr);
120+ old_axys.x.max = *((long*)ptr);
116121 ptr += sizeof(long);
117- old_axys.y_min = *((long*)ptr);
122+ old_axys.y.min = *((long*)ptr);
118123 ptr += sizeof(long);
119- old_axys.y_max = *((long*)ptr);
124+ old_axys.y.max = *((long*)ptr);
120125 ptr += sizeof(long);
121126 }
122127
@@ -130,87 +135,86 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0, const XYinfo& a
130135 &nitems, &bytes_after, &data) == Success)
131136 {
132137 if (act_format == 8 && act_type == XA_INTEGER && nitems == 1) {
133- old_swap_xy = *((char*)data);
138+ old_axys.swap_xy = *((char*)data);
134139
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);
137154 }
138155 }
156+
139157 // TODO? evdev < 2.3.2 with swap_xy had a bug which calibrated before swapping (eg X calib on Y axis)
140158 // see http://cgit.freedesktop.org/xorg/driver/xf86-input-evdev/commit/?h=evdev-2.3-branch&id=3772676fd65065b43a94234127537ab5030b09f8
141159
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);
145163 #endif // HAVE_XI_PROP
146164
147165 }
148166
167+// Destructor
149168 CalibratorEvdev::~CalibratorEvdev () {
150169 XCloseDevice(display, dev);
151170 XCloseDisplay(display);
152171 }
153172
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)
155175 {
156176 bool success = true;
157177
158178 // swap x and y axis, indicated by swap_xy
159179 // 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;
161183
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");
168185
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);
176189
177190 // 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+
188194 // close
189195 XSync(display, False);
190196
191-
192-
193- printf("\n\n--> Making the calibration permanent <--\n");
197+ trace("\t--> Making the calibration permanent <--\n");
194198 switch (output_type) {
195199 case OUTYPE_AUTO:
196200 // xorg.conf.d or alternatively xinput commands
197201 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);
199203 } 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);
201205 }
202206 break;
203207 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);
205209 break;
206210 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);
208212 break;
209213 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);
211215 break;
212216 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");
214218 success = false;
215219 }
216220
@@ -220,49 +224,77 @@ bool CalibratorEvdev::finish_data(const XYinfo new_axys, int swap_xy)
220224 bool CalibratorEvdev::set_swapxy(const int swap_xy)
221225 {
222226 // xinput set-int-prop "divername" "Evdev Axes Swap" 8 0
223- char* arr_cmd[3];
227+ const char* arr_cmd[3];
224228 //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";
228230 char str_swap_xy[20];
229- sprintf(str_swap_xy, "%d", swap_xy);
231+ snprintf(str_swap_xy, 20, "%d", swap_xy);
230232 arr_cmd[2] = str_swap_xy;
231233
232234 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+
233261 return (ret == EXIT_SUCCESS);
234262 }
235263
236264 bool CalibratorEvdev::set_calibration(const XYinfo new_axys)
237265 {
238266 // xinput set-int-prop 4 223 32 5 500 8 300
239- char* arr_cmd[6];
267+ const char* arr_cmd[6];
240268 //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";
244270 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);
246272 arr_cmd[2] = str_min_x;
247273 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);
249275 arr_cmd[3] = str_max_x;
250276 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);
252278 arr_cmd[4] = str_min_y;
253279 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);
255281 arr_cmd[5] = str_max_y;
256282
257283 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+
258290 return (ret == EXIT_SUCCESS);
259291 }
260292
261-Atom CalibratorEvdev::xinput_parse_atom(Display *display, const char *name) {
293+Atom CalibratorEvdev::xinput_parse_atom(Display *display, const char *name)
294+{
262295 Bool is_atom = True;
263- int i;
264296
265- for (i = 0; name[i] != '\0'; i++) {
297+ for (int i = 0; name[i] != '\0'; i++) {
266298 if (!isdigit(name[i])) {
267299 is_atom = False;
268300 break;
@@ -280,13 +312,12 @@ Display *display, const char *name, Bool only_extended)
280312 {
281313 XDeviceInfo *devices;
282314 XDeviceInfo *found = NULL;
283- int loop;
284315 int num_devices;
285316 int len = strlen(name);
286317 Bool is_id = True;
287318 XID id = (XID)-1;
288319
289- for (loop=0; loop<len; loop++) {
320+ for (int loop=0; loop<len; loop++) {
290321 if (!isdigit(name[loop])) {
291322 is_id = False;
292323 break;
@@ -299,15 +330,14 @@ Display *display, const char *name, Bool only_extended)
299330
300331 devices = XListInputDevices(display, &num_devices);
301332
302- for (loop=0; loop<num_devices; loop++) {
333+ for (int loop = 0; loop < num_devices; loop++) {
303334 if ((!only_extended || (devices[loop].use >= IsXExtensionDevice)) &&
304335 ((!is_id && strcmp(devices[loop].name, name) == 0) ||
305336 (is_id && devices[loop].id == id))) {
306337 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);
311341 return NULL;
312342 } else {
313343 found = &devices[loop];
@@ -318,8 +348,7 @@ Display *display, const char *name, Bool only_extended)
318348 return found;
319349 }
320350
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)
323352 {
324353 #ifndef HAVE_XI_PROP
325354 return EXIT_FAILURE;
@@ -327,7 +356,7 @@ Display *display, Atom type, int format, int argc, char **argv)
327356
328357 Atom prop;
329358 Atom old_type;
330- char *name;
359+ const char *name;
331360 int i;
332361 Atom float_atom;
333362 int old_format, nelements = 0;
@@ -342,7 +371,7 @@ Display *display, Atom type, int format, int argc, char **argv)
342371
343372 if (argc < 3)
344373 {
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");
346375 return EXIT_FAILURE;
347376 }
348377
@@ -351,7 +380,7 @@ Display *display, Atom type, int format, int argc, char **argv)
351380 prop = xinput_parse_atom(display, name);
352381
353382 if (prop == None) {
354- fprintf(stderr, "invalid property %s\n", name);
383+ error ( "invalid property %s\n", name);
355384 return EXIT_FAILURE;
356385 }
357386
@@ -362,7 +391,7 @@ Display *display, Atom type, int format, int argc, char **argv)
362391 if (XGetDeviceProperty(display, dev, prop, 0, 0, False, AnyPropertyType,
363392 &old_type, &old_format, &act_nitems,
364393 &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",
366395 name);
367396 return EXIT_FAILURE;
368397 } else {
@@ -376,7 +405,7 @@ Display *display, Atom type, int format, int argc, char **argv)
376405 }
377406
378407 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 "
380409 "its type and format\n", name);
381410 return EXIT_FAILURE;
382411 }
@@ -398,29 +427,29 @@ Display *display, Atom type, int format, int argc, char **argv)
398427 data.l[i] = atoi(argv[2 + i]);
399428 break;
400429 default:
401- fprintf(stderr, "unexpected size for property %s", name);
430+ error ( "unexpected size for property %s", name);
402431 return EXIT_FAILURE;
403432 }
404433 } else if (type == float_atom) {
405434 if (format != 32) {
406- fprintf(stderr, "unexpected format %d for property %s\n",
435+ error ( "unexpected format %d for property %s\n",
407436 format, name);
408437 return EXIT_FAILURE;
409438 }
410439 *(float *)(data.l + i) = strtod(argv[2 + i], &endptr);
411440 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]);
413442 return EXIT_FAILURE;
414443 }
415444 } else if (type == XA_ATOM) {
416445 if (format != 32) {
417- fprintf(stderr, "unexpected format %d for property %s\n",
446+ error ( "unexpected format %d for property %s\n",
418447 format, name);
419448 return EXIT_FAILURE;
420449 }
421450 data.a[i] = xinput_parse_atom(display, argv[2 + i]);
422451 } else {
423- fprintf(stderr, "unexpected type for property %s\n", name);
452+ error ( "unexpected type for property %s\n", name);
424453 return EXIT_FAILURE;
425454 }
426455 }
@@ -433,7 +462,7 @@ Display *display, Atom type, int format, int argc, char **argv)
433462
434463 }
435464
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)
437466 {
438467 const char* sysfs_name = get_sysfs_name();
439468 bool not_sysfs_name = (sysfs_name == NULL);
@@ -441,23 +470,24 @@ bool CalibratorEvdev::output_xorgconfd(const XYinfo new_axys, int swap_xy, int n
441470 sysfs_name = "!!Name_Of_TouchScreen!!";
442471
443472 // 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");
453483
454484 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);
456486
457487 return true;
458488 }
459489
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)
461491 {
462492 const char* sysfs_name = get_sysfs_name();
463493 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
465495 sysfs_name = "!!Name_Of_TouchScreen!!";
466496
467497 // 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");
475506
476507 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);
478509
479510 return true;
480511 }
481512
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)
483514 {
484515 // 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);
489518
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);
490521 return true;
491522 }
--- a/src/calibrator/Evdev.hpp
+++ b/src/calibrator/Evdev.hpp
@@ -35,29 +35,29 @@ class CalibratorEvdev: public Calibrator
3535 {
3636 private:
3737 Display *display;
38- XDeviceInfo *info;
38+ XDeviceInfo *devInfo;
3939 XDevice *dev;
4040
41- int old_swap_xy;
4241 public:
43- CalibratorEvdev(const char* const device_name, const XYinfo& axys, const bool verbose,
42+ CalibratorEvdev(const char* const device_name, const XYinfo& axys,
4443 XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0,
4544 const OutputType output_type=OUTYPE_AUTO, const char* geometry=0);
4645 ~CalibratorEvdev();
4746
48- virtual bool finish_data(const XYinfo new_axys, int swap_xy);
47+ virtual bool finish_data(const XYinfo new_axys);
4948
5049 bool set_swapxy(const int swap_xy);
50+ bool set_invert_xy(bool axisX, const int invert_x, const int invert_y );
5151 bool set_calibration(const XYinfo new_axys);
5252
5353 // xinput_ functions (from the xinput project)
5454 Atom xinput_parse_atom(Display *display, const char* name);
5555 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);
5757 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);
6161 };
6262
6363 #endif
--- a/src/calibrator/Usbtouchscreen.cpp
+++ b/src/calibrator/Usbtouchscreen.cpp
@@ -1,5 +1,6 @@
11 /*
22 * Copyright (c) 2009 Soren Hauberg
3+ * Copyright (c) 2011 Antoine Hue
34 *
45 * Permission is hereby granted, free of charge, to any person obtaining a copy
56 * of this software and associated documentation files (the "Software"), to deal
@@ -48,67 +49,67 @@ static const char *p_flip_x = "flip_x";
4849 static const char *p_flip_y = "flip_y";
4950 static const char *p_swap_xy = "swap_xy";
5051
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)
5354 {
5455 if (strcmp(device_name, "Usbtouchscreen") != 0)
5556 throw WrongCalibratorException("Not a usbtouchscreen device");
5657
5758 // Reset the currently running kernel
5859 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);
6263
64+#if 0 // do not modify current
6365 write_bool_parameter(p_transform_xy, false);
6466 write_bool_parameter(p_flip_x, false);
6567 write_bool_parameter(p_flip_y, false);
6668 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");
6971 }
7072
7173 CalibratorUsbtouchscreen::~CalibratorUsbtouchscreen()
7274 {
75+#if 0 // do not modify current
7376 // Dirty exit, so we restore the parameters of the running kernel
7477 write_bool_parameter (p_transform_xy, val_transform_xy);
7578 write_bool_parameter (p_flip_x, val_flip_x);
7679 write_bool_parameter (p_flip_y, val_flip_y);
7780 write_bool_parameter (p_swap_xy, val_swap_xy);
81+#endif
7882 }
7983
80-bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy)
84+bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys)
8185 {
8286 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");
8488 return false;
8589 }
8690
8791 // 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);
9394
9495 // Send the estimated parameters to the currently running kernel
9596 write_int_parameter(p_range_x, range_x);
9697 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);
101102 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);
105106
106107 // Read, then write calibration parameters to modprobe_conf_local,
107108 // to keep the for the next boot
108109 FILE *fid = fopen(modprobe_conf_local, "r");
109110 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");
112113 return false;
113114 }
114115
@@ -129,16 +130,16 @@ bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy)
129130 char *new_opt = new char[opt_len];
130131 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",
131132 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));
136137 new_contents += new_opt;
137138
138139 fid = fopen(modprobe_conf_local, "w");
139140 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");
142143 return false;
143144 }
144145 fprintf(fid, "%s", new_contents.c_str ());
@@ -154,7 +155,7 @@ void CalibratorUsbtouchscreen::read_int_parameter(const char *param, int &value)
154155 sprintf(filename, "%s/%s", module_prefix, param);
155156 FILE *fid = fopen(filename, "r");
156157 if (fid == NULL) {
157- fprintf(stderr, "Could not read parameter '%s'\n", param);
158+ error ( "Could not read parameter '%s'\n", param);
158159 return;
159160 }
160161
@@ -169,7 +170,7 @@ void CalibratorUsbtouchscreen::read_int_parameter(const char *param, int &value)
169170 sprintf(filename, "%s/%s", module_prefix, param);
170171 FILE *fid = fopen(filename, "r");
171172 if (fid == NULL) {
172- fprintf(stderr, "Could not read parameter '%s'\n", param);
173+ error ( "Could not read parameter '%s'\n", param);
173174 return;
174175 }
175176
@@ -186,7 +187,7 @@ void CalibratorUsbtouchscreen::read_int_parameter(const char *param, int &value)
186187 sprintf(filename, "%s/%s", module_prefix, param);
187188 FILE *fid = fopen(filename, "w");
188189 if (fid == NULL) {
189- fprintf(stderr, "Could not save parameter '%s'\n", param);
190+ error ( "Could not save parameter '%s'\n", param);
190191 return;
191192 }
192193
@@ -200,7 +201,7 @@ void CalibratorUsbtouchscreen::write_bool_parameter(const char *param, const boo
200201 sprintf(filename, "%s/%s", module_prefix, param);
201202 FILE *fid = fopen(filename, "w");
202203 if (fid == NULL) {
203- fprintf(stderr, "Could not save parameter '%s'\n", param);
204+ error ("Could not save parameter '%s'\n", param);
204205 return;
205206 }
206207
--- a/src/calibrator/Usbtouchscreen.hpp
+++ b/src/calibrator/Usbtouchscreen.hpp
@@ -33,19 +33,19 @@ class CalibratorUsbtouchscreen: public Calibrator
3333 {
3434 public:
3535 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,
3737 const OutputType output_type=OUTYPE_AUTO, const char* geometry=0);
3838 ~CalibratorUsbtouchscreen();
3939
40- virtual bool finish_data(const XYinfo new_axys, int swap_xy);
40+ virtual bool finish_data(const XYinfo new_axys);
4141
4242 protected:
4343 // Globals for kernel parameters from startup.
4444 // 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;
4646
4747 // Helper functions
48- char yesno(const bool value)
48+ inline char yesno(const bool value)
4949 {
5050 if (value)
5151 return 'Y';
--- a/src/calibrator/XorgPrint.cpp
+++ b/src/calibrator/XorgPrint.cpp
@@ -1,5 +1,6 @@
11 /*
22 * Copyright (c) 2009 Tias Guns
3+ * Copyright (c) 2011 Antoine Hue
34 *
45 * Permission is hereby granted, free of charge, to any person obtaining a copy
56 * of this software and associated documentation files (the "Software"), to deal
@@ -24,48 +25,50 @@
2425
2526 #include <cstdio>
2627
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)
2930 {
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");
3435 }
3536
36-bool CalibratorXorgPrint::finish_data(const XYinfo new_axys, int swap_xy)
37+bool CalibratorXorgPrint::finish_data(const XYinfo new_axys)
3738 {
3839 bool success = true;
3940
40- // we suppose the previous 'swap_xy' value was 0
41+ // we suppose the previous 'swap_xy', 'invert_x', 'invert_y' value was 0
4142 // (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;
4346
44- printf("\n\n--> Making the calibration permanent <--\n");
47+ info ("\t--> Making the calibration permanent <--\n");
4548 switch (output_type) {
4649 case OUTYPE_AUTO:
4750 // xorg.conf.d or alternatively hal config
4851 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);
5053 } 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);
5255 }
5356 break;
5457 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);
5659 break;
5760 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);
5962 break;
6063 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");
6265 success = false;
6366 }
6467
6568 return success;
6669 }
6770
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)
6972 {
7073 const char* sysfs_name = get_sysfs_name();
7174 bool not_sysfs_name = (sysfs_name == NULL);
@@ -73,25 +76,26 @@ bool CalibratorXorgPrint::output_xorgconfd(const XYinfo new_axys, int swap_xy, i
7376 sysfs_name = "!!Name_Of_TouchScreen!!";
7477
7578 // 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");
8791
8892 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);
9094
9195 return true;
9296 }
9397
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)
9599 {
96100 const char* sysfs_name = get_sysfs_name();
97101 bool not_sysfs_name = (sysfs_name == NULL);
@@ -99,19 +103,21 @@ bool CalibratorXorgPrint::output_hal(const XYinfo new_axys, int swap_xy, int new
99103 sysfs_name = "!!Name_Of_TouchScreen!!";
100104
101105 // 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");
112118
113119 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);
115121
116122 return true;
117123 }
--- a/src/calibrator/XorgPrint.hpp
+++ b/src/calibrator/XorgPrint.hpp
@@ -33,13 +33,14 @@ class CalibratorXorgPrint: public Calibrator
3333 {
3434 public:
3535 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,
3737 const OutputType output_type=OUTYPE_AUTO, const char* geometry=0);
3838
39- virtual bool finish_data(const XYinfo new_axys, int swap_xy);
39+ virtual bool finish_data(const XYinfo new_axys);
40+
4041 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);
4344 };
4445
4546 #endif
--- a/src/main_common.cpp
+++ b/src/main_common.cpp
@@ -54,7 +54,7 @@ static char* my_strdup(const char* s) {
5454 * retuns number of devices found,
5555 * the data of the device is returned in the last 3 function parameters
5656 */
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,
5858 XID& device_id, const char*& device_name, XYinfo& device_axys)
5959 {
6060 bool pre_device_is_id = true;
@@ -62,13 +62,13 @@ static int find_device(const char* pre_device, bool verbose, bool list_devices,
6262
6363 Display* display = XOpenDisplay(NULL);
6464 if (display == NULL) {
65- fprintf(stderr, "Unable to connect to X server\n");
65+ error ( "Unable to connect to X server\n");
6666 exit(1);
6767 }
6868
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");
7272 exit(1);
7373 }
7474
@@ -77,7 +77,7 @@ static int find_device(const char* pre_device, bool verbose, bool list_devices,
7777 XExtensionVersion *version = XGetExtensionVersion(display, INAME);
7878
7979 if (version && (version != (XExtensionVersion*) NoSuchExtension)) {
80- printf("DEBUG: %s version is %i.%i\n",
80+ trace ("%s version is %i.%i\n",
8181 INAME, version->major_version, version->minor_version);
8282 XFree(version);
8383 }
@@ -94,9 +94,7 @@ static int find_device(const char* pre_device, bool verbose, bool list_devices,
9494 }
9595 }
9696
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");
10098 int ndevices;
10199 XDeviceInfoPtr list, slist;
102100 slist=list=(XDeviceInfoPtr) XListInputDevices (display, &ndevices);
@@ -126,27 +124,25 @@ static int find_device(const char* pre_device, bool verbose, bool list_devices,
126124 XAxisInfoPtr ax = (XAxisInfoPtr) V->axes;
127125
128126 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",
131128 list->name, (int)list->id);
132129 } else if (V->num_axes < 2 ||
133130 (ax[0].min_value == -1 && ax[0].max_value == -1) ||
134131 (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",
137133 list->name, (int)list->id);
138134 } else {
139135 /* a calibratable device (has 2 axis valuators) */
140136 found++;
141137 device_id = list->id;
142138 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;
147143
148144 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);
150146 }
151147
152148 }
@@ -183,7 +179,6 @@ static void usage(char* cmd, unsigned thr_misclick)
183179
184180 Calibrator* Calibrator::make_calibrator(int argc, char** argv)
185181 {
186- bool verbose = false;
187182 bool list_devices = false;
188183 bool fake = false;
189184 bool precalib = false;
@@ -200,7 +195,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
200195 // Display help ?
201196 if (strcmp("-h", argv[i]) == 0 ||
202197 strcmp("--help", argv[i]) == 0) {
203- fprintf(stderr, "xinput_calibrator, v%s\n\n", VERSION);
198+ error ( "xinput_calibrator, v%s\n\n", VERSION);
204199 usage(argv[0], thr_misclick);
205200 exit(0);
206201 } else
@@ -221,7 +216,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
221216 if (argc > i+1)
222217 pre_device = argv[++i];
223218 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");
225220 usage(argv[0], thr_misclick);
226221 exit(1);
227222 }
@@ -231,13 +226,13 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
231226 if (strcmp("--precalib", argv[i]) == 0) {
232227 precalib = true;
233228 if (argc > i+1)
234- pre_axys.x_min = atoi(argv[++i]);
229+ pre_axys.x.min = atoi(argv[++i]);
235230 if (argc > i+1)
236- pre_axys.x_max = atoi(argv[++i]);
231+ pre_axys.x.max = atoi(argv[++i]);
237232 if (argc > i+1)
238- pre_axys.y_min = atoi(argv[++i]);
233+ pre_axys.y.min = atoi(argv[++i]);
239234 if (argc > i+1)
240- pre_axys.y_max = atoi(argv[++i]);
235+ pre_axys.y.max = atoi(argv[++i]);
241236 } else
242237
243238 // Get mis-click threshold ?
@@ -245,7 +240,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
245240 if (argc > i+1)
246241 thr_misclick = atoi(argv[++i]);
247242 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");
249244 usage(argv[0], thr_misclick);
250245 exit(1);
251246 }
@@ -264,12 +259,12 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
264259 else if (strcmp("xinput", argv[i]) == 0)
265260 output_type = OUTYPE_XINPUT;
266261 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");
268263 usage(argv[0], thr_misclick);
269264 exit(1);
270265 }
271266 } else {
272- fprintf(stderr, "Error: --output-type needs one argument.\n\n");
267+ error ( "--output-type needs one argument.\n\n");
273268 usage(argv[0], thr_misclick);
274269 exit(1);
275270 }
@@ -304,18 +299,16 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
304299 device_name = "Fake_device";
305300 device_axys = XYinfo(0,1000,0,1000);
306301
307- if (verbose) {
308- printf("DEBUG: Faking device: %s\n", device_name);
309- }
302+ trace ("Faking device: %s\n", device_name);
310303 } else {
311304 // 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);
313306
314307 if (list_devices) {
315308 // printed the list in find_device
316309 if (nr_found == 0)
317310 printf("No calibratable devices found.\n");
318- exit(0);
311+ exit(2);
319312 }
320313
321314 if (nr_found == 0) {
@@ -326,30 +319,26 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
326319 exit(1);
327320
328321 } 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);
330323 }
331324
332- if (verbose) {
333- printf("DEBUG: Selected device: %s\n", device_name);
334- }
325+ trace ("Selected device: %s\n", device_name);
335326 }
336327
337328 // override min/max XY from command line ?
338329 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);
353342 }
354343
355344
@@ -357,24 +346,22 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
357346 try {
358347 // try Usbtouchscreen driver
359348 return new CalibratorUsbtouchscreen(device_name, device_axys,
360- verbose, thr_misclick, thr_doubleclick, output_type, geometry);
349+ thr_misclick, thr_doubleclick, output_type, geometry);
361350
362351 } 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());
365353 }
366354
367355 try {
368356 // 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,
370358 thr_misclick, thr_doubleclick, output_type, geometry);
371359
372360 } 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());
375362 }
376363
377364 // lastly, presume a standard Xorg driver (evtouch, mutouch, ...)
378365 return new CalibratorXorgPrint(device_name, device_axys,
379- verbose, thr_misclick, thr_doubleclick, output_type, geometry);
366+ thr_misclick, thr_doubleclick, output_type, geometry);
380367 }