A generic touchscreen calibration program for X.Org
Revision | c8ba2708cd465c2b45e9a800ca739213e4677a79 (tree) |
---|---|
Time | 2013-04-10 20:41:11 |
Author | Tias Guns <tias@ulys...> |
Commiter | Tias Guns |
Merge pull request #50 from schnitzeltony/sysfs-event-param
Handle sysfs name for --device parameter
@@ -31,8 +31,11 @@ | ||
31 | 31 | |
32 | 32 | #include "calibrator.hh" |
33 | 33 | |
34 | -// static instance | |
34 | +// static instances | |
35 | 35 | bool Calibrator::verbose = false; |
36 | +const char* Calibrator::SYSFS_INPUT="/sys/class/input"; | |
37 | +const char* Calibrator::SYSFS_DEVNAME="device/name"; | |
38 | + | |
36 | 39 | |
37 | 40 | Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0, |
38 | 41 | const int thr_misclick, const int thr_doubleclick, |
@@ -202,9 +205,6 @@ const char* Calibrator::get_sysfs_name() | ||
202 | 205 | } |
203 | 206 | |
204 | 207 | bool Calibrator::is_sysfs_name(const char* name) { |
205 | - const char* SYSFS_INPUT="/sys/class/input"; | |
206 | - const char* SYSFS_DEVNAME="device/name"; | |
207 | - | |
208 | 208 | DIR* dp = opendir(SYSFS_INPUT); |
209 | 209 | if (dp == NULL) |
210 | 210 | return false; |
@@ -241,6 +241,10 @@ protected: | ||
241 | 241 | |
242 | 242 | // manually specified output filename |
243 | 243 | const char* output_filename; |
244 | + | |
245 | + // sysfs path/file | |
246 | + static const char* SYSFS_INPUT; | |
247 | + static const char* SYSFS_DEVNAME; | |
244 | 248 | }; |
245 | 249 | |
246 | 250 | // Interfance for a CalibratorTester |
@@ -29,6 +29,7 @@ | ||
29 | 29 | #include "calibrator/XorgPrint.hpp" |
30 | 30 | |
31 | 31 | #include <cstring> |
32 | +#include <fstream> | |
32 | 33 | #include <stdio.h> |
33 | 34 | #include <stdlib.h> |
34 | 35 | #include <stdexcept> |
@@ -58,6 +59,7 @@ int Calibrator::find_device(const char* pre_device, bool list_devices, | ||
58 | 59 | XID& device_id, const char*& device_name, XYinfo& device_axys) |
59 | 60 | { |
60 | 61 | bool pre_device_is_id = true; |
62 | + bool pre_device_is_sysfs = false; | |
61 | 63 | int found = 0; |
62 | 64 | |
63 | 65 | Display* display = XOpenDisplay(NULL); |
@@ -94,6 +96,25 @@ int Calibrator::find_device(const char* pre_device, bool list_devices, | ||
94 | 96 | } |
95 | 97 | } |
96 | 98 | |
99 | + std::string pre_device_sysfs; | |
100 | + if (pre_device != NULL && !pre_device_is_id) { | |
101 | + /* avoid overflow below - 10000 devices should be OK */ | |
102 | + if ( strlen(pre_device) < strlen("event") + 4 && | |
103 | + strncmp(pre_device, "event", strlen("event")) == 0 ) { | |
104 | + // check whether the pre_device is an sysfs-path name | |
105 | + char filename[40]; // actually 35, but hey... | |
106 | + (void) sprintf(filename, "%s/%s/%s", SYSFS_INPUT, pre_device, SYSFS_DEVNAME); | |
107 | + | |
108 | + std::ifstream ifile(filename); | |
109 | + if (ifile.is_open()) { | |
110 | + if (!ifile.eof()) { | |
111 | + pre_device_is_sysfs = true; | |
112 | + std::getline(ifile, pre_device_sysfs); | |
113 | + ifile.close(); | |
114 | + } | |
115 | + } | |
116 | + } | |
117 | + } | |
97 | 118 | |
98 | 119 | if (verbose) |
99 | 120 | printf("DEBUG: Skipping virtual master devices and devices without axis valuators.\n"); |
@@ -108,7 +129,7 @@ int Calibrator::find_device(const char* pre_device, bool list_devices, | ||
108 | 129 | // if we are looking for a specific device |
109 | 130 | if (pre_device != NULL) { |
110 | 131 | if ((pre_device_is_id && list->id == (XID) atoi(pre_device)) || |
111 | - (!pre_device_is_id && strcmp(list->name, pre_device) == 0)) { | |
132 | + (!pre_device_is_id && strcmp(list->name, pre_device_is_sysfs ? pre_device_sysfs.c_str() : pre_device ) == 0)) { | |
112 | 133 | // OK, fall through |
113 | 134 | } else { |
114 | 135 | // skip, not this device |
@@ -168,11 +189,11 @@ int Calibrator::find_device(const char* pre_device, bool list_devices, | ||
168 | 189 | |
169 | 190 | static void usage(char* cmd, unsigned thr_misclick) |
170 | 191 | { |
171 | - fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device <device name or id>] [--precalib <minx> <maxx> <miny> <maxy>] [--misclick <nr of pixels>] [--output-type <auto|xorg.conf.d|hal|xinput>] [--fake] [--geometry <w>x<h>] [--no-timeout]\n", cmd); | |
192 | + fprintf(stderr, "Usage: %s [-h|--help] [-v|--verbose] [--list] [--device <device name or XID or sysfs path>] [--precalib <minx> <maxx> <miny> <maxy>] [--misclick <nr of pixels>] [--output-type <auto|xorg.conf.d|hal|xinput>] [--fake] [--geometry <w>x<h>] [--no-timeout]\n", cmd); | |
172 | 193 | fprintf(stderr, "\t-h, --help: print this help message\n"); |
173 | 194 | fprintf(stderr, "\t-v, --verbose: print debug messages during the process\n"); |
174 | 195 | fprintf(stderr, "\t--list: list calibratable input devices and quit\n"); |
175 | - fprintf(stderr, "\t--device <device name or id>: select a specific device to calibrate\n"); | |
196 | + fprintf(stderr, "\t--device <device name or XID or sysfs event name (e.g event5)>: select a specific device to calibrate\n"); | |
176 | 197 | fprintf(stderr, "\t--precalib: manually provide the current calibration setting (eg. the values in xorg.conf)\n"); |
177 | 198 | fprintf(stderr, "\t--misclick: set the misclick threshold (0=off, default: %i pixels)\n", |
178 | 199 | thr_misclick); |