diff options
| -rw-r--r-- | src/common.h | 15 | ||||
| -rw-r--r-- | src/gestures.c | 30 | ||||
| -rw-r--r-- | src/memory.c | 2 | ||||
| -rw-r--r-- | src/memory.h | 4 | ||||
| -rw-r--r-- | src/test.c | 13 |
5 files changed, 43 insertions, 21 deletions
diff --git a/src/common.h b/src/common.h index 27082b7..1b4d007 100644 --- a/src/common.h +++ b/src/common.h | |||
| @@ -61,4 +61,19 @@ | |||
| 61 | #define SETBIT(m, x) (m |= BITMASK(x)) | 61 | #define SETBIT(m, x) (m |= BITMASK(x)) |
| 62 | #define CLEARBIT(m, x) (m &= ~BITMASK(x)) | 62 | #define CLEARBIT(m, x) (m &= ~BITMASK(x)) |
| 63 | 63 | ||
| 64 | /* Count number of bits (Sean Eron Andersson's Bit Hacks) */ | ||
| 65 | static inline int bitcount(unsigned v) | ||
| 66 | { | ||
| 67 | v -= ((v>>1) & 0x55555555); | ||
| 68 | v = (v&0x33333333) + ((v>>2) & 0x33333333); | ||
| 69 | return (((v + (v>>4)) & 0xF0F0F0F) * 0x1010101) >> 24; | ||
| 70 | } | ||
| 71 | |||
| 72 | /* Return index of first bit [0-31], -1 on zero */ | ||
| 73 | #define firstbit(v) (__builtin_ffs(v) - 1) | ||
| 74 | |||
| 75 | /* boost-style foreach bit */ | ||
| 76 | #define foreach_bit(i, m) \ | ||
| 77 | for (i = firstbit(m); i >= 0; i = firstbit((m) & (~0U << i + 1))) | ||
| 78 | |||
| 64 | #endif | 79 | #endif |
diff --git a/src/gestures.c b/src/gestures.c index 7346043..f44e6ab 100644 --- a/src/gestures.c +++ b/src/gestures.c | |||
| @@ -58,7 +58,6 @@ static void extract_pointers(struct Gestures *gs, struct MTouch* mt) | |||
| 58 | 58 | ||
| 59 | if (mt->state.nfinger < 2) { | 59 | if (mt->state.nfinger < 2) { |
| 60 | mt->mem.pointing = mt->state.nfinger; | 60 | mt->mem.pointing = mt->state.nfinger; |
| 61 | mt->mem.npoint = mt->state.nfinger; | ||
| 62 | mt->mem.ybar = mt->caps.abs_position_y.maximum; | 61 | mt->mem.ybar = mt->caps.abs_position_y.maximum; |
| 63 | return; | 62 | return; |
| 64 | } | 63 | } |
| @@ -69,7 +68,6 @@ static void extract_pointers(struct Gestures *gs, struct MTouch* mt) | |||
| 69 | continue; | 68 | continue; |
| 70 | if (f[i].hw.position_y <= mt->mem.ybar) { | 69 | if (f[i].hw.position_y <= mt->mem.ybar) { |
| 71 | mt->mem.pointing = BITONES(mt->state.nfinger); | 70 | mt->mem.pointing = BITONES(mt->state.nfinger); |
| 72 | mt->mem.npoint = mt->state.nfinger; | ||
| 73 | return; | 71 | return; |
| 74 | } | 72 | } |
| 75 | } | 73 | } |
| @@ -77,15 +75,13 @@ static void extract_pointers(struct Gestures *gs, struct MTouch* mt) | |||
| 77 | } | 75 | } |
| 78 | 76 | ||
| 79 | mt->mem.pointing = 0; | 77 | mt->mem.pointing = 0; |
| 80 | mt->mem.npoint = 0; | ||
| 81 | mt->mem.ybar = mt->caps.yclick; | 78 | mt->mem.ybar = mt->caps.yclick; |
| 82 | for (i = 0; i < mt->state.nfinger; i++) { | 79 | for (i = 0; i < mt->state.nfinger; i++) { |
| 83 | if (f[i].hw.position_y > mt->caps.yclick) | 80 | if (f[i].hw.position_y > mt->caps.yclick) |
| 84 | continue; | 81 | continue; |
| 85 | if (!mt->mem.npoint || f[i].hw.position_y > mt->mem.ybar) | 82 | if (!mt->mem.pointing || f[i].hw.position_y > mt->mem.ybar) |
| 86 | mt->mem.ybar = f[i].hw.position_y; | 83 | mt->mem.ybar = f[i].hw.position_y; |
| 87 | SETBIT(mt->mem.pointing, i); | 84 | SETBIT(mt->mem.pointing, i); |
| 88 | mt->mem.npoint++; | ||
| 89 | } | 85 | } |
| 90 | 86 | ||
| 91 | } | 87 | } |
| @@ -97,7 +93,6 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt) | |||
| 97 | int dx, dy, xcut, ycut, xmax = 0, ymax = 0; | 93 | int dx, dy, xcut, ycut, xmax = 0, ymax = 0; |
| 98 | 94 | ||
| 99 | mt->mem.moving = 0; | 95 | mt->mem.moving = 0; |
| 100 | mt->mem.nmove = 0; | ||
| 101 | 96 | ||
| 102 | if (mt->state.nfinger == 0) | 97 | if (mt->state.nfinger == 0) |
| 103 | return; | 98 | return; |
| @@ -128,22 +123,21 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt) | |||
| 128 | if (!GETBIT(mt->mem.pointing, i)) | 123 | if (!GETBIT(mt->mem.pointing, i)) |
| 129 | continue; | 124 | continue; |
| 130 | if (abs(mt->mem.dx[i]) > xcut || | 125 | if (abs(mt->mem.dx[i]) > xcut || |
| 131 | abs(mt->mem.dy[i]) > ycut) { | 126 | abs(mt->mem.dy[i]) > ycut) |
| 132 | SETBIT(mt->mem.moving, i); | 127 | SETBIT(mt->mem.moving, i); |
| 133 | mt->mem.nmove++; | ||
| 134 | } | ||
| 135 | } | 128 | } |
| 136 | 129 | ||
| 137 | /* accumulate all movement during delay */ | 130 | /* accumulate all movement during delay */ |
| 138 | if (mt->mem.nmove && mt->state.evtime >= mt->mem.move_time) { | 131 | if (mt->mem.moving && mt->state.evtime >= mt->mem.move_time) { |
| 132 | int nmove = bitcount(mt->mem.moving); | ||
| 139 | for (i = 0; i < mt->state.nfinger; i++) { | 133 | for (i = 0; i < mt->state.nfinger; i++) { |
| 140 | if (GETBIT(mt->mem.moving, i)) { | 134 | if (GETBIT(mt->mem.moving, i)) { |
| 141 | gs->dx += mt->mem.dx[i]; | 135 | gs->dx += mt->mem.dx[i]; |
| 142 | gs->dy += mt->mem.dy[i]; | 136 | gs->dy += mt->mem.dy[i]; |
| 143 | } | 137 | } |
| 144 | } | 138 | } |
| 145 | gs->dx /= mt->mem.nmove; | 139 | gs->dx /= nmove; |
| 146 | gs->dy /= mt->mem.nmove; | 140 | gs->dy /= nmove; |
| 147 | memset(mt->mem.dx, 0, sizeof(mt->mem.dx)); | 141 | memset(mt->mem.dx, 0, sizeof(mt->mem.dx)); |
| 148 | memset(mt->mem.dy, 0, sizeof(mt->mem.dy)); | 142 | memset(mt->mem.dy, 0, sizeof(mt->mem.dy)); |
| 149 | } | 143 | } |
| @@ -153,10 +147,11 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt) | |||
| 153 | static void extract_buttons(struct Gestures *gs, struct MTouch* mt) | 147 | static void extract_buttons(struct Gestures *gs, struct MTouch* mt) |
| 154 | { | 148 | { |
| 155 | unsigned btdata = mt->state.button & BITONES(DIM_BUTTON); | 149 | unsigned btdata = mt->state.button & BITONES(DIM_BUTTON); |
| 150 | int npoint = bitcount(mt->mem.pointing); | ||
| 156 | if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) { | 151 | if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) { |
| 157 | if (mt->mem.npoint == 2) | 152 | if (npoint == 2) |
| 158 | btdata = BITMASK(MT_BUTTON_RIGHT); | 153 | btdata = BITMASK(MT_BUTTON_RIGHT); |
| 159 | if (mt->mem.npoint == 3) | 154 | if (npoint == 3) |
| 160 | btdata = BITMASK(MT_BUTTON_MIDDLE); | 155 | btdata = BITMASK(MT_BUTTON_MIDDLE); |
| 161 | } | 156 | } |
| 162 | if (mt->state.button != mt->prev_state.button) { | 157 | if (mt->state.button != mt->prev_state.button) { |
| @@ -170,18 +165,19 @@ static void extract_buttons(struct Gestures *gs, struct MTouch* mt) | |||
| 170 | 165 | ||
| 171 | static void extract_type(struct Gestures *gs, struct MTouch* mt) | 166 | static void extract_type(struct Gestures *gs, struct MTouch* mt) |
| 172 | { | 167 | { |
| 168 | int npoint = bitcount(mt->mem.pointing); | ||
| 173 | if (gs->btmask) | 169 | if (gs->btmask) |
| 174 | SETBIT(gs->type, GS_BUTTON); | 170 | SETBIT(gs->type, GS_BUTTON); |
| 175 | if (gs->dx || gs->dy) { | 171 | if (gs->dx || gs->dy) { |
| 176 | if (mt->mem.npoint == 1) | 172 | if (npoint == 1) |
| 177 | SETBIT(gs->type, GS_MOVE); | 173 | SETBIT(gs->type, GS_MOVE); |
| 178 | if (mt->mem.npoint == 2) { | 174 | if (npoint == 2) { |
| 179 | if (gs->dx) | 175 | if (gs->dx) |
| 180 | SETBIT(gs->type, GS_HSCROLL); | 176 | SETBIT(gs->type, GS_HSCROLL); |
| 181 | if (gs->dy) | 177 | if (gs->dy) |
| 182 | SETBIT(gs->type, GS_VSCROLL); | 178 | SETBIT(gs->type, GS_VSCROLL); |
| 183 | } | 179 | } |
| 184 | if (mt->mem.npoint == 3) { | 180 | if (npoint == 3) { |
| 185 | if (gs->dx) | 181 | if (gs->dx) |
| 186 | SETBIT(gs->type, GS_HSWIPE); | 182 | SETBIT(gs->type, GS_HSWIPE); |
| 187 | if (gs->dy) | 183 | if (gs->dy) |
diff --git a/src/memory.c b/src/memory.c index 15b483c..0e2edba 100644 --- a/src/memory.c +++ b/src/memory.c | |||
| @@ -32,8 +32,6 @@ void output_memory(const struct Memory *m) | |||
| 32 | xf86Msg(X_INFO, "btdata: %04x\n", m->btdata); | 32 | xf86Msg(X_INFO, "btdata: %04x\n", m->btdata); |
| 33 | xf86Msg(X_INFO, "pointing: %04x\n", m->pointing); | 33 | xf86Msg(X_INFO, "pointing: %04x\n", m->pointing); |
| 34 | xf86Msg(X_INFO, "moving: %04x\n", m->moving); | 34 | xf86Msg(X_INFO, "moving: %04x\n", m->moving); |
| 35 | xf86Msg(X_INFO, "npoint: %d\n", m->npoint); | ||
| 36 | xf86Msg(X_INFO, "ybar: %d\n", m->ybar); | 35 | xf86Msg(X_INFO, "ybar: %d\n", m->ybar); |
| 37 | xf86Msg(X_INFO, "move_time: %lld\n", m->move_time); | 36 | xf86Msg(X_INFO, "move_time: %lld\n", m->move_time); |
| 38 | xf86Msg(X_INFO, "nmove: %d\n", m->nmove); | ||
| 39 | } | 37 | } |
diff --git a/src/memory.h b/src/memory.h index 81cdae0..23d2ce6 100644 --- a/src/memory.h +++ b/src/memory.h | |||
| @@ -26,9 +26,9 @@ | |||
| 26 | 26 | ||
| 27 | struct Memory { | 27 | struct Memory { |
| 28 | unsigned btdata, pointing, moving; | 28 | unsigned btdata, pointing, moving; |
| 29 | int npoint, ybar; | 29 | int ybar; |
| 30 | mstime_t move_time; | 30 | mstime_t move_time; |
| 31 | int dx[DIM_FINGER], dy[DIM_FINGER], nmove; | 31 | int dx[DIM_FINGER], dy[DIM_FINGER]; |
| 32 | 32 | ||
| 33 | 33 | ||
| 34 | 34 | ||
| @@ -19,10 +19,23 @@ | |||
| 19 | * | 19 | * |
| 20 | **************************************************************************/ | 20 | **************************************************************************/ |
| 21 | 21 | ||
| 22 | #include "common.h" | ||
| 22 | #include <stdio.h> | 23 | #include <stdio.h> |
| 23 | #include <time.h> | 24 | #include <time.h> |
| 24 | 25 | ||
| 26 | static void print_bitfield(unsigned m) | ||
| 27 | { | ||
| 28 | int i; | ||
| 29 | |||
| 30 | printf("%d\n", m); | ||
| 31 | foreach_bit(i, m) | ||
| 32 | printf("%d %d\n", i, 1 << i); | ||
| 33 | } | ||
| 34 | |||
| 25 | int main(int argc, char *argv[]) | 35 | int main(int argc, char *argv[]) |
| 26 | { | 36 | { |
| 37 | print_bitfield(5); | ||
| 38 | print_bitfield(126); | ||
| 39 | print_bitfield(0); | ||
| 27 | return 0; | 40 | return 0; |
| 28 | } | 41 | } |
