A generic touchscreen calibration program for X.Org
Revision | 4cc7337a86c1de07475a3756c6268b9d2d642613 (tree) |
---|---|
Time | 2011-04-20 19:24:48 |
Author | Antoine Hue <antoine@peti...> |
Commiter | Tias Guns |
Completing file reorganization with correct headers
@@ -28,19 +28,21 @@ SUBDIRS = \ | ||
28 | 28 | calibrator \ |
29 | 29 | gui |
30 | 30 | |
31 | -AM_CXXFLAGS = -Wall -ansi -pedantic -Wmissing-declarations | |
31 | +AM_CXXFLAGS = -Wall -ansi -pedantic | |
32 | 32 | |
33 | 33 | bin_PROGRAMS = xinput_calibrator |
34 | 34 | |
35 | +COMMON_SRCS=calibrator.cpp calibrator/XorgPrint.cpp calibrator/Evdev.cpp calibrator/Usbtouchscreen.cpp main_common.cpp | |
36 | + | |
35 | 37 | # only one of the BUILD_ flags should be set |
36 | 38 | if BUILD_X11 |
37 | -xinput_calibrator_SOURCES = main_x11.cpp | |
39 | +xinput_calibrator_SOURCES = gui/x11.cpp main_x11.cpp $(COMMON_SRCS) | |
38 | 40 | xinput_calibrator_LDADD = $(XINPUT_LIBS) $(XRANDR_LIBS) $(X11_LIBS) |
39 | 41 | xinput_calibrator_CXXFLAGS = $(XINPUT_CFLAGS) $(X11_CFLAGS) $(XRANDR_CFLAGS) $(AM_CXXFLAGS) |
40 | 42 | endif |
41 | 43 | |
42 | 44 | if BUILD_GTKMM |
43 | -xinput_calibrator_SOURCES = main_gtkmm.cpp | |
45 | +xinput_calibrator_SOURCES = gui/gtkmm.cpp main_gtkmm.cpp $(COMMON_SRCS) | |
44 | 46 | xinput_calibrator_LDADD = $(XINPUT_LIBS) $(GTKMM_LIBS) |
45 | 47 | xinput_calibrator_CXXFLAGS = $(XINPUT_CFLAGS) $(GTKMM_CFLAGS) $(AM_CXXFLAGS) |
46 | 48 |
@@ -52,4 +54,4 @@ endif | ||
52 | 54 | EXTRA_DIST = \ |
53 | 55 | calibrator.cpp \ |
54 | 56 | calibrator.hh \ |
55 | - main_common.hpp | |
57 | + main_common.cpp |
@@ -25,7 +25,7 @@ | ||
25 | 25 | #include <dirent.h> |
26 | 26 | #include <iostream> |
27 | 27 | #include <fstream> |
28 | -#include <string> | |
28 | +#include <cstring> | |
29 | 29 | |
30 | 30 | #include "calibrator.hh" |
31 | 31 |
@@ -24,37 +24,115 @@ | ||
24 | 24 | #ifndef _calibrator_hh |
25 | 25 | #define _calibrator_hh |
26 | 26 | |
27 | -// Abstract base class for calculating new calibration parameters | |
27 | +#include <stdexcept> | |
28 | +#include <X11/Xlib.h> | |
29 | + | |
30 | +/* | |
31 | + * Number of blocks. We partition the screen into 'num_blocks' x 'num_blocks' | |
32 | + * rectangles of equal size. We then ask the user to press points that are | |
33 | + * located at the corner closes to the center of the four blocks in the corners | |
34 | + * of the screen. The following ascii art illustrates the situation. We partition | |
35 | + * the screen into 8 blocks in each direction. We then let the user press the | |
36 | + * points marked with 'O'. | |
37 | + * | |
38 | + * +--+--+--+--+--+--+--+--+ | |
39 | + * | | | | | | | | | | |
40 | + * +--O--+--+--+--+--+--O--+ | |
41 | + * | | | | | | | | | | |
42 | + * +--+--+--+--+--+--+--+--+ | |
43 | + * | | | | | | | | | | |
44 | + * +--+--+--+--+--+--+--+--+ | |
45 | + * | | | | | | | | | | |
46 | + * +--+--+--+--+--+--+--+--+ | |
47 | + * | | | | | | | | | | |
48 | + * +--+--+--+--+--+--+--+--+ | |
49 | + * | | | | | | | | | | |
50 | + * +--+--+--+--+--+--+--+--+ | |
51 | + * | | | | | | | | | | |
52 | + * +--O--+--+--+--+--+--O--+ | |
53 | + * | | | | | | | | | | |
54 | + * +--+--+--+--+--+--+--+--+ | |
55 | + */ | |
56 | +const int num_blocks = 8; | |
57 | + | |
58 | +/// struct to hold min/max info of the X and Y axis | |
59 | +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) {} | |
67 | +}; | |
68 | + | |
69 | +/// Names of the points | |
70 | +enum { | |
71 | + UL = 0, // Upper-left | |
72 | + UR = 1, // Upper-right | |
73 | + LL = 2, // Lower-left | |
74 | + LR = 3, // Lower-right | |
75 | + NUM_POINTS | |
76 | +}; | |
77 | + | |
78 | +/// Output types | |
79 | +enum OutputType { | |
80 | + OUTYPE_AUTO, | |
81 | + OUTYPE_XORGCONFD, | |
82 | + OUTYPE_HAL, | |
83 | + OUTYPE_XINPUT | |
84 | +}; | |
85 | + | |
86 | +class WrongCalibratorException : public std::invalid_argument { | |
87 | + public: | |
88 | + WrongCalibratorException(const std::string& msg = "") : | |
89 | + std::invalid_argument(msg) {} | |
90 | +}; | |
91 | + | |
92 | +/// Base class for calculating new calibration parameters | |
28 | 93 | class Calibrator |
29 | 94 | { |
30 | 95 | public: |
31 | - /* Constructor for a specific calibrator | |
32 | - * | |
33 | - * The constructor will throw an exception, | |
34 | - * if the touchscreen is not of the type it supports | |
35 | - */ | |
36 | - Calibrator(const char* const device_name, const XYinfo& axys, | |
37 | - const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
96 | + /// Parse arguments and create calibrator | |
97 | + static Calibrator* make_calibrator(int argc, char** argv); | |
98 | + | |
99 | + /// Constructor | |
100 | + /// | |
101 | + /// The constructor will throw an exception, | |
102 | + /// if the touchscreen is not of the type it supports | |
103 | + Calibrator(const char* const device_name, | |
104 | + const XYinfo& axys, | |
105 | + const bool verbose, | |
106 | + const int thr_misclick=0, | |
107 | + const int thr_doubleclick=0, | |
108 | + const OutputType output_type=OUTYPE_AUTO, | |
109 | + const char* geometry=0); | |
110 | + | |
38 | 111 | ~Calibrator() {} |
39 | 112 | |
40 | - // set the doubleclick treshold | |
113 | + /// set the doubleclick treshold | |
41 | 114 | void set_threshold_doubleclick(int t); |
42 | - // set the misclick treshold | |
115 | + | |
116 | + /// set the misclick treshold | |
43 | 117 | void set_threshold_misclick(int t); |
44 | - // get the number of clicks already registered | |
118 | + | |
119 | + /// get the number of clicks already registered | |
45 | 120 | int get_numclicks(); |
46 | - // return geometry string or NULL | |
121 | + | |
122 | + /// return geometry string or NULL | |
47 | 123 | const char* get_geometry(); |
48 | - // reset clicks | |
124 | + | |
125 | + /// reset clicks | |
49 | 126 | void reset() { |
50 | 127 | num_clicks = 0; |
51 | 128 | } |
52 | - // add a click with the given coordinates | |
129 | + | |
130 | + /// add a click with the given coordinates | |
53 | 131 | bool add_click(int x, int y); |
54 | - // calculate and apply the calibration | |
132 | + /// calculate and apply the calibration | |
55 | 133 | bool finish(int width, int height); |
56 | - // get the sysfs name of the device, | |
57 | - // returns NULL if it can not be found | |
134 | + /// get the sysfs name of the device, | |
135 | + /// returns NULL if it can not be found | |
58 | 136 | const char* get_sysfs_name(); |
59 | 137 | |
60 | 138 | protected: |
@@ -73,7 +151,7 @@ protected: | ||
73 | 151 | // nr of clicks registered |
74 | 152 | int num_clicks; |
75 | 153 | // click coordinates |
76 | - int clicked_x[4], clicked_y[4]; | |
154 | + int clicked_x[NUM_POINTS], clicked_y[NUM_POINTS]; | |
77 | 155 | |
78 | 156 | // Threshold to keep the same point from being clicked twice. |
79 | 157 | // Set to zero if you don't want this check |
@@ -20,12 +20,16 @@ | ||
20 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 | 21 | * THE SOFTWARE. |
22 | 22 | */ |
23 | -#include <ctype.h> | |
23 | + | |
24 | +#include "calibrator/Evdev.hpp" | |
24 | 25 | |
25 | 26 | #include <X11/Xlib.h> |
26 | -#include <X11/extensions/XInput.h> | |
27 | 27 | #include <X11/Xatom.h> |
28 | 28 | //#include <X11/Xutil.h> |
29 | +#include <ctype.h> | |
30 | +#include <cstdio> | |
31 | +#include <cstring> | |
32 | +#include <cstdlib> | |
29 | 33 | |
30 | 34 | #ifndef EXIT_SUCCESS |
31 | 35 | #define EXIT_SUCCESS 1 |
@@ -34,39 +38,6 @@ | ||
34 | 38 | #define EXIT_FAILURE 0 |
35 | 39 | #endif |
36 | 40 | |
37 | -/*************************************** | |
38 | - * Class for dynamic evdev calibration | |
39 | - * uses xinput "Evdev Axis Calibration" | |
40 | - ***************************************/ | |
41 | -class CalibratorEvdev: public Calibrator | |
42 | -{ | |
43 | -private: | |
44 | - Display *display; | |
45 | - XDeviceInfo *info; | |
46 | - XDevice *dev; | |
47 | - | |
48 | - int old_swap_xy; | |
49 | -public: | |
50 | - CalibratorEvdev(const char* const device_name, const XYinfo& axys, const bool verbose, | |
51 | - XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0, | |
52 | - const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
53 | - ~CalibratorEvdev(); | |
54 | - | |
55 | - virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
56 | - | |
57 | - bool set_swapxy(const int swap_xy); | |
58 | - bool set_calibration(const XYinfo new_axys); | |
59 | - | |
60 | - // xinput_ functions (from the xinput project) | |
61 | - Atom xinput_parse_atom(Display *display, const char* name); | |
62 | - XDeviceInfo* xinput_find_device_info(Display *display, const char* name, Bool only_extended); | |
63 | - int xinput_do_set_prop(Display *display, Atom type, int format, int argc, char* argv[]); | |
64 | -protected: | |
65 | - bool output_xorgconfd(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
66 | - bool output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
67 | - bool output_xinput(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
68 | -}; | |
69 | - | |
70 | 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) |
71 | 42 | : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type, geometry), old_swap_xy(0) |
72 | 43 | { |
@@ -1,4 +1,4 @@ | ||
1 | 1 | EXTRA_DIST = \ |
2 | - calibratorEvdev.cpp \ | |
3 | - calibratorUsbtouchscreen.cpp \ | |
4 | - calibratorXorgPrint.cpp | |
2 | + Evdev.cpp \ | |
3 | + Usbtouchscreen.cpp \ | |
4 | + XorgPrint.cpp |
@@ -19,120 +19,34 @@ | ||
19 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20 | 20 | * THE SOFTWARE. |
21 | 21 | */ |
22 | -#include <string> | |
22 | + | |
23 | +#include "calibrator/Usbtouchscreen.hpp" | |
24 | + | |
25 | +#include <cstdlib> | |
26 | +#include <cstdio> | |
27 | +#include <cstring> | |
23 | 28 | |
24 | 29 | /************************* |
25 | 30 | * Variables for usbtouchscreen specifically |
26 | 31 | *************************/ |
27 | 32 | // The file to which the calibration parameters are saved. |
28 | 33 | // (XXX: is this distribution dependend?) |
29 | -const char *modprobe_conf_local = "/etc/modprobe.conf.local"; | |
34 | +static const char *modprobe_conf_local = "/etc/modprobe.conf.local"; | |
30 | 35 | |
31 | 36 | // Prefix to the kernel path where we can set the parameters |
32 | -const char *module_prefix = "/sys/module/usbtouchscreen/parameters"; | |
37 | +static const char *module_prefix = "/sys/module/usbtouchscreen/parameters"; | |
33 | 38 | |
34 | 39 | // Names of kernel parameters |
35 | -const char *p_range_x = "range_x"; | |
36 | -const char *p_range_y = "range_y"; | |
37 | -const char *p_min_x = "min_x"; | |
38 | -const char *p_min_y = "min_y"; | |
39 | -const char *p_max_x = "max_x"; | |
40 | -const char *p_max_y = "max_y"; | |
41 | -const char *p_transform_xy = "transform_xy"; | |
42 | -const char *p_flip_x = "flip_x"; | |
43 | -const char *p_flip_y = "flip_y"; | |
44 | -const char *p_swap_xy = "swap_xy"; | |
45 | - | |
46 | - | |
47 | -/********************************** | |
48 | - * Class for usbtouchscreen driver, | |
49 | - * writes output parameters to running kernel and to modprobe.conf | |
50 | - **********************************/ | |
51 | -class CalibratorUsbtouchscreen: public Calibrator | |
52 | -{ | |
53 | -public: | |
54 | - CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys, | |
55 | - const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, | |
56 | - const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
57 | - ~CalibratorUsbtouchscreen(); | |
58 | - | |
59 | - virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
60 | - | |
61 | -protected: | |
62 | - // Globals for kernel parameters from startup. | |
63 | - // We revert to these if the program aborts | |
64 | - bool val_transform_xy, val_flip_x, val_flip_y, val_swap_xy; | |
65 | - | |
66 | - // Helper functions | |
67 | - char yesno(const bool value) | |
68 | - { | |
69 | - if (value) | |
70 | - return 'Y'; | |
71 | - else | |
72 | - return 'N'; | |
73 | - } | |
74 | - | |
75 | - void read_int_parameter(const char *param, int &value) | |
76 | - { | |
77 | - int dummy; | |
78 | - char filename[100]; | |
79 | - sprintf(filename, "%s/%s", module_prefix, param); | |
80 | - FILE *fid = fopen(filename, "r"); | |
81 | - if (fid == NULL) { | |
82 | - fprintf(stderr, "Could not read parameter '%s'\n", param); | |
83 | - return; | |
84 | - } | |
85 | - | |
86 | - dummy = fscanf(fid, "%d", &value); | |
87 | - fclose(fid); | |
88 | - } | |
89 | - | |
90 | - void read_bool_parameter(const char *param, bool &value) | |
91 | - { | |
92 | - char *dummy; | |
93 | - char filename[100]; | |
94 | - sprintf(filename, "%s/%s", module_prefix, param); | |
95 | - FILE *fid = fopen(filename, "r"); | |
96 | - if (fid == NULL) { | |
97 | - fprintf(stderr, "Could not read parameter '%s'\n", param); | |
98 | - return; | |
99 | - } | |
100 | - | |
101 | - char val[3]; | |
102 | - dummy = fgets(val, 2, fid); | |
103 | - fclose(fid); | |
104 | - | |
105 | - value = (val[0] == yesno(true)); | |
106 | - } | |
107 | - | |
108 | - void write_int_parameter(const char *param, const int value) | |
109 | - { | |
110 | - char filename[100]; | |
111 | - sprintf(filename, "%s/%s", module_prefix, param); | |
112 | - FILE *fid = fopen(filename, "w"); | |
113 | - if (fid == NULL) { | |
114 | - fprintf(stderr, "Could not save parameter '%s'\n", param); | |
115 | - return; | |
116 | - } | |
117 | - | |
118 | - fprintf(fid, "%d", value); | |
119 | - fclose(fid); | |
120 | - } | |
121 | - | |
122 | - void write_bool_parameter(const char *param, const bool value) | |
123 | - { | |
124 | - char filename[100]; | |
125 | - sprintf(filename, "%s/%s", module_prefix, param); | |
126 | - FILE *fid = fopen(filename, "w"); | |
127 | - if (fid == NULL) { | |
128 | - fprintf(stderr, "Could not save parameter '%s'\n", param); | |
129 | - return; | |
130 | - } | |
131 | - | |
132 | - fprintf(fid, "%c", yesno (value)); | |
133 | - fclose(fid); | |
134 | - } | |
135 | -}; | |
40 | +static const char *p_range_x = "range_x"; | |
41 | +static const char *p_range_y = "range_y"; | |
42 | +static const char *p_min_x = "min_x"; | |
43 | +static const char *p_min_y = "min_y"; | |
44 | +static const char *p_max_x = "max_x"; | |
45 | +static const char *p_max_y = "max_y"; | |
46 | +static const char *p_transform_xy = "transform_xy"; | |
47 | +static const char *p_flip_x = "flip_x"; | |
48 | +static const char *p_flip_y = "flip_y"; | |
49 | +static const char *p_swap_xy = "swap_xy"; | |
136 | 50 | |
137 | 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) |
138 | 52 | : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type, geometry) |
@@ -232,3 +146,64 @@ bool CalibratorUsbtouchscreen::finish_data(const XYinfo new_axys, int swap_xy) | ||
232 | 146 | |
233 | 147 | return true; |
234 | 148 | } |
149 | + | |
150 | +void CalibratorUsbtouchscreen::read_int_parameter(const char *param, int &value) | |
151 | + { | |
152 | + int dummy; | |
153 | + char filename[100]; | |
154 | + sprintf(filename, "%s/%s", module_prefix, param); | |
155 | + FILE *fid = fopen(filename, "r"); | |
156 | + if (fid == NULL) { | |
157 | + fprintf(stderr, "Could not read parameter '%s'\n", param); | |
158 | + return; | |
159 | + } | |
160 | + | |
161 | + dummy = fscanf(fid, "%d", &value); | |
162 | + fclose(fid); | |
163 | + } | |
164 | + | |
165 | + void CalibratorUsbtouchscreen::read_bool_parameter(const char *param, bool &value) | |
166 | + { | |
167 | + char *dummy; | |
168 | + char filename[100]; | |
169 | + sprintf(filename, "%s/%s", module_prefix, param); | |
170 | + FILE *fid = fopen(filename, "r"); | |
171 | + if (fid == NULL) { | |
172 | + fprintf(stderr, "Could not read parameter '%s'\n", param); | |
173 | + return; | |
174 | + } | |
175 | + | |
176 | + char val[3]; | |
177 | + dummy = fgets(val, 2, fid); | |
178 | + fclose(fid); | |
179 | + | |
180 | + value = (val[0] == yesno(true)); | |
181 | + } | |
182 | + | |
183 | + void CalibratorUsbtouchscreen::write_int_parameter(const char *param, const int value) | |
184 | + { | |
185 | + char filename[100]; | |
186 | + sprintf(filename, "%s/%s", module_prefix, param); | |
187 | + FILE *fid = fopen(filename, "w"); | |
188 | + if (fid == NULL) { | |
189 | + fprintf(stderr, "Could not save parameter '%s'\n", param); | |
190 | + return; | |
191 | + } | |
192 | + | |
193 | + fprintf(fid, "%d", value); | |
194 | + fclose(fid); | |
195 | + } | |
196 | + | |
197 | +void CalibratorUsbtouchscreen::write_bool_parameter(const char *param, const bool value) | |
198 | + { | |
199 | + char filename[100]; | |
200 | + sprintf(filename, "%s/%s", module_prefix, param); | |
201 | + FILE *fid = fopen(filename, "w"); | |
202 | + if (fid == NULL) { | |
203 | + fprintf(stderr, "Could not save parameter '%s'\n", param); | |
204 | + return; | |
205 | + } | |
206 | + | |
207 | + fprintf(fid, "%c", yesno (value)); | |
208 | + fclose(fid); | |
209 | + } |
@@ -20,22 +20,9 @@ | ||
20 | 20 | * THE SOFTWARE. |
21 | 21 | */ |
22 | 22 | |
23 | -/*************************************** | |
24 | - * Class for generic Xorg driver, | |
25 | - * outputs new Xorg.conf and FDI policy, on stdout | |
26 | - ***************************************/ | |
27 | -class CalibratorXorgPrint: public Calibrator | |
28 | -{ | |
29 | -public: | |
30 | - CalibratorXorgPrint(const char* const device_name, const XYinfo& axys, | |
31 | - const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, | |
32 | - const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
23 | +#include "calibrator/XorgPrint.hpp" | |
33 | 24 | |
34 | - virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
35 | -protected: | |
36 | - bool output_xorgconfd(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
37 | - bool output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
38 | -}; | |
25 | +#include <cstdio> | |
39 | 26 | |
40 | 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) |
41 | 28 | : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type, geometry) |
@@ -1,3 +1,3 @@ | ||
1 | 1 | EXTRA_DIST = \ |
2 | - gui_gtkmm.cpp \ | |
3 | - gui_x11.cpp | |
2 | + gtkmm.cpp \ | |
3 | + x11.cpp |
@@ -20,13 +20,8 @@ | ||
20 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 | 21 | * THE SOFTWARE. |
22 | 22 | */ |
23 | -#include <gtkmm/main.h> | |
24 | -#include <gtkmm/window.h> | |
25 | -#include <gtkmm/drawingarea.h> | |
26 | -#include <cairomm/context.h> | |
27 | - | |
28 | -#include "calibrator.hh" | |
29 | 23 | |
24 | +#include "gui/gtkmm.hpp" | |
30 | 25 | |
31 | 26 | // Timeout parameters |
32 | 27 | const int time_step = 100; // in milliseconds |
@@ -48,36 +43,6 @@ const std::string help_text[help_lines] = { | ||
48 | 43 | "(To abort, press any key or wait)" |
49 | 44 | }; |
50 | 45 | |
51 | - | |
52 | -/******************************************* | |
53 | - * GTK-mm class for the the calibration GUI | |
54 | - *******************************************/ | |
55 | -class CalibrationArea : public Gtk::DrawingArea | |
56 | -{ | |
57 | -public: | |
58 | - CalibrationArea(Calibrator* w); | |
59 | - | |
60 | -protected: | |
61 | - // Data | |
62 | - Calibrator* calibrator; | |
63 | - double X[4], Y[4]; | |
64 | - int display_width, display_height; | |
65 | - int time_elapsed; | |
66 | - | |
67 | - const char* message; | |
68 | - | |
69 | - // Signal handlers | |
70 | - bool on_timer_signal(); | |
71 | - bool on_expose_event(GdkEventExpose *event); | |
72 | - bool on_button_press_event(GdkEventButton *event); | |
73 | - bool on_key_press_event(GdkEventKey *event); | |
74 | - | |
75 | - // Helper functions | |
76 | - void set_display_size(int width, int height); | |
77 | - void redraw(); | |
78 | - void draw_message(const char* msg); | |
79 | -}; | |
80 | - | |
81 | 46 | CalibrationArea::CalibrationArea(Calibrator* calibrator0) |
82 | 47 | : calibrator(calibrator0), time_elapsed(0), message(NULL) |
83 | 48 | { |
@@ -19,6 +19,9 @@ | ||
19 | 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
20 | 20 | * THE SOFTWARE. |
21 | 21 | */ |
22 | + | |
23 | +#include "gui/x11.hpp" | |
24 | + | |
22 | 25 | #include <X11/X.h> |
23 | 26 | #include <X11/Xlib.h> |
24 | 27 | #include <X11/Xutil.h> |
@@ -34,12 +37,10 @@ | ||
34 | 37 | #include <signal.h> |
35 | 38 | #include <string.h> |
36 | 39 | |
37 | -#include "calibrator.hh" | |
38 | - | |
39 | 40 | |
40 | 41 | // Timeout parameters |
41 | 42 | const int time_step = 100; // in milliseconds |
42 | -const int max_time = 15000; // 5000 = 5 sec | |
43 | +const int max_time = 15000; // in milliseconds, 5000 = 5 sec | |
43 | 44 | |
44 | 45 | // Clock appereance |
45 | 46 | const int cross_lines = 25; |
@@ -57,58 +58,18 @@ const std::string help_text[help_lines] = { | ||
57 | 58 | "(To abort, press any key or wait)" |
58 | 59 | }; |
59 | 60 | |
60 | -// color management | |
61 | -enum { BLACK=0, WHITE=1, GRAY=2, DIMGRAY=3, RED=4 }; | |
62 | -const int nr_colors = 5; | |
63 | -const char* colors[nr_colors] = {"BLACK", "WHITE", "GRAY", "DIMGRAY", "RED"}; | |
64 | - | |
61 | +const char* GuiCalibratorX11::colors[GuiCalibratorX11::NUM_COLORS] = {"BLACK", "WHITE", "GRAY", "DIMGRAY", "RED"}; | |
65 | 62 | |
66 | 63 | void sigalarm_handler(int num); |
67 | 64 | |
68 | - | |
69 | -/******************************************* | |
70 | - * X11 class for the the calibration GUI | |
71 | - *******************************************/ | |
72 | -class GuiCalibratorX11 | |
65 | +/// Create singleton instance associated to calibrator w | |
66 | +void GuiCalibratorX11::make_instance(Calibrator* w) | |
73 | 67 | { |
74 | -public: | |
75 | - GuiCalibratorX11(Calibrator* w); | |
76 | - ~GuiCalibratorX11(); | |
77 | - static bool set_instance(GuiCalibratorX11* W); | |
78 | - static void give_timer_signal(); | |
79 | - | |
80 | -protected: | |
81 | - // Data | |
82 | - Calibrator* calibrator; | |
83 | - double X[4], Y[4]; | |
84 | - int display_width, display_height; | |
85 | - int time_elapsed; | |
86 | - | |
87 | - // X11 vars | |
88 | - Display* display; | |
89 | - int screen_num; | |
90 | - Window win; | |
91 | - GC gc; | |
92 | - XFontStruct* font_info; | |
93 | - // color mngmt | |
94 | - unsigned long pixel[nr_colors]; | |
95 | - | |
96 | - | |
97 | - // Signal handlers | |
98 | - bool on_timer_signal(); | |
99 | - bool on_expose_event(); | |
100 | - bool on_button_press_event(XEvent event); | |
101 | - | |
102 | - // Helper functions | |
103 | - void set_display_size(int width, int height); | |
104 | - void redraw(); | |
105 | - void draw_message(const char* msg); | |
106 | - | |
107 | -private: | |
108 | - static GuiCalibratorX11* instance; | |
109 | -}; | |
110 | -GuiCalibratorX11* GuiCalibratorX11::instance = NULL; | |
68 | + instance = new GuiCalibratorX11(w); | |
69 | +} | |
111 | 70 | |
71 | +// Singleton instance | |
72 | +GuiCalibratorX11* GuiCalibratorX11::instance = NULL; | |
112 | 73 | |
113 | 74 | GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0) |
114 | 75 | : calibrator(calibrator0), time_elapsed(0) |
@@ -181,7 +142,7 @@ GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0) | ||
181 | 142 | |
182 | 143 | Colormap colormap = DefaultColormap(display, screen_num); |
183 | 144 | XColor color; |
184 | - for (int i = 0; i != nr_colors; i++) { | |
145 | + for (int i = 0; i != NUM_COLORS; i++) { | |
185 | 146 | XParseColor(display, colormap, colors[i], &color); |
186 | 147 | XAllocColor(display, colormap, &color); |
187 | 148 | pixel[i] = color.pixel; |
@@ -392,14 +353,6 @@ void GuiCalibratorX11::give_timer_signal() | ||
392 | 353 | } |
393 | 354 | } |
394 | 355 | |
395 | -bool GuiCalibratorX11::set_instance(GuiCalibratorX11* W) | |
396 | -{ | |
397 | - bool wasSet = (instance != NULL); | |
398 | - instance = W; | |
399 | - | |
400 | - return wasSet; | |
401 | -} | |
402 | - | |
403 | 356 | |
404 | 357 | // handle SIGALRM signal, pass to singleton |
405 | 358 | void sigalarm_handler(int num) |
@@ -31,17 +31,16 @@ | ||
31 | 31 | class GuiCalibratorX11 |
32 | 32 | { |
33 | 33 | public: |
34 | - GuiCalibratorX11(Calibrator* w); | |
35 | - ~GuiCalibratorX11(); | |
36 | - static bool set_instance(GuiCalibratorX11* W); | |
34 | + static void make_instance(Calibrator* w); | |
37 | 35 | static void give_timer_signal(); |
38 | 36 | |
39 | 37 | protected: |
40 | - static const int nr_colors = 5; | |
41 | - static const char* colors[nr_colors]; | |
38 | + GuiCalibratorX11(Calibrator* w); | |
39 | + ~GuiCalibratorX11(); | |
40 | + | |
42 | 41 | // Data |
43 | 42 | Calibrator* calibrator; |
44 | - double X[4], Y[4]; | |
43 | + double X[NUM_POINTS], Y[NUM_POINTS]; | |
45 | 44 | int display_width, display_height; |
46 | 45 | int time_elapsed; |
47 | 46 |
@@ -51,9 +50,11 @@ protected: | ||
51 | 50 | Window win; |
52 | 51 | GC gc; |
53 | 52 | XFontStruct* font_info; |
54 | - // color mngmt | |
55 | - unsigned long pixel[nr_colors]; | |
56 | 53 | |
54 | + // color management | |
55 | + enum { BLACK=0, WHITE=1, GRAY=2, DIMGRAY=3, RED=4, NUM_COLORS }; | |
56 | + static const char* colors[NUM_COLORS]; | |
57 | + unsigned long pixel[NUM_COLORS]; | |
57 | 58 | |
58 | 59 | // Signal handlers |
59 | 60 | bool on_timer_signal(); |
@@ -21,6 +21,13 @@ | ||
21 | 21 | * THE SOFTWARE. |
22 | 22 | */ |
23 | 23 | |
24 | +#include "calibrator.hh" | |
25 | + | |
26 | +// Calibrator implementations | |
27 | +#include "calibrator/Usbtouchscreen.hpp" | |
28 | +#include "calibrator/Evdev.hpp" | |
29 | +#include "calibrator/XorgPrint.hpp" | |
30 | + | |
24 | 31 | #include <cstring> |
25 | 32 | #include <stdio.h> |
26 | 33 | #include <stdlib.h> |
@@ -29,13 +36,8 @@ | ||
29 | 36 | #include <X11/Xlib.h> |
30 | 37 | #include <X11/extensions/XInput.h> |
31 | 38 | |
32 | -#include "main_common.hpp" | |
33 | -#include "calibrator/calibratorUsbtouchscreen.hpp" | |
34 | -#include "calibrator/calibratorEvdev.hpp" | |
35 | -#include "calibrator/calibratorXorgPrint.hpp" | |
36 | - | |
37 | 39 | // strdup: non-ansi |
38 | -char* my_strdup(const char* s) { | |
40 | +static char* my_strdup(const char* s) { | |
39 | 41 | size_t len = strlen(s) + 1; |
40 | 42 | void* p = malloc(len); |
41 | 43 |
@@ -52,7 +54,7 @@ char* my_strdup(const char* s) { | ||
52 | 54 | * retuns number of devices found, |
53 | 55 | * the data of the device is returned in the last 3 function parameters |
54 | 56 | */ |
55 | -int find_device(const char* pre_device, bool verbose, bool list_devices, | |
57 | +static int find_device(const char* pre_device, bool verbose, bool list_devices, | |
56 | 58 | XID& device_id, const char*& device_name, XYinfo& device_axys) |
57 | 59 | { |
58 | 60 | bool pre_device_is_id = true; |
@@ -179,7 +181,7 @@ static void usage(char* cmd, unsigned thr_misclick) | ||
179 | 181 | fprintf(stderr, "\t--geometry: manually provide the geometry for the calibration window\n"); |
180 | 182 | } |
181 | 183 | |
182 | -Calibrator* main_common(int argc, char** argv) | |
184 | +Calibrator* Calibrator::make_calibrator(int argc, char** argv) | |
183 | 185 | { |
184 | 186 | bool verbose = false; |
185 | 187 | bool list_devices = false; |
@@ -198,7 +200,7 @@ Calibrator* main_common(int argc, char** argv) | ||
198 | 200 | // Display help ? |
199 | 201 | if (strcmp("-h", argv[i]) == 0 || |
200 | 202 | strcmp("--help", argv[i]) == 0) { |
201 | - fprintf(stderr, "xinput_calibratior, v%s\n\n", VERSION); | |
203 | + fprintf(stderr, "xinput_calibrator, v%s\n\n", VERSION); | |
202 | 204 | usage(argv[0], thr_misclick); |
203 | 205 | exit(0); |
204 | 206 | } else |
@@ -276,7 +278,6 @@ Calibrator* main_common(int argc, char** argv) | ||
276 | 278 | // specify window geometry? |
277 | 279 | if (strcmp("--geometry", argv[i]) == 0) { |
278 | 280 | geometry = argv[++i]; |
279 | - //sscanf(argv[++i],"%dx%d+%d+%d",&win_width,&win_height,&win_xoff,&win_yoff); | |
280 | 281 | } else |
281 | 282 | |
282 | 283 | // Fake calibratable device ? |
@@ -294,7 +295,7 @@ Calibrator* main_common(int argc, char** argv) | ||
294 | 295 | } |
295 | 296 | |
296 | 297 | |
297 | - // Choose the device to calibrate | |
298 | + /// Choose the device to calibrate | |
298 | 299 | XID device_id = (XID) -1; |
299 | 300 | const char* device_name = NULL; |
300 | 301 | XYinfo device_axys; |
@@ -24,15 +24,14 @@ | ||
24 | 24 | // Must be before Xlib stuff |
25 | 25 | #include <gtkmm/main.h> |
26 | 26 | #include <gtkmm/window.h> |
27 | -#include <gtkmm/drawingarea.h> | |
28 | 27 | #include <cairomm/context.h> |
29 | 28 | |
30 | -#include "main_common.hpp" | |
31 | -#include "gui/gui_gtkmm.cpp" | |
29 | +#include "calibrator.hh" | |
30 | +#include "gui/gtkmm.hpp" | |
32 | 31 | |
33 | 32 | int main(int argc, char** argv) |
34 | 33 | { |
35 | - Calibrator* calibrator = main_common(argc, argv); | |
34 | + Calibrator* calibrator = Calibrator::make_calibrator(argc, argv); | |
36 | 35 | |
37 | 36 | // GTK-mm setup |
38 | 37 | Gtk::Main kit(argc, argv); |
@@ -20,15 +20,14 @@ | ||
20 | 20 | * THE SOFTWARE. |
21 | 21 | */ |
22 | 22 | |
23 | -#include "main_common.hpp" | |
24 | -#include "gui/gui_x11.cpp" | |
23 | +#include "calibrator.hh" | |
24 | +#include "gui/x11.hpp" | |
25 | 25 | |
26 | 26 | int main(int argc, char** argv) |
27 | 27 | { |
28 | - Calibrator* calibrator = main_common(argc, argv); | |
28 | + Calibrator* calibrator = Calibrator::make_calibrator(argc, argv); | |
29 | 29 | |
30 | - GuiCalibratorX11 gui(calibrator); | |
31 | - GuiCalibratorX11::set_instance(&gui); | |
30 | + GuiCalibratorX11::make_instance( calibrator ); | |
32 | 31 | |
33 | 32 | // wait for timer signal, processes events |
34 | 33 | while(1) |