summaryrefslogtreecommitdiff
path: root/src/gestures.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gestures.c')
-rw-r--r--src/gestures.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/gestures.c b/src/gestures.c
new file mode 100644
index 0000000..8dfb939
--- /dev/null
+++ b/src/gestures.c
@@ -0,0 +1,39 @@
1#include "gestures.h"
2
3/******************************************************/
4
5void extract_gestures(struct Gestures *gs, struct MTouch* mt)
6{
7 const struct FingerState *b = mt->ns.finger;
8 const struct FingerState *e = b + mt->ns.nfinger;
9 const struct FingerState *p, *fs;
10 int nof = count_fingers(&mt->os);
11 int nsf = count_fingers(&mt->ns);
12 int dn = 0, i;
13 memset(gs, 0, sizeof(struct Gestures));
14 if (nof == nsf) {
15 for (p = b; p != e; p++) {
16 if (fs = find_finger(&mt->os, p->id)) {
17 gs->dx += p->hw.position_x - fs->hw.position_x;
18 gs->dy += p->hw.position_y - fs->hw.position_y;
19 dn++;
20 }
21 }
22 }
23 if (gs->dx || gs->dy) {
24 gs->dx /= dn;
25 gs->dy /= dn;
26 if (nsf == 1)
27 SETBIT(gs->type, GS_MOVE);
28 }
29 for (i = 0; i < DIM_BUTTON; i++) {
30 if (GETBIT(mt->ns.button, i) != GETBIT(mt->os.button, i)) {
31 SETBIT(gs->type, GS_BUTTON);
32 gs->btix[gs->nbt] = i + 1;
33 gs->btval[gs->nbt] = GETBIT(mt->ns.button, i);
34 gs->nbt++;
35 }
36 }
37 mt->os = mt->ns;
38}
39