From 0587ab0488c46b61d175793f2deedc3a7aa9b600 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sun, 21 Mar 2010 14:54:15 +0100 Subject: Add millisecond event times Expand the (x, y) notion of the current hardware events to the more useful (x, y, t) notion. This patch was inspired by a gesture patch from Arturo Castro . Signed-off-by: Henrik Rydberg --- src/hwdata.c | 9 +++++++++ src/hwdata.h | 4 ++++ src/state.c | 3 +++ src/state.h | 1 + 4 files changed, 17 insertions(+) diff --git a/src/hwdata.c b/src/hwdata.c index e76bcd8..f204884 100644 --- a/src/hwdata.c +++ b/src/hwdata.c @@ -26,6 +26,14 @@ void init_hwdata(struct HWData *hw) memset(hw, 0, sizeof(struct HWData)); } +static mstime_t get_mstime() +{ + static const mstime_t ms = 1000; + struct timeval now; + gettimeofday(&now, NULL); + return now.tv_usec / ms + now.tv_sec * ms; +} + static void set_value(struct HWData *hw, int code, int value) { if (hw->nread < DIM_FINGER) { @@ -50,6 +58,7 @@ static void accept_packet(struct HWData *hw) { hw->nread = 0; hw->mread[hw->nread] = 0; + hw->evtime = get_mstime(); } int read_hwdata(struct HWData *hw, const struct input_event* ev) diff --git a/src/hwdata.h b/src/hwdata.h index aa589e0..c00fb39 100644 --- a/src/hwdata.h +++ b/src/hwdata.h @@ -51,6 +51,9 @@ struct FingerData { int position_x, position_y; }; +/* year-proof millisecond event time */ +typedef __u64 mstime_t; + /** * struct HWData - hardware reads * @@ -67,6 +70,7 @@ struct HWData { unsigned mask[DIM_FINGER], mread[DIM_FINGER]; unsigned button; int nfinger, nread; + mstime_t evtime; }; void init_hwdata(struct HWData *hw); diff --git a/src/state.c b/src/state.c index 31eca70..182a508 100644 --- a/src/state.c +++ b/src/state.c @@ -105,6 +105,7 @@ void modify_state(struct State *s, s->button = hw->button; s->nfinger = hw->nfinger; + s->evtime = hw->evtime; /* sort fingers in touching order */ qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp); @@ -141,6 +142,8 @@ void output_state(const struct State *s) GETBIT(s->button, MT_BUTTON_RIGHT)); xf86Msg(X_INFO, "fingers: %d\n", s->nfinger); + xf86Msg(X_INFO, "evtime: %lld\n", + s->evtime); for (i = 0; i < s->nfinger; i++) { xf86Msg(X_INFO, " %+02d %+05d:%+05d +%05d:%+05d " diff --git a/src/state.h b/src/state.h index 340803a..2c2d2b7 100644 --- a/src/state.h +++ b/src/state.h @@ -35,6 +35,7 @@ struct State { struct FingerState finger[DIM_FINGER]; unsigned button; int nfinger; + mstime_t evtime; int lastid; }; -- cgit v1.2.3