diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2008-11-09 04:20:53 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2008-11-09 04:20:53 +0100 |
| commit | b8f7fdfe1b8974a6677e73cfe7c83da70a35f4ae (patch) | |
| tree | 544cbe58102898d9eab3c80fc5be1414670810bf | |
| parent | 7952ef288f490045a4ab19b510be32512f217324 (diff) | |
Gesture interface in place
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | src/gestures.c | 39 | ||||
| -rw-r--r-- | src/gestures.h | 25 | ||||
| -rw-r--r-- | src/mtouch.c | 7 | ||||
| -rw-r--r-- | src/mtouch.h | 1 | ||||
| -rw-r--r-- | src/multitouch.c | 46 |
6 files changed, 86 insertions, 33 deletions
| @@ -9,6 +9,7 @@ o_src = capabilities \ | |||
| 9 | hwdata \ | 9 | hwdata \ |
| 10 | state \ | 10 | state \ |
| 11 | mtouch \ | 11 | mtouch \ |
| 12 | gestures \ | ||
| 12 | multitouch | 13 | multitouch |
| 13 | 14 | ||
| 14 | TARGETS = $(addsuffix /test,$(MODULES)) | 15 | TARGETS = $(addsuffix /test,$(MODULES)) |
diff --git a/src/gestures.c b/src/gestures.c new file mode 100644 index 0000000..8dfb939 --- /dev/null +++ b/src/gestures.c | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | #include "gestures.h" | ||
| 2 | |||
| 3 | /******************************************************/ | ||
| 4 | |||
| 5 | void extract_gestures(struct Gestures *gs, struct MTouch* mt) | ||
| 6 | { | ||
| 7 | const struct FingerState *b = mt->ns.finger; | ||
| 8 | const struct FingerState *e = b + mt->ns.nfinger; | ||
| 9 | const struct FingerState *p, *fs; | ||
| 10 | int nof = count_fingers(&mt->os); | ||
| 11 | int nsf = count_fingers(&mt->ns); | ||
| 12 | int dn = 0, i; | ||
| 13 | memset(gs, 0, sizeof(struct Gestures)); | ||
| 14 | if (nof == nsf) { | ||
| 15 | for (p = b; p != e; p++) { | ||
| 16 | if (fs = find_finger(&mt->os, p->id)) { | ||
| 17 | gs->dx += p->hw.position_x - fs->hw.position_x; | ||
| 18 | gs->dy += p->hw.position_y - fs->hw.position_y; | ||
| 19 | dn++; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | } | ||
| 23 | if (gs->dx || gs->dy) { | ||
| 24 | gs->dx /= dn; | ||
| 25 | gs->dy /= dn; | ||
| 26 | if (nsf == 1) | ||
| 27 | SETBIT(gs->type, GS_MOVE); | ||
| 28 | } | ||
| 29 | for (i = 0; i < DIM_BUTTON; i++) { | ||
| 30 | if (GETBIT(mt->ns.button, i) != GETBIT(mt->os.button, i)) { | ||
| 31 | SETBIT(gs->type, GS_BUTTON); | ||
| 32 | gs->btix[gs->nbt] = i + 1; | ||
| 33 | gs->btval[gs->nbt] = GETBIT(mt->ns.button, i); | ||
| 34 | gs->nbt++; | ||
| 35 | } | ||
| 36 | } | ||
| 37 | mt->os = mt->ns; | ||
| 38 | } | ||
| 39 | |||
diff --git a/src/gestures.h b/src/gestures.h new file mode 100644 index 0000000..18ac920 --- /dev/null +++ b/src/gestures.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | #ifndef GESTURES_H | ||
| 2 | #define GESTURES_H | ||
| 3 | |||
| 4 | #include "mtouch.h" | ||
| 5 | |||
| 6 | //////////////////////////////////////////////////////// | ||
| 7 | |||
| 8 | #define GS_MOVE 0 | ||
| 9 | #define GS_BUTTON 1 | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////// | ||
| 12 | |||
| 13 | struct Gestures { | ||
| 14 | unsigned type; | ||
| 15 | int dx, dy; | ||
| 16 | int nbt, btix[DIM_BUTTON], btval[DIM_BUTTON]; | ||
| 17 | }; | ||
| 18 | |||
| 19 | //////////////////////////////////////////////////////// | ||
| 20 | |||
| 21 | void extract_gestures(struct Gestures *gs, struct MTouch* mt); | ||
| 22 | |||
| 23 | //////////////////////////////////////////////////////// | ||
| 24 | |||
| 25 | #endif | ||
diff --git a/src/mtouch.c b/src/mtouch.c index 6952611..ebe8f2a 100644 --- a/src/mtouch.c +++ b/src/mtouch.c | |||
| @@ -45,3 +45,10 @@ bool read_synchronized_event(struct MTouch *mt, int fd) | |||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | /******************************************************/ | 47 | /******************************************************/ |
| 48 | |||
| 49 | void parse_event(struct MTouch *mt) | ||
| 50 | { | ||
| 51 | modify_state(&mt->ns, &mt->hw, &mt->caps); | ||
| 52 | } | ||
| 53 | |||
| 54 | /******************************************************/ | ||
diff --git a/src/mtouch.h b/src/mtouch.h index 5edc6e5..c56e5a3 100644 --- a/src/mtouch.h +++ b/src/mtouch.h | |||
| @@ -22,6 +22,7 @@ int open_mtouch(struct MTouch *mt, int fd); | |||
| 22 | int close_mtouch(struct MTouch *mt, int fd); | 22 | int close_mtouch(struct MTouch *mt, int fd); |
| 23 | 23 | ||
| 24 | bool read_synchronized_event(struct MTouch *mt, int fd); | 24 | bool read_synchronized_event(struct MTouch *mt, int fd); |
| 25 | void parse_event(struct MTouch *mt); | ||
| 25 | 26 | ||
| 26 | //////////////////////////////////////////////////////// | 27 | //////////////////////////////////////////////////////// |
| 27 | 28 | ||
diff --git a/src/multitouch.c b/src/multitouch.c index cf06f97..8411718 100644 --- a/src/multitouch.c +++ b/src/multitouch.c | |||
| @@ -21,8 +21,7 @@ | |||
| 21 | * | 21 | * |
| 22 | **************************************************************************/ | 22 | **************************************************************************/ |
| 23 | 23 | ||
| 24 | #include "mtouch.h" | 24 | #include "gestures.h" |
| 25 | #include "mipointer.h" | ||
| 26 | 25 | ||
| 27 | //////////////////////////////////////////////////////////////////////////// | 26 | //////////////////////////////////////////////////////////////////////////// |
| 28 | 27 | ||
| @@ -123,40 +122,20 @@ static int device_close(LocalDevicePtr local) | |||
| 123 | 122 | ||
| 124 | //////////////////////////////////////////////////////////////////////////// | 123 | //////////////////////////////////////////////////////////////////////////// |
| 125 | 124 | ||
| 126 | static void handle_state(LocalDevicePtr local, | 125 | static void handle_gestures(LocalDevicePtr local, |
| 127 | const struct State *os, | 126 | const struct Gestures *gs) |
| 128 | const struct State *ns) | ||
| 129 | { | 127 | { |
| 130 | const struct FingerState *fs, *p, *e = ns->finger + ns->nfinger; | 128 | int i; |
| 131 | int dx = 0, dy = 0, dn = 0, n = 0, i; | 129 | if (GETBIT(gs->type, GS_MOVE)) { |
| 132 | if (count_fingers(ns) == count_fingers(os)) { | 130 | xf86PostMotionEvent(local->dev, 0, 0, 2, gs->dx, gs->dy); |
| 133 | for (p = ns->finger; p != e; p++) { | ||
| 134 | if (fs = find_finger(os, p->id)) { | ||
| 135 | dx += p->hw.position_x - fs->hw.position_x; | ||
| 136 | dy += p->hw.position_y - fs->hw.position_y; | ||
| 137 | dn++; | ||
| 138 | } | ||
| 139 | } | ||
| 140 | } | ||
| 141 | if (dx || dy) { | ||
| 142 | dx /= dn; | ||
| 143 | dy /= dn; | ||
| 144 | xf86PostMotionEvent(local->dev, 0, 0, 2, dx, dy); | ||
| 145 | //xf86Msg(X_INFO, "motion: %d %d\n", dx, dy); | 131 | //xf86Msg(X_INFO, "motion: %d %d\n", dx, dy); |
| 146 | n++; | ||
| 147 | } | 132 | } |
| 148 | for (i = 0; i < DIM_BUTTON; i++) { | 133 | if (GETBIT(gs->type, GS_BUTTON)) { |
| 149 | if (GETBIT(ns->button, i) != GETBIT(os->button, i)) { | 134 | for (i = 0; i < gs->nbt; i++) |
| 150 | xf86PostButtonEvent(local->dev, FALSE, | 135 | xf86PostButtonEvent(local->dev, FALSE, |
| 151 | i + 1, GETBIT(ns->button, i), | 136 | gs->btix[i], gs->btval[i], |
| 152 | 0, 0); | 137 | 0, 0); |
| 153 | //xf86Msg(X_INFO, "button: %d -> %d\n", | ||
| 154 | //i, GETBIT(ns->button, i)); | ||
| 155 | n++; | ||
| 156 | } | ||
| 157 | } | 138 | } |
| 158 | //if (n) | ||
| 159 | //output_state(ns); | ||
| 160 | } | 139 | } |
| 161 | 140 | ||
| 162 | //////////////////////////////////////////////////////////////////////////// | 141 | //////////////////////////////////////////////////////////////////////////// |
| @@ -164,11 +143,12 @@ static void handle_state(LocalDevicePtr local, | |||
| 164 | /* called for each full received packet from the touchpad */ | 143 | /* called for each full received packet from the touchpad */ |
| 165 | static void read_input(LocalDevicePtr local) | 144 | static void read_input(LocalDevicePtr local) |
| 166 | { | 145 | { |
| 146 | struct Gestures gs; | ||
| 167 | struct MTouch *mt = local->private; | 147 | struct MTouch *mt = local->private; |
| 168 | while (read_synchronized_event(mt, local->fd)) { | 148 | while (read_synchronized_event(mt, local->fd)) { |
| 169 | modify_state(&mt->ns, &mt->hw, &mt->caps); | 149 | parse_event(mt); |
| 170 | handle_state(local, &mt->os, &mt->ns); | 150 | extract_gestures(&gs, mt); |
| 171 | mt->os = mt->ns; | 151 | handle_gestures(local, &gs); |
| 172 | } | 152 | } |
| 173 | } | 153 | } |
| 174 | 154 | ||
