diff options
author | Henrik Rydberg <rydberg@euromail.se> | 2008-11-06 23:01:41 +0100 |
---|---|---|
committer | Henrik Rydberg <rydberg@euromail.se> | 2008-11-06 23:01:41 +0100 |
commit | d44b4794c679141a08fd802475bb542ecf5b7c51 (patch) | |
tree | 74251970cfbcc58d0252366be6e5e668149b8a48 /src | |
parent | 63de72d8d810e3692c96c7385b497bb4d68ef54a (diff) | |
download | xorg-input-kobomultitouch-d44b4794c679141a08fd802475bb542ecf5b7c51.tar.gz xorg-input-kobomultitouch-d44b4794c679141a08fd802475bb542ecf5b7c51.tar.bz2 xorg-input-kobomultitouch-d44b4794c679141a08fd802475bb542ecf5b7c51.zip |
ok, fast (but not fastest) matcher in place, no check output...
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
-rw-r--r-- | src/common.h | 3 | ||||
-rw-r--r-- | src/hwdata.h | 1 | ||||
-rw-r--r-- | src/multitouch.c | 2 | ||||
-rw-r--r-- | src/state.c | 72 | ||||
-rw-r--r-- | src/state.h | 3 |
5 files changed, 72 insertions, 9 deletions
diff --git a/src/common.h b/src/common.h index 5a83f95..c57ae1a 100644 --- a/src/common.h +++ b/src/common.h @@ -7,6 +7,7 @@ #include <xf86Xinput.h> #include <linux/input.h> #include <errno.h> +#include <match/match.h> //#include <exevents.h> //////////////////////////////////////////////////////// @@ -27,8 +28,6 @@ #define ABS_MT_POSITION_X 0x35 #define ABS_MT_POSITION_Y 0x36 -typedef int bool; - #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) //////////////////////////////////////////////////////// diff --git a/src/hwdata.h b/src/hwdata.h index 239e022..59cff0d 100644 --- a/src/hwdata.h +++ b/src/hwdata.h @@ -3,7 +3,6 @@ #include "common.h" -#define DIM_FINGER 16 #define DIM_BUTTON 3 #define MT_BUTTON_LEFT 0 diff --git a/src/multitouch.c b/src/multitouch.c index f6e3d05..21f3e1e 100644 --- a/src/multitouch.c +++ b/src/multitouch.c @@ -82,7 +82,7 @@ static void read_input(LocalDevicePtr local) if (local->fd >= 0) { while (read_synchronized_event(mt, local->fd)) { modify_state(&mt->ns, &mt->hw); - // and something in between here + output_state(&mt->ns); mt->os = mt->ns; } } diff --git a/src/state.c b/src/state.c index 46b7fef..fc3580d 100644 --- a/src/state.c +++ b/src/state.c @@ -1,4 +1,5 @@ #include "state.h" +#include <stdlib.h> /******************************************************/ @@ -9,11 +10,58 @@ void init_state(struct State *s) /******************************************************/ +inline int fincomp(const struct FingerState* a,const struct FingerState* b) +{ + return a->id - b->id; +} + +inline float dist2(const struct FingerData* a,const struct FingerData* b) +{ + float dx = a->position_x - b->position_x; + float dy = a->position_y - b->position_y; + + return dx * dx + dy * dy; +} + void modify_state(struct State *s, const struct HWData* hw) { - int i; - if (s->button[0] != hw->button[0]) - xf86Msg(X_INFO, "multitouch: button changed\n"); + float A[DIM2_FINGER], *row; + int id[DIM_FINGER], index[DIM_FINGER], i, j; + + for (j = 0; j < s->nfinger; j++) { + id[j] = s->finger[j].id; + row = A + hw->nfinger * j; + for (i = 0; i < hw->nfinger; i++) + row[i] = dist2(&hw->finger[i], &s->finger[j].hw); + } + + match_fingers(index, A, hw->nfinger, s->nfinger); + + s->nfinger = 0; + + /* update matched fingers */ + for (i = 0; i < hw->nfinger; i++) { + if ((j = index[i]) >= 0) { + s->finger[s->nfinger].id = id[j]; + s->finger[s->nfinger].hw = hw->finger[i]; + s->nfinger++; + } + } + + /* create new fingers */ + for (i = 0; i < hw->nfinger; i++) { + if (index[i] < 0) { + s->finger[s->nfinger].id = ++s->lastid; + s->finger[s->nfinger].hw = hw->finger[i]; + s->nfinger++; + } + } + + /* sort fingers in touching order */ + qsort(s->finger, s->nfinger, sizeof(struct FingerState), + (int (*)(const void*,const void*))fincomp); + + /* copy buttons */ for (i = 0; i < DIM_BUTTON; i++) s->button[i] = hw->button[i]; } @@ -23,9 +71,11 @@ void modify_state(struct State *s, const struct HWData* hw) const struct FingerState *find_finger(const struct State *s, int id) { int i; + for (i = 0; i < s->nfinger; i++) if (s->finger[i].id == id) - return s->finger+i; + return s->finger + i; + return NULL; } @@ -33,6 +83,20 @@ const struct FingerState *find_finger(const struct State *s, int id) void output_state(const struct State *s) { + int i; + printf("buttons: %d%d%d\n", s->button[0], s->button[1], s->button[2]); + printf("fingers: %d\n", s->nfinger); + for (i = 0; i < s->nfinger; i++) { + printf(" %+02d %+05d:%+05d +%05d:%+05d %+05d %+05d:%+05d\n", + s->finger[i].id, + s->finger[i].hw.touch_major, + s->finger[i].hw.touch_minor, + s->finger[i].hw.width_major, + s->finger[i].hw.width_minor, + s->finger[i].hw.orientation, + s->finger[i].hw.position_x, + s->finger[i].hw.position_y); + } } /******************************************************/ diff --git a/src/state.h b/src/state.h index 9c36617..8b41920 100644 --- a/src/state.h +++ b/src/state.h @@ -14,7 +14,8 @@ struct FingerState { struct State { struct FingerState finger[DIM_FINGER]; - int nfinger, button[DIM_BUTTON]; + int button[DIM_BUTTON]; + int nfinger, lastid; }; //////////////////////////////////////////////////////// |