Skip to content

Commit 9dae715

Browse files
committed
Completing file reorganization with correct headers
1 parent ad47b76 commit 9dae715

File tree

14 files changed

+237
-303
lines changed

14 files changed

+237
-303
lines changed

src/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
xinput_calibrator_x11
22
xinput_calibrator_gtkmm
3+
xinput_calibrator

src/Makefile.am

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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,5 @@ endif
5254
EXTRA_DIST = \
5355
calibrator.cpp \
5456
calibrator.hh \
55-
main_common.hpp
57+
main_common.cpp
58+

src/calibrator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

src/calibrator.hh

Lines changed: 96 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/calibrator/Evdev.cpp

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

0 commit comments

Comments
 (0)