• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Keine 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

Revisione5985c9e2b840df27ec5494e0480190f53748c97 (tree)
Zeit2013-04-10 04:22:26
AutorAndreas Müller <schnitzeltony@goog...>
CommiterAndreas Müller

Log Message

Handle sysfs name for --device parameter

This makes life much easier for systemd/udev hotplug invocation

Signed-off-by: Andreas Müller <schnitzeltony@googlemail.com>

Ändern Zusammenfassung

Diff

--- a/src/calibrator.cpp
+++ b/src/calibrator.cpp
@@ -31,8 +31,11 @@
3131
3232 #include "calibrator.hh"
3333
34-// static instance
34+// static instances
3535 bool Calibrator::verbose = false;
36+const char* Calibrator::SYSFS_INPUT="/sys/class/input";
37+const char* Calibrator::SYSFS_DEVNAME="device/name";
38+
3639
3740 Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0,
3841 const int thr_misclick, const int thr_doubleclick,
@@ -202,9 +205,6 @@ const char* Calibrator::get_sysfs_name()
202205 }
203206
204207 bool Calibrator::is_sysfs_name(const char* name) {
205- const char* SYSFS_INPUT="/sys/class/input";
206- const char* SYSFS_DEVNAME="device/name";
207-
208208 DIR* dp = opendir(SYSFS_INPUT);
209209 if (dp == NULL)
210210 return false;
--- a/src/calibrator.hh
+++ b/src/calibrator.hh
@@ -241,6 +241,10 @@ protected:
241241
242242 // manually specified output filename
243243 const char* output_filename;
244+
245+ // sysfs path/file
246+ static const char* SYSFS_INPUT;
247+ static const char* SYSFS_DEVNAME;
244248 };
245249
246250 // Interfance for a CalibratorTester
--- a/src/main_common.cpp
+++ b/src/main_common.cpp
@@ -29,6 +29,7 @@
2929 #include "calibrator/XorgPrint.hpp"
3030
3131 #include <cstring>
32+#include <fstream>
3233 #include <stdio.h>
3334 #include <stdlib.h>
3435 #include <stdexcept>
@@ -58,6 +59,7 @@ int Calibrator::find_device(const char* pre_device, bool list_devices,
5859 XID& device_id, const char*& device_name, XYinfo& device_axys)
5960 {
6061 bool pre_device_is_id = true;
62+ bool pre_device_is_sysfs = false;
6163 int found = 0;
6264
6365 Display* display = XOpenDisplay(NULL);
@@ -94,6 +96,25 @@ int Calibrator::find_device(const char* pre_device, bool list_devices,
9496 }
9597 }
9698
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+ }
97118
98119 if (verbose)
99120 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,
108129 // if we are looking for a specific device
109130 if (pre_device != NULL) {
110131 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)) {
112133 // OK, fall through
113134 } else {
114135 // skip, not this device
@@ -168,11 +189,11 @@ int Calibrator::find_device(const char* pre_device, bool list_devices,
168189
169190 static void usage(char* cmd, unsigned thr_misclick)
170191 {
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);
172193 fprintf(stderr, "\t-h, --help: print this help message\n");
173194 fprintf(stderr, "\t-v, --verbose: print debug messages during the process\n");
174195 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");
176197 fprintf(stderr, "\t--precalib: manually provide the current calibration setting (eg. the values in xorg.conf)\n");
177198 fprintf(stderr, "\t--misclick: set the misclick threshold (0=off, default: %i pixels)\n",
178199 thr_misclick);