summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 @@
#define SETBIT(m, x) (m |= BITMASK(x))
#define CLEARBIT(m, x) (m &= ~BITMASK(x))
+static inline int maxval(int x, int y) { return x > y ? x : y; }
+static inline int minval(int x, int y) { return x < y ? x : y; }
+
+static inline int clamp15(int x)
+{
+ return x < -32767 ? -32767 : x > 32767 ? 32767 : x;
+}
+
+/* absolute scale is assumed to fit in 15 bits */
+static inline int dist2(int dx, int dy)
+{
+ dx = clamp15(dx);
+ dy = clamp15(dy);
+ return dx * dx + dy * dy;
+}
+
/* Count number of bits (Sean Eron Andersson's Bit Hacks) */
static inline int bitcount(unsigned v)
{
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 @@
static const int FINGER_ATTACK_MS = 70;
static const int FINGER_DECAY_MS = 120;
-static inline int maxval(int x, int y) { return x > y ? x : y; }
-
inline int dxval(const struct FingerState *a, const struct FingerState *b)
{
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);
int read_hwdata(struct HWData *hw, const struct input_event* ev);
void output_hwdata(const struct HWData *hw);
+static inline int finger_dist2(const struct FingerData *a,
+ const struct FingerData *b)
+{
+ return dist2(a->position_x - b->position_x,
+ a->position_y - b->position_y);
+}
+
#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 @@
#define NOTOUCH(hw, c) ((hw)->touch_major == 0 && (c)->has_touch_major)
-const int XMAX = 32767;
-
void init_hwstate(struct HWState *s)
{
memset(s, 0, sizeof(struct HWState));
}
-static inline int clamp15(int x)
-{
- return x < -XMAX ? -XMAX : x > XMAX ? XMAX : x;
-}
-
-/* abslute scale is assumed to fit in 15 bits */
-inline int dist2(const struct FingerData *a, const struct FingerData *b)
-{
- int dx = clamp15(a->position_x - b->position_x);
- int dy = clamp15(a->position_y - b->position_y);
-
- return dx * dx + dy * dy;
-}
-
/* Dmitry Torokhov's code from kernel/driver/input/input.c */
static int defuzz(int value, int old_val, int fuzz)
{
@@ -104,7 +88,7 @@ void modify_hwstate(struct HWState *s,
sid[j] = 0;
row = A + hw->nfinger * j;
for (i = 0; i < hw->nfinger; i++)
- row[i] = dist2(&hw->finger[i], &s->finger[j].hw);
+ row[i] = finger_dist2(&hw->finger[i], &s->finger[j].hw);
}
match_fingers(hw2s, A, hw->nfinger, s->nfinger);