Elm glayer: Set mimimun momentum for ABORT
[framework/uifw/elementary.git] / src / lib / elm_gesture_layer.c
index 8fd8524..1cfd219 100644 (file)
@@ -8,6 +8,7 @@
 #define ELM_GESTURE_NEGATIVE_ANGLE (-1.0) /* Magic number */
 #define ELM_GESTURE_MOMENTUM_TIMEOUT 50
 #define ELM_GESTURE_MULTI_TIMEOUT 50
+#define ELM_GESTURE_MINIMUM_MOMENTUM 0.001
 
 /* Some Trigo values */
 #define RAD_90DEG  M_PI_2
@@ -328,9 +329,16 @@ _add_touched_device(Eina_List *list, Pointer_Event *pe)
         return list;
      }
 
-   p = malloc(sizeof(Pointer_Event));
-   memcpy(p, pe, sizeof(Pointer_Event)); /* Freed in _remove_touched_device() */
-   return eina_list_append(list, p);
+   if ((pe->event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
+         (pe->event_type == EVAS_CALLBACK_MULTI_DOWN))
+     {  /* Add touched device on DOWN event only */
+        p = malloc(sizeof(Pointer_Event));
+        /* Freed in _remove_touched_device()    */
+        memcpy(p, pe, sizeof(Pointer_Event));
+        return eina_list_append(list, p);
+     }
+
+   return list;
 }
 /* END   - Functions to manage touched-device list */
 
@@ -1093,8 +1101,8 @@ compare_match_fingers(const void *data1, const void *data2)
 
 static int
 compare_pe_device(const void *data1, const void *data2)
-{  /* Compare coords of first item in list to cur coords */
-   const Pointer_Event *pe1 = eina_list_data_get(eina_list_last(data1));
+{  /* Compare device of first item in list to our pe device */
+   const Pointer_Event *pe1 = eina_list_data_get(data1);
    const Pointer_Event *pe2 = data2;
 
    /* Only match if last was a down event */
@@ -1263,7 +1271,19 @@ _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe,
      {
       case EVAS_CALLBACK_MULTI_DOWN:
       case EVAS_CALLBACK_MOUSE_DOWN:
+         /* Check if got tap on same cord was tapped before */
          pe_list = eina_list_search_unsorted(st->l, compare_match_fingers, pe);
+
+         if ((!pe_list) &&
+               eina_list_search_unsorted(st->l, compare_pe_device, pe))
+           {  /* This device was touched in other cord before completion */
+              ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
+                    &st->info, EINA_FALSE);
+              consume_event(wd, event_info, event_type, ev_flag);
+
+              return EINA_FALSE;
+           }
+
          pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
          if ((pe->device == 0) && (eina_list_count(pe_list) == 1))
            {  /* This is the first mouse down we got */
@@ -1697,6 +1717,15 @@ _momentum_test(Evas_Object *obj, Pointer_Event *pe,
    Gesture_Info *gesture = wd->gesture[g_type];
    if (!gesture ) return;
 
+   /* When continues enable = TRUE a gesture may START on MOVE event */
+   /* We don't allow this to happen with the if-statement below.     */
+   /* When continues enable = FALSE a gesture may START on DOWN only */
+   /* Therefor it would NOT start on MOVE event.                     */
+   /* NOTE that touched list is updated AFTER this function returns  */
+   /* so (count == 0) when we get here on first touch on surface.    */
+   if ((wd->glayer_continues_enable) && (!eina_list_count(wd->touched)))
+     return; /* Got move on mouse-over move */
+
    Momentum_Type *st = gesture->data;
    Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
    if (!st)
@@ -1712,8 +1741,8 @@ _momentum_test(Evas_Object *obj, Pointer_Event *pe,
    /* First make avarage of all touched devices to determine center point */
    Eina_List *l;
    Pointer_Event *p;
-   Pointer_Event pe_local = *pe;  /* Copy pe event info to local */
-   int cnt = 1;    /* We start counter counting current pe event */
+   Pointer_Event pe_local = *pe;           /* Copy pe event info to local */
+   unsigned int cnt = 1;    /* We start counter counting current pe event */
    EINA_LIST_FOREACH(wd->touched, l, p)
       if (p->device != pe_local.device)
         {
@@ -1832,7 +1861,13 @@ _momentum_test(Evas_Object *obj, Pointer_Event *pe,
          _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe_local.x, pe_local.y,
                st->t_st_x, st->t_st_y, pe_local.timestamp);
 
-         ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END, &st->info,
+         if ((fabs(st->info.mx) > ELM_GESTURE_MINIMUM_MOMENTUM) ||
+               (fabs(st->info.my) > ELM_GESTURE_MINIMUM_MOMENTUM))
+           state_to_report = ELM_GESTURE_STATE_END;
+         else
+           state_to_report = ELM_GESTURE_STATE_ABORT;
+
+         ev_flag = _set_state(gesture, state_to_report, &st->info,
                EINA_FALSE);
          consume_event(wd, event_info, event_type, ev_flag);
          return;
@@ -1945,6 +1980,15 @@ _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
    Gesture_Info *gesture = wd->gesture[g_type];
    if (!gesture ) return;
 
+   /* When continues enable = TRUE a gesture may START on MOVE event */
+   /* We don't allow this to happen with the if-statement below.     */
+   /* When continues enable = FALSE a gesture may START on DOWN only */
+   /* Therefor it would NOT start on MOVE event.                     */
+   /* NOTE that touched list is updated AFTER this function returns  */
+   /* so (count == 0) when we get here on first touch on surface.    */
+   if ((wd->glayer_continues_enable) && (!eina_list_count(wd->touched)))
+     return; /* Got move on mouse-over move */
+
    Line_Type *st = gesture->data;
    if (!st)
      {
@@ -2089,7 +2133,7 @@ _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
           }
      }
 
-   st->info.n = started;
+   st->info.momentum.n = started;
 
 
    if (ended &&
@@ -2325,7 +2369,6 @@ get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
  *
  * @ingroup Elm_Gesture_Layer
  */
-/* FIXME change float to double */
 static double
 compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
       Evas_Coord x2, Evas_Coord y2, unsigned int tm2, double zoom_finger_factor)