A generic touchscreen calibration program for X.Org
Révision | eed08ae683258a321ef9f9480b7b2c3179b1bb09 (tree) |
---|---|
l'heure | 2011-04-20 19:24:48 |
Auteur | Antoine Hue <antoine@peti...> |
Commiter | Tias Guns |
Software engineering to avoid #include "XXX.cpp": + file headers + correct includes
@@ -0,0 +1,63 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2009 Tias Guns | |
3 | + * Copyright 2007 Peter Hutterer (xinput_ methods from xinput) | |
4 | + * | |
5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 | + * of this software and associated documentation files (the "Software"), to deal | |
7 | + * in the Software without restriction, including without limitation the rights | |
8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | + * copies of the Software, and to permit persons to whom the Software is | |
10 | + * furnished to do so, subject to the following conditions: | |
11 | + * | |
12 | + * The above copyright notice and this permission notice shall be included in | |
13 | + * all copies or substantial portions of the Software. | |
14 | + * | |
15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
21 | + * THE SOFTWARE. | |
22 | + */ | |
23 | + | |
24 | +#ifndef CALIBRATOR_EVDEV_HPP | |
25 | +#define CALIBRATOR_EVDEV_HPP | |
26 | + | |
27 | +#include "calibrator.hh" | |
28 | +#include <X11/extensions/XInput.h> | |
29 | + | |
30 | +/*************************************** | |
31 | + * Class for dynamic evdev calibration | |
32 | + * uses xinput "Evdev Axis Calibration" | |
33 | + ***************************************/ | |
34 | +class CalibratorEvdev: public Calibrator | |
35 | +{ | |
36 | +private: | |
37 | + Display *display; | |
38 | + XDeviceInfo *info; | |
39 | + XDevice *dev; | |
40 | + | |
41 | + int old_swap_xy; | |
42 | +public: | |
43 | + CalibratorEvdev(const char* const device_name, const XYinfo& axys, const bool verbose, | |
44 | + XID device_id=(XID)-1, const int thr_misclick=0, const int thr_doubleclick=0, | |
45 | + const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
46 | + ~CalibratorEvdev(); | |
47 | + | |
48 | + virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
49 | + | |
50 | + bool set_swapxy(const int swap_xy); | |
51 | + bool set_calibration(const XYinfo new_axys); | |
52 | + | |
53 | + // xinput_ functions (from the xinput project) | |
54 | + Atom xinput_parse_atom(Display *display, const char* name); | |
55 | + XDeviceInfo* xinput_find_device_info(Display *display, const char* name, Bool only_extended); | |
56 | + int xinput_do_set_prop(Display *display, Atom type, int format, int argc, char* argv[]); | |
57 | +protected: | |
58 | + bool output_xorgconfd(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
59 | + bool output_hal(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
60 | + bool output_xinput(const XYinfo new_axys, int swap_xy, int new_swap_xy); | |
61 | +}; | |
62 | + | |
63 | +#endif |
@@ -110,7 +110,7 @@ protected: | ||
110 | 110 | char filename[100]; |
111 | 111 | sprintf(filename, "%s/%s", module_prefix, param); |
112 | 112 | FILE *fid = fopen(filename, "w"); |
113 | - if (fid == NULL) { | |
113 | + if (fid == NULL) { | |
114 | 114 | fprintf(stderr, "Could not save parameter '%s'\n", param); |
115 | 115 | return; |
116 | 116 | } |
@@ -0,0 +1,65 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2009 Soren Hauberg | |
3 | + * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | + * of this software and associated documentation files (the "Software"), to deal | |
6 | + * in the Software without restriction, including without limitation the rights | |
7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | + * copies of the Software, and to permit persons to whom the Software is | |
9 | + * furnished to do so, subject to the following conditions: | |
10 | + * | |
11 | + * The above copyright notice and this permission notice shall be included in | |
12 | + * all copies or substantial portions of the Software. | |
13 | + * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | + * THE SOFTWARE. | |
21 | + */ | |
22 | + | |
23 | +#ifndef CALIBRATOR_USBTOUCHSCREEN_HPP | |
24 | +#define CALIBRATOR_USBTOUCHSCREEN_HPP | |
25 | + | |
26 | +#include "calibrator.hh" | |
27 | + | |
28 | +/********************************** | |
29 | + * Class for usbtouchscreen driver, | |
30 | + * writes output parameters to running kernel and to modprobe.conf | |
31 | + **********************************/ | |
32 | +class CalibratorUsbtouchscreen: public Calibrator | |
33 | +{ | |
34 | +public: | |
35 | + CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys, | |
36 | + const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, | |
37 | + const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
38 | + ~CalibratorUsbtouchscreen(); | |
39 | + | |
40 | + virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
41 | + | |
42 | +protected: | |
43 | + // Globals for kernel parameters from startup. | |
44 | + // We revert to these if the program aborts | |
45 | + bool val_transform_xy, val_flip_x, val_flip_y, val_swap_xy; | |
46 | + | |
47 | + // Helper functions | |
48 | + char yesno(const bool value) | |
49 | + { | |
50 | + if (value) | |
51 | + return 'Y'; | |
52 | + else | |
53 | + return 'N'; | |
54 | + } | |
55 | + | |
56 | + void read_int_parameter(const char *param, int &value); | |
57 | + | |
58 | + void read_bool_parameter(const char *param, bool &value); | |
59 | + | |
60 | + void write_int_parameter(const char *param, const int value); | |
61 | + | |
62 | + void write_bool_parameter(const char *param, const bool value); | |
63 | +}; | |
64 | + | |
65 | +#endif |
@@ -0,0 +1,45 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2009 Tias Guns | |
3 | + * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | + * of this software and associated documentation files (the "Software"), to deal | |
6 | + * in the Software without restriction, including without limitation the rights | |
7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | + * copies of the Software, and to permit persons to whom the Software is | |
9 | + * furnished to do so, subject to the following conditions: | |
10 | + * | |
11 | + * The above copyright notice and this permission notice shall be included in | |
12 | + * all copies or substantial portions of the Software. | |
13 | + * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | + * THE SOFTWARE. | |
21 | + */ | |
22 | + | |
23 | +#ifndef CALIBRATOR_XORGPRINT_HPP | |
24 | +#define CALIBRATOR_XORGPRINT_HPP | |
25 | + | |
26 | +#include "calibrator.hh" | |
27 | + | |
28 | +/*************************************** | |
29 | + * Class for generic Xorg driver, | |
30 | + * outputs new Xorg.conf and FDI policy, on stdout | |
31 | + ***************************************/ | |
32 | +class CalibratorXorgPrint: public Calibrator | |
33 | +{ | |
34 | +public: | |
35 | + CalibratorXorgPrint(const char* const device_name, const XYinfo& axys, | |
36 | + const bool verbose, const int thr_misclick=0, const int thr_doubleclick=0, | |
37 | + const OutputType output_type=OUTYPE_AUTO, const char* geometry=0); | |
38 | + | |
39 | + virtual bool finish_data(const XYinfo new_axys, int swap_xy); | |
40 | +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); | |
43 | +}; | |
44 | + | |
45 | +#endif |
@@ -0,0 +1,59 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2009 Tias Guns | |
3 | + * Copyright (c) 2009 Soren Hauberg | |
4 | + * | |
5 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | |
6 | + * of this software and associated documentation files (the "Software"), to deal | |
7 | + * in the Software without restriction, including without limitation the rights | |
8 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | + * copies of the Software, and to permit persons to whom the Software is | |
10 | + * furnished to do so, subject to the following conditions: | |
11 | + * | |
12 | + * The above copyright notice and this permission notice shall be included in | |
13 | + * all copies or substantial portions of the Software. | |
14 | + * | |
15 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
21 | + * THE SOFTWARE. | |
22 | + */ | |
23 | + | |
24 | +#ifndef GUI_GTKMM_HPP | |
25 | +#define GUI_GTKMM_HPP | |
26 | + | |
27 | +#include <gtkmm/drawingarea.h> | |
28 | +#include "calibrator.hh" | |
29 | + | |
30 | +/******************************************* | |
31 | + * GTK-mm class for the the calibration GUI | |
32 | + *******************************************/ | |
33 | +class CalibrationArea : public Gtk::DrawingArea | |
34 | +{ | |
35 | +public: | |
36 | + CalibrationArea(Calibrator* w); | |
37 | + | |
38 | +protected: | |
39 | + // Data | |
40 | + Calibrator* calibrator; | |
41 | + double X[4], Y[4]; | |
42 | + int display_width, display_height; | |
43 | + int time_elapsed; | |
44 | + | |
45 | + const char* message; | |
46 | + | |
47 | + // Signal handlers | |
48 | + bool on_timer_signal(); | |
49 | + bool on_expose_event(GdkEventExpose *event); | |
50 | + bool on_button_press_event(GdkEventButton *event); | |
51 | + bool on_key_press_event(GdkEventKey *event); | |
52 | + | |
53 | + // Helper functions | |
54 | + void set_display_size(int width, int height); | |
55 | + void redraw(); | |
56 | + void draw_message(const char* msg); | |
57 | +}; | |
58 | + | |
59 | +#endif |
@@ -0,0 +1,72 @@ | ||
1 | +/* | |
2 | + * Copyright (c) 2009 Tias Guns | |
3 | + * | |
4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | + * of this software and associated documentation files (the "Software"), to deal | |
6 | + * in the Software without restriction, including without limitation the rights | |
7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | + * copies of the Software, and to permit persons to whom the Software is | |
9 | + * furnished to do so, subject to the following conditions: | |
10 | + * | |
11 | + * The above copyright notice and this permission notice shall be included in | |
12 | + * all copies or substantial portions of the Software. | |
13 | + * | |
14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | + * THE SOFTWARE. | |
21 | + */ | |
22 | + | |
23 | +#ifndef GUI_CALIBRATOR_X11 | |
24 | +#define GUI_CALIBRATOR_X11 | |
25 | + | |
26 | +#include "calibrator.hh" | |
27 | + | |
28 | +/******************************************* | |
29 | + * X11 class for the the calibration GUI | |
30 | + *******************************************/ | |
31 | +class GuiCalibratorX11 | |
32 | +{ | |
33 | +public: | |
34 | + GuiCalibratorX11(Calibrator* w); | |
35 | + ~GuiCalibratorX11(); | |
36 | + static bool set_instance(GuiCalibratorX11* W); | |
37 | + static void give_timer_signal(); | |
38 | + | |
39 | +protected: | |
40 | + static const int nr_colors = 5; | |
41 | + static const char* colors[nr_colors]; | |
42 | + // Data | |
43 | + Calibrator* calibrator; | |
44 | + double X[4], Y[4]; | |
45 | + int display_width, display_height; | |
46 | + int time_elapsed; | |
47 | + | |
48 | + // X11 vars | |
49 | + Display* display; | |
50 | + int screen_num; | |
51 | + Window win; | |
52 | + GC gc; | |
53 | + XFontStruct* font_info; | |
54 | + // color mngmt | |
55 | + unsigned long pixel[nr_colors]; | |
56 | + | |
57 | + | |
58 | + // Signal handlers | |
59 | + bool on_timer_signal(); | |
60 | + bool on_expose_event(); | |
61 | + bool on_button_press_event(XEvent event); | |
62 | + | |
63 | + // Helper functions | |
64 | + void set_display_size(int width, int height); | |
65 | + void redraw(); | |
66 | + void draw_message(const char* msg); | |
67 | + | |
68 | +private: | |
69 | + static GuiCalibratorX11* instance; | |
70 | +}; | |
71 | + | |
72 | +#endif |
@@ -20,6 +20,7 @@ | ||
20 | 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
21 | 21 | * THE SOFTWARE. |
22 | 22 | */ |
23 | + | |
23 | 24 | #include <cstring> |
24 | 25 | #include <stdio.h> |
25 | 26 | #include <stdlib.h> |
@@ -28,69 +29,12 @@ | ||
28 | 29 | #include <X11/Xlib.h> |
29 | 30 | #include <X11/extensions/XInput.h> |
30 | 31 | |
31 | -/* | |
32 | - * Number of blocks. We partition the screen into 'num_blocks' x 'num_blocks' | |
33 | - * rectangles of equal size. We then ask the user to press points that are | |
34 | - * located at the corner closes to the center of the four blocks in the corners | |
35 | - * of the screen. The following ascii art illustrates the situation. We partition | |
36 | - * the screen into 8 blocks in each direction. We then let the user press the | |
37 | - * points marked with 'O'. | |
38 | - * | |
39 | - * +--+--+--+--+--+--+--+--+ | |
40 | - * | | | | | | | | | | |
41 | - * +--O--+--+--+--+--+--O--+ | |
42 | - * | | | | | | | | | | |
43 | - * +--+--+--+--+--+--+--+--+ | |
44 | - * | | | | | | | | | | |
45 | - * +--+--+--+--+--+--+--+--+ | |
46 | - * | | | | | | | | | | |
47 | - * +--+--+--+--+--+--+--+--+ | |
48 | - * | | | | | | | | | | |
49 | - * +--+--+--+--+--+--+--+--+ | |
50 | - * | | | | | | | | | | |
51 | - * +--+--+--+--+--+--+--+--+ | |
52 | - * | | | | | | | | | | |
53 | - * +--O--+--+--+--+--+--O--+ | |
54 | - * | | | | | | | | | | |
55 | - * +--+--+--+--+--+--+--+--+ | |
56 | - */ | |
57 | -const int num_blocks = 8; | |
58 | - | |
59 | -// Names of the points | |
60 | -enum { | |
61 | - UL = 0, // Upper-left | |
62 | - UR = 1, // Upper-right | |
63 | - LL = 2, // Lower-left | |
64 | - LR = 3 // Lower-right | |
65 | -}; | |
66 | - | |
67 | -// Output types | |
68 | -enum OutputType { | |
69 | - OUTYPE_AUTO, | |
70 | - OUTYPE_XORGCONFD, | |
71 | - OUTYPE_HAL, | |
72 | - OUTYPE_XINPUT | |
73 | -}; | |
74 | - | |
75 | -// struct to hold min/max info of the X and Y axis | |
76 | -struct XYinfo { | |
77 | - int x_min; | |
78 | - int x_max; | |
79 | - int y_min; | |
80 | - int y_max; | |
81 | - XYinfo() : x_min(-1), x_max(-1), y_min(-1), y_max(-1) {} | |
82 | - XYinfo(int xmi, int xma, int ymi, int yma) : | |
83 | - x_min(xmi), x_max(xma), y_min(ymi), y_max(yma) {} | |
84 | -}; | |
85 | - | |
86 | -class WrongCalibratorException : public std::invalid_argument { | |
87 | - public: | |
88 | - WrongCalibratorException(const std::string& msg = "") : | |
89 | - std::invalid_argument(msg) {} | |
90 | -}; | |
32 | +#include "main_common.hpp" | |
33 | +#include "calibrator/calibratorUsbtouchscreen.hpp" | |
34 | +#include "calibrator/calibratorEvdev.hpp" | |
35 | +#include "calibrator/calibratorXorgPrint.hpp" | |
91 | 36 | |
92 | 37 | // strdup: non-ansi |
93 | -char* my_strdup(const char* s); | |
94 | 38 | char* my_strdup(const char* s) { |
95 | 39 | size_t len = strlen(s) + 1; |
96 | 40 | void* p = malloc(len); |
@@ -101,13 +45,6 @@ char* my_strdup(const char* s) { | ||
101 | 45 | return (char*) memcpy(p, s, len); |
102 | 46 | } |
103 | 47 | |
104 | -// all need struct XYinfo, and some the consts too | |
105 | -#include "calibrator.cpp" | |
106 | -#include "calibrator/calibratorXorgPrint.cpp" | |
107 | -#include "calibrator/calibratorEvdev.cpp" | |
108 | -#include "calibrator/calibratorUsbtouchscreen.cpp" | |
109 | - | |
110 | - | |
111 | 48 | /** |
112 | 49 | * find a calibratable touchscreen device (using XInput) |
113 | 50 | * |
@@ -115,7 +52,6 @@ char* my_strdup(const char* s) { | ||
115 | 52 | * retuns number of devices found, |
116 | 53 | * the data of the device is returned in the last 3 function parameters |
117 | 54 | */ |
118 | -int find_device(const char*, bool, bool, XID&, const char*&, XYinfo&); | |
119 | 55 | int find_device(const char* pre_device, bool verbose, bool list_devices, |
120 | 56 | XID& device_id, const char*& device_name, XYinfo& device_axys) |
121 | 57 | { |
@@ -243,7 +179,6 @@ static void usage(char* cmd, unsigned thr_misclick) | ||
243 | 179 | fprintf(stderr, "\t--geometry: manually provide the geometry for the calibration window\n"); |
244 | 180 | } |
245 | 181 | |
246 | -Calibrator* main_common(int argc, char** argv); | |
247 | 182 | Calibrator* main_common(int argc, char** argv) |
248 | 183 | { |
249 | 184 | bool verbose = false; |
@@ -348,7 +283,7 @@ Calibrator* main_common(int argc, char** argv) | ||
348 | 283 | if (strcmp("--fake", argv[i]) == 0) { |
349 | 284 | fake = true; |
350 | 285 | } |
351 | - | |
286 | + | |
352 | 287 | // unknown option |
353 | 288 | else { |
354 | 289 | fprintf(stderr, "Unknown option: %s\n\n", argv[i]); |
@@ -357,7 +292,7 @@ Calibrator* main_common(int argc, char** argv) | ||
357 | 292 | } |
358 | 293 | } |
359 | 294 | } |
360 | - | |
295 | + | |
361 | 296 | |
362 | 297 | // Choose the device to calibrate |
363 | 298 | XID device_id = (XID) -1; |