From a0a4c6c30704a792193ff49d7fcaab63dac8a07a Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 28 Mar 2011 20:55:29 +0200 Subject: Introduce touch gesture events Touch gesture events follow the same logic as drags, except they cannot be held back but are emitted immediately. Signed-off-by: Henrik Rydberg --- include/grail-types.h | 28 +++++++++++++++ src/Makefile.am | 1 + src/gestures-touch.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/grail-gestures.h | 4 +++ src/grail-inserter.c | 22 +++++++----- src/grail-inserter.h | 1 + src/grail-recognizer.c | 2 ++ src/grail-recognizer.h | 2 ++ 8 files changed, 146 insertions(+), 8 deletions(-) create mode 100644 src/gestures-touch.c diff --git a/include/grail-types.h b/include/grail-types.h index f274963..840ece3 100644 --- a/include/grail-types.h +++ b/include/grail-types.h @@ -59,11 +59,20 @@ #define GRAIL_TYPE_SYSFLAG1 26 /* reserved system flag */ +#define GRAIL_TYPE_TOUCH1 32 /* one-finger touch */ +#define GRAIL_TYPE_TOUCH2 33 /* two-finger touch */ +#define GRAIL_TYPE_TOUCH3 34 /* three-finger touch */ +#define GRAIL_TYPE_TOUCH4 35 /* four-finger touch */ +#define GRAIL_TYPE_TOUCH5 36 /* five-finger touch */ +#define GRAIL_TYPE_ETOUCH 37 /* three-finger environment touch */ +#define GRAIL_TYPE_MTOUCH 38 /* four-finger meta touch */ + #define GRAIL_MAIN_DRAG 0 #define GRAIL_MAIN_PINCH 1 #define GRAIL_MAIN_ROTATE 2 #define GRAIL_MAIN_TAP 3 #define GRAIL_MAIN_SYSFLAG 4 +#define GRAIL_MAIN_TOUCH 5 #define GRAIL_PROP_DRAG_DX 0 /* horizontal position delta */ #define GRAIL_PROP_DRAG_DY 1 /* vertical position delta */ @@ -160,5 +169,24 @@ #define GRAIL_PROP_TAP_X_T4 20 #define GRAIL_PROP_TAP_Y_T4 21 +#define GRAIL_PROP_TOUCH_X1 0 /* bounding box x1 */ +#define GRAIL_PROP_TOUCH_Y1 1 /* bounding box y1 */ +#define GRAIL_PROP_TOUCH_X2 2 /* bounding box x2 */ +#define GRAIL_PROP_TOUCH_Y2 3 /* bounding box y2 */ +#define GRAIL_PROP_TOUCH_ID_T0 4 /* first touch id */ +#define GRAIL_PROP_TOUCH_X_T0 5 /* first touch horizontal position */ +#define GRAIL_PROP_TOUCH_Y_T0 6 /* first touch vertical position */ +#define GRAIL_PROP_TOUCH_ID_T1 7 +#define GRAIL_PROP_TOUCH_X_T1 8 +#define GRAIL_PROP_TOUCH_Y_T1 9 +#define GRAIL_PROP_TOUCH_ID_T2 10 +#define GRAIL_PROP_TOUCH_X_T2 11 +#define GRAIL_PROP_TOUCH_Y_T2 12 +#define GRAIL_PROP_TOUCH_ID_T3 13 +#define GRAIL_PROP_TOUCH_X_T3 14 +#define GRAIL_PROP_TOUCH_Y_T3 15 +#define GRAIL_PROP_TOUCH_ID_T4 16 +#define GRAIL_PROP_TOUCH_X_T4 17 +#define GRAIL_PROP_TOUCH_Y_T4 18 #endif diff --git a/src/Makefile.am b/src/Makefile.am index 855d428..da1a46e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,7 @@ libutouch_grail_la_SOURCES = \ grail-inserter.h \ grail-gestures.c \ grail-gestures.h \ + gestures-touch.c \ gestures-drag.c \ gestures-pinch.c \ gestures-rotate.c \ diff --git a/src/gestures-touch.c b/src/gestures-touch.c new file mode 100644 index 0000000..b6a2706 --- /dev/null +++ b/src/gestures-touch.c @@ -0,0 +1,94 @@ +/***************************************************************************** + * + * grail - Gesture Recognition And Instantiation Library + * + * Copyright (C) 2010 Canonical Ltd. + * Copyright (C) 2010 Henrik Rydberg + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + ****************************************************************************/ + +#include "grail-recognizer.h" +#include +#include + +static const int getype[DIM_TOUCH + 1] = { + -1, + GRAIL_TYPE_TOUCH1, + GRAIL_TYPE_TOUCH2, + GRAIL_TYPE_TOUCH3, + GRAIL_TYPE_TOUCH4, + GRAIL_TYPE_TOUCH5, +}; + +int gru_touch(struct grail *ge, + const struct utouch_frame *frame) +{ + struct gesture_recognizer *gru = ge->gru; + struct combo_model *state = &gru->touch; + struct move_model *move = &gru->move; + if (frame->slot_revision != frame->prev->slot_revision) { + if (state->active) { + gru_end(ge, state->gid, move, + state->prop, state->nprop); + state->active = 0; + } + } + if (!state->active) { + int type = getype[move->ntouch]; + if (type <= 0) + return 0; + state->gid = gin_gid_begin(ge, type, -PRIO_GESTURE, frame); + state->active = 1; + } + state->nprop = gin_add_contact_props(ge->gin, state->prop, frame); + gru_event(ge, state->gid, move, state->prop, state->nprop); + return 1; +} + +int gru_wintouch(struct grail *ge, + const struct utouch_frame *frame) +{ + struct gesture_recognizer *gru = ge->gru; + struct combo_model *state = &gru->wintouch; + struct move_model *move = &gru->move; + if (frame->slot_revision != frame->prev->slot_revision) { + if (state->active && out_of_bounds(state, move)) { + gru_end(ge, state->gid, move, + state->prop, state->nprop); + state->active = 0; + } + } + if (!state->active) { + if (move->ntouch == 4) { + state->gid = gin_gid_begin(ge, GRAIL_TYPE_MTOUCH, + -PRIO_META, frame); + state->mintouch = 1; + state->maxtouch = 4; + state->active = 1; + } else if (move->ntouch == 3) { + state->gid = gin_gid_begin(ge, GRAIL_TYPE_ETOUCH, + -PRIO_ENV, frame); + state->mintouch = 1; + state->maxtouch = 3; + state->active = 1; + } else { + return 0; + } + } + state->nprop = gin_add_contact_props(ge->gin, state->prop, frame); + gru_event(ge, state->gid, move, state->prop, state->nprop); + return 1; +} diff --git a/src/grail-gestures.h b/src/grail-gestures.h index d92a24b..a24bbbd 100644 --- a/src/grail-gestures.h +++ b/src/grail-gestures.h @@ -77,6 +77,8 @@ struct combo_model { grail_prop_t prop[DIM_GRAIL_PROP]; }; +int gru_touch(struct grail *ge, + const struct utouch_frame *frame); int gru_drag(struct grail *ge, const struct utouch_frame *frame); int gru_pinch(struct grail *ge, @@ -90,6 +92,8 @@ static inline int out_of_bounds(const struct combo_model *s, return m->ntouch < s->mintouch || m->ntouch > s->maxtouch; } +int gru_wintouch(struct grail *ge, + const struct utouch_frame *frame); int gru_windrag(struct grail *ge, const struct utouch_frame *frame); int gru_winpinch(struct grail *ge, diff --git a/src/grail-inserter.c b/src/grail-inserter.c index ff4f0b6..1ee8e5a 100644 --- a/src/grail-inserter.c +++ b/src/grail-inserter.c @@ -119,7 +119,7 @@ void gin_frame_begin(struct grail *ge, const struct utouch_frame *frame) void gin_frame_end(struct grail *ge, const struct utouch_frame *frame) { struct gesture_inserter *gin = ge->gin; - int i, hold = 0, discard = 0; + int i, hold[2] = { 0, 0 }, discard[2] = { 0, 0 }; setup_new_gestures(ge, frame); @@ -127,17 +127,17 @@ void gin_frame_end(struct grail *ge, const struct utouch_frame *frame) struct slot_state *s = &gin->state[i]; if (!s->nclient) continue; - if (s->priority > hold) - hold = s->priority; + if (s->priority > hold[s->slice]) + hold[s->slice] = s->priority; if (s->status != GRAIL_STATUS_UPDATE) continue; - if (s->priority > discard) - discard = s->priority; + if (s->priority > discard[s->slice]) + discard[s->slice] = s->priority; } grail_mask_foreach(i, gin->used, sizeof(gin->used)) { struct slot_state *s = &gin->state[i]; - if (!s->nclient || s->priority < discard) + if (!s->nclient || s->priority < discard[s->slice]) gin_gid_discard(ge, s->id); } @@ -145,7 +145,7 @@ void gin_frame_end(struct grail *ge, const struct utouch_frame *frame) struct slot_state *s = &gin->state[i]; struct gesture_event ev; grail_mask_set(gin->types, s->type); - if (s->priority < hold) + if (s->priority < hold[s->slice]) continue; while (!gebuf_empty(&s->buf)) { gebuf_get(&s->buf, &ev); @@ -171,7 +171,13 @@ int gin_gid_begin(struct grail *ge, int type, int priority, return -1; s = &gin->state[i]; s->type = type; - s->priority = priority; + if (priority < 0) { + s->priority = -priority; + s->slice = 1; + } else { + s->priority = priority; + s->slice = 0; + } s->id = gin->gestureid++ & MAX_GESTURE_ID; s->status = GRAIL_STATUS_BEGIN; s->nclient = 0; diff --git a/src/grail-inserter.h b/src/grail-inserter.h index fb944dd..12d0dc9 100644 --- a/src/grail-inserter.h +++ b/src/grail-inserter.h @@ -37,6 +37,7 @@ struct slot_state { int type; int priority; + int slice; int id; int status; int nclient; diff --git a/src/grail-recognizer.c b/src/grail-recognizer.c index fb0ae85..5bc27ff 100644 --- a/src/grail-recognizer.c +++ b/src/grail-recognizer.c @@ -47,9 +47,11 @@ void gru_recognize(struct grail *ge, const struct utouch_frame *frame) if (!ge->gin || !ge->gru) return; gru_motion(ge, frame); + gru_touch(ge, frame); gru_drag(ge, frame); gru_pinch(ge, frame); gru_rotate(ge, frame); + gru_wintouch(ge, frame); gru_windrag(ge, frame); gru_winpinch(ge, frame); gru_winrotate(ge, frame); diff --git a/src/grail-recognizer.h b/src/grail-recognizer.h index 56e5b8d..3844511 100644 --- a/src/grail-recognizer.h +++ b/src/grail-recognizer.h @@ -27,9 +27,11 @@ struct gesture_recognizer { struct move_model move; + struct combo_model touch; struct combo_model drag; struct combo_model pinch; struct combo_model rotate; + struct combo_model wintouch; struct combo_model windrag; struct combo_model winpinch; struct combo_model winrotate; -- cgit v1.2.3