Remove unused device and stamp from swipe_impl

This commit is contained in:
Rico Tiongson 2019-02-07 01:10:06 +08:00
parent 8d4756f7d2
commit d4f7504643

View File

@ -90,7 +90,7 @@ int main(int argc, char** args) {
} }
struct swipe_gesture { struct swipe_gesture {
string device, stamp, fingers; string fingers;
string dx, dy, udx, udy; string dx, dy, udx, udy;
xdo_t* xdo; xdo_t* xdo;
virtual void on_update() = 0; virtual void on_update() = 0;
@ -234,32 +234,26 @@ namespace service {
auto data = sentence.data(); auto data = sentence.data();
cmatch matches; cmatch matches;
if (regex_match(data, matches, gesture_begin)) { if (regex_match(data, matches, gesture_begin)) {
swipe.device = matches[1]; swipe.fingers = matches[1];
swipe.stamp = matches[2];
swipe.fingers = matches[3];
swipe.on_begin(); swipe.on_begin();
} }
else if (regex_match(data, matches, gesture_end)) { else if (regex_match(data, matches, gesture_end)) {
swipe.device = matches[1]; swipe.fingers = matches[1];
swipe.stamp = matches[2];
swipe.fingers = matches[3];
swipe.on_end(); swipe.on_end();
} }
else if (regex_match(data, matches, gesture_update)) { else if (regex_match(data, matches, gesture_update)) {
swipe.device = matches[1]; swipe.fingers = matches[1];
swipe.stamp = matches[2]; swipe.dx = matches[2];
swipe.fingers = matches[3]; swipe.dy = matches[3];
swipe.dx = matches[4]; swipe.udx = matches[4];
swipe.dy = matches[5]; swipe.udy = matches[5];
swipe.udx = matches[6];
swipe.udy = matches[7];
swipe.on_update(); swipe.on_update();
} }
} }
} }
// starts service // starts service
void start() { void start() {
int x = system("stdbuf -oL -eL libinput debug-events | " PROGRAM " buffer"); int x = system("stdbuf -oL -e0 libinput debug-events | " PROGRAM " buffer");
} }
// stops service // stops service
void stop() { void stop() {
@ -342,41 +336,43 @@ namespace util {
} }
string join(cstr delim, string arr[], int n) { string join(cstr delim, string arr[], int n) {
string ans = arr[0]; string ans = "^\\s*" + arr[0];
for (int i = 1; i < n; ++i) { for (int i = 1; i < n; ++i) {
ans += delim; ans += delim;
ans += arr[i]; ans += arr[i];
} }
ans += "\\s*$";
return ans; return ans;
} }
string build_gesture_begin() { string build_gesture_begin() {
string device = "\\s*(\\S+)\\s*"; string device = "\\S+";
string gesture = "\\s*GESTURE_SWIPE_BEGIN\\s*"; string gesture = "GESTURE_SWIPE_BEGIN";
string seconds = "\\s*(\\S+)\\s*"; string seconds = "\\S+";
string fingers = "\\s*(\\d+)\\s*"; string fingers = "(\\d+)";
string arr[] = {device, gesture, seconds, fingers}; string arr[] = {device, gesture, seconds, fingers};
return join("\\s+", arr, 4); return join("\\s+", arr, 4);
} }
string build_gesture_update() { string build_gesture_update() {
string device = "\\s*(\\S+)\\s*"; string device = "\\S+";
string gesture = "\\s*GESTURE_SWIPE_UPDATE\\s*"; string gesture = "GESTURE_SWIPE_UPDATE";
string seconds = "\\s*(\\S+)\\s*"; string seconds = "\\S+";
string fingers = "\\s*(\\d+)\\s*"; string fingers = "(\\d+)";
string num_1 = "\\s*(" + number_regex() + ")\\s*"; string num_1 = "\\s*(" + number_regex() + ")";
string num_2 = num_1; string num_2 = num_1;
string num_div = num_1 + "/" + num_2; string num_div = num_1 + "/" + num_2;
string num_accel = "\\s*\\(\\s*" + num_div + "\\s*unaccelerated\\s*\\)\\s*"; string num_accel = "\\(" + num_div + "\\s+unaccelerated\\)";
string arr[] = {device, gesture, seconds, fingers, num_div, num_accel}; string arr[] = {device, gesture, seconds, fingers, num_div, num_accel};
return join("\\s+", arr, 6); string result = join("\\s+", arr, 6);
return result;
} }
string build_gesture_end() { string build_gesture_end() {
string device = "\\s*(\\S+)\\s*"; string device = "\\S+";
string gesture = "\\s*GESTURE_SWIPE_END\\s*"; string gesture = "GESTURE_SWIPE_END";
string seconds = "\\s*(\\S+)\\s*"; string seconds = "\\S+";
string fingers = "\\s*(\\d+)\\s*"; string fingers = "(\\d+)";
string arr[] = {device, gesture, seconds, fingers}; string arr[] = {device, gesture, seconds, fingers};
return join("\\s+", arr, 4); return join("\\s+", arr, 4);
} }