summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common.h16
-rw-r--r--src/gestures.c2
-rw-r--r--src/hwdata.h7
-rw-r--r--src/hwstate.c18
4 files changed, 24 insertions, 19 deletions
diff --git a/src/common.h b/src/common.h
index 1b4d007..32be48d 100644
--- a/src/common.h
+++ b/src/common.h
@@ -61,6 +61,22 @@
61#define SETBIT(m, x) (m |= BITMASK(x)) 61#define SETBIT(m, x) (m |= BITMASK(x))
62#define CLEARBIT(m, x) (m &= ~BITMASK(x)) 62#define CLEARBIT(m, x) (m &= ~BITMASK(x))
63 63
64static inline int maxval(int x, int y) { return x > y ? x : y; }
65static inline int minval(int x, int y) { return x < y ? x : y; }
66
67static inline int clamp15(int x)
68{
69 return x < -32767 ? -32767 : x > 32767 ? 32767 : x;
70}
71
72/* absolute scale is assumed to fit in 15 bits */
73static inline int dist2(int dx, int dy)
74{
75 dx = clamp15(dx);
76 dy = clamp15(dy);
77 return dx * dx + dy * dy;
78}
79
64/* Count number of bits (Sean Eron Andersson's Bit Hacks) */ 80/* Count number of bits (Sean Eron Andersson's Bit Hacks) */
65static inline int bitcount(unsigned v) 81static inline int bitcount(unsigned v)
66{ 82{
diff --git a/src/gestures.c b/src/gestures.c
index f44e6ab..a0ef5d4 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -31,8 +31,6 @@
31static const int FINGER_ATTACK_MS = 70; 31static const int FINGER_ATTACK_MS = 70;
32static const int FINGER_DECAY_MS = 120; 32static const int FINGER_DECAY_MS = 120;
33 33
34static inline int maxval(int x, int y) { return x > y ? x : y; }
35
36inline int dxval(const struct FingerState *a, const struct FingerState *b) 34inline int dxval(const struct FingerState *a, const struct FingerState *b)
37{ 35{
38 return a->hw.position_x - b->hw.position_x; 36 return a->hw.position_x - b->hw.position_x;
diff --git a/src/hwdata.h b/src/hwdata.h
index 15a9fcb..5dd99cf 100644
--- a/src/hwdata.h
+++ b/src/hwdata.h
@@ -81,4 +81,11 @@ void init_hwdata(struct HWData *hw);
81int read_hwdata(struct HWData *hw, const struct input_event* ev); 81int read_hwdata(struct HWData *hw, const struct input_event* ev);
82void output_hwdata(const struct HWData *hw); 82void output_hwdata(const struct HWData *hw);
83 83
84static inline int finger_dist2(const struct FingerData *a,
85 const struct FingerData *b)
86{
87 return dist2(a->position_x - b->position_x,
88 a->position_y - b->position_y);
89}
90
84#endif 91#endif
diff --git a/src/hwstate.c b/src/hwstate.c
index 07bab31..a68b81a 100644
--- a/src/hwstate.c
+++ b/src/hwstate.c
@@ -25,27 +25,11 @@
25 25
26#define NOTOUCH(hw, c) ((hw)->touch_major == 0 && (c)->has_touch_major) 26#define NOTOUCH(hw, c) ((hw)->touch_major == 0 && (c)->has_touch_major)
27 27
28const int XMAX = 32767;
29
30void init_hwstate(struct HWState *s) 28void init_hwstate(struct HWState *s)
31{ 29{
32 memset(s, 0, sizeof(struct HWState)); 30 memset(s, 0, sizeof(struct HWState));
33} 31}
34 32
35static inline int clamp15(int x)
36{
37 return x < -XMAX ? -XMAX : x > XMAX ? XMAX : x;
38}
39
40/* abslute scale is assumed to fit in 15 bits */
41inline int dist2(const struct FingerData *a, const struct FingerData *b)
42{
43 int dx = clamp15(a->position_x - b->position_x);
44 int dy = clamp15(a->position_y - b->position_y);
45
46 return dx * dx + dy * dy;
47}
48
49/* Dmitry Torokhov's code from kernel/driver/input/input.c */ 33/* Dmitry Torokhov's code from kernel/driver/input/input.c */
50static int defuzz(int value, int old_val, int fuzz) 34static int defuzz(int value, int old_val, int fuzz)
51{ 35{
@@ -104,7 +88,7 @@ void modify_hwstate(struct HWState *s,
104 sid[j] = 0; 88 sid[j] = 0;
105 row = A + hw->nfinger * j; 89 row = A + hw->nfinger * j;
106 for (i = 0; i < hw->nfinger; i++) 90 for (i = 0; i < hw->nfinger; i++)
107 row[i] = dist2(&hw->finger[i], &s->finger[j].hw); 91 row[i] = finger_dist2(&hw->finger[i], &s->finger[j].hw);
108 } 92 }
109 93
110 match_fingers(hw2s, A, hw->nfinger, s->nfinger); 94 match_fingers(hw2s, A, hw->nfinger, s->nfinger);