summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gestures.c50
1 files changed, 32 insertions, 18 deletions
diff --git a/src/gestures.c b/src/gestures.c
index ebf103f..f26aba8 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -21,18 +21,13 @@
21 21
22#include "gestures.h" 22#include "gestures.h"
23 23
24/******************************************************/ 24static void extract_movement(struct Gestures *gs, struct MTouch* mt)
25
26void extract_gestures(struct Gestures *gs, struct MTouch* mt)
27{ 25{
28 const struct FingerState *b = mt->state.finger; 26 const struct FingerState *b = mt->state.finger;
29 const struct FingerState *e = b + mt->state.nfinger; 27 const struct FingerState *e = b + mt->state.nfinger;
30 const struct FingerState *p, *fs; 28 const struct FingerState *p, *fs;
31 int nof = mt->prev_state.nfinger;
32 int nsf = mt->state.nfinger;
33 int dn = 0, i; 29 int dn = 0, i;
34 memset(gs, 0, sizeof(struct Gestures)); 30 if (mt->state.nfinger == mt->prev_state.nfinger) {
35 if (nof == nsf) {
36 for (p = b; p != e; p++) { 31 for (p = b; p != e; p++) {
37 fs = find_finger(&mt->prev_state, p->id); 32 fs = find_finger(&mt->prev_state, p->id);
38 if (fs) { 33 if (fs) {
@@ -42,25 +37,44 @@ void extract_gestures(struct Gestures *gs, struct MTouch* mt)
42 } 37 }
43 } 38 }
44 } 39 }
45 if (gs->dx || gs->dy) { 40 if (dn) {
46 gs->dx /= dn; 41 gs->dx /= dn;
47 gs->dy /= dn; 42 gs->dy /= dn;
48 if (nsf == 1)
49 SETBIT(gs->type, GS_MOVE);
50 if (nsf == 2)
51 SETBIT(gs->type, GS_VSCROLL);
52 if (nsf == 3)
53 SETBIT(gs->type, GS_HSCROLL);
54 } 43 }
44}
45
46static void extract_buttons(struct Gestures *gs, struct MTouch* mt)
47{
55 if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) { 48 if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) {
56 if (nsf == 2) 49 if (mt->state.nfinger == 2)
57 mt->state.button = BITMASK(MT_BUTTON_RIGHT); 50 mt->state.button = BITMASK(MT_BUTTON_RIGHT);
58 if (nsf == 3) 51 if (mt->state.nfinger == 3)
59 mt->state.button = BITMASK(MT_BUTTON_MIDDLE); 52 mt->state.button = BITMASK(MT_BUTTON_MIDDLE);
60 } 53 }
61 gs->btmask = (mt->state.button ^ mt->prev_state.button) & 54 gs->btmask = (mt->state.button ^ mt->prev_state.button) & BITONES(DIM_BUTTON);
62 BITONES(DIM_BUTTON);
63 gs->btdata = mt->state.button & BITONES(DIM_BUTTON); 55 gs->btdata = mt->state.button & BITONES(DIM_BUTTON);
56}
57
58static void extract_type(struct Gestures *gs, struct MTouch* mt)
59{
60 if (gs->dx || gs->dy) {
61 if (mt->state.nfinger == 1)
62 SETBIT(gs->type, GS_MOVE);
63 if (mt->state.nfinger == 2)
64 SETBIT(gs->type, GS_VSCROLL);
65 if (mt->state.nfinger == 3)
66 SETBIT(gs->type, GS_HSCROLL);
67 }
68}
69
70/******************************************************/
71
72void extract_gestures(struct Gestures *gs, struct MTouch* mt)
73{
74 memset(gs, 0, sizeof(struct Gestures));
75 extract_movement(gs, mt);
76 extract_buttons(gs, mt);
77 extract_type(gs, mt);
64 mt->prev_state = mt->state; 78 mt->prev_state = mt->state;
65} 79}
66 80