summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArturo Castro <arturo@openframeworks.cc>2010-04-14 15:34:46 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-04-15 06:10:08 +0200
commit428a29ac5dc8ebf6a1092c2d989fa020d79791af (patch)
treec21c7ca701327d555a89daccf467253b64cc14cb /src
parent80ccdaa7441ab9d729b7736d6a784632e216ba74 (diff)
Extract pointing fingers
Multi-finger clicks and taps are goverened by the number of pointing fingers on the trackpad. This number can be different from the actual number of fingers on the trackpad. For instance, a finger resting at the bottom of an integrated button, or a finger that accidentally touches the pad during a press, are not pointing fingers. This patch introduces extract_pointers(), which computes the number of pointing fingers on the trackpad, and uses that number to determine the logical button state. [rydberg@euromail.se: various cleanups] Signed-off-by: Arturo Castro <arturo@openframeworks.cc> Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
-rw-r--r--src/gestures.c44
-rw-r--r--src/memory.h3
2 files changed, 44 insertions, 3 deletions
diff --git a/src/gestures.c b/src/gestures.c
index d075356..915a521 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -29,6 +29,45 @@
29static const int FINGER_ATTACK_MS = 70; 29static const int FINGER_ATTACK_MS = 70;
30static const int FINGER_DECAY_MS = 120; 30static const int FINGER_DECAY_MS = 120;
31 31
32static void extract_pointers(struct Gestures *gs, struct MTouch* mt)
33{
34 const struct FingerState *f = mt->state.finger;
35 int i;
36
37 if (mt->state.nfinger < 2) {
38 mt->mem.pointing = mt->state.nfinger;
39 mt->mem.npoint = mt->state.nfinger;
40 mt->mem.ybar = mt->caps.abs_position_y.maximum;
41 return;
42 }
43
44 if (mt->state.nfinger == mt->prev_state.nfinger) {
45 for (i = 0; i < mt->state.nfinger; i++) {
46 if (GETBIT(mt->mem.pointing, i))
47 continue;
48 if (f[i].hw.position_y <= mt->mem.ybar) {
49 mt->mem.pointing = BITONES(mt->state.nfinger);
50 mt->mem.npoint = mt->state.nfinger;
51 return;
52 }
53 }
54 return;
55 }
56
57 mt->mem.pointing = 0;
58 mt->mem.npoint = 0;
59 mt->mem.ybar = mt->caps.yclick;
60 for (i = 0; i < mt->state.nfinger; i++) {
61 if (f[i].hw.position_y > mt->caps.yclick)
62 continue;
63 if (!mt->mem.npoint || f[i].hw.position_y > mt->mem.ybar)
64 mt->mem.ybar = f[i].hw.position_y;
65 SETBIT(mt->mem.pointing, i);
66 mt->mem.npoint++;
67 }
68
69}
70
32static void extract_movement(struct Gestures *gs, struct MTouch* mt) 71static void extract_movement(struct Gestures *gs, struct MTouch* mt)
33{ 72{
34 const struct FingerState *prev[DIM_FINGER]; 73 const struct FingerState *prev[DIM_FINGER];
@@ -73,9 +112,9 @@ static void extract_buttons(struct Gestures *gs, struct MTouch* mt)
73{ 112{
74 unsigned btdata = mt->state.button & BITONES(DIM_BUTTON); 113 unsigned btdata = mt->state.button & BITONES(DIM_BUTTON);
75 if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) { 114 if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) {
76 if (mt->state.nfinger == 2) 115 if (mt->mem.npoint == 2)
77 btdata = BITMASK(MT_BUTTON_RIGHT); 116 btdata = BITMASK(MT_BUTTON_RIGHT);
78 if (mt->state.nfinger == 3) 117 if (mt->mem.npoint == 3)
79 btdata = BITMASK(MT_BUTTON_MIDDLE); 118 btdata = BITMASK(MT_BUTTON_MIDDLE);
80 } 119 }
81 gs->btmask = (btdata ^ mt->mem.btdata) & BITONES(DIM_BUTTON); 120 gs->btmask = (btdata ^ mt->mem.btdata) & BITONES(DIM_BUTTON);
@@ -110,6 +149,7 @@ static void extract_type(struct Gestures *gs, struct MTouch* mt)
110void extract_gestures(struct Gestures *gs, struct MTouch* mt) 149void extract_gestures(struct Gestures *gs, struct MTouch* mt)
111{ 150{
112 memset(gs, 0, sizeof(struct Gestures)); 151 memset(gs, 0, sizeof(struct Gestures));
152 extract_pointers(gs, mt);
113 extract_movement(gs, mt); 153 extract_movement(gs, mt);
114 extract_buttons(gs, mt); 154 extract_buttons(gs, mt);
115 extract_type(gs, mt); 155 extract_type(gs, mt);
diff --git a/src/memory.h b/src/memory.h
index 0ab4d04..3b947b9 100644
--- a/src/memory.h
+++ b/src/memory.h
@@ -25,7 +25,8 @@
25#include "mtstate.h" 25#include "mtstate.h"
26 26
27struct Memory { 27struct Memory {
28 unsigned btdata; 28 unsigned btdata, pointing;
29 int npoint, ybar;
29 mstime_t move_time; 30 mstime_t move_time;
30 int move_x, move_y; 31 int move_x, move_y;
31}; 32};