From 5df590f1721f29a9d8c356b79b8a84af006dae07 Mon Sep 17 00:00:00 2001 From: Rico Tiongson Date: Thu, 7 Feb 2019 03:39:27 +0800 Subject: [PATCH] Add a flag for gesture begin to ignore unneeded update/end --- src/comfortable-swipe.cpp | 49 +++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/comfortable-swipe.cpp b/src/comfortable-swipe.cpp index f665ba8..25afc4b 100644 --- a/src/comfortable-swipe.cpp +++ b/src/comfortable-swipe.cpp @@ -231,31 +231,36 @@ namespace service { ); // start reading lines from input one by one static string sentence; + bool flag_begin = false; while (getline(cin, sentence)) { auto data = sentence.data(); cmatch matches; - if (regex_match(data, matches, gesture_begin)) { - swipe.device = matches[1]; - swipe.stamp = matches[2]; - swipe.fingers = matches[3]; - swipe.on_begin(); - } - else if (regex_match(data, matches, gesture_end)) { - swipe.device = matches[1]; - swipe.stamp = matches[2]; - swipe.fingers = matches[3]; - swipe.on_end(); - } - else if (regex_match(data, matches, gesture_update)) { - swipe.device = matches[1]; - swipe.stamp = matches[2]; - swipe.fingers = matches[3]; - swipe.dx = matches[4]; - swipe.dy = matches[5]; - swipe.udx = matches[6]; - swipe.udy = matches[7]; - swipe.on_update(); - } + if (!flag_begin) { + if (regex_match(data, matches, gesture_begin)) { + swipe.device = matches[1]; + swipe.stamp = matches[2]; + swipe.fingers = matches[3]; + swipe.on_begin(); + flag_begin = true; + } + } else { + if (regex_match(data, matches, gesture_update)) { + swipe.device = matches[1]; + swipe.stamp = matches[2]; + swipe.fingers = matches[3]; + swipe.dx = matches[4]; + swipe.dy = matches[5]; + swipe.udx = matches[6]; + swipe.udy = matches[7]; + swipe.on_update(); + } else if (regex_match(data, matches, gesture_end)) { + swipe.device = matches[1]; + swipe.stamp = matches[2]; + swipe.fingers = matches[3]; + swipe.on_end(); + flag_begin = false; + } + } } } // starts service