• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

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

Revisão4cc7337a86c1de07475a3756c6268b9d2d642613 (tree)
Hora2011-04-20 19:24:48
AutorAntoine Hue <antoine@peti...>
CommiterTias Guns

Mensagem de Log

Completing file reorganization with correct headers

Mudança Sumário

Diff

--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,19 +28,21 @@ SUBDIRS = \
2828 calibrator \
2929 gui
3030
31-AM_CXXFLAGS = -Wall -ansi -pedantic -Wmissing-declarations
31+AM_CXXFLAGS = -Wall -ansi -pedantic
3232
3333 bin_PROGRAMS = xinput_calibrator
3434
35+COMMON_SRCS=calibrator.cpp calibrator/XorgPrint.cpp calibrator/Evdev.cpp calibrator/Usbtouchscreen.cpp main_common.cpp
36+
3537 # only one of the BUILD_ flags should be set
3638 if BUILD_X11
37-xinput_calibrator_SOURCES = main_x11.cpp
39+xinput_calibrator_SOURCES = gui/x11.cpp main_x11.cpp $(COMMON_SRCS)
3840 xinput_calibrator_LDADD = $(XINPUT_LIBS) $(XRANDR_LIBS) $(X11_LIBS)
3941 xinput_calibrator_CXXFLAGS = $(XINPUT_CFLAGS) $(X11_CFLAGS) $(XRANDR_CFLAGS) $(AM_CXXFLAGS)
4042 endif
4143
4244 if BUILD_GTKMM
43-xinput_calibrator_SOURCES = main_gtkmm.cpp
45+xinput_calibrator_SOURCES = gui/gtkmm.cpp main_gtkmm.cpp $(COMMON_SRCS)
4446 xinput_calibrator_LDADD = $(XINPUT_LIBS) $(GTKMM_LIBS)
4547 xinput_calibrator_CXXFLAGS = $(XINPUT_CFLAGS) $(GTKMM_CFLAGS) $(AM_CXXFLAGS)
4648
@@ -52,4 +54,4 @@ endif
5254 EXTRA_DIST = \
5355 calibrator.cpp \
5456 calibrator.hh \
55- main_common.hpp
57+ main_common.cpp
--- a/src/calibrator.cpp
+++ b/src/calibrator.cpp
@@ -25,7 +25,7 @@
2525 #include <dirent.h>
2626 #include <iostream>
2727 #include <fstream>
28-#include <string>
28+#include <cstring>
2929
3030 #include "calibrator.hh"
3131
--- a/src/calibrator.hh
+++ b/src/calibrator.hh
@@ -24,37 +24,115 @@
2424 #ifndef _calibrator_hh
2525 #define _calibrator_hh
2626
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
2893 class Calibrator
2994 {
3095 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+
38111 ~Calibrator() {}
39112
40- // set the doubleclick treshold
113+ /// set the doubleclick treshold
41114 void set_threshold_doubleclick(int t);
42- // set the misclick treshold
115+
116+ /// set the misclick treshold
43117 void set_threshold_misclick(int t);
44- // get the number of clicks already registered
118+
119+ /// get the number of clicks already registered
45120 int get_numclicks();
46- // return geometry string or NULL
121+
122+ /// return geometry string or NULL
47123 const char* get_geometry();
48- // reset clicks
124+
125+ /// reset clicks
49126 void reset() {
50127 num_clicks = 0;
51128 }
52- // add a click with the given coordinates
129+
130+ /// add a click with the given coordinates
53131 bool add_click(int x, int y);
54- // calculate and apply the calibration
132+ /// calculate and apply the calibration
55133 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
58136 const char* get_sysfs_name();
59137
60138 protected:
@@ -73,7 +151,7 @@ protected:
73151 // nr of clicks registered
74152 int num_clicks;
75153 // click coordinates
76- int clicked_x[4], clicked_y[4];
154+ int clicked_x[NUM_POINTS], clicked_y[NUM_POINTS];
77155
78156 // Threshold to keep the same point from being clicked twice.
79157 // Set to zero if you don't want this check
--- a/src/calibrator/Evdev.cpp
+++ b/src/calibrator/Evdev.cpp
@@ -20,12 +20,16 @@
2020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121 * THE SOFTWARE.
2222 */
23-#include <ctype.h>
23+
24+#include "calibrator/Evdev.hpp"
2425
2526 #include <X11/Xlib.h>
26-#include <X11/extensions/XInput.h>
2727 #include <X11/Xatom.h>
2828 //#include <X11/Xutil.h>
29+#include <ctype.h>
30+#include <cstdio>
31+#include <cstring>
32+#include <cstdlib>
2933
3034 #ifndef EXIT_SUCCESS
3135 #define EXIT_SUCCESS 1
@@ -34,39 +38,6 @@
3438 #define EXIT_FAILURE 0
3539 #endif
3640
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-
7041 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)
7142 : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type, geometry), old_swap_xy(0)
7243 {
--- a/src/calibrator/Makefile.am
+++ b/src/calibrator/Makefile.am
@@ -1,4 +1,4 @@
11 EXTRA_DIST = \
2- calibratorEvdev.cpp \
3- calibratorUsbtouchscreen.cpp \
4- calibratorXorgPrint.cpp
2+ Evdev.cpp \
3+ Usbtouchscreen.cpp \
4+ XorgPrint.cpp
--- a/src/calibrator/Usbtouchscreen.cpp
+++ b/src/calibrator/Usbtouchscreen.cpp
@@ -19,120 +19,34 @@
1919 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020 * THE SOFTWARE.
2121 */
22-#include <string>
22+
23+#include "calibrator/Usbtouchscreen.hpp"
24+
25+#include <cstdlib>
26+#include <cstdio>
27+#include <cstring>
2328
2429 /*************************
2530 * Variables for usbtouchscreen specifically
2631 *************************/
2732 // The file to which the calibration parameters are saved.
2833 // (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";
3035
3136 // 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";
3338
3439 // 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";
13650
13751 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)
13852 : 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)
232146
233147 return true;
234148 }
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+ }
--- a/src/calibrator/XorgPrint.cpp
+++ b/src/calibrator/XorgPrint.cpp
@@ -20,22 +20,9 @@
2020 * THE SOFTWARE.
2121 */
2222
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"
3324
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>
3926
4027 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)
4128 : Calibrator(device_name0, axys0, verbose0, thr_misclick, thr_doubleclick, output_type, geometry)
--- a/src/gui/Makefile.am
+++ b/src/gui/Makefile.am
@@ -1,3 +1,3 @@
11 EXTRA_DIST = \
2- gui_gtkmm.cpp \
3- gui_x11.cpp
2+ gtkmm.cpp \
3+ x11.cpp
--- a/src/gui/gtkmm.cpp
+++ b/src/gui/gtkmm.cpp
@@ -20,13 +20,8 @@
2020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121 * THE SOFTWARE.
2222 */
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"
2923
24+#include "gui/gtkmm.hpp"
3025
3126 // Timeout parameters
3227 const int time_step = 100; // in milliseconds
@@ -48,36 +43,6 @@ const std::string help_text[help_lines] = {
4843 "(To abort, press any key or wait)"
4944 };
5045
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-
8146 CalibrationArea::CalibrationArea(Calibrator* calibrator0)
8247 : calibrator(calibrator0), time_elapsed(0), message(NULL)
8348 {
--- a/src/gui/x11.cpp
+++ b/src/gui/x11.cpp
@@ -19,6 +19,9 @@
1919 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020 * THE SOFTWARE.
2121 */
22+
23+#include "gui/x11.hpp"
24+
2225 #include <X11/X.h>
2326 #include <X11/Xlib.h>
2427 #include <X11/Xutil.h>
@@ -34,12 +37,10 @@
3437 #include <signal.h>
3538 #include <string.h>
3639
37-#include "calibrator.hh"
38-
3940
4041 // Timeout parameters
4142 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
4344
4445 // Clock appereance
4546 const int cross_lines = 25;
@@ -57,58 +58,18 @@ const std::string help_text[help_lines] = {
5758 "(To abort, press any key or wait)"
5859 };
5960
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"};
6562
6663 void sigalarm_handler(int num);
6764
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)
7367 {
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+}
11170
71+// Singleton instance
72+GuiCalibratorX11* GuiCalibratorX11::instance = NULL;
11273
11374 GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0)
11475 : calibrator(calibrator0), time_elapsed(0)
@@ -181,7 +142,7 @@ GuiCalibratorX11::GuiCalibratorX11(Calibrator* calibrator0)
181142
182143 Colormap colormap = DefaultColormap(display, screen_num);
183144 XColor color;
184- for (int i = 0; i != nr_colors; i++) {
145+ for (int i = 0; i != NUM_COLORS; i++) {
185146 XParseColor(display, colormap, colors[i], &color);
186147 XAllocColor(display, colormap, &color);
187148 pixel[i] = color.pixel;
@@ -392,14 +353,6 @@ void GuiCalibratorX11::give_timer_signal()
392353 }
393354 }
394355
395-bool GuiCalibratorX11::set_instance(GuiCalibratorX11* W)
396-{
397- bool wasSet = (instance != NULL);
398- instance = W;
399-
400- return wasSet;
401-}
402-
403356
404357 // handle SIGALRM signal, pass to singleton
405358 void sigalarm_handler(int num)
--- a/src/gui/x11.hpp
+++ b/src/gui/x11.hpp
@@ -31,17 +31,16 @@
3131 class GuiCalibratorX11
3232 {
3333 public:
34- GuiCalibratorX11(Calibrator* w);
35- ~GuiCalibratorX11();
36- static bool set_instance(GuiCalibratorX11* W);
34+ static void make_instance(Calibrator* w);
3735 static void give_timer_signal();
3836
3937 protected:
40- static const int nr_colors = 5;
41- static const char* colors[nr_colors];
38+ GuiCalibratorX11(Calibrator* w);
39+ ~GuiCalibratorX11();
40+
4241 // Data
4342 Calibrator* calibrator;
44- double X[4], Y[4];
43+ double X[NUM_POINTS], Y[NUM_POINTS];
4544 int display_width, display_height;
4645 int time_elapsed;
4746
@@ -51,9 +50,11 @@ protected:
5150 Window win;
5251 GC gc;
5352 XFontStruct* font_info;
54- // color mngmt
55- unsigned long pixel[nr_colors];
5653
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];
5758
5859 // Signal handlers
5960 bool on_timer_signal();
--- a/src/main_common.cpp
+++ b/src/main_common.cpp
@@ -21,6 +21,13 @@
2121 * THE SOFTWARE.
2222 */
2323
24+#include "calibrator.hh"
25+
26+// Calibrator implementations
27+#include "calibrator/Usbtouchscreen.hpp"
28+#include "calibrator/Evdev.hpp"
29+#include "calibrator/XorgPrint.hpp"
30+
2431 #include <cstring>
2532 #include <stdio.h>
2633 #include <stdlib.h>
@@ -29,13 +36,8 @@
2936 #include <X11/Xlib.h>
3037 #include <X11/extensions/XInput.h>
3138
32-#include "main_common.hpp"
33-#include "calibrator/calibratorUsbtouchscreen.hpp"
34-#include "calibrator/calibratorEvdev.hpp"
35-#include "calibrator/calibratorXorgPrint.hpp"
36-
3739 // strdup: non-ansi
38-char* my_strdup(const char* s) {
40+static char* my_strdup(const char* s) {
3941 size_t len = strlen(s) + 1;
4042 void* p = malloc(len);
4143
@@ -52,7 +54,7 @@ char* my_strdup(const char* s) {
5254 * retuns number of devices found,
5355 * the data of the device is returned in the last 3 function parameters
5456 */
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,
5658 XID& device_id, const char*& device_name, XYinfo& device_axys)
5759 {
5860 bool pre_device_is_id = true;
@@ -179,7 +181,7 @@ static void usage(char* cmd, unsigned thr_misclick)
179181 fprintf(stderr, "\t--geometry: manually provide the geometry for the calibration window\n");
180182 }
181183
182-Calibrator* main_common(int argc, char** argv)
184+Calibrator* Calibrator::make_calibrator(int argc, char** argv)
183185 {
184186 bool verbose = false;
185187 bool list_devices = false;
@@ -198,7 +200,7 @@ Calibrator* main_common(int argc, char** argv)
198200 // Display help ?
199201 if (strcmp("-h", argv[i]) == 0 ||
200202 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);
202204 usage(argv[0], thr_misclick);
203205 exit(0);
204206 } else
@@ -276,7 +278,6 @@ Calibrator* main_common(int argc, char** argv)
276278 // specify window geometry?
277279 if (strcmp("--geometry", argv[i]) == 0) {
278280 geometry = argv[++i];
279- //sscanf(argv[++i],"%dx%d+%d+%d",&win_width,&win_height,&win_xoff,&win_yoff);
280281 } else
281282
282283 // Fake calibratable device ?
@@ -294,7 +295,7 @@ Calibrator* main_common(int argc, char** argv)
294295 }
295296
296297
297- // Choose the device to calibrate
298+ /// Choose the device to calibrate
298299 XID device_id = (XID) -1;
299300 const char* device_name = NULL;
300301 XYinfo device_axys;
--- a/src/main_gtkmm.cpp
+++ b/src/main_gtkmm.cpp
@@ -24,15 +24,14 @@
2424 // Must be before Xlib stuff
2525 #include <gtkmm/main.h>
2626 #include <gtkmm/window.h>
27-#include <gtkmm/drawingarea.h>
2827 #include <cairomm/context.h>
2928
30-#include "main_common.hpp"
31-#include "gui/gui_gtkmm.cpp"
29+#include "calibrator.hh"
30+#include "gui/gtkmm.hpp"
3231
3332 int main(int argc, char** argv)
3433 {
35- Calibrator* calibrator = main_common(argc, argv);
34+ Calibrator* calibrator = Calibrator::make_calibrator(argc, argv);
3635
3736 // GTK-mm setup
3837 Gtk::Main kit(argc, argv);
--- a/src/main_x11.cpp
+++ b/src/main_x11.cpp
@@ -20,15 +20,14 @@
2020 * THE SOFTWARE.
2121 */
2222
23-#include "main_common.hpp"
24-#include "gui/gui_x11.cpp"
23+#include "calibrator.hh"
24+#include "gui/x11.hpp"
2525
2626 int main(int argc, char** argv)
2727 {
28- Calibrator* calibrator = main_common(argc, argv);
28+ Calibrator* calibrator = Calibrator::make_calibrator(argc, argv);
2929
30- GuiCalibratorX11 gui(calibrator);
31- GuiCalibratorX11::set_instance(&gui);
30+ GuiCalibratorX11::make_instance( calibrator );
3231
3332 // wait for timer signal, processes events
3433 while(1)