#define ELM_GESTURE_MULTI_TIMEOUT 50
#define ELM_GESTURE_MINIMUM_MOMENTUM 0.001
+#define ELM_GESTURE_TAP_TIMEOUT 0.2
+
/* Some Trigo values */
#define RAD_90DEG M_PI_2
#define RAD_180DEG M_PI
{ /* Mark EVAS_EVENT_FLAG_ON_HOLD on events that are used by gesture layer */
/* ev_flags != EVAS_EVENT_FLAG_NONE means target used event and g-layer */
/* should not refeed this event. */
- if(!event_info)
+ if (!event_info)
return; /* This happens when restarting gestures */
- if ((ev_flags) || (!wd->repeat_events))
+ if (!wd->repeat_events) ev_flags |= EVAS_EVENT_FLAG_ON_HOLD;
+
+ if (ev_flags)
{
switch(event_type)
{
return;
Widget_Data *wd = elm_widget_data_get(gesture->obj);
- wd->dbl_timeout = NULL;
Eina_List *data;
Pointer_Event *pe;
+ if (wd->dbl_timeout)
+ {
+ ecore_timer_del(wd->dbl_timeout);
+ wd->dbl_timeout = NULL;
+ }
+
if (!gesture->data)
return;
/**
* @internal
*
- * This function sets state a tap-gesture to END or ABORT
+ * This function checks if the tap gesture is done.
*
* @param data gesture info pointer
+ * @return EINA_TRUE if it is done.
*
* @ingroup Elm_Gesture_Layer
*/
-static void
-_tap_gesture_finish(void *data)
-{ /* This function will test each tap gesture when timer expires */
- Gesture_Info *gesture = data;
- Elm_Gesture_State s = ELM_GESTURE_STATE_END;
+static Eina_Bool
+_tap_gesture_check_finish(Gesture_Info *gesture)
+{
/* Here we check if taps-gesture was completed successfuly */
/* Count how many taps were recieved on each device then */
/* determine if it matches n_taps_needed defined on START */
Taps_Type *st = gesture->data;
Eina_List *l;
Eina_List *pe_list;
+ if (!st || !st->l) return EINA_FALSE;
EINA_LIST_FOREACH(st->l, l, pe_list)
{
if (eina_list_count(pe_list) != st->n_taps_needed)
{ /* No match taps number on device, ABORT */
- s = ELM_GESTURE_STATE_ABORT;
- break;
+ return EINA_FALSE;
}
}
+ return EINA_TRUE;
+}
+
+/**
+ * @internal
+ *
+ * This function sets state a tap-gesture to END or ABORT
+ *
+ * @param data gesture info pointer
+ *
+ * @ingroup Elm_Gesture_Layer
+ */
+static void
+_tap_gesture_finish(void *data)
+{ /* This function will test each tap gesture when timer expires */
+ Elm_Gesture_State s = ELM_GESTURE_STATE_ABORT;
+ Gesture_Info *gesture = data;
+ Taps_Type *st = gesture->data;
+
+ if (_tap_gesture_check_finish(gesture))
+ {
+ s = ELM_GESTURE_STATE_END;
+ }
+
st->info.n = eina_list_count(st->l);
_set_state(gesture, s, gesture->info, EINA_FALSE);
_tap_gestures_test_reset(gesture);
if (!wd) return EINA_FALSE;
if (IS_TESTED(ELM_GESTURE_N_TAPS))
- _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TAPS]);
+ _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TAPS]);
if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
- _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
+ _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
- _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
+ _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
_clear_if_finished(data);
wd->dbl_timeout = NULL;
/**
* @internal
*
- * This function checks if a tap gesture should start
+ * This function checks the state of a tap gesture.
*
* @param wd Gesture Layer Widget Data.
* @param pe The recent input event as stored in pe struct.
* @param gesture what gesture is tested
* @param how many taps for this gesture (1, 2 or 3)
*
- * @return Flag to determine if we need to set a timer for finish
- *
* @ingroup Elm_Gesture_Layer
*/
-static Eina_Bool
-_tap_gesture_start(Widget_Data *wd, Pointer_Event *pe,
+static void
+_tap_gesture_test(Widget_Data *wd, Pointer_Event *pe,
void *event_info, Evas_Callback_Type event_type,
Gesture_Info *gesture, int taps)
{ /* Here we fill Tap struct */
+ if (!pe)
+ return;
+
Taps_Type *st = gesture->data;
if (!st)
{ /* Allocated once on first time */
&st->info, EINA_FALSE);
consume_event(wd, event_info, event_type, ev_flag);
- return EINA_FALSE;
+ return;
}
pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
+ if (!wd->dbl_timeout)
+ {
+ wd->dbl_timeout = ecore_timer_add(ELM_GESTURE_TAP_TIMEOUT,
+ _multi_tap_timeout, gesture->obj);
+ }
+ else
+ {
+ ecore_timer_reset(wd->dbl_timeout);
+ }
+
if ((pe->device == 0) && (eina_list_count(pe_list) == 1))
{ /* This is the first mouse down we got */
ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
st->n_taps_needed = taps * 2; /* count DOWN and UP */
- return EINA_TRUE;
+ return;
+ }
+ else if (eina_list_count(pe_list) > st->n_taps_needed)
+ {
+ /* If we arleady got too many touches for this gesture. */
+ ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
+ &st->info, EINA_FALSE);
}
break;
case EVAS_CALLBACK_MOUSE_UP:
pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
if (!pe_list)
- return EINA_FALSE;
+ return;
pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
+
+ if (((gesture->g_type == ELM_GESTURE_N_TAPS) &&
+ !IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS) &&
+ !IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS)) ||
+ ((gesture->g_type == ELM_GESTURE_N_DOUBLE_TAPS) &&
+ !IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS)))
+ {
+ if (_tap_gesture_check_finish(gesture))
+ {
+ _tap_gesture_finish(gesture);
+ return;
+ }
+ }
+
break;
case EVAS_CALLBACK_MULTI_MOVE:
break;
default:
- return EINA_FALSE;
- }
-
- return EINA_FALSE;
-}
-
-
-/**
- * @internal
- *
- * This function checks all click/tap and double/triple taps
- *
- * @param obj The gesture-layer object.
- * @param pe The recent input event as stored in pe struct.
- * @param event_info Original input event pointer.
- * @param event_type Type of original input event.
- *
- * @ingroup Elm_Gesture_Layer
- */
-static void
-_tap_gestures_test(Evas_Object *obj, Pointer_Event *pe,
- void *event_info, Evas_Callback_Type event_type)
-{ /* Here we fill Recent_Taps struct and fire-up click/tap timers */
- Eina_Bool need_timer = EINA_FALSE;
- Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
-
- if (!pe) /* this happens when unhandled event arrived */
- return; /* see _make_pointer_event function */
-
- if (IS_TESTED(ELM_GESTURE_N_TAPS))
- need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
- wd->gesture[ELM_GESTURE_N_TAPS], 1);
-
- if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
- need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
- wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS], 2);
-
- if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
- need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
- wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS], 3);
-
- if ((need_timer) && (!wd->dbl_timeout))
- { /* Set a timer to finish these gestures */
- wd->dbl_timeout = ecore_timer_add(0.4, _multi_tap_timeout,
- obj);
+ return ;
}
}
_compute_taps_center(Long_Tap_Type *st,
Evas_Coord *x_out, Evas_Coord *y_out, Pointer_Event *pe)
{
- if(!eina_list_count(st->touched))
+ if (!eina_list_count(st->touched))
return;
Eina_List *l;
case EVAS_CALLBACK_MULTI_MOVE:
case EVAS_CALLBACK_MOUSE_MOVE:
- if(st->info.n &&
+ if (st->info.n &&
((gesture->state == ELM_GESTURE_STATE_START) ||
(gesture->state == ELM_GESTURE_STATE_MOVE)))
{ /* Report MOVE only if STARTED */
* @ingroup Elm_Gesture_Layer
*/
static void
-_set_momentum(Elm_Gesture_Momentum_Info *momentum, Evas_Coord x1, Evas_Coord y1,
- Evas_Coord x2, Evas_Coord y2, unsigned int t1x, unsigned int t1y,
- unsigned int t2)
+_set_momentum(Elm_Gesture_Momentum_Info *momentum,
+ Evas_Coord xx1, Evas_Coord yy1,
+ Evas_Coord xx2, Evas_Coord yy2,
+ unsigned int t1x, unsigned int t1y, unsigned int t2)
{
Evas_Coord velx = 0, vely = 0, vel;
- Evas_Coord dx = x2 - x1;
- Evas_Coord dy = y2 - y1;
+ Evas_Coord dx = xx2 - xx1;
+ Evas_Coord dy = yy2 - yy1;
int dtx = t2 - t1x;
int dty = t2 - t1y;
if (dtx > 0)
* @ingroup Elm_Gesture_Layer
*/
static double
-get_angle(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
+get_angle(Evas_Coord xx1, Evas_Coord yy1, Evas_Coord xx2, Evas_Coord yy2)
{
double a, xx, yy, rt = (-1);
- xx = fabs(x2 - x1);
- yy = fabs(y2 - y1);
+ xx = fabs(xx2 - xx1);
+ yy = fabs(yy2 - yy1);
- if (((int) xx) && ((int) yy))
+ if (((int)xx) && ((int)yy))
{
rt = a = RAD2DEG(atan(yy / xx));
- if (x1 < x2)
+ if (xx1 < xx2)
{
- if (y1 < y2)
- {
- rt = 360 - a;
- }
- else
- {
- rt = (a);
- }
+ if (yy1 < yy2) rt = 360 - a;
+ else rt = a;
}
else
{
- if (y1 < y2)
- {
- rt = 180 + a;
- }
- else
- {
- rt = 180 - a;
- }
+ if (yy1 < yy2) rt = 180 + a;
+ else rt = 180 - a;
}
}
if (rt < 0)
{ /* Do this only if rt is not set */
- if (((int) xx))
+ if (((int)xx))
{ /* Horizontal line */
- if (x2 < x1)
- {
- rt = 180;
- }
- else
- {
- rt = 0.0;
- }
+ if (xx2 < xx1) rt = 180;
+ else rt = 0.0;
}
else
{ /* Vertical line */
- if (y2 < y1)
- {
- rt = 90;
- }
- else
- {
- rt = 270;
- }
+ if (yy2 < yy1) rt = 90;
+ else rt = 270;
}
}
* original circle 180 0 We want: 270 90
* 270 180
*/
-
rt = 450 - rt;
- if (rt >= 360)
- rt -= 360;
+ if (rt >= 360) rt -= 360;
return rt;
}
* @ingroup Elm_Gesture_Layer
*/
static void
-get_vector(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2,
- Evas_Coord *l, double *a)
+get_vector(Evas_Coord xx1, Evas_Coord yy1, Evas_Coord xx2, Evas_Coord yy2,
+ Evas_Coord *l, double *a)
{
Evas_Coord xx, yy;
- xx = x2 - x1;
- yy = y2 - y1;
- *l = (Evas_Coord) sqrt(xx*xx + yy*yy);
- *a = get_angle(x1, y1, x2, y2);
+ xx = xx2 - xx1;
+ yy = yy2 - yy1;
+ *l = (Evas_Coord) sqrt((xx * xx) + (yy * yy));
+ *a = get_angle(xx1, yy1, xx2, yy2);
}
static int
-_get_direction(Evas_Coord x1, Evas_Coord x2)
+_get_direction(Evas_Coord xx1, Evas_Coord xx2)
{
- if (x2 < x1)
- return -1;
-
- if (x2 > x1)
- return 1;
-
+ if (xx2 < xx1) return -1;
+ if (xx2 > xx1) return 1;
return 0;
}
/**
*/
static void
_momentum_test(Evas_Object *obj, Pointer_Event *pe,
- void *event_info, Evas_Callback_Type event_type,
- Elm_Gesture_Type g_type)
+ void *event_info, Evas_Callback_Type event_type,
+ Elm_Gesture_Type g_type)
{
Widget_Data *wd = elm_widget_data_get(obj);
if (!wd) return;
* @ingroup Elm_Gesture_Layer
*/
static Evas_Coord
-get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
- Evas_Coord y2, Evas_Coord *x, Evas_Coord *y)
+get_finger_gap_length(Evas_Coord xx1, Evas_Coord yy1,
+ Evas_Coord xx2, Evas_Coord yy2,
+ Evas_Coord *x, Evas_Coord *y)
{
double a, b, xx, yy, gap;
- xx = fabs(x2 - x1);
- yy = fabs(y2 - y1);
- gap = sqrt(xx*xx + yy*yy);
+ xx = fabs(xx2 - xx1);
+ yy = fabs(yy2 - yy1);
+ gap = sqrt((xx * xx) + (yy * yy));
/* START - Compute zoom center point */
/* The triangle defined as follows:
* b
* http://en.wikipedia.org/wiki/Trigonometric_functions
*************************************/
- if (((int) xx) && ((int) yy))
+ if (((int)xx) && ((int)yy))
{
double A = atan((yy / xx));
#if defined(DEBUG_GESTURE_LAYER)
#endif
a = (Evas_Coord) ((gap / 2) * sin(A));
b = (Evas_Coord) ((gap / 2) * cos(A));
- *x = (Evas_Coord) ((x2 > x1) ? (x1 + b) : (x2 + b));
- *y = (Evas_Coord) ((y2 > y1) ? (y1 + a) : (y2 + a));
+ *x = (Evas_Coord) ((xx2 > xx1) ? (xx1 + b) : (xx2 + b));
+ *y = (Evas_Coord) ((yy2 > yy1) ? (yy1 + a) : (yy2 + a));
}
else
{
- if ((int) xx)
+ if ((int)xx)
{ /* horiz line, take half width */
#if defined(DEBUG_GESTURE_LAYER)
printf("==== HORIZ ====\n");
#endif
- *x = (Evas_Coord) ((x1 + x2) / 2);
- *y = (Evas_Coord) (y1);
+ *x = (Evas_Coord) ((xx1 + xx2) / 2);
+ *y = (Evas_Coord) (yy1);
}
- if ((int) yy)
+ if ((int)yy)
{ /* vert line, take half width */
#if defined(DEBUG_GESTURE_LAYER)
printf("==== VERT ====\n");
#endif
- *x = (Evas_Coord) (x1);
- *y = (Evas_Coord) ((y1 + y2) / 2);
+ *x = (Evas_Coord) (xx1);
+ *y = (Evas_Coord) ((yy1 + yy2) / 2);
}
}
/* END - Compute zoom center point */
* @ingroup Elm_Gesture_Layer
*/
static double
-compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1,
- Evas_Coord x2, Evas_Coord y2, double zoom_finger_factor)
+compute_zoom(Zoom_Type *st,
+ Evas_Coord xx1, Evas_Coord yy1,
+ Evas_Coord xx2, Evas_Coord yy2,
+ double zoom_finger_factor)
{
double rt = 1.0;
unsigned int tm_end = (st->zoom_mv.timestamp > st->zoom_mv1.timestamp) ?
- st->zoom_mv.timestamp : st->zoom_mv1.timestamp;
+ st->zoom_mv.timestamp : st->zoom_mv1.timestamp;
- Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
- &st->info.x, &st->info.y);
+ Evas_Coord diam = get_finger_gap_length(xx1, yy1, xx2, yy2,
+ &st->info.x, &st->info.y);
st->info.radius = diam / 2;
/* We use factor only on the difference between gap-base */
/* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
- (float) st->zoom_base) * zoom_finger_factor));
+ (float) st->zoom_base) * zoom_finger_factor));
/* Momentum: zoom per second: */
st->info.momentum = _zoom_momentum_get(st, tm_end, rt);
Eina_List *l;
Pointer_Event *p;
- if(eina_list_count(wd->touched) > 2)
+ if (eina_list_count(wd->touched) > 2)
{ /* Process zoom only when 2 fingers on surface */
ev_flag = _set_state(gesture_zoom,
ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
static void
_get_rotate_properties(Rotate_Type *st,
- Evas_Coord x1, Evas_Coord y1,
- Evas_Coord x2, Evas_Coord y2,
- double *angle)
+ Evas_Coord xx1, Evas_Coord yy1,
+ Evas_Coord xx2, Evas_Coord yy2,
+ double *angle)
{ /* FIXME: Fix momentum computation, it's wrong */
double prev_angle = *angle;
- st->info.radius = get_finger_gap_length(x1, y1, x2, y2,
- &st->info.x, &st->info.y) / 2;
+ st->info.radius = get_finger_gap_length(xx1, yy1, xx2, yy2,
+ &st->info.x, &st->info.y) / 2;
- *angle = get_angle(x1, y1, x2, y2);
+ *angle = get_angle(xx1, yy1, xx2, yy2);
if (angle == &st->info.angle)
{ /* Fingers are moving, compute momentum */
Eina_List *l;
Pointer_Event *p;
- if(eina_list_count(wd->touched) > 2)
+ if (eina_list_count(wd->touched) > 2)
{ /* Process rotate only when 2 fingers on surface */
ev_flag = _set_state(gesture,
ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
int i;
Gesture_Info *g;
printf("Gesture | State | is tested\n");
- for(i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
+ for (i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
{
g = wd->gesture[i];
- if(g)
+ if (g)
printf(" %d %d %d\n", i, g->state, g->test);
}
#endif
_n_long_tap_test(data, pe, event_info, event_type,
ELM_GESTURE_N_LONG_TAPS);
- /* This takes care of single, double and tripple tap */
- _tap_gestures_test(data, pe, event_info, event_type);
+ if (IS_TESTED(ELM_GESTURE_N_TAPS))
+ _tap_gesture_test(wd, pe, event_info, event_type,
+ wd->gesture[ELM_GESTURE_N_TAPS], 1);
+
+ if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
+ _tap_gesture_test(wd, pe, event_info, event_type,
+ wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS], 2);
+
+ if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
+ _tap_gesture_test(wd, pe, event_info, event_type,
+ wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS], 3);
if (IS_TESTED(ELM_GESTURE_MOMENTUM))
_momentum_test(data, pe, event_info, event_type,
if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
_event_history_add(data, event_info, event_type);
- else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
- (event_type == EVAS_CALLBACK_MULTI_UP))
- {
- Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type);
- if (pending)
- {
- consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD);
- _event_history_add(data, event_info, event_type);
- }
- }
/* we maintain list of touched devices */
/* We also use move to track current device x.y pos */