aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-05-14 01:10:17 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-05-14 01:41:39 +0200
commit2b271ed5348daec2bcf90b83da47781e2d8b964c (patch)
tree1828f251cf4b7d4f6a66a6af67c2681998f2483e
parentf02210172efc6bfc05c4598c14e1268d2828097e (diff)
downloadxorg-input-kobomultitouch-2b271ed5348daec2bcf90b83da47781e2d8b964c.tar.gz
xorg-input-kobomultitouch-2b271ed5348daec2bcf90b83da47781e2d8b964c.tar.bz2
xorg-input-kobomultitouch-2b271ed5348daec2bcf90b83da47781e2d8b964c.zip
janitor: Move min/max and dist functions up to common.h
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-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);