diff options
| -rw-r--r-- | src/gestures.c | 28 | ||||
| -rw-r--r-- | src/memory.h | 2 |
2 files changed, 22 insertions, 8 deletions
diff --git a/src/gestures.c b/src/gestures.c index e032214..b04c679 100644 --- a/src/gestures.c +++ b/src/gestures.c | |||
| @@ -21,11 +21,14 @@ | |||
| 21 | 21 | ||
| 22 | #include "gestures.h" | 22 | #include "gestures.h" |
| 23 | 23 | ||
| 24 | /* timer for cursor stability on finger touch/release */ | ||
| 25 | static const int AFTER_FINGER_CHANGE_MS = 70; | ||
| 26 | |||
| 24 | static void extract_movement(struct Gestures *gs, struct MTouch* mt) | 27 | static void extract_movement(struct Gestures *gs, struct MTouch* mt) |
| 25 | { | 28 | { |
| 26 | const struct FingerState *prev[DIM_FINGER]; | 29 | const struct FingerState *prev[DIM_FINGER]; |
| 27 | const struct FingerState *f = mt->state.finger; | 30 | const struct FingerState *f = mt->state.finger; |
| 28 | int same_fingers, i; | 31 | int same_fingers, i, x = 0, y = 0; |
| 29 | 32 | ||
| 30 | if (mt->state.nfinger == 0) | 33 | if (mt->state.nfinger == 0) |
| 31 | return; | 34 | return; |
| @@ -36,16 +39,25 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt) | |||
| 36 | same_fingers = same_fingers && prev[i]; | 39 | same_fingers = same_fingers && prev[i]; |
| 37 | } | 40 | } |
| 38 | 41 | ||
| 39 | if (!same_fingers) | ||
| 40 | return; | ||
| 41 | |||
| 42 | for (i = 0; i < mt->state.nfinger; i++) { | 42 | for (i = 0; i < mt->state.nfinger; i++) { |
| 43 | gs->dx += f[i].hw.position_x - prev[i]->hw.position_x; | 43 | x += f[i].hw.position_x; |
| 44 | gs->dy += f[i].hw.position_y - prev[i]->hw.position_y; | 44 | y += f[i].hw.position_y; |
| 45 | } | ||
| 46 | x /= mt->state.nfinger; | ||
| 47 | y /= mt->state.nfinger; | ||
| 48 | |||
| 49 | if (!same_fingers) { | ||
| 50 | mt->mem.move_time = mt->state.evtime + AFTER_FINGER_CHANGE_MS; | ||
| 51 | } else if (mt->state.evtime >= mt->mem.move_time) { | ||
| 52 | gs->dx = x - mt->mem.move_x; | ||
| 53 | gs->dy = y - mt->mem.move_y; | ||
| 54 | } else { | ||
| 55 | /* accumulate all movement during delay */ | ||
| 56 | return; | ||
| 45 | } | 57 | } |
| 46 | 58 | ||
| 47 | gs->dx /= mt->state.nfinger; | 59 | mt->mem.move_x = x; |
| 48 | gs->dy /= mt->state.nfinger; | 60 | mt->mem.move_y = y; |
| 49 | } | 61 | } |
| 50 | 62 | ||
| 51 | static void extract_buttons(struct Gestures *gs, struct MTouch* mt) | 63 | static void extract_buttons(struct Gestures *gs, struct MTouch* mt) |
diff --git a/src/memory.h b/src/memory.h index a6c51ec..0ab4d04 100644 --- a/src/memory.h +++ b/src/memory.h | |||
| @@ -26,6 +26,8 @@ | |||
| 26 | 26 | ||
| 27 | struct Memory { | 27 | struct Memory { |
| 28 | unsigned btdata; | 28 | unsigned btdata; |
| 29 | mstime_t move_time; | ||
| 30 | int move_x, move_y; | ||
| 29 | }; | 31 | }; |
| 30 | 32 | ||
| 31 | void init_memory(struct Memory *mem); | 33 | void init_memory(struct Memory *mem); |
