A generic touchscreen calibration program for X.Org
Revision | efb8aa384d54ae9145787f2308fc18e8c3e40d06 (tree) |
---|---|
Zeit | 2012-03-09 08:51:57 |
Autor | 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> |
@@ -348,7 +349,7 @@ Calibrator* main_common(int argc, char** argv) | ||
348 | 349 | if (strcmp("--fake", argv[i]) == 0) { |
349 | 350 | fake = true; |
350 | 351 | } |
351 | - | |
352 | + | |
352 | 353 | // unknown option |
353 | 354 | else { |
354 | 355 | fprintf(stderr, "Unknown option: %s\n\n", argv[i]); |
@@ -357,7 +358,7 @@ Calibrator* main_common(int argc, char** argv) | ||
357 | 358 | } |
358 | 359 | } |
359 | 360 | } |
360 | - | |
361 | + | |
361 | 362 | |
362 | 363 | // Choose the device to calibrate |
363 | 364 | XID device_id = (XID) -1; |