diff options
-rw-r--r-- | inputdev.cc | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/inputdev.cc b/inputdev.cc index addf8ce..c607cf1 100644 --- a/inputdev.cc +++ b/inputdev.cc @@ -123,6 +123,7 @@ bool MagicState::process(struct input_event const &ev) }; unsigned int code; + struct timespec now; assert(state_ < ARRAY_SIZE(SEQUENCE)); @@ -139,22 +140,18 @@ bool MagicState::process(struct input_event const &ev) default: code = ev.code; } - if (state_ > 0) { - struct timespec now; - - clock_gettime(CLOCK_MONOTONIC, &now); - if (compare(next_, now) < 0) - // reset state due to timeout - state_ = 0; + clock_gettime(CLOCK_MONOTONIC, &now); + if (state_ > 0 && compare(next_, now) < 0) + // reset state due to timeout + state_ = 0; + if (SEQUENCE[state_] != code) { + state_ = 0; + } else { + ++state_; add(next_, now, TIMEOUT); } - if (SEQUENCE[state_] == code) - ++state_; - else - state_ = 0; - if (state_ == ARRAY_SIZE(SEQUENCE)) { state_ = 0; return true; |