Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions man/xinput_calibrator.1
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,12 @@ This is useful if the calibration values are stored in your xorg.conf, but the d
set the misclick threshold (0=off, default: 15 pixels)
.PP
.TP 8
.B \-\-no-timeout
turns off the timeout
.B \-\-no\-timeout
turns off the timeout; same as --timeout 0
.PP
.TP 8
.B \-\-timeout \fIsec\fP
sets the timeout, in seconds (0=no timeout, default: 15 sec)
.PP
.TP 8
.B \-\-output\-type \fIauto|xorg.conf.d|hal|xinput\fP
Expand Down
4 changes: 2 additions & 2 deletions src/calibrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ const char* Calibrator::SYSFS_DEVNAME="device/name";
Calibrator::Calibrator(const char* const device_name0, const XYinfo& axys0,
const int thr_misclick, const int thr_doubleclick,
const OutputType output_type0, const char* geometry0,
const bool use_timeout0, const char* output_filename0)
const int timeout0, const char* output_filename0)
: device_name(device_name0),
threshold_doubleclick(thr_doubleclick), threshold_misclick(thr_misclick),
output_type(output_type0), geometry(geometry0), use_timeout(use_timeout0),
output_type(output_type0), geometry(geometry0), timeout(timeout0),
output_filename(output_filename0)
{
old_axys = axys0;
Expand Down
8 changes: 4 additions & 4 deletions src/calibrator.hh
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public:
const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO,
const char* geometry=0,
const bool use_timeout=1,
const int timeout=0,
const char* output_filename = 0);

virtual ~Calibrator() {}
Expand Down Expand Up @@ -181,8 +181,8 @@ public:
/// returns NULL if it can not be found
const char* get_sysfs_name();

const bool get_use_timeout() const
{ return use_timeout; }
const int get_timeout() const
{ return timeout; }

/// get output filename set at cmdline or NULL
const char* get_output_filename() const
Expand Down Expand Up @@ -237,7 +237,7 @@ protected:
// manually specified geometry string
const char* geometry;

const bool use_timeout;
const int timeout;

// manually specified output filename
const char* output_filename;
Expand Down
8 changes: 4 additions & 4 deletions src/calibrator/Evdev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0,
const int thr_doubleclick,
const OutputType output_type,
const char* geometry,
const bool use_timeout,
const int timeout,
const char* output_filename)
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename)
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, timeout, output_filename)
{
// init
display = XOpenDisplay(NULL);
Expand Down Expand Up @@ -167,9 +167,9 @@ CalibratorEvdev::CalibratorEvdev(const char* const device_name0,
const int thr_doubleclick,
const OutputType output_type,
const char* geometry,
const bool use_timeout,
const int timeout,
const char* output_filename)
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, output_filename) { }
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, timeout, output_filename) { }

// Destructor
CalibratorEvdev::~CalibratorEvdev () {
Expand Down
4 changes: 2 additions & 2 deletions src/calibrator/Evdev.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CalibratorEvdev: public Calibrator
const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO,
const char* geometry=0,
const bool use_timeout=false,
const int timeout=0,
const char* output_filename = 0);

public:
Expand All @@ -58,7 +58,7 @@ class CalibratorEvdev: public Calibrator
const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO,
const char* geometry=0,
const bool use_timeout=false,
const int timeout=0,
const char* output_filename = 0);
virtual ~CalibratorEvdev();

Expand Down
4 changes: 2 additions & 2 deletions src/calibrator/Usbtouchscreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ static const char *p_flip_x = "flip_x";
static const char *p_flip_y = "flip_y";
static const char *p_swap_xy = "swap_xy";

CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const bool use_timeout, const char* output_filename)
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename)
CalibratorUsbtouchscreen::CalibratorUsbtouchscreen(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const int timeout, const char* output_filename)
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, timeout, output_filename)
{
if (strcmp(device_name, "Usbtouchscreen") != 0)
throw WrongCalibratorException("Not a usbtouchscreen device");
Expand Down
2 changes: 1 addition & 1 deletion src/calibrator/Usbtouchscreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CalibratorUsbtouchscreen: public Calibrator
CalibratorUsbtouchscreen(const char* const device_name, const XYinfo& axys,
const int thr_misclick=0, const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO, const char* geometry=0,
const bool use_timeout=false, const char* output_filename = 0);
const int timeout=0, const char* output_filename = 0);
virtual ~CalibratorUsbtouchscreen();

virtual bool finish_data(const XYinfo &new_axys);
Expand Down
4 changes: 2 additions & 2 deletions src/calibrator/XorgPrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

#include <cstdio>

CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const bool use_timeout, const char* output_filename)
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, use_timeout, output_filename)
CalibratorXorgPrint::CalibratorXorgPrint(const char* const device_name0, const XYinfo& axys0, const int thr_misclick, const int thr_doubleclick, const OutputType output_type, const char* geometry, const int timeout, const char* output_filename)
: Calibrator(device_name0, axys0, thr_misclick, thr_doubleclick, output_type, geometry, timeout, output_filename)
{
printf("Calibrating standard Xorg driver \"%s\"\n", device_name);
printf("\tcurrent calibration values: min_x=%d, max_x=%d and min_y=%d, max_y=%d\n",
Expand Down
2 changes: 1 addition & 1 deletion src/calibrator/XorgPrint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CalibratorXorgPrint: public Calibrator
CalibratorXorgPrint(const char* const device_name, const XYinfo& axys,
const int thr_misclick=0, const int thr_doubleclick=0,
const OutputType output_type=OUTYPE_AUTO, const char* geometry=0,
const bool use_timeout=false, const char* output_filename = 0);
const int timeout=0, const char* output_filename = 0);

virtual bool finish_data(const XYinfo &new_axys);

Expand Down
11 changes: 8 additions & 3 deletions src/gui/gtkmm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ CalibrationArea::CalibrationArea(Calibrator* calibrator0)
set_display_size(get_width(), get_height());

// Setup timer for animation
if(calibrator->get_use_timeout()){
if(calibrator->get_timeout() > 0){
sigc::slot<bool> slot = sigc::mem_fun(*this, &CalibrationArea::on_timer_signal);
Glib::signal_timeout().connect(slot, time_step);
}
Expand Down Expand Up @@ -136,7 +136,11 @@ bool CalibrationArea::on_expose_event(GdkEventExpose *event)
cr->arc(X[i], Y[i], cross_circle, 0.0, 2.0 * M_PI);
cr->stroke();
}
if(calibrator->get_use_timeout()){

int max_time = 15000;

if(calibrator->get_timeout() > 0) {
max_time = calibrator->get_timeout();
// Draw the clock background
cr->arc(display_width/2, display_height/2, clock_radius/2, 0.0, 2.0 * M_PI);
cr->set_source_rgb(0.5, 0.5, 0.5);
Expand Down Expand Up @@ -189,7 +193,8 @@ void CalibrationArea::redraw()

bool CalibrationArea::on_timer_signal()
{
if (calibrator->get_use_timeout()) {
if (calibrator->get_timeout() > 0) {
int max_time = calibrator->get_timeout();
time_elapsed += time_step;
if (time_elapsed > max_time) {
exit(0);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/gui_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void get_display_texts(std::list<std::string> *texts, Calibrator *calibrator)
texts->push_back(str);
/* 4th line */
str = "(To abort, press any key";
if(calibrator->get_use_timeout())
if(calibrator->get_timeout()>0)
str += " or wait)";
else
str += ")";
Expand Down
1 change: 0 additions & 1 deletion src/gui/gui_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

// Timeout parameters
const int time_step = 100; // in milliseconds
const int max_time = 15000; // in milliseconds, 5000 = 5 sec

// Clock appereance
const int cross_lines = 25;
Expand Down
7 changes: 4 additions & 3 deletions src/gui/x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void GuiCalibratorX11::redraw()
}

// Draw the clock background
if(calibrator->get_use_timeout()){
if(calibrator->get_timeout() > 0) {
XSetForeground(display, gc, pixel[DIMGRAY]);
XSetLineAttributes(display, gc, 0, LineSolid, CapRound, JoinRound);
XFillArc(display, win, gc, (display_width-clock_radius)/2, (display_height - clock_radius)/2,
Expand All @@ -284,8 +284,9 @@ void GuiCalibratorX11::on_expose_event()
void GuiCalibratorX11::on_timer_signal()
{
// Update clock
if(calibrator->get_use_timeout()) {

if(calibrator->get_timeout() > 0) {
int max_time = calibrator->get_timeout();

time_elapsed += time_step;
if (time_elapsed > max_time) {
exit(0);
Expand Down
43 changes: 29 additions & 14 deletions src/main_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include <X11/Xlib.h>
#include <X11/extensions/XInput.h>

#define DEFAULT_TIMEOUT 15

// strdup: non-ansi
static char* my_strdup(const char* s) {
size_t len = strlen(s) + 1;
Expand Down Expand Up @@ -189,7 +191,7 @@ int Calibrator::find_device(const char* pre_device, bool list_devices,

static void usage(char* cmd, unsigned thr_misclick)
{
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);
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>] [--timeout <sec> | --no-timeout]\n", cmd);
fprintf(stderr, "\t-h, --help: print this help message\n");
fprintf(stderr, "\t-v, --verbose: print debug messages during the process\n");
fprintf(stderr, "\t--list: list calibratable input devices and quit\n");
Expand All @@ -200,6 +202,7 @@ static void usage(char* cmd, unsigned thr_misclick)
fprintf(stderr, "\t--output-type <auto|xorg.conf.d|hal|xinput>: type of config to ouput (auto=automatically detect, default: auto)\n");
fprintf(stderr, "\t--fake: emulate a fake device (for testing purposes)\n");
fprintf(stderr, "\t--geometry: manually provide the geometry (width and height) for the calibration window\n");
fprintf(stderr, "\t--timeout <sec>: set timeout in seconds (0='no timeout', default: %d sec)\n", DEFAULT_TIMEOUT);
fprintf(stderr, "\t--no-timeout: turns off the timeout\n");
fprintf(stderr, "\t--output-filename: write calibration data to file (USB: override default /etc/modprobe.conf.local\n");
}
Expand All @@ -209,7 +212,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
bool list_devices = false;
bool fake = false;
bool precalib = false;
bool use_timeout = true;
int timeout = DEFAULT_TIMEOUT * 1000;
XYinfo pre_axys;
const char* pre_device = NULL;
const char* geometry = NULL;
Expand Down Expand Up @@ -309,15 +312,25 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
fake = true;
} else

// Disable timeout
if (strcmp("--no-timeout", argv[i]) == 0) {
use_timeout = false;
} else

// Output file
if (strcmp("--output-filename", argv[i]) == 0) {
output_filename = argv[++i];
}
// Set timeout
if (strcmp("--no-timeout", argv[i]) == 0) {
timeout = 0;
} else

if (strcmp("--timeout", argv[i]) == 0) {
if (argc > i+1)
timeout = atoi (argv[++i]) * 1000;
else {
fprintf(stderr, "Error: --timeout needs a number (seconds) as argument. Set to 0 to disable timeout.\n\n");
usage(argv[0], thr_misclick);
exit(1);
}
} else

// Output file
if (strcmp("--output-filename", argv[i]) == 0) {
output_filename = argv[++i];
}

// unknown option
else {
Expand All @@ -328,6 +341,8 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
}
}

if (verbose)
printf("DEBUG: Timeout: %d ms\n", timeout);

/// Choose the device to calibrate
XID device_id = (XID) -1;
Expand Down Expand Up @@ -392,7 +407,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
// try Usbtouchscreen driver
return new CalibratorUsbtouchscreen(device_name, device_axys,
thr_misclick, thr_doubleclick, output_type, geometry,
use_timeout, output_filename);
timeout, output_filename);

} catch(WrongCalibratorException& x) {
if (verbose)
Expand All @@ -403,7 +418,7 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
// next, try Evdev driver (with XID)
return new CalibratorEvdev(device_name, device_axys, device_id,
thr_misclick, thr_doubleclick, output_type, geometry,
use_timeout, output_filename);
timeout, output_filename);

} catch(WrongCalibratorException& x) {
if (verbose)
Expand All @@ -413,5 +428,5 @@ Calibrator* Calibrator::make_calibrator(int argc, char** argv)
// lastly, presume a standard Xorg driver (evtouch, mutouch, ...)
return new CalibratorXorgPrint(device_name, device_axys,
thr_misclick, thr_doubleclick, output_type, geometry,
use_timeout, output_filename);
timeout, output_filename);
}