Allow the ESC key to interrupt the calibration process.

This commit is contained in:
matthieu
2009-11-26 10:58:45 +00:00
parent 910b2d77db
commit cff976af37

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: xtsscale.c,v 1.9 2009/11/25 23:00:57 matthieu Exp $ */ /* $OpenBSD: xtsscale.c,v 1.10 2009/11/26 10:58:45 matthieu Exp $ */
/* /*
* Copyright (c) 2007 Robert Nagy <robert@openbsd.org> * Copyright (c) 2007 Robert Nagy <robert@openbsd.org>
* Copyright (c) 2009 Matthieu Herrb <matthieu@herrb.eu> * Copyright (c) 2009 Matthieu Herrb <matthieu@herrb.eu>
@@ -97,6 +97,7 @@ XftColor cross, errorColor, promptColor, bg;
XftDraw *draw; XftDraw *draw;
unsigned int width, height; /* window size */ unsigned int width, height; /* window size */
char *progname; char *progname;
Bool interrupted = False;
int cx[5], cy[5]; int cx[5], cy[5];
int x[5], y[5]; int x[5], y[5];
@@ -107,6 +108,7 @@ Bool old_swap;
static char *prompt_message[] = { static char *prompt_message[] = {
"TOUCH SCREEN CALIBRATION", "TOUCH SCREEN CALIBRATION",
"Press on the cross hairs please...", "Press on the cross hairs please...",
"Use the ESC key to cancel.",
NULL NULL
}; };
@@ -117,11 +119,26 @@ static char *error_message[] = {
}; };
void void
cleanup_exit() cleanup_exit(XDevice *device)
{ {
long values[4];
values[0] = old_calib.minx;
values[1] = old_calib.maxx;
values[2] = old_calib.miny;
values[3] = old_calib.maxy;
XChangeDeviceProperty(display, device, prop_calibration,
XA_INTEGER, 32, PropModeReplace, (unsigned char *)values, 4);
XChangeDeviceProperty(display, device, prop_swap,
XA_INTEGER, 8, PropModeReplace, (unsigned char *)&old_swap, 1);
XCloseDevice(display, device);
XUngrabServer(display); XUngrabServer(display);
XUngrabKeyboard(display, CurrentTime); XUngrabKeyboard(display, CurrentTime);
XCloseDisplay(display); XCloseDisplay(display);
exit(1);
} }
void void
@@ -351,12 +368,13 @@ register_events(XDeviceInfo *info, XDevice *device,
return number; return number;
} }
static void static Bool
get_events(int i) get_events(int i)
{ {
XEvent Event; XEvent Event;
XDeviceMotionEvent *motion = (XDeviceMotionEvent *) &Event; XDeviceMotionEvent *motion = (XDeviceMotionEvent *) &Event;
int j, a; int j, a;
char c;
x[i] = y[i] = -1; x[i] = y[i] = -1;
while (1) { while (1) {
@@ -380,8 +398,16 @@ get_events(int i)
} else if (Event.type == button_release_type) { } else if (Event.type == button_release_type) {
if (x[i] != -1 && y[i] != -1) if (x[i] != -1 && y[i] != -1)
break; break;
} else if (Event.type == KeyPress) {
a = XLookupString(&Event.xkey, &c, 1, NULL, NULL);
if ((a == 1) && ((c == 'q') || (c == 'Q') ||
(c == '\03') || (c == '\033'))) {
interrupted++;
return False;
} }
} }
}
return True;
} }
int int
@@ -539,9 +565,12 @@ calib:
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
draw_graphics(cpx[i], cpy[i], i); draw_graphics(cpx[i], cpy[i], i);
XFlush(display); XFlush(display);
get_events(i); if (!get_events(i))
break;
XftDrawRect(draw, &bg, 0, 0, width, height); XftDrawRect(draw, &bg, 0, 0, width, height);
} }
if (interrupted)
cleanup_exit(device);
/* Check if X and Y should be swapped */ /* Check if X and Y should be swapped */
if (fabs(x[0] - x[1]) > fabs(y[0] - y[1])) { if (fabs(x[0] - x[1]) > fabs(y[0] - y[1])) {