Add default true persist option to display positions with persistence
Setting --persist=0 will cause only the current detected contact positions
to be plotted. This behavior can be toggled at run time by pressing the
'p' key.
BUG=chromium-os:29063
TEST=mtplot --persist=1 # shows persistent dots
TEST=mtplot --persist=0 # does not show persistent dots
Change-Id: I1d70dd89e8880423a26fae4534c01ec7a0658d1e
diff --git a/mtplot.c b/mtplot.c
index b89291f..d6c5174 100644
--- a/mtplot.c
+++ b/mtplot.c
@@ -431,6 +431,7 @@
// Program Options
bool monotonic = true;
+bool persist = true;
static Display *dpy;
static unsigned long blackColor;
@@ -555,6 +556,8 @@
static void MtStatePaint(struct mt_state *s) {
int i;
+ if (!persist)
+ XClearWindow(dpy, w);
for (i = slot_min; i <= slot_max; i++)
MtSlotPaint(&s->slot[i - slot_min]);
XFlush(dpy);
@@ -825,18 +828,22 @@
static const struct option long_options[] = {
{ "display", required_argument, NULL, 'd' },
{ "monotonic", optional_argument, NULL, 'm' },
+ { "persist", optional_argument, NULL, 'p' },
{ 0, },
};
// Print usage information.
static int Usage(void) {
printf("USAGE:\n");
- printf(" %s /dev/input/eventX [--display DISPLAY] [--monotonic]\n",
+ printf(" %s /dev/input/eventX [--display DISPLAY] [--monotonic] [--persist]\n",
program_invocation_short_name);
printf("\n");
printf(" -m, --monotonic[=0|1] =1: requests input events with monotonic timestamps\n"
" if supported by the kernel (default)\n"
" =0: request input events with wallclock timestamps\n");
+ printf(" -p, --persist[=0|1] =1: display persistent trails for each contact (default)\n"
+ " =0: only display the current contact positions\n"
+ " To toggle at runtime press 'p'\n");
return EXIT_FAILURE;
}
@@ -852,7 +859,7 @@
fd_set rdfs;
while (1) {
- int c = getopt_long_only(argc, argv, "d:m:", long_options, NULL);
+ int c = getopt_long_only(argc, argv, "d:m:p:", long_options, NULL);
if (c == -1)
break;
switch (c) {
@@ -862,6 +869,9 @@
case 'm':
monotonic = (optarg) ? atoi(optarg) : true;
break;
+ case 'p':
+ persist = (optarg) ? atoi(optarg) : true;
+ break;
default: // Fall through case
printf("Unknown option '%c'\n", c);
case '?':
@@ -996,6 +1006,8 @@
KeySym ks = XLookupKeysym(&xke, 0);
if (ks == XK_Escape)
XClearWindow(dpy, w);
+ else if (ks == XK_p)
+ persist = !persist;
}
}
}