diff options
| -rw-r--r-- | match/match.c | 10 | ||||
| -rw-r--r-- | match/match.h | 4 | ||||
| -rw-r--r-- | src/hwdata.c | 20 | ||||
| -rw-r--r-- | src/hwdata.h | 5 | ||||
| -rw-r--r-- | src/multitouch.c | 20 | ||||
| -rw-r--r-- | src/state.c | 55 | ||||
| -rw-r--r-- | src/state.h | 5 |
7 files changed, 61 insertions, 58 deletions
diff --git a/match/match.c b/match/match.c index 604faaf..44297d9 100644 --- a/match/match.c +++ b/match/match.c | |||
| @@ -12,13 +12,9 @@ const float BIG_VALUE = 1e20; | |||
| 12 | 12 | ||
| 13 | typedef unsigned short col_t; | 13 | typedef unsigned short col_t; |
| 14 | 14 | ||
| 15 | #define GETBIT2(m, row, col) ((m[col]>>row)&1U) | 15 | #define GETBIT2(m, row, col) ((m[col]>>(row))&1U) |
| 16 | #define SETBIT2(m, row, col) (m[col]|=(1U<<row)) | 16 | #define SETBIT2(m, row, col) (m[col]|=(1U<<(row))) |
| 17 | #define CLEARBIT2(m, row, col) (m[col]&=~(1U<<row)) | 17 | #define CLEARBIT2(m, row, col) (m[col]&=~(1U<<(row))) |
| 18 | |||
| 19 | #define GETBIT(m, x) ((m>>x)&1U) | ||
| 20 | #define SETBIT(m, x) (m|=(1U<<x)) | ||
| 21 | #define CLEARBIT(m, x) (m&=~(1U<<x)) | ||
| 22 | 18 | ||
| 23 | /********************************************************/ | 19 | /********************************************************/ |
| 24 | 20 | ||
diff --git a/match/match.h b/match/match.h index 8936de4..03bf600 100644 --- a/match/match.h +++ b/match/match.h | |||
| @@ -13,6 +13,10 @@ | |||
| 13 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | 13 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| 14 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) | 14 | #define MAX(a, b) ((a) < (b) ? (b) : (a)) |
| 15 | 15 | ||
| 16 | #define GETBIT(m, x) ((m>>(x))&1U) | ||
| 17 | #define SETBIT(m, x) (m|=(1U<<(x))) | ||
| 18 | #define CLEARBIT(m, x) (m&=~(1U<<(x))) | ||
| 19 | |||
| 16 | typedef int bool; | 20 | typedef int bool; |
| 17 | 21 | ||
| 18 | //////////////////////////////////////////////////////// | 22 | //////////////////////////////////////////////////////// |
diff --git a/src/hwdata.c b/src/hwdata.c index 029d68a..1882910 100644 --- a/src/hwdata.c +++ b/src/hwdata.c | |||
| @@ -11,7 +11,6 @@ void init_hwdata(struct HWData *hw) | |||
| 11 | 11 | ||
| 12 | bool read_hwdata(struct HWData *hw, const struct input_event* ev) | 12 | bool read_hwdata(struct HWData *hw, const struct input_event* ev) |
| 13 | { | 13 | { |
| 14 | bool on = ev->value != 0; | ||
| 15 | switch (ev->type) { | 14 | switch (ev->type) { |
| 16 | case EV_SYN: | 15 | case EV_SYN: |
| 17 | switch (ev->code) { | 16 | switch (ev->code) { |
| @@ -22,20 +21,29 @@ bool read_hwdata(struct HWData *hw, const struct input_event* ev) | |||
| 22 | case EV_KEY: | 21 | case EV_KEY: |
| 23 | switch (ev->code) { | 22 | switch (ev->code) { |
| 24 | case BTN_LEFT: | 23 | case BTN_LEFT: |
| 25 | hw->button[MT_BUTTON_LEFT] = on; | 24 | if (ev->value) |
| 25 | SETBIT(hw->button, MT_BUTTON_LEFT); | ||
| 26 | else | ||
| 27 | CLEARBIT(hw->button, MT_BUTTON_LEFT); | ||
| 26 | break; | 28 | break; |
| 27 | case BTN_MIDDLE: | 29 | case BTN_MIDDLE: |
| 28 | hw->button[MT_BUTTON_MIDDLE] = on; | 30 | if (ev->value) |
| 31 | SETBIT(hw->button, MT_BUTTON_MIDDLE); | ||
| 32 | else | ||
| 33 | CLEARBIT(hw->button, MT_BUTTON_MIDDLE); | ||
| 29 | break; | 34 | break; |
| 30 | case BTN_RIGHT: | 35 | case BTN_RIGHT: |
| 31 | hw->button[MT_BUTTON_RIGHT] = on; | 36 | if (ev->value) |
| 37 | SETBIT(hw->button, MT_BUTTON_RIGHT); | ||
| 38 | else | ||
| 39 | CLEARBIT(hw->button, MT_BUTTON_RIGHT); | ||
| 32 | break; | 40 | break; |
| 33 | case BTN_MT_REPORT_PACKET: | 41 | case BTN_MT_REPORT_PACKET: |
| 34 | if (on) | 42 | if (ev->value) |
| 35 | hw->nfinger = 0; | 43 | hw->nfinger = 0; |
| 36 | break; | 44 | break; |
| 37 | case BTN_MT_REPORT_FINGER: | 45 | case BTN_MT_REPORT_FINGER: |
| 38 | if (!on && hw->nfinger < DIM_FINGER) | 46 | if (!ev->value && hw->nfinger < DIM_FINGER) |
| 39 | hw->nfinger++; | 47 | hw->nfinger++; |
| 40 | break; | 48 | break; |
| 41 | } | 49 | } |
diff --git a/src/hwdata.h b/src/hwdata.h index 59cff0d..f91f11b 100644 --- a/src/hwdata.h +++ b/src/hwdata.h | |||
| @@ -9,6 +9,8 @@ | |||
| 9 | #define MT_BUTTON_MIDDLE 1 | 9 | #define MT_BUTTON_MIDDLE 1 |
| 10 | #define MT_BUTTON_RIGHT 2 | 10 | #define MT_BUTTON_RIGHT 2 |
| 11 | 11 | ||
| 12 | typedef unsigned int button_t; | ||
| 13 | |||
| 12 | //////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////// |
| 13 | 15 | ||
| 14 | struct FingerData { | 16 | struct FingerData { |
| @@ -22,7 +24,8 @@ struct FingerData { | |||
| 22 | 24 | ||
| 23 | struct HWData { | 25 | struct HWData { |
| 24 | struct FingerData finger[DIM_FINGER]; | 26 | struct FingerData finger[DIM_FINGER]; |
| 25 | int nfinger, button[DIM_BUTTON]; | 27 | button_t button; |
| 28 | int nfinger; | ||
| 26 | }; | 29 | }; |
| 27 | 30 | ||
| 28 | //////////////////////////////////////////////////////// | 31 | //////////////////////////////////////////////////////// |
diff --git a/src/multitouch.c b/src/multitouch.c index 987cf34..a16d1b1 100644 --- a/src/multitouch.c +++ b/src/multitouch.c | |||
| @@ -128,7 +128,7 @@ 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, i; | 131 | int dx = 0, dy = 0, n = 0, i; |
| 132 | for (p = ns->finger; p != e; p++) { | 132 | for (p = ns->finger; p != e; p++) { |
| 133 | if (fs = find_finger(os, p->id)) { | 133 | if (fs = find_finger(os, p->id)) { |
| 134 | dx += p->hw.position_x - fs->hw.position_x; | 134 | dx += p->hw.position_x - fs->hw.position_x; |
| @@ -136,15 +136,23 @@ static void handle_state(LocalDevicePtr local, | |||
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | if (dx || dy) { | 138 | if (dx || dy) { |
| 139 | output_state(ns); | ||
| 140 | xf86Msg(X_INFO, "motion: %d %d\n", dx, dy); | ||
| 141 | xf86PostMotionEvent(local->dev, 0, 0, 2, dx, dy); | 139 | xf86PostMotionEvent(local->dev, 0, 0, 2, dx, dy); |
| 140 | xf86Msg(X_INFO, "motion: %d %d\n", dx, dy); | ||
| 141 | n++; | ||
| 142 | } | 142 | } |
| 143 | for (i = 0; i < DIM_BUTTON; i++) | 143 | for (i = 0; i < DIM_BUTTON; i++) { |
| 144 | if (ns->button[i] != os->button[i]) | 144 | if (GETBIT(ns->button, i) != GETBIT(os->button, i)) { |
| 145 | xf86PostButtonEvent(local->dev, FALSE, | 145 | xf86PostButtonEvent(local->dev, FALSE, |
| 146 | i + 1, ns->button[i], | 146 | i, GETBIT(ns->button, i), |
| 147 | 0, 0); | 147 | 0, 0); |
| 148 | xf86Msg(X_INFO, "button: %d -> %d\n", | ||
| 149 | i, GETBIT(ns->button, i)); | ||
| 150 | n++; | ||
| 151 | } | ||
| 152 | } | ||
| 153 | if (n) { | ||
| 154 | output_state(ns); | ||
| 155 | } | ||
| 148 | } | 156 | } |
| 149 | 157 | ||
| 150 | //////////////////////////////////////////////////////////////////////////// | 158 | //////////////////////////////////////////////////////////////////////////// |
diff --git a/src/state.c b/src/state.c index e5ca1c1..1391322 100644 --- a/src/state.c +++ b/src/state.c | |||
| @@ -36,12 +36,6 @@ static void set_finger(struct FingerState* fs, | |||
| 36 | fs->hw.width_minor = hw->width_major; | 36 | fs->hw.width_minor = hw->width_major; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | inline bool good_finger(const struct FingerState* fs) | ||
| 40 | { | ||
| 41 | return fs->hw.touch_major > 0 && fs->hw.width_major > 0 && | ||
| 42 | fs->hw.touch_minor > 0 && fs->hw.width_minor > 0; | ||
| 43 | } | ||
| 44 | |||
| 45 | /******************************************************/ | 39 | /******************************************************/ |
| 46 | 40 | ||
| 47 | void modify_state(struct State *s, | 41 | void modify_state(struct State *s, |
| @@ -49,43 +43,30 @@ void modify_state(struct State *s, | |||
| 49 | const struct Capabilities* caps) | 43 | const struct Capabilities* caps) |
| 50 | { | 44 | { |
| 51 | float A[DIM2_FINGER], *row; | 45 | float A[DIM2_FINGER], *row; |
| 52 | int id[DIM_FINGER], index[DIM_FINGER], i, j; | 46 | int sid[DIM_FINGER], hw2s[DIM_FINGER], id, sk, hwk; |
| 53 | struct FingerState *fs = s->finger; | 47 | |
| 54 | 48 | /* setup distance matrix for finger id matching */ | |
| 55 | for (j = 0; j < s->nfinger; j++) { | 49 | for (sk = 0; sk < s->nfinger; sk++) { |
| 56 | id[j] = s->finger[j].id; | 50 | sid[sk] = s->finger[sk].id; |
| 57 | row = A + hw->nfinger * j; | 51 | row = A + hw->nfinger * sk; |
| 58 | for (i = 0; i < hw->nfinger; i++) | 52 | for (hwk = 0; hwk < hw->nfinger; hwk++) |
| 59 | row[i] = dist2(&hw->finger[i], &s->finger[j].hw); | 53 | row[hwk] = dist2(&hw->finger[hwk], &s->finger[sk].hw); |
| 60 | } | 54 | } |
| 61 | 55 | ||
| 62 | match_fingers(index, A, hw->nfinger, s->nfinger); | 56 | match_fingers(hw2s, A, hw->nfinger, s->nfinger); |
| 63 | 57 | ||
| 64 | /* update matched fingers and create new ones */ | 58 | /* update matched fingers and create new ones */ |
| 65 | for (i = 0; i < hw->nfinger; i++) { | 59 | for (hwk = 0; hwk < hw->nfinger; hwk++) { |
| 66 | j = index[i]; | 60 | sk = hw2s[hwk]; |
| 67 | if (j >= 0) | 61 | id = sk < 0 ? s->nextid++ : sid[sk]; |
| 68 | set_finger(fs, hw->finger + i, id[j], caps); | 62 | set_finger(s->finger + hwk, hw->finger + hwk, id, caps); |
| 69 | else | ||
| 70 | set_finger(fs, hw->finger + i, ++s->lastid, caps); | ||
| 71 | if (good_finger(fs)) | ||
| 72 | fs++; | ||
| 73 | } | 63 | } |
| 74 | s->nfinger = fs - s->finger; | 64 | |
| 65 | s->button = hw->button; | ||
| 66 | s->nfinger = hw->nfinger; | ||
| 75 | 67 | ||
| 76 | /* sort fingers in touching order */ | 68 | /* sort fingers in touching order */ |
| 77 | qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp); | 69 | qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp); |
| 78 | |||
| 79 | /* make sure wrap-around does not create very strange effects */ | ||
| 80 | if (s->lastid > INT_MAX / 2) { | ||
| 81 | s->lastid = 0; | ||
| 82 | for (j = 0; j < s->nfinger; j++) | ||
| 83 | s->finger[j].id = ++s->lastid; | ||
| 84 | } | ||
| 85 | |||
| 86 | /* copy buttons */ | ||
| 87 | for (i = 0; i < DIM_BUTTON; i++) | ||
| 88 | s->button[i] = hw->button[i]; | ||
| 89 | } | 70 | } |
| 90 | 71 | ||
| 91 | /******************************************************/ | 72 | /******************************************************/ |
| @@ -107,7 +88,9 @@ void output_state(const struct State *s) | |||
| 107 | { | 88 | { |
| 108 | int i; | 89 | int i; |
| 109 | xf86Msg(X_INFO, "buttons: %d%d%d\n", | 90 | xf86Msg(X_INFO, "buttons: %d%d%d\n", |
| 110 | s->button[0], s->button[1], s->button[2]); | 91 | GETBIT(s->button, MT_BUTTON_LEFT), |
| 92 | GETBIT(s->button, MT_BUTTON_MIDDLE), | ||
| 93 | GETBIT(s->button, MT_BUTTON_RIGHT)); | ||
| 111 | xf86Msg(X_INFO, "fingers: %d\n", | 94 | xf86Msg(X_INFO, "fingers: %d\n", |
| 112 | s->nfinger); | 95 | s->nfinger); |
| 113 | for (i = 0; i < s->nfinger; i++) { | 96 | for (i = 0; i < s->nfinger; i++) { |
diff --git a/src/state.h b/src/state.h index 7bf4438..65ae581 100644 --- a/src/state.h +++ b/src/state.h | |||
| @@ -15,8 +15,9 @@ struct FingerState { | |||
| 15 | 15 | ||
| 16 | struct State { | 16 | struct State { |
| 17 | struct FingerState finger[DIM_FINGER]; | 17 | struct FingerState finger[DIM_FINGER]; |
| 18 | int button[DIM_BUTTON]; | 18 | button_t button; |
| 19 | int nfinger, lastid; | 19 | int nfinger; |
| 20 | int nextid; | ||
| 20 | }; | 21 | }; |
| 21 | 22 | ||
| 22 | //////////////////////////////////////////////////////// | 23 | //////////////////////////////////////////////////////// |
