diff options
| -rw-r--r-- | src/common.h | 4 | ||||
| -rw-r--r-- | src/multitouch.c | 26 | ||||
| -rw-r--r-- | src/state.c | 38 | ||||
| -rw-r--r-- | src/state.h | 4 |
4 files changed, 57 insertions, 15 deletions
diff --git a/src/common.h b/src/common.h index c57ae1a..0ddfaaf 100644 --- a/src/common.h +++ b/src/common.h | |||
| @@ -30,6 +30,10 @@ | |||
| 30 | 30 | ||
| 31 | #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) | 31 | #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) |
| 32 | 32 | ||
| 33 | #define GETBIT(m, x) ((m>>(x))&1U) | ||
| 34 | #define SETBIT(m, x) (m|=(1U<<(x))) | ||
| 35 | #define CLEARBIT(m, x) (m&=~(1U<<(x))) | ||
| 36 | |||
| 33 | //////////////////////////////////////////////////////// | 37 | //////////////////////////////////////////////////////// |
| 34 | 38 | ||
| 35 | #endif | 39 | #endif |
diff --git a/src/multitouch.c b/src/multitouch.c index a16d1b1..0ef808e 100644 --- a/src/multitouch.c +++ b/src/multitouch.c | |||
| @@ -128,16 +128,21 @@ static void handle_state(LocalDevicePtr local, | |||
| 128 | const struct State *ns) | 128 | const struct State *ns) |
| 129 | { | 129 | { |
| 130 | const struct FingerState *fs, *p, *e = ns->finger + ns->nfinger; | 130 | const struct FingerState *fs, *p, *e = ns->finger + ns->nfinger; |
| 131 | int dx = 0, dy = 0, n = 0, i; | 131 | int dx = 0, dy = 0, dn = 0, n = 0, i; |
| 132 | for (p = ns->finger; p != e; p++) { | 132 | if (count_fingers(ns) == count_fingers(os)) { |
| 133 | if (fs = find_finger(os, p->id)) { | 133 | for (p = ns->finger; p != e; p++) { |
| 134 | dx += p->hw.position_x - fs->hw.position_x; | 134 | if (fs = find_finger(os, p->id)) { |
| 135 | dy += p->hw.position_y - fs->hw.position_y; | 135 | dx += p->hw.position_x - fs->hw.position_x; |
| 136 | dy += p->hw.position_y - fs->hw.position_y; | ||
| 137 | dn++; | ||
| 138 | } | ||
| 136 | } | 139 | } |
| 137 | } | 140 | } |
| 138 | if (dx || dy) { | 141 | if (dx || dy) { |
| 142 | dx /= dn; | ||
| 143 | dy /= dn; | ||
| 139 | xf86PostMotionEvent(local->dev, 0, 0, 2, dx, dy); | 144 | xf86PostMotionEvent(local->dev, 0, 0, 2, dx, dy); |
| 140 | xf86Msg(X_INFO, "motion: %d %d\n", dx, dy); | 145 | //xf86Msg(X_INFO, "motion: %d %d\n", dx, dy); |
| 141 | n++; | 146 | n++; |
| 142 | } | 147 | } |
| 143 | for (i = 0; i < DIM_BUTTON; i++) { | 148 | for (i = 0; i < DIM_BUTTON; i++) { |
| @@ -145,14 +150,13 @@ static void handle_state(LocalDevicePtr local, | |||
| 145 | xf86PostButtonEvent(local->dev, FALSE, | 150 | xf86PostButtonEvent(local->dev, FALSE, |
| 146 | i, GETBIT(ns->button, i), | 151 | i, GETBIT(ns->button, i), |
| 147 | 0, 0); | 152 | 0, 0); |
| 148 | xf86Msg(X_INFO, "button: %d -> %d\n", | 153 | //xf86Msg(X_INFO, "button: %d -> %d\n", |
| 149 | i, GETBIT(ns->button, i)); | 154 | //i, GETBIT(ns->button, i)); |
| 150 | n++; | 155 | n++; |
| 151 | } | 156 | } |
| 152 | } | 157 | } |
| 153 | if (n) { | 158 | //if (n) |
| 154 | output_state(ns); | 159 | //output_state(ns); |
| 155 | } | ||
| 156 | } | 160 | } |
| 157 | 161 | ||
| 158 | //////////////////////////////////////////////////////////////////////////// | 162 | //////////////////////////////////////////////////////////////////////////// |
diff --git a/src/state.c b/src/state.c index 1391322..290ec95 100644 --- a/src/state.c +++ b/src/state.c | |||
| @@ -2,6 +2,9 @@ | |||
| 2 | #include <stdlib.h> | 2 | #include <stdlib.h> |
| 3 | #include <limits.h> | 3 | #include <limits.h> |
| 4 | 4 | ||
| 5 | const double FTW = 0.1; | ||
| 6 | const double FTS = 0.1; | ||
| 7 | |||
| 5 | /******************************************************/ | 8 | /******************************************************/ |
| 6 | 9 | ||
| 7 | void init_state(struct State *s) | 10 | void init_state(struct State *s) |
| @@ -36,6 +39,17 @@ static void set_finger(struct FingerState* fs, | |||
| 36 | fs->hw.width_minor = hw->width_major; | 39 | fs->hw.width_minor = hw->width_major; |
| 37 | } | 40 | } |
| 38 | 41 | ||
| 42 | static bool touching_finger(const struct FingerData* hw, | ||
| 43 | const struct Capabilities* caps) | ||
| 44 | { | ||
| 45 | if (caps->has_touch_major && caps->has_width_major) | ||
| 46 | return hw->width_major > 0 && | ||
| 47 | hw->touch_major > FTW * hw->width_major; | ||
| 48 | if (caps->has_touch_major) | ||
| 49 | hw->touch_major > FTS * caps->abs_touch_major.maximum; | ||
| 50 | return 1; | ||
| 51 | } | ||
| 52 | |||
| 39 | /******************************************************/ | 53 | /******************************************************/ |
| 40 | 54 | ||
| 41 | void modify_state(struct State *s, | 55 | void modify_state(struct State *s, |
| @@ -43,7 +57,8 @@ void modify_state(struct State *s, | |||
| 43 | const struct Capabilities* caps) | 57 | const struct Capabilities* caps) |
| 44 | { | 58 | { |
| 45 | float A[DIM2_FINGER], *row; | 59 | float A[DIM2_FINGER], *row; |
| 46 | int sid[DIM_FINGER], hw2s[DIM_FINGER], id, sk, hwk; | 60 | int sid[DIM_FINGER], hw2s[DIM_FINGER]; |
| 61 | int id, sk, hwk; | ||
| 47 | 62 | ||
| 48 | /* setup distance matrix for finger id matching */ | 63 | /* setup distance matrix for finger id matching */ |
| 49 | for (sk = 0; sk < s->nfinger; sk++) { | 64 | for (sk = 0; sk < s->nfinger; sk++) { |
| @@ -58,8 +73,12 @@ void modify_state(struct State *s, | |||
| 58 | /* update matched fingers and create new ones */ | 73 | /* update matched fingers and create new ones */ |
| 59 | for (hwk = 0; hwk < hw->nfinger; hwk++) { | 74 | for (hwk = 0; hwk < hw->nfinger; hwk++) { |
| 60 | sk = hw2s[hwk]; | 75 | sk = hw2s[hwk]; |
| 61 | id = sk < 0 ? s->nextid++ : sid[sk]; | 76 | id = sk >= 0 ? sid[sk] : 0; |
| 62 | set_finger(s->finger + hwk, hw->finger + hwk, id, caps); | 77 | if (!touching_finger(&hw->finger[hwk], caps)) |
| 78 | id = 0; | ||
| 79 | else while (!id) | ||
| 80 | id = ++s->lastid; | ||
| 81 | set_finger(&s->finger[hwk], &hw->finger[hwk], id, caps); | ||
| 63 | } | 82 | } |
| 64 | 83 | ||
| 65 | s->button = hw->button; | 84 | s->button = hw->button; |
| @@ -75,6 +94,8 @@ const struct FingerState *find_finger(const struct State *s, int id) | |||
| 75 | { | 94 | { |
| 76 | int i; | 95 | int i; |
| 77 | 96 | ||
| 97 | if (!id) | ||
| 98 | return NULL; | ||
| 78 | for (i = 0; i < s->nfinger; i++) | 99 | for (i = 0; i < s->nfinger; i++) |
| 79 | if (s->finger[i].id == id) | 100 | if (s->finger[i].id == id) |
| 80 | return s->finger + i; | 101 | return s->finger + i; |
| @@ -84,6 +105,17 @@ const struct FingerState *find_finger(const struct State *s, int id) | |||
| 84 | 105 | ||
| 85 | /******************************************************/ | 106 | /******************************************************/ |
| 86 | 107 | ||
| 108 | int count_fingers(const struct State *s) | ||
| 109 | { | ||
| 110 | int i, n = 0; | ||
| 111 | for (i = 0; i < s->nfinger; i++) | ||
| 112 | if (s->finger[i].id) | ||
| 113 | n++; | ||
| 114 | return n; | ||
| 115 | } | ||
| 116 | |||
| 117 | /******************************************************/ | ||
| 118 | |||
| 87 | void output_state(const struct State *s) | 119 | void output_state(const struct State *s) |
| 88 | { | 120 | { |
| 89 | int i; | 121 | int i; |
diff --git a/src/state.h b/src/state.h index 65ae581..5a59192 100644 --- a/src/state.h +++ b/src/state.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | //////////////////////////////////////////////////////// | 7 | //////////////////////////////////////////////////////// |
| 8 | 8 | ||
| 9 | /* zero id means not mapped (not touching) */ | ||
| 9 | struct FingerState { | 10 | struct FingerState { |
| 10 | struct FingerData hw; | 11 | struct FingerData hw; |
| 11 | int id; | 12 | int id; |
| @@ -17,7 +18,7 @@ struct State { | |||
| 17 | struct FingerState finger[DIM_FINGER]; | 18 | struct FingerState finger[DIM_FINGER]; |
| 18 | button_t button; | 19 | button_t button; |
| 19 | int nfinger; | 20 | int nfinger; |
| 20 | int nextid; | 21 | int lastid; |
| 21 | }; | 22 | }; |
| 22 | 23 | ||
| 23 | //////////////////////////////////////////////////////// | 24 | //////////////////////////////////////////////////////// |
| @@ -29,6 +30,7 @@ void modify_state(struct State *s, | |||
| 29 | void output_state(const struct State *s); | 30 | void output_state(const struct State *s); |
| 30 | 31 | ||
| 31 | const struct FingerState *find_finger(const struct State *s, int id); | 32 | const struct FingerState *find_finger(const struct State *s, int id); |
| 33 | int count_fingers(const struct State *s); | ||
| 32 | 34 | ||
| 33 | //////////////////////////////////////////////////////// | 35 | //////////////////////////////////////////////////////// |
| 34 | 36 | ||
