From b8f7fdfe1b8974a6677e73cfe7c83da70a35f4ae Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Sun, 9 Nov 2008 04:20:53 +0100 Subject: Gesture interface in place Signed-off-by: Henrik Rydberg --- src/gestures.c | 39 +++++++++++++++++++++++++++++++++++++++ src/gestures.h | 25 +++++++++++++++++++++++++ src/mtouch.c | 7 +++++++ src/mtouch.h | 1 + src/multitouch.c | 46 +++++++++++++--------------------------------- 5 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 src/gestures.c create mode 100644 src/gestures.h (limited to 'src') 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 @@ +#include "gestures.h" + +/******************************************************/ + +void extract_gestures(struct Gestures *gs, struct MTouch* mt) +{ + const struct FingerState *b = mt->ns.finger; + const struct FingerState *e = b + mt->ns.nfinger; + const struct FingerState *p, *fs; + int nof = count_fingers(&mt->os); + int nsf = count_fingers(&mt->ns); + int dn = 0, i; + memset(gs, 0, sizeof(struct Gestures)); + if (nof == nsf) { + for (p = b; p != e; p++) { + if (fs = find_finger(&mt->os, p->id)) { + gs->dx += p->hw.position_x - fs->hw.position_x; + gs->dy += p->hw.position_y - fs->hw.position_y; + dn++; + } + } + } + if (gs->dx || gs->dy) { + gs->dx /= dn; + gs->dy /= dn; + if (nsf == 1) + SETBIT(gs->type, GS_MOVE); + } + for (i = 0; i < DIM_BUTTON; i++) { + if (GETBIT(mt->ns.button, i) != GETBIT(mt->os.button, i)) { + SETBIT(gs->type, GS_BUTTON); + gs->btix[gs->nbt] = i + 1; + gs->btval[gs->nbt] = GETBIT(mt->ns.button, i); + gs->nbt++; + } + } + mt->os = mt->ns; +} + 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 @@ +#ifndef GESTURES_H +#define GESTURES_H + +#include "mtouch.h" + +//////////////////////////////////////////////////////// + +#define GS_MOVE 0 +#define GS_BUTTON 1 + +//////////////////////////////////////////////////////// + +struct Gestures { + unsigned type; + int dx, dy; + int nbt, btix[DIM_BUTTON], btval[DIM_BUTTON]; +}; + +//////////////////////////////////////////////////////// + +void extract_gestures(struct Gestures *gs, struct MTouch* mt); + +//////////////////////////////////////////////////////// + +#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) } /******************************************************/ + +void parse_event(struct MTouch *mt) +{ + modify_state(&mt->ns, &mt->hw, &mt->caps); +} + +/******************************************************/ 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); int close_mtouch(struct MTouch *mt, int fd); bool read_synchronized_event(struct MTouch *mt, int fd); +void parse_event(struct MTouch *mt); //////////////////////////////////////////////////////// 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 @@ * **************************************************************************/ -#include "mtouch.h" -#include "mipointer.h" +#include "gestures.h" //////////////////////////////////////////////////////////////////////////// @@ -123,40 +122,20 @@ static int device_close(LocalDevicePtr local) //////////////////////////////////////////////////////////////////////////// -static void handle_state(LocalDevicePtr local, - const struct State *os, - const struct State *ns) +static void handle_gestures(LocalDevicePtr local, + const struct Gestures *gs) { - const struct FingerState *fs, *p, *e = ns->finger + ns->nfinger; - int dx = 0, dy = 0, dn = 0, n = 0, i; - if (count_fingers(ns) == count_fingers(os)) { - for (p = ns->finger; p != e; p++) { - if (fs = find_finger(os, p->id)) { - dx += p->hw.position_x - fs->hw.position_x; - dy += p->hw.position_y - fs->hw.position_y; - dn++; - } - } - } - if (dx || dy) { - dx /= dn; - dy /= dn; - xf86PostMotionEvent(local->dev, 0, 0, 2, dx, dy); + int i; + if (GETBIT(gs->type, GS_MOVE)) { + xf86PostMotionEvent(local->dev, 0, 0, 2, gs->dx, gs->dy); //xf86Msg(X_INFO, "motion: %d %d\n", dx, dy); - n++; } - for (i = 0; i < DIM_BUTTON; i++) { - if (GETBIT(ns->button, i) != GETBIT(os->button, i)) { + if (GETBIT(gs->type, GS_BUTTON)) { + for (i = 0; i < gs->nbt; i++) xf86PostButtonEvent(local->dev, FALSE, - i + 1, GETBIT(ns->button, i), + gs->btix[i], gs->btval[i], 0, 0); - //xf86Msg(X_INFO, "button: %d -> %d\n", - //i, GETBIT(ns->button, i)); - n++; - } } - //if (n) - //output_state(ns); } //////////////////////////////////////////////////////////////////////////// @@ -164,11 +143,12 @@ static void handle_state(LocalDevicePtr local, /* called for each full received packet from the touchpad */ static void read_input(LocalDevicePtr local) { + struct Gestures gs; struct MTouch *mt = local->private; while (read_synchronized_event(mt, local->fd)) { - modify_state(&mt->ns, &mt->hw, &mt->caps); - handle_state(local, &mt->os, &mt->ns); - mt->os = mt->ns; + parse_event(mt); + extract_gestures(&gs, mt); + handle_gestures(local, &gs); } } -- cgit v1.2.3