aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2008-11-07 00:57:33 +0100
committerHenrik Rydberg <rydberg@euromail.se>2008-11-07 00:57:33 +0100
commit8331c4858987bce53afac9c06ab45808fd751dbd (patch)
treed7ae3bb72ebfb4dd1f16eb29fd66f201b41dd84b
parentd44b4794c679141a08fd802475bb542ecf5b7c51 (diff)
downloadxorg-input-kobomultitouch-8331c4858987bce53afac9c06ab45808fd751dbd.tar.gz
xorg-input-kobomultitouch-8331c4858987bce53afac9c06ab45808fd751dbd.tar.bz2
xorg-input-kobomultitouch-8331c4858987bce53afac9c06ab45808fd751dbd.zip
Works nicely - state output seems reasonable
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--src/multitouch.c2
-rw-r--r--src/state.c83
-rw-r--r--src/state.h5
3 files changed, 55 insertions, 35 deletions
diff --git a/src/multitouch.c b/src/multitouch.c
index 21f3e1e..c18f3d3 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -81,7 +81,7 @@ static void read_input(LocalDevicePtr local)
struct MTouch *mt = local->private;
if (local->fd >= 0) {
while (read_synchronized_event(mt, local->fd)) {
- modify_state(&mt->ns, &mt->hw);
+ modify_state(&mt->ns, &mt->hw, &mt->caps);
output_state(&mt->ns);
mt->os = mt->ns;
}
diff --git a/src/state.c b/src/state.c
index fc3580d..eff9c3e 100644
--- a/src/state.c
+++ b/src/state.c
@@ -10,9 +10,9 @@ void init_state(struct State *s)
/******************************************************/
-inline int fincomp(const struct FingerState* a,const struct FingerState* b)
+static int fincmp(const void* a,const void* b)
{
- return a->id - b->id;
+ return ((struct FingerState *)a)->id - ((struct FingerState *)b)->id;
}
inline float dist2(const struct FingerData* a,const struct FingerData* b)
@@ -23,10 +23,33 @@ inline float dist2(const struct FingerData* a,const struct FingerData* b)
return dx * dx + dy * dy;
}
-void modify_state(struct State *s, const struct HWData* hw)
+static void set_finger(struct FingerState* fs,
+ const struct FingerData* hw, int id,
+ const struct Capabilities* caps)
+{
+ fs->hw = *hw;
+ fs->id = id;
+ if (!caps->has_touch_minor)
+ fs->hw.touch_minor = hw->touch_major;
+ if (!caps->has_width_minor)
+ fs->hw.width_minor = hw->width_major;
+}
+
+inline bool good_finger(const struct FingerState* fs)
+{
+ return fs->hw.touch_major > 0 && fs->hw.width_major > 0 &&
+ fs->hw.touch_minor > 0 && fs->hw.width_minor > 0;
+}
+
+/******************************************************/
+
+void modify_state(struct State *s,
+ const struct HWData* hw,
+ const struct Capabilities* caps)
{
float A[DIM2_FINGER], *row;
int id[DIM_FINGER], index[DIM_FINGER], i, j;
+ struct FingerState *fs = s->finger;
for (j = 0; j < s->nfinger; j++) {
id[j] = s->finger[j].id;
@@ -37,29 +60,20 @@ void modify_state(struct State *s, const struct HWData* 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 */
+ /* update matched fingers and create new ones */
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++;
- }
+ j = index[i];
+ if (j >= 0)
+ set_finger(fs, hw->finger + i, id[j], caps);
+ else
+ set_finger(fs, hw->finger + i, ++s->lastid, caps);
+ if (good_finger(fs))
+ fs++;
}
+ s->nfinger = fs - s->finger;
/* sort fingers in touching order */
- qsort(s->finger, s->nfinger, sizeof(struct FingerState),
- (int (*)(const void*,const void*))fincomp);
+ qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp);
/* copy buttons */
for (i = 0; i < DIM_BUTTON; i++)
@@ -84,18 +98,21 @@ 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);
+ xf86Msg(X_INFO, "buttons: %d%d%d\n",
+ s->button[0], s->button[1], s->button[2]);
+ xf86Msg(X_INFO, "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);
+ xf86Msg(X_INFO,
+ " %+02d %+05d:%+05d +%05d:%+05d %+06d %+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 8b41920..7bf4438 100644
--- a/src/state.h
+++ b/src/state.h
@@ -1,6 +1,7 @@
#ifndef MTEVENT_H
#define MTEVENT_H
+#include "capabilities.h"
#include "hwdata.h"
////////////////////////////////////////////////////////
@@ -21,7 +22,9 @@ struct State {
////////////////////////////////////////////////////////
void init_state(struct State *s);
-void modify_state(struct State *s, const struct HWData* hw);
+void modify_state(struct State *s,
+ const struct HWData* hw,
+ const struct Capabilities* caps);
void output_state(const struct State *s);
const struct FingerState *find_finger(const struct State *s, int id);