diff options
Diffstat (limited to 'src/state.c')
| -rw-r--r-- | src/state.c | 37 |
1 files changed, 12 insertions, 25 deletions
diff --git a/src/state.c b/src/state.c index 4c8370f..5387828 100644 --- a/src/state.c +++ b/src/state.c | |||
| @@ -26,21 +26,17 @@ | |||
| 26 | const double FTW = 0.05; | 26 | const double FTW = 0.05; |
| 27 | const double FTS = 0.05; | 27 | const double FTS = 0.05; |
| 28 | 28 | ||
| 29 | /******************************************************/ | ||
| 30 | |||
| 31 | void init_state(struct State *s) | 29 | void init_state(struct State *s) |
| 32 | { | 30 | { |
| 33 | memset(s, 0, sizeof(struct State)); | 31 | memset(s, 0, sizeof(struct State)); |
| 34 | } | 32 | } |
| 35 | 33 | ||
| 36 | /******************************************************/ | 34 | static int fincmp(const void *a, const void *b) |
| 37 | |||
| 38 | static int fincmp(const void* a,const void* b) | ||
| 39 | { | 35 | { |
| 40 | return ((struct FingerState *)a)->id - ((struct FingerState *)b)->id; | 36 | return ((struct FingerState *)a)->id - ((struct FingerState *)b)->id; |
| 41 | } | 37 | } |
| 42 | 38 | ||
| 43 | inline float dist2(const struct FingerData* a,const struct FingerData* b) | 39 | inline float dist2(const struct FingerData *a, const struct FingerData *b) |
| 44 | { | 40 | { |
| 45 | float dx = a->position_x - b->position_x; | 41 | float dx = a->position_x - b->position_x; |
| 46 | float dy = a->position_y - b->position_y; | 42 | float dy = a->position_y - b->position_y; |
| @@ -48,9 +44,9 @@ inline float dist2(const struct FingerData* a,const struct FingerData* b) | |||
| 48 | return dx * dx + dy * dy; | 44 | return dx * dx + dy * dy; |
| 49 | } | 45 | } |
| 50 | 46 | ||
| 51 | static void set_finger(struct FingerState* fs, | 47 | static void set_finger(struct FingerState *fs, |
| 52 | const struct FingerData* hw, int id, | 48 | const struct FingerData *hw, int id, |
| 53 | const struct Capabilities* caps) | 49 | const struct Capabilities *caps) |
| 54 | { | 50 | { |
| 55 | fs->hw = *hw; | 51 | fs->hw = *hw; |
| 56 | fs->id = id; | 52 | fs->id = id; |
| @@ -60,8 +56,8 @@ static void set_finger(struct FingerState* fs, | |||
| 60 | fs->hw.width_minor = hw->width_major; | 56 | fs->hw.width_minor = hw->width_major; |
| 61 | } | 57 | } |
| 62 | 58 | ||
| 63 | static bool touching_finger(const struct FingerData* hw, | 59 | static int touching_finger(const struct FingerData *hw, |
| 64 | const struct Capabilities* caps) | 60 | const struct Capabilities *caps) |
| 65 | { | 61 | { |
| 66 | if (caps->has_touch_major && caps->has_width_major) | 62 | if (caps->has_touch_major && caps->has_width_major) |
| 67 | return hw->width_major > 0 && | 63 | return hw->width_major > 0 && |
| @@ -71,11 +67,9 @@ static bool touching_finger(const struct FingerData* hw, | |||
| 71 | return 1; | 67 | return 1; |
| 72 | } | 68 | } |
| 73 | 69 | ||
| 74 | /******************************************************/ | ||
| 75 | |||
| 76 | void modify_state(struct State *s, | 70 | void modify_state(struct State *s, |
| 77 | const struct HWData* hw, | 71 | const struct HWData *hw, |
| 78 | const struct Capabilities* caps) | 72 | const struct Capabilities *caps) |
| 79 | { | 73 | { |
| 80 | float A[DIM2_FINGER], *row; | 74 | float A[DIM2_FINGER], *row; |
| 81 | int sid[DIM_FINGER], hw2s[DIM_FINGER]; | 75 | int sid[DIM_FINGER], hw2s[DIM_FINGER]; |
| @@ -97,8 +91,9 @@ void modify_state(struct State *s, | |||
| 97 | id = sk >= 0 ? sid[sk] : 0; | 91 | id = sk >= 0 ? sid[sk] : 0; |
| 98 | if (!touching_finger(&hw->finger[hwk], caps)) | 92 | if (!touching_finger(&hw->finger[hwk], caps)) |
| 99 | id = 0; | 93 | id = 0; |
| 100 | else while (!id) | 94 | else |
| 101 | id = ++s->lastid; | 95 | while (!id) |
| 96 | id = ++s->lastid; | ||
| 102 | set_finger(&s->finger[hwk], &hw->finger[hwk], id, caps); | 97 | set_finger(&s->finger[hwk], &hw->finger[hwk], id, caps); |
| 103 | } | 98 | } |
| 104 | 99 | ||
| @@ -109,8 +104,6 @@ void modify_state(struct State *s, | |||
| 109 | qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp); | 104 | qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp); |
| 110 | } | 105 | } |
| 111 | 106 | ||
| 112 | /******************************************************/ | ||
| 113 | |||
| 114 | const struct FingerState *find_finger(const struct State *s, int id) | 107 | const struct FingerState *find_finger(const struct State *s, int id) |
| 115 | { | 108 | { |
| 116 | int i; | 109 | int i; |
| @@ -124,8 +117,6 @@ const struct FingerState *find_finger(const struct State *s, int id) | |||
| 124 | return NULL; | 117 | return NULL; |
| 125 | } | 118 | } |
| 126 | 119 | ||
| 127 | /******************************************************/ | ||
| 128 | |||
| 129 | int count_fingers(const struct State *s) | 120 | int count_fingers(const struct State *s) |
| 130 | { | 121 | { |
| 131 | int i, n = 0; | 122 | int i, n = 0; |
| @@ -135,8 +126,6 @@ int count_fingers(const struct State *s) | |||
| 135 | return n; | 126 | return n; |
| 136 | } | 127 | } |
| 137 | 128 | ||
| 138 | /******************************************************/ | ||
| 139 | |||
| 140 | void output_state(const struct State *s) | 129 | void output_state(const struct State *s) |
| 141 | { | 130 | { |
| 142 | int i; | 131 | int i; |
| @@ -159,5 +148,3 @@ void output_state(const struct State *s) | |||
| 159 | s->finger[i].hw.position_y); | 148 | s->finger[i].hw.position_y); |
| 160 | } | 149 | } |
| 161 | } | 150 | } |
| 162 | |||
| 163 | /******************************************************/ | ||
