diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-08-19 22:15:55 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-08-19 22:15:55 +0200 |
| commit | 76f51a7675801acfe8e58c6a21192668d23d3320 (patch) | |
| tree | 73109e613e93fbb8f20fabdbec9f7e0d5356f4dd | |
| parent | 8331322a0fec7277366a29a970eafbb795c08432 (diff) | |
Add contact information to the property list
Add the five first contacts to the property list, and unify the
handling of all gesture types in this regard. To avoid duplication,
move the scaling of properties closer to the gesture recognizer.
Move all gesture event handling code to grail-event.c, simplifying
the structure somewhat.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
| -rw-r--r-- | include/grail-types.h | 69 | ||||
| -rw-r--r-- | src/gestures-drag.c | 29 | ||||
| -rw-r--r-- | src/gestures-pinch.c | 23 | ||||
| -rw-r--r-- | src/gestures-rotate.c | 17 | ||||
| -rw-r--r-- | src/gestures-tapping.c | 17 | ||||
| -rw-r--r-- | src/grail-event.c | 93 | ||||
| -rw-r--r-- | src/grail-gestures.c | 25 | ||||
| -rw-r--r-- | src/grail-gestures.h | 2 | ||||
| -rw-r--r-- | src/grail-inserter.c | 124 | ||||
| -rw-r--r-- | src/grail-inserter.h | 12 |
10 files changed, 220 insertions, 191 deletions
diff --git a/include/grail-types.h b/include/grail-types.h index de9197b..f274963 100644 --- a/include/grail-types.h +++ b/include/grail-types.h | |||
| @@ -71,6 +71,25 @@ | |||
| 71 | #define GRAIL_PROP_DRAG_VY 3 /* vertical velocity */ | 71 | #define GRAIL_PROP_DRAG_VY 3 /* vertical velocity */ |
| 72 | #define GRAIL_PROP_DRAG_X 4 /* horizontal position */ | 72 | #define GRAIL_PROP_DRAG_X 4 /* horizontal position */ |
| 73 | #define GRAIL_PROP_DRAG_Y 5 /* vertical position */ | 73 | #define GRAIL_PROP_DRAG_Y 5 /* vertical position */ |
| 74 | #define GRAIL_PROP_DRAG_X1 6 /* bounding box x1 */ | ||
| 75 | #define GRAIL_PROP_DRAG_Y1 7 /* bounding box y1 */ | ||
| 76 | #define GRAIL_PROP_DRAG_X2 8 /* bounding box x2 */ | ||
| 77 | #define GRAIL_PROP_DRAG_Y2 9 /* bounding box y2 */ | ||
| 78 | #define GRAIL_PROP_DRAG_ID_T0 10 /* first touch id */ | ||
| 79 | #define GRAIL_PROP_DRAG_X_T0 11 /* first touch horizontal position */ | ||
| 80 | #define GRAIL_PROP_DRAG_Y_T0 12 /* first touch vertical position */ | ||
| 81 | #define GRAIL_PROP_DRAG_ID_T1 13 | ||
| 82 | #define GRAIL_PROP_DRAG_X_T1 14 | ||
| 83 | #define GRAIL_PROP_DRAG_Y_T1 15 | ||
| 84 | #define GRAIL_PROP_DRAG_ID_T2 16 | ||
| 85 | #define GRAIL_PROP_DRAG_X_T2 17 | ||
| 86 | #define GRAIL_PROP_DRAG_Y_T2 18 | ||
| 87 | #define GRAIL_PROP_DRAG_ID_T3 19 | ||
| 88 | #define GRAIL_PROP_DRAG_X_T3 20 | ||
| 89 | #define GRAIL_PROP_DRAG_Y_T3 21 | ||
| 90 | #define GRAIL_PROP_DRAG_ID_T4 22 | ||
| 91 | #define GRAIL_PROP_DRAG_X_T4 23 | ||
| 92 | #define GRAIL_PROP_DRAG_Y_T4 24 | ||
| 74 | 93 | ||
| 75 | #define GRAIL_PROP_PINCH_DR 0 /* radius delta */ | 94 | #define GRAIL_PROP_PINCH_DR 0 /* radius delta */ |
| 76 | #define GRAIL_PROP_PINCH_VR 1 /* radial velocity */ | 95 | #define GRAIL_PROP_PINCH_VR 1 /* radial velocity */ |
| @@ -79,6 +98,21 @@ | |||
| 79 | #define GRAIL_PROP_PINCH_Y1 4 /* bounding box y1 */ | 98 | #define GRAIL_PROP_PINCH_Y1 4 /* bounding box y1 */ |
| 80 | #define GRAIL_PROP_PINCH_X2 5 /* bounding box x2 */ | 99 | #define GRAIL_PROP_PINCH_X2 5 /* bounding box x2 */ |
| 81 | #define GRAIL_PROP_PINCH_Y2 6 /* bounding box y2 */ | 100 | #define GRAIL_PROP_PINCH_Y2 6 /* bounding box y2 */ |
| 101 | #define GRAIL_PROP_PINCH_ID_T0 7 /* first touch id */ | ||
| 102 | #define GRAIL_PROP_PINCH_X_T0 8 /* first touch horizontal position */ | ||
| 103 | #define GRAIL_PROP_PINCH_Y_T0 9 /* first touch vertical position */ | ||
| 104 | #define GRAIL_PROP_PINCH_ID_T1 10 | ||
| 105 | #define GRAIL_PROP_PINCH_X_T1 11 | ||
| 106 | #define GRAIL_PROP_PINCH_Y_T1 12 | ||
| 107 | #define GRAIL_PROP_PINCH_ID_T2 13 | ||
| 108 | #define GRAIL_PROP_PINCH_X_T2 14 | ||
| 109 | #define GRAIL_PROP_PINCH_Y_T2 15 | ||
| 110 | #define GRAIL_PROP_PINCH_ID_T3 16 | ||
| 111 | #define GRAIL_PROP_PINCH_X_T3 17 | ||
| 112 | #define GRAIL_PROP_PINCH_Y_T3 18 | ||
| 113 | #define GRAIL_PROP_PINCH_ID_T4 19 | ||
| 114 | #define GRAIL_PROP_PINCH_X_T4 20 | ||
| 115 | #define GRAIL_PROP_PINCH_Y_T4 21 | ||
| 82 | 116 | ||
| 83 | #define GRAIL_PROP_ROTATE_DA 0 /* angle delta */ | 117 | #define GRAIL_PROP_ROTATE_DA 0 /* angle delta */ |
| 84 | #define GRAIL_PROP_ROTATE_VA 1 /* angular velocity */ | 118 | #define GRAIL_PROP_ROTATE_VA 1 /* angular velocity */ |
| @@ -87,9 +121,44 @@ | |||
| 87 | #define GRAIL_PROP_ROTATE_Y1 4 /* bounding box y1 */ | 121 | #define GRAIL_PROP_ROTATE_Y1 4 /* bounding box y1 */ |
| 88 | #define GRAIL_PROP_ROTATE_X2 5 /* bounding box x2 */ | 122 | #define GRAIL_PROP_ROTATE_X2 5 /* bounding box x2 */ |
| 89 | #define GRAIL_PROP_ROTATE_Y2 6 /* bounding box y2 */ | 123 | #define GRAIL_PROP_ROTATE_Y2 6 /* bounding box y2 */ |
| 124 | #define GRAIL_PROP_ROTATE_ID_T0 7 /* first touch id */ | ||
| 125 | #define GRAIL_PROP_ROTATE_X_T0 8 /* first touch horizontal position */ | ||
| 126 | #define GRAIL_PROP_ROTATE_Y_T0 9 /* first touch vertical position */ | ||
| 127 | #define GRAIL_PROP_ROTATE_ID_T1 10 | ||
| 128 | #define GRAIL_PROP_ROTATE_X_T1 11 | ||
| 129 | #define GRAIL_PROP_ROTATE_Y_T1 12 | ||
| 130 | #define GRAIL_PROP_ROTATE_ID_T2 13 | ||
| 131 | #define GRAIL_PROP_ROTATE_X_T2 14 | ||
| 132 | #define GRAIL_PROP_ROTATE_Y_T2 15 | ||
| 133 | #define GRAIL_PROP_ROTATE_ID_T3 16 | ||
| 134 | #define GRAIL_PROP_ROTATE_X_T3 17 | ||
| 135 | #define GRAIL_PROP_ROTATE_Y_T3 18 | ||
| 136 | #define GRAIL_PROP_ROTATE_ID_T4 19 | ||
| 137 | #define GRAIL_PROP_ROTATE_X_T4 20 | ||
| 138 | #define GRAIL_PROP_ROTATE_Y_T4 21 | ||
| 90 | 139 | ||
| 91 | #define GRAIL_PROP_TAP_DT 0 /* tap time (ms) */ | 140 | #define GRAIL_PROP_TAP_DT 0 /* tap time (ms) */ |
| 92 | #define GRAIL_PROP_TAP_X 1 /* horizontal position */ | 141 | #define GRAIL_PROP_TAP_X 1 /* horizontal position */ |
| 93 | #define GRAIL_PROP_TAP_Y 2 /* vertical position */ | 142 | #define GRAIL_PROP_TAP_Y 2 /* vertical position */ |
| 143 | #define GRAIL_PROP_TAP_X1 3 /* bounding box x1 */ | ||
| 144 | #define GRAIL_PROP_TAP_Y1 4 /* bounding box y1 */ | ||
| 145 | #define GRAIL_PROP_TAP_X2 5 /* bounding box x2 */ | ||
| 146 | #define GRAIL_PROP_TAP_Y2 6 /* bounding box y2 */ | ||
| 147 | #define GRAIL_PROP_TAP_ID_T0 7 /* first touch id */ | ||
| 148 | #define GRAIL_PROP_TAP_X_T0 8 /* first touch horizontal position */ | ||
| 149 | #define GRAIL_PROP_TAP_Y_T0 9 /* first touch vertical position */ | ||
| 150 | #define GRAIL_PROP_TAP_ID_T1 10 | ||
| 151 | #define GRAIL_PROP_TAP_X_T1 11 | ||
| 152 | #define GRAIL_PROP_TAP_Y_T1 12 | ||
| 153 | #define GRAIL_PROP_TAP_ID_T2 13 | ||
| 154 | #define GRAIL_PROP_TAP_X_T2 14 | ||
| 155 | #define GRAIL_PROP_TAP_Y_T2 15 | ||
| 156 | #define GRAIL_PROP_TAP_ID_T3 16 | ||
| 157 | #define GRAIL_PROP_TAP_X_T3 17 | ||
| 158 | #define GRAIL_PROP_TAP_Y_T3 18 | ||
| 159 | #define GRAIL_PROP_TAP_ID_T4 19 | ||
| 160 | #define GRAIL_PROP_TAP_X_T4 20 | ||
| 161 | #define GRAIL_PROP_TAP_Y_T4 21 | ||
| 162 | |||
| 94 | 163 | ||
| 95 | #endif | 164 | #endif |
diff --git a/src/gestures-drag.c b/src/gestures-drag.c index 253bc9d..8b57b99 100644 --- a/src/gestures-drag.c +++ b/src/gestures-drag.c | |||
| @@ -33,20 +33,27 @@ static const int getype[DIM_TOUCH + 1] = { | |||
| 33 | GRAIL_TYPE_DRAG5, | 33 | GRAIL_TYPE_DRAG5, |
| 34 | }; | 34 | }; |
| 35 | 35 | ||
| 36 | static void set_props(struct combo_model *s, const struct move_model *m) | 36 | static void set_props(const struct gesture_inserter *gin, |
| 37 | struct combo_model *s, const struct move_model *m, | ||
| 38 | const struct touch_frame *frame) | ||
| 37 | { | 39 | { |
| 38 | if (m->single) { | 40 | if (m->single) { |
| 39 | s->prop[GRAIL_PROP_DRAG_DX] = m->fm[FM_X].raw_delta; | 41 | s->prop[GRAIL_PROP_DRAG_DX] = |
| 40 | s->prop[GRAIL_PROP_DRAG_DY] = m->fm[FM_Y].raw_delta; | 42 | gin->scale_x * m->fm[FM_X].raw_delta; |
| 43 | s->prop[GRAIL_PROP_DRAG_DY] = | ||
| 44 | gin->scale_y * m->fm[FM_Y].raw_delta; | ||
| 41 | } else { | 45 | } else { |
| 42 | s->prop[GRAIL_PROP_DRAG_DX] = m->fm[FM_X].action_delta; | 46 | s->prop[GRAIL_PROP_DRAG_DX] = |
| 43 | s->prop[GRAIL_PROP_DRAG_DY] = m->fm[FM_Y].action_delta; | 47 | gin->scale_x * m->fm[FM_X].action_delta; |
| 48 | s->prop[GRAIL_PROP_DRAG_DY] = | ||
| 49 | gin->scale_y * m->fm[FM_Y].action_delta; | ||
| 44 | } | 50 | } |
| 45 | s->prop[GRAIL_PROP_DRAG_VX] = m->fm[FM_X].velocity; | 51 | s->prop[GRAIL_PROP_DRAG_VX] = gin->scale_x * m->fm[FM_X].velocity; |
| 46 | s->prop[GRAIL_PROP_DRAG_VY] = m->fm[FM_Y].velocity; | 52 | s->prop[GRAIL_PROP_DRAG_VY] = gin->scale_y * m->fm[FM_Y].velocity; |
| 47 | s->prop[GRAIL_PROP_DRAG_X] = m->fm[FM_X].value; | 53 | s->prop[GRAIL_PROP_DRAG_X] = gin_prop_x(gin, m->fm[FM_X].value); |
| 48 | s->prop[GRAIL_PROP_DRAG_Y] = m->fm[FM_Y].value; | 54 | s->prop[GRAIL_PROP_DRAG_Y] = gin_prop_y(gin, m->fm[FM_Y].value); |
| 49 | s->nprop = 6; | 55 | s->nprop = 6; |
| 56 | s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame); | ||
| 50 | } | 57 | } |
| 51 | 58 | ||
| 52 | static const int fm_mask = 0x03; | 59 | static const int fm_mask = 0x03; |
| @@ -77,7 +84,7 @@ int gru_drag(struct grail *ge, | |||
| 77 | } | 84 | } |
| 78 | if (!move->single && !(move->active & fm_mask)) | 85 | if (!move->single && !(move->active & fm_mask)) |
| 79 | return 0; | 86 | return 0; |
| 80 | set_props(state, move); | 87 | set_props(ge->gin, state, move, frame); |
| 81 | gru_event(ge, state->gid, move, state->prop, state->nprop); | 88 | gru_event(ge, state->gid, move, state->prop, state->nprop); |
| 82 | return 1; | 89 | return 1; |
| 83 | } | 90 | } |
| @@ -118,7 +125,7 @@ int gru_windrag(struct grail *ge, | |||
| 118 | } | 125 | } |
| 119 | if (!move->single && !(move->active & fm_mask)) | 126 | if (!move->single && !(move->active & fm_mask)) |
| 120 | return 0; | 127 | return 0; |
| 121 | set_props(state, move); | 128 | set_props(ge->gin, state, move, frame); |
| 122 | gru_event(ge, state->gid, move, state->prop, state->nprop); | 129 | gru_event(ge, state->gid, move, state->prop, state->nprop); |
| 123 | return 1; | 130 | return 1; |
| 124 | } | 131 | } |
diff --git a/src/gestures-pinch.c b/src/gestures-pinch.c index d05b06f..45f1cb3 100644 --- a/src/gestures-pinch.c +++ b/src/gestures-pinch.c | |||
| @@ -35,23 +35,16 @@ static const int getype[DIM_TOUCH + 1] = { | |||
| 35 | 35 | ||
| 36 | static const int fm_mask = 0x04; | 36 | static const int fm_mask = 0x04; |
| 37 | 37 | ||
| 38 | static void set_props(struct combo_model *s, | 38 | static void set_props(const struct gesture_inserter *gin, |
| 39 | struct combo_model *s, | ||
| 39 | const struct move_model *m, | 40 | const struct move_model *m, |
| 40 | const struct touch_frame *frame) | 41 | const struct touch_frame *frame) |
| 41 | { | 42 | { |
| 42 | struct grail_coord min, max; | 43 | s->prop[GRAIL_PROP_PINCH_DR] = gin->scale_r * m->fm[FM_R].action_delta; |
| 43 | s->prop[GRAIL_PROP_PINCH_DR] = m->fm[FM_R].action_delta; | 44 | s->prop[GRAIL_PROP_PINCH_VR] = gin->scale_r * m->fm[FM_R].velocity; |
| 44 | s->prop[GRAIL_PROP_PINCH_VR] = m->fm[FM_R].velocity; | 45 | s->prop[GRAIL_PROP_PINCH_R] = gin->scale_r * m->fm[FM_R].value; |
| 45 | s->prop[GRAIL_PROP_PINCH_R] = m->fm[FM_R].value; | ||
| 46 | s->nprop = 3; | 46 | s->nprop = 3; |
| 47 | if (!frame->nactive) | 47 | s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame); |
| 48 | return; | ||
| 49 | gru_compute_bbox(&min, &max, frame); | ||
| 50 | s->prop[GRAIL_PROP_PINCH_X1] = min.x; | ||
| 51 | s->prop[GRAIL_PROP_PINCH_Y1] = min.y; | ||
| 52 | s->prop[GRAIL_PROP_PINCH_X2] = max.x; | ||
| 53 | s->prop[GRAIL_PROP_PINCH_Y2] = max.y; | ||
| 54 | s->nprop = 7; | ||
| 55 | } | 48 | } |
| 56 | 49 | ||
| 57 | int gru_pinch(struct grail *ge, | 50 | int gru_pinch(struct grail *ge, |
| @@ -80,7 +73,7 @@ int gru_pinch(struct grail *ge, | |||
| 80 | } | 73 | } |
| 81 | if (!(move->active & fm_mask)) | 74 | if (!(move->active & fm_mask)) |
| 82 | return 0; | 75 | return 0; |
| 83 | set_props(state, move, frame); | 76 | set_props(ge->gin, state, move, frame); |
| 84 | gru_event(ge, state->gid, move, state->prop, state->nprop); | 77 | gru_event(ge, state->gid, move, state->prop, state->nprop); |
| 85 | return 1; | 78 | return 1; |
| 86 | } | 79 | } |
| @@ -121,7 +114,7 @@ int gru_winpinch(struct grail *ge, | |||
| 121 | } | 114 | } |
| 122 | if (!(move->active & fm_mask)) | 115 | if (!(move->active & fm_mask)) |
| 123 | return 0; | 116 | return 0; |
| 124 | set_props(state, move, frame); | 117 | set_props(ge->gin, state, move, frame); |
| 125 | gru_event(ge, state->gid, move, state->prop, state->nprop); | 118 | gru_event(ge, state->gid, move, state->prop, state->nprop); |
| 126 | return 1; | 119 | return 1; |
| 127 | } | 120 | } |
diff --git a/src/gestures-rotate.c b/src/gestures-rotate.c index 23bbfd6..8985257 100644 --- a/src/gestures-rotate.c +++ b/src/gestures-rotate.c | |||
| @@ -35,22 +35,15 @@ static const int getype[DIM_TOUCH + 1] = { | |||
| 35 | 35 | ||
| 36 | static const int fm_mask = 0x08; | 36 | static const int fm_mask = 0x08; |
| 37 | 37 | ||
| 38 | static void set_props(struct combo_model *s, const struct move_model *m, | 38 | static void set_props(const struct gesture_inserter *gin, |
| 39 | struct combo_model *s, const struct move_model *m, | ||
| 39 | const struct touch_frame *frame) | 40 | const struct touch_frame *frame) |
| 40 | { | 41 | { |
| 41 | struct grail_coord min, max; | ||
| 42 | s->prop[GRAIL_PROP_ROTATE_DA] = m->fm[FM_A].action_delta; | 42 | s->prop[GRAIL_PROP_ROTATE_DA] = m->fm[FM_A].action_delta; |
| 43 | s->prop[GRAIL_PROP_ROTATE_VA] = m->fm[FM_A].velocity; | 43 | s->prop[GRAIL_PROP_ROTATE_VA] = m->fm[FM_A].velocity; |
| 44 | s->prop[GRAIL_PROP_ROTATE_A] = m->fm[FM_A].value; | 44 | s->prop[GRAIL_PROP_ROTATE_A] = m->fm[FM_A].value; |
| 45 | s->nprop = 3; | 45 | s->nprop = 3; |
| 46 | if (!frame->nactive) | 46 | s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame); |
| 47 | return; | ||
| 48 | gru_compute_bbox(&min, &max, frame); | ||
| 49 | s->prop[GRAIL_PROP_ROTATE_X1] = min.x; | ||
| 50 | s->prop[GRAIL_PROP_ROTATE_Y1] = min.y; | ||
| 51 | s->prop[GRAIL_PROP_ROTATE_X2] = max.x; | ||
| 52 | s->prop[GRAIL_PROP_ROTATE_Y2] = max.y; | ||
| 53 | s->nprop = 7; | ||
| 54 | } | 47 | } |
| 55 | 48 | ||
| 56 | int gru_rotate(struct grail *ge, | 49 | int gru_rotate(struct grail *ge, |
| @@ -79,7 +72,7 @@ int gru_rotate(struct grail *ge, | |||
| 79 | } | 72 | } |
| 80 | if (!(move->active & fm_mask)) | 73 | if (!(move->active & fm_mask)) |
| 81 | return 0; | 74 | return 0; |
| 82 | set_props(state, move, frame); | 75 | set_props(ge->gin, state, move, frame); |
| 83 | gru_event(ge, state->gid, move, state->prop, state->nprop); | 76 | gru_event(ge, state->gid, move, state->prop, state->nprop); |
| 84 | return 1; | 77 | return 1; |
| 85 | } | 78 | } |
| @@ -120,7 +113,7 @@ int gru_winrotate(struct grail *ge, | |||
| 120 | } | 113 | } |
| 121 | if (!(move->active & fm_mask)) | 114 | if (!(move->active & fm_mask)) |
| 122 | return 0; | 115 | return 0; |
| 123 | set_props(state, move, frame); | 116 | set_props(ge->gin, state, move, frame); |
| 124 | gru_event(ge, state->gid, move, state->prop, state->nprop); | 117 | gru_event(ge, state->gid, move, state->prop, state->nprop); |
| 125 | return 1; | 118 | return 1; |
| 126 | } | 119 | } |
diff --git a/src/gestures-tapping.c b/src/gestures-tapping.c index 52c5fdb..371dbde 100644 --- a/src/gestures-tapping.c +++ b/src/gestures-tapping.c | |||
| @@ -31,6 +31,17 @@ static const int TAP_MIN_GAP_MS = 25; | |||
| 31 | 31 | ||
| 32 | static const int fm_mask = 0x03; | 32 | static const int fm_mask = 0x03; |
| 33 | 33 | ||
| 34 | static void set_props(const struct gesture_inserter *gin, | ||
| 35 | struct tapping_model *s, const struct move_model *m, | ||
| 36 | const struct touch_frame *frame) | ||
| 37 | { | ||
| 38 | s->prop[GRAIL_PROP_TAP_DT] = m->time - s->start; | ||
| 39 | s->prop[GRAIL_PROP_TAP_X] = gin_prop_x(gin, m->fm[FM_X].value); | ||
| 40 | s->prop[GRAIL_PROP_TAP_Y] = gin_prop_y(gin, m->fm[FM_Y].value); | ||
| 41 | s->nprop = 3; | ||
| 42 | s->nprop += gin_add_contact_props(gin, s->prop + s->nprop, frame); | ||
| 43 | } | ||
| 44 | |||
| 34 | int gru_tapping(struct grail *ge, | 45 | int gru_tapping(struct grail *ge, |
| 35 | const struct touch_frame *frame) | 46 | const struct touch_frame *frame) |
| 36 | { | 47 | { |
| @@ -44,11 +55,7 @@ int gru_tapping(struct grail *ge, | |||
| 44 | if (!state->ntouch) | 55 | if (!state->ntouch) |
| 45 | state->start = move->time; | 56 | state->start = move->time; |
| 46 | if (move->ntouch >= state->ntouch) { | 57 | if (move->ntouch >= state->ntouch) { |
| 47 | state->prop[GRAIL_PROP_TAP_DT] = | 58 | set_props(ge->gin, state, move, frame); |
| 48 | move->time - state->start; | ||
| 49 | state->prop[GRAIL_PROP_TAP_X] = move->fm[FM_X].value; | ||
| 50 | state->prop[GRAIL_PROP_TAP_Y] = move->fm[FM_Y].value; | ||
| 51 | state->nprop = 3; | ||
| 52 | } | 59 | } |
| 53 | if (move->ntouch > state->ntouch) { | 60 | if (move->ntouch > state->ntouch) { |
| 54 | state->ntouch = move->ntouch; | 61 | state->ntouch = move->ntouch; |
diff --git a/src/grail-event.c b/src/grail-event.c index 6479cc0..2cf8209 100644 --- a/src/grail-event.c +++ b/src/grail-event.c | |||
| @@ -22,8 +22,101 @@ | |||
| 22 | 22 | ||
| 23 | #include "grail-inserter.h" | 23 | #include "grail-inserter.h" |
| 24 | #include "grail-impl.h" | 24 | #include "grail-impl.h" |
| 25 | #include <malloc.h> | ||
| 26 | #include <string.h> | ||
| 27 | #include <errno.h> | ||
| 25 | #include <math.h> | 28 | #include <math.h> |
| 26 | 29 | ||
| 30 | static void compute_bbox(struct grail_coord *min, struct grail_coord *max, | ||
| 31 | const struct touch_frame *frame) | ||
| 32 | { | ||
| 33 | float x, y; | ||
| 34 | int i; | ||
| 35 | if (frame->nactive < 1) | ||
| 36 | return; | ||
| 37 | x = frame->active[0]->x; | ||
| 38 | y = frame->active[0]->y; | ||
| 39 | min->x = max->x = x; | ||
| 40 | min->y = max->y = y; | ||
| 41 | for (i = 1; i < frame->nactive; i++) { | ||
| 42 | x = frame->active[i]->x; | ||
| 43 | y = frame->active[i]->y; | ||
| 44 | if (x < min->x) | ||
| 45 | min->x = x; | ||
| 46 | if (y < min->y) | ||
| 47 | min->y = y; | ||
| 48 | if (x > max->x) | ||
| 49 | max->x = x; | ||
| 50 | if (y > max->y) | ||
| 51 | max->y = y; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | int gin_add_contact_props(const struct gesture_inserter *gin, | ||
| 56 | grail_prop_t *prop, const struct touch_frame *frame) | ||
| 57 | { | ||
| 58 | struct grail_coord min, max; | ||
| 59 | int i, n = 0, ntouch = frame->nactive; | ||
| 60 | if (!ntouch) | ||
| 61 | return n; | ||
| 62 | if (ntouch > 5) | ||
| 63 | ntouch = 5; | ||
| 64 | compute_bbox(&min, &max, frame); | ||
| 65 | prop[n++] = gin_prop_x(gin, min.x); | ||
| 66 | prop[n++] = gin_prop_y(gin, min.y); | ||
| 67 | prop[n++] = gin_prop_x(gin, max.x); | ||
| 68 | prop[n++] = gin_prop_y(gin, max.y); | ||
| 69 | for (i = 0; i < ntouch; i++) { | ||
| 70 | const struct touch *ct = frame->active[i]; | ||
| 71 | prop[n++] = ct->id; | ||
| 72 | prop[n++] = gin_prop_x(gin, ct->x); | ||
| 73 | prop[n++] = gin_prop_y(gin, ct->y); | ||
| 74 | } | ||
| 75 | return n; | ||
| 76 | } | ||
| 77 | |||
| 78 | int gin_get_clients(struct grail *ge, | ||
| 79 | struct grail_client_info *info, int maxinfo, | ||
| 80 | const grail_mask_t* types, int btypes, | ||
| 81 | const grail_mask_t* span, int bspan, | ||
| 82 | const struct touch_frame *frame) | ||
| 83 | { | ||
| 84 | struct grail_coord pos[DIM_TOUCH]; | ||
| 85 | int i, npos = 0; | ||
| 86 | if (!ge->get_clients) | ||
| 87 | return 0; | ||
| 88 | grail_mask_foreach(i, span, bspan) { | ||
| 89 | pos[npos].x = gin_prop_x(ge->gin, frame->touch[i].x); | ||
| 90 | pos[npos].y = gin_prop_y(ge->gin, frame->touch[i].y); | ||
| 91 | npos++; | ||
| 92 | } | ||
| 93 | return ge->get_clients(ge, info, maxinfo, pos, npos, types, btypes); | ||
| 94 | } | ||
| 95 | |||
| 96 | void gin_send_event(struct grail *ge, struct slot_state *s, | ||
| 97 | const struct gesture_event *ev, | ||
| 98 | const struct touch_frame *frame) | ||
| 99 | { | ||
| 100 | const struct gesture_inserter *gin = ge->gin; | ||
| 101 | struct grail_event gev; | ||
| 102 | int i; | ||
| 103 | if (!ge->gesture) | ||
| 104 | return; | ||
| 105 | gev.type = s->type; | ||
| 106 | gev.id = s->id; | ||
| 107 | gev.status = ev->status; | ||
| 108 | gev.ntouch = ev->ntouch; | ||
| 109 | gev.nprop = ev->nprop; | ||
| 110 | gev.time = ev->time; | ||
| 111 | gev.pos.x = gin_prop_x(gin, ev->pos.x); | ||
| 112 | gev.pos.y = gin_prop_y(gin, ev->pos.y); | ||
| 113 | memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t)); | ||
| 114 | for (i = 0; i < s->nclient; i++) { | ||
| 115 | gev.client_id = s->client_id[i]; | ||
| 116 | ge->gesture(ge, &gev); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | |||
| 27 | int grail_get_contacts(const struct grail *ge, | 120 | int grail_get_contacts(const struct grail *ge, |
| 28 | struct grail_contact *touch, int max_touch) | 121 | struct grail_contact *touch, int max_touch) |
| 29 | { | 122 | { |
diff --git a/src/grail-gestures.c b/src/grail-gestures.c index 1e89074..4262af7 100644 --- a/src/grail-gestures.c +++ b/src/grail-gestures.c | |||
| @@ -217,28 +217,3 @@ void gru_end(struct grail *ge, int gid, const struct move_model *m, | |||
| 217 | gin_gid_end(ge, gid, m->fm[FM_X].value, m->fm[FM_Y].value, m->ntouch, | 217 | gin_gid_end(ge, gid, m->fm[FM_X].value, m->fm[FM_Y].value, m->ntouch, |
| 218 | prop, nprop); | 218 | prop, nprop); |
| 219 | } | 219 | } |
| 220 | |||
| 221 | void gru_compute_bbox(struct grail_coord *min, struct grail_coord *max, | ||
| 222 | const struct touch_frame *frame) | ||
| 223 | { | ||
| 224 | float x, y; | ||
| 225 | int i; | ||
| 226 | if (frame->nactive < 1) | ||
| 227 | return; | ||
| 228 | x = frame->active[0]->x; | ||
| 229 | y = frame->active[0]->y; | ||
| 230 | min->x = max->x = x; | ||
| 231 | min->y = max->y = y; | ||
| 232 | for (i = 1; i < frame->nactive; i++) { | ||
| 233 | x = frame->active[i]->x; | ||
| 234 | y = frame->active[i]->y; | ||
| 235 | if (x < min->x) | ||
| 236 | min->x = x; | ||
| 237 | if (y < min->y) | ||
| 238 | min->y = y; | ||
| 239 | if (x > max->x) | ||
| 240 | max->x = x; | ||
| 241 | if (y > max->y) | ||
| 242 | max->y = y; | ||
| 243 | } | ||
| 244 | } | ||
diff --git a/src/grail-gestures.h b/src/grail-gestures.h index edd641b..e716757 100644 --- a/src/grail-gestures.h +++ b/src/grail-gestures.h | |||
| @@ -68,8 +68,6 @@ void gru_event(struct grail *ge, int gid, | |||
| 68 | void gru_end(struct grail *ge, int gid, | 68 | void gru_end(struct grail *ge, int gid, |
| 69 | const struct move_model *move, | 69 | const struct move_model *move, |
| 70 | const grail_prop_t *prop, int nprop); | 70 | const grail_prop_t *prop, int nprop); |
| 71 | void gru_compute_bbox(struct grail_coord *min, struct grail_coord *max, | ||
| 72 | const struct touch_frame *frame); | ||
| 73 | 71 | ||
| 74 | struct combo_model { | 72 | struct combo_model { |
| 75 | int active, gid; | 73 | int active, gid; |
diff --git a/src/grail-inserter.c b/src/grail-inserter.c index 2e5e7af..d77da79 100644 --- a/src/grail-inserter.c +++ b/src/grail-inserter.c | |||
| @@ -29,90 +29,6 @@ | |||
| 29 | 29 | ||
| 30 | static const int MAX_GESTURE_ID = 0xfff; | 30 | static const int MAX_GESTURE_ID = 0xfff; |
| 31 | 31 | ||
| 32 | static const int grail_main_type[DIM_GRAIL_TYPE] = { | ||
| 33 | GRAIL_MAIN_DRAG, | ||
| 34 | GRAIL_MAIN_PINCH, | ||
| 35 | GRAIL_MAIN_ROTATE, | ||
| 36 | GRAIL_MAIN_DRAG, | ||
| 37 | GRAIL_MAIN_PINCH, | ||
| 38 | GRAIL_MAIN_ROTATE, | ||
| 39 | GRAIL_MAIN_DRAG, | ||
| 40 | GRAIL_MAIN_PINCH, | ||
| 41 | GRAIL_MAIN_ROTATE, | ||
| 42 | GRAIL_MAIN_DRAG, | ||
| 43 | GRAIL_MAIN_PINCH, | ||
| 44 | GRAIL_MAIN_ROTATE, | ||
| 45 | GRAIL_MAIN_DRAG, | ||
| 46 | GRAIL_MAIN_PINCH, | ||
| 47 | GRAIL_MAIN_ROTATE, | ||
| 48 | GRAIL_MAIN_TAP, | ||
| 49 | GRAIL_MAIN_TAP, | ||
| 50 | GRAIL_MAIN_TAP, | ||
| 51 | GRAIL_MAIN_TAP, | ||
| 52 | GRAIL_MAIN_TAP, | ||
| 53 | GRAIL_MAIN_DRAG, | ||
| 54 | GRAIL_MAIN_PINCH, | ||
| 55 | GRAIL_MAIN_ROTATE, | ||
| 56 | GRAIL_MAIN_DRAG, | ||
| 57 | GRAIL_MAIN_PINCH, | ||
| 58 | GRAIL_MAIN_ROTATE, | ||
| 59 | }; | ||
| 60 | |||
| 61 | static void transform_pos(const struct gesture_inserter *gin, | ||
| 62 | struct grail_coord *pos) | ||
| 63 | { | ||
| 64 | pos->x *= gin->scale_x; | ||
| 65 | pos->x += gin->trans_x; | ||
| 66 | pos->y *= gin->scale_y; | ||
| 67 | pos->y += gin->trans_y; | ||
| 68 | } | ||
| 69 | |||
| 70 | static void transform_prop(const struct gesture_inserter *gin, int type, | ||
| 71 | grail_prop_t *prop, int nprop) | ||
| 72 | { | ||
| 73 | switch (grail_main_type[type]) { | ||
| 74 | case GRAIL_MAIN_DRAG: | ||
| 75 | prop[GRAIL_PROP_DRAG_DX] *= gin->scale_x; | ||
| 76 | prop[GRAIL_PROP_DRAG_DY] *= gin->scale_y; | ||
| 77 | prop[GRAIL_PROP_DRAG_VX] *= gin->scale_x; | ||
| 78 | prop[GRAIL_PROP_DRAG_VY] *= gin->scale_y; | ||
| 79 | prop[GRAIL_PROP_DRAG_X] *= gin->scale_x; | ||
| 80 | prop[GRAIL_PROP_DRAG_X] += gin->trans_x; | ||
| 81 | prop[GRAIL_PROP_DRAG_Y] *= gin->scale_y; | ||
| 82 | prop[GRAIL_PROP_DRAG_Y] += gin->trans_y; | ||
| 83 | break; | ||
| 84 | case GRAIL_MAIN_PINCH: | ||
| 85 | prop[GRAIL_PROP_PINCH_DR] *= gin->scale_r; | ||
| 86 | prop[GRAIL_PROP_PINCH_VR] *= gin->scale_r; | ||
| 87 | prop[GRAIL_PROP_PINCH_R] *= gin->scale_r; | ||
| 88 | prop[GRAIL_PROP_PINCH_X1] *= gin->scale_x; | ||
| 89 | prop[GRAIL_PROP_PINCH_X1] += gin->trans_x; | ||
| 90 | prop[GRAIL_PROP_PINCH_Y1] *= gin->scale_y; | ||
| 91 | prop[GRAIL_PROP_PINCH_Y1] += gin->trans_y; | ||
| 92 | prop[GRAIL_PROP_PINCH_X2] *= gin->scale_x; | ||
| 93 | prop[GRAIL_PROP_PINCH_X2] += gin->trans_x; | ||
| 94 | prop[GRAIL_PROP_PINCH_Y2] *= gin->scale_y; | ||
| 95 | prop[GRAIL_PROP_PINCH_Y2] += gin->trans_y; | ||
| 96 | break; | ||
| 97 | case GRAIL_MAIN_ROTATE: | ||
| 98 | prop[GRAIL_PROP_ROTATE_X1] *= gin->scale_x; | ||
| 99 | prop[GRAIL_PROP_ROTATE_X1] += gin->trans_x; | ||
| 100 | prop[GRAIL_PROP_ROTATE_Y1] *= gin->scale_y; | ||
| 101 | prop[GRAIL_PROP_ROTATE_Y1] += gin->trans_y; | ||
| 102 | prop[GRAIL_PROP_ROTATE_X2] *= gin->scale_x; | ||
| 103 | prop[GRAIL_PROP_ROTATE_X2] += gin->trans_x; | ||
| 104 | prop[GRAIL_PROP_ROTATE_Y2] *= gin->scale_y; | ||
| 105 | prop[GRAIL_PROP_ROTATE_Y2] += gin->trans_y; | ||
| 106 | break; | ||
| 107 | case GRAIL_MAIN_TAP: | ||
| 108 | prop[GRAIL_PROP_TAP_X] *= gin->scale_x; | ||
| 109 | prop[GRAIL_PROP_TAP_X] += gin->trans_x; | ||
| 110 | prop[GRAIL_PROP_TAP_Y] *= gin->scale_y; | ||
| 111 | prop[GRAIL_PROP_TAP_Y] += gin->trans_y; | ||
| 112 | break; | ||
| 113 | }; | ||
| 114 | } | ||
| 115 | |||
| 116 | static int find_gslot(const struct gesture_inserter *gin, int gid) | 32 | static int find_gslot(const struct gesture_inserter *gin, int gid) |
| 117 | { | 33 | { |
| 118 | int i; | 34 | int i; |
| @@ -122,29 +38,6 @@ static int find_gslot(const struct gesture_inserter *gin, int gid) | |||
| 122 | return -1; | 38 | return -1; |
| 123 | } | 39 | } |
| 124 | 40 | ||
| 125 | static void send_event(struct grail *ge, struct slot_state *s, | ||
| 126 | const struct gesture_event *ev) | ||
| 127 | { | ||
| 128 | struct grail_event gev; | ||
| 129 | int i; | ||
| 130 | if (!ge->gesture) | ||
| 131 | return; | ||
| 132 | gev.type = s->type; | ||
| 133 | gev.id = s->id; | ||
| 134 | gev.status = ev->status; | ||
| 135 | gev.ntouch = ev->ntouch; | ||
| 136 | gev.nprop = ev->nprop; | ||
| 137 | gev.time = ev->time; | ||
| 138 | gev.pos = ev->pos; | ||
| 139 | transform_pos(ge->gin, &gev.pos); | ||
| 140 | memcpy(gev.prop, ev->prop, ev->nprop * sizeof(grail_prop_t)); | ||
| 141 | transform_prop(ge->gin, gev.type, gev.prop, gev.nprop); | ||
| 142 | for (i = 0; i < s->nclient; i++) { | ||
| 143 | gev.client_id = s->client_id[i]; | ||
| 144 | ge->gesture(ge, &gev); | ||
| 145 | } | ||
| 146 | } | ||
| 147 | |||
| 148 | // todo: spanning tree for multi-user case | 41 | // todo: spanning tree for multi-user case |
| 149 | static void setup_new_gestures(struct grail *ge, | 42 | static void setup_new_gestures(struct grail *ge, |
| 150 | const struct touch_frame *frame) | 43 | const struct touch_frame *frame) |
| @@ -167,19 +60,8 @@ static void setup_new_gestures(struct grail *ge, | |||
| 167 | grail_mask_set_mask(span, s->span, sizeof(span)); | 60 | grail_mask_set_mask(span, s->span, sizeof(span)); |
| 168 | } | 61 | } |
| 169 | 62 | ||
| 170 | if (ge->get_clients) { | 63 | nclient = gin_get_clients(ge, info, DIM_CLIENT, types, sizeof(types), |
| 171 | struct grail_coord coord[DIM_CLIENT]; | 64 | span, sizeof(span), frame); |
| 172 | int ncoord = 0; | ||
| 173 | grail_mask_foreach(i, span, sizeof(span)) { | ||
| 174 | const struct touch *t = &frame->touch[i]; | ||
| 175 | coord[ncoord].x = t->x; | ||
| 176 | coord[ncoord].y = t->y; | ||
| 177 | transform_pos(gin, &coord[ncoord]); | ||
| 178 | ncoord++; | ||
| 179 | } | ||
| 180 | nclient = ge->get_clients(ge, info, DIM_CLIENT, | ||
| 181 | coord, ncoord, types, sizeof(types)); | ||
| 182 | } | ||
| 183 | 65 | ||
| 184 | grail_mask_foreach(i, gin->fresh, sizeof(gin->fresh)) { | 66 | grail_mask_foreach(i, gin->fresh, sizeof(gin->fresh)) { |
| 185 | struct slot_state *s = &gin->state[i]; | 67 | struct slot_state *s = &gin->state[i]; |
| @@ -263,7 +145,7 @@ void gin_frame_end(struct grail *ge, | |||
| 263 | continue; | 145 | continue; |
| 264 | while (!gebuf_empty(&s->buf)) { | 146 | while (!gebuf_empty(&s->buf)) { |
| 265 | gebuf_get(&s->buf, &ev); | 147 | gebuf_get(&s->buf, &ev); |
| 266 | send_event(ge, s, &ev); | 148 | gin_send_event(ge, s, &ev, frame); |
| 267 | } | 149 | } |
| 268 | } | 150 | } |
| 269 | 151 | ||
diff --git a/src/grail-inserter.h b/src/grail-inserter.h index f8ec5ca..c5a865a 100644 --- a/src/grail-inserter.h +++ b/src/grail-inserter.h | |||
| @@ -67,6 +67,18 @@ static inline float gin_prop_y(const struct gesture_inserter *gin, float y) | |||
| 67 | return gin->scale_y * y + gin->trans_y; | 67 | return gin->scale_y * y + gin->trans_y; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | int gin_add_contact_props(const struct gesture_inserter *gin, | ||
| 71 | grail_prop_t *prop, const struct touch_frame *frame); | ||
| 72 | |||
| 73 | int gin_get_clients(struct grail *ge, | ||
| 74 | struct grail_client_info *info, int maxinfo, | ||
| 75 | const grail_mask_t* types, int btypes, | ||
| 76 | const grail_mask_t* span, int bspan, | ||
| 77 | const struct touch_frame *frame); | ||
| 78 | void gin_send_event(struct grail *ge, struct slot_state *s, | ||
| 79 | const struct gesture_event *ev, | ||
| 80 | const struct touch_frame *frame); | ||
| 81 | |||
| 70 | int gin_init(struct grail *ge); | 82 | int gin_init(struct grail *ge); |
| 71 | void gin_destroy(struct grail *ge); | 83 | void gin_destroy(struct grail *ge); |
| 72 | 84 | ||
