summaryrefslogtreecommitdiff
path: root/src/hwstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/hwstate.c')
-rw-r--r--src/hwstate.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/hwstate.c b/src/hwstate.c
index 40cef5b..4af636c 100644
--- a/src/hwstate.c
+++ b/src/hwstate.c
@@ -44,16 +44,37 @@ inline int dist2(const struct FingerData *a, const struct FingerData *b)
44 return dx * dx + dy * dy; 44 return dx * dx + dy * dy;
45} 45}
46 46
47/* Dmitry Torokhov's code from kernel/driver/input/input.c */
48static int defuzz(int value, int old_val, int fuzz)
49{
50 if (fuzz) {
51 if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2)
52 return old_val;
53
54 if (value > old_val - fuzz && value < old_val + fuzz)
55 return (old_val * 3 + value) / 4;
56
57 if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2)
58 return (old_val + value) / 2;
59 }
60
61 return value;
62}
63
47static void set_finger(struct FingerState *fs, 64static void set_finger(struct FingerState *fs,
48 const struct FingerData *hw, int id, 65 const struct FingerData *hw, int id,
49 const struct Capabilities *caps) 66 const struct Capabilities *caps)
50{ 67{
68 int x = defuzz(hw->position_x, fs->hw.position_x, caps->xfuzz);
69 int y = defuzz(hw->position_y, fs->hw.position_y, caps->yfuzz);
51 fs->hw = *hw; 70 fs->hw = *hw;
52 fs->id = id; 71 fs->id = id;
53 if (!caps->has_touch_minor) 72 if (!caps->has_touch_minor)
54 fs->hw.touch_minor = hw->touch_major; 73 fs->hw.touch_minor = hw->touch_major;
55 if (!caps->has_width_minor) 74 if (!caps->has_width_minor)
56 fs->hw.width_minor = hw->width_major; 75 fs->hw.width_minor = hw->width_major;
76 fs->hw.position_x = x;
77 fs->hw.position_y = y;
57} 78}
58 79
59void modify_hwstate(struct HWState *s, 80void modify_hwstate(struct HWState *s,