/* ELM_GESTURE_NEGATIVE_ANGLE - magic number says we didn't compute this yet */
#define ELM_GESTURE_NEGATIVE_ANGLE (-1.0) /* Magic number */
#define ELM_GESTURE_MOMENTUM_TIMEOUT 50
+#define ELM_GESTURE_MULTI_TIMEOUT 50
/* Some Trigo values */
#define RAD_90DEG M_PI_2
struct _Long_Tap_Type
{
Elm_Gesture_Taps_Info info;
- unsigned int center_x;
- unsigned int center_y;
- unsigned int n_taps;
+ Evas_Coord center_x;
+ Evas_Coord center_y;
+ unsigned int max_touched;
Ecore_Timer *timeout; /* When this expires, long tap STARTed */
Eina_List *touched;
};
unsigned int t_st_x; /* Time start on X */
unsigned int t_st_y; /* Time start on Y */
unsigned int t_end; /* Time end */
+ unsigned int t_up; /* Recent up event time */
int xdir, ydir;
};
typedef struct _Momentum_Type Momentum_Type;
Ecore_Timer *dbl_timeout; /* When this expires, dbl click/taps ABORTed */
Eina_List *pending; /* List of devices need to refeed *UP event */
Eina_List *touched; /* Information of touched devices */
- Eina_List *recent_device_event; /* Information of recent pe event of each device */
Eina_Bool repeat_events : 1;
};
static Eina_List *
_remove_touched_device(Eina_List *list, Pointer_Event *pe)
{
+ Eina_List *lst = NULL;
Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
if (p)
{
+ lst = eina_list_remove(list, p);
free(p);
- return eina_list_remove(list, p);
+ return lst;
}
return list;
}
/* END - Functions to manage touched-device list */
-/* START - Functions to manage recent device event list */
-/* This list holds the recent-event for each device */
-/* it will hold a single recent-event for each device */
-/* We are using those PE events of this list to */
-/* send them later to test funcs to restart gestures */
-/* We only keep DOWN, MOVE events in this list. */
-/* So when no touch this list is empty. */
-/**
- * @internal
- *
- * Recoed Pointer Event in touched device list
- * Note: This fuction allocates memory for PE event
- * This memory is released here when device untouched
- * or in cleanup.
- * @param list Pointer to touched device list.
- * @param Pointer_Event Pointer to PE.
- *
- * @ingroup Elm_Gesture_Layer
- */
-static Eina_List *
-_add_recent_device_event(Eina_List *list, Pointer_Event *pe)
-{
- void *data = eina_list_search_sorted(list, compare_device, pe);
- Eina_List *l = list;
- Pointer_Event *p = NULL;
- if(data) /* First remove recent event for this device */
- l = eina_list_remove(list, data);
-
-
- switch(pe->event_type)
- {
- case EVAS_CALLBACK_MOUSE_DOWN:
- case EVAS_CALLBACK_MOUSE_MOVE:
- case EVAS_CALLBACK_MULTI_DOWN:
- case EVAS_CALLBACK_MULTI_MOVE:
- p = malloc(sizeof(Pointer_Event));
- memcpy(p, pe, sizeof(Pointer_Event)); /* Freed in here or on cleanup */
- l = eina_list_sorted_insert(l, compare_device, p);
- break;
-
- /* Kept those cases for referance */
- case EVAS_CALLBACK_MOUSE_IN:
- case EVAS_CALLBACK_MOUSE_OUT:
- case EVAS_CALLBACK_MOUSE_WHEEL:
- case EVAS_CALLBACK_MOUSE_UP:
- case EVAS_CALLBACK_MULTI_UP:
- case EVAS_CALLBACK_KEY_DOWN:
- case EVAS_CALLBACK_KEY_UP:
- break;
-
- default:
- return l;
- }
-
- return l;
-}
-/* END - Functions to manage recent device event list */
-
/**
* @internal
*
if (pending)
{
- wd->pending = eina_list_remove_list(wd->pending, pending);
- int device = ELM_MOUSE_DEVICE;
- if (wd->event_history_list->event_type == EVAS_CALLBACK_MULTI_UP)
- device = ((Evas_Event_Multi_Up *)
- (wd->event_history_list->event))->device;
+ wd->pending = eina_list_remove_list(wd->pending, pending);
}
else
- wd->pending = _add_device_pending(wd->pending,
- wd->event_history_list->event,
- wd->event_history_list->event_type);
+ {
+ wd->pending = _add_device_pending(wd->pending,
+ wd->event_history_list->event,
+ wd->event_history_list->event_type);
+ }
}
free(wd->event_history_list->event);
EINA_LIST_FREE(wd->touched, data)
free(data);
- EINA_LIST_FREE(wd->recent_device_event, data)
- free(data);
-
if (!elm_widget_disabled_get(obj))
_unregister_callbacks(obj);
* @ingroup Elm_Gesture_Layer
*/
static void
-_compute_taps_center(Long_Tap_Type *st, Pointer_Event *pe)
+_compute_taps_center(Long_Tap_Type *st,
+ Evas_Coord *x_out, Evas_Coord *y_out, Pointer_Event *pe)
{
if(!eina_list_count(st->touched))
return;
}
}
- st->info.x = x / eina_list_count(st->touched);
- st->info.y = y / eina_list_count(st->touched);
+ *x_out = x / eina_list_count(st->touched);
+ *y_out = y / eina_list_count(st->touched);
}
/**
*/
static void
_n_long_tap_test(Evas_Object *obj, Pointer_Event *pe,
- void *event_info, Evas_Callback_Type event_type,
- Elm_Gesture_Types g_type)
+ void *event_info, Evas_Callback_Type event_type,
+ Elm_Gesture_Types g_type)
{ /* Here we fill Recent_Taps struct and fire-up click/tap timers */
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 */
-
+ return; /* see _make_pointer_event function */
Gesture_Info *gesture = wd->gesture[g_type];
- if (!gesture ) return;
+ if (!gesture) return;
Long_Tap_Type *st = gesture->data;
if (!st)
{
case EVAS_CALLBACK_MULTI_DOWN:
case EVAS_CALLBACK_MOUSE_DOWN:
- st->touched = _add_touched_device(st->touched, pe);
- st->info.n = eina_list_count(st->touched);
- if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
- { /* This is the first mouse down we got */
- st->info.timestamp = pe->timestamp;
+ st->touched = _add_touched_device(st->touched, pe);
+ st->info.n = eina_list_count(st->touched);
+ if (st->info.n > st->max_touched)
+ st->max_touched = st->info.n;
+ else
+ { /* User removed finger from touch, then put back - ABORT */
+ if ((gesture->state == ELM_GESTURE_STATE_START) ||
+ (gesture->state == ELM_GESTURE_STATE_MOVE))
+ {
+ ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
+ &st->info, EINA_FALSE);
+ consume_event(wd, event_info, event_type, ev_flag);
+ }
+ }
- /* To test long tap */
- /* When this timer expires, gesture STARTED */
- if (!st->timeout)
- st->timeout = ecore_timer_add(wd->long_tap_start_timeout,
- _long_tap_timeout, gesture);
- }
+ if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
+ { /* This is the first mouse down we got */
+ st->info.timestamp = pe->timestamp;
- consume_event(wd, event_info, event_type, ev_flag);
- _compute_taps_center(st, pe);
- break;
+ /* To test long tap */
+ /* When this timer expires, gesture STARTED */
+ if (!st->timeout)
+ st->timeout = ecore_timer_add(wd->long_tap_start_timeout,
+ _long_tap_timeout, gesture);
+ }
+
+ consume_event(wd, event_info, event_type, ev_flag);
+ _compute_taps_center(st, &st->info.x, &st->info.y, pe);
+ st->center_x = st->info.x;
+ st->center_y = st->info.y;
+ break;
case EVAS_CALLBACK_MULTI_UP:
case EVAS_CALLBACK_MOUSE_UP:
- st->touched = _remove_touched_device(st->touched, pe);
- if (st->info.n &&
- ((gesture->state == ELM_GESTURE_STATE_START) ||
+ st->touched = _remove_touched_device(st->touched, pe);
+ _compute_taps_center(st, &st->center_x, &st->center_y, pe);
+ if (st->info.n &&
+ ((gesture->state == ELM_GESTURE_STATE_START) ||
(gesture->state == ELM_GESTURE_STATE_MOVE)))
- { /* Report END only for gesture that STARTed */
- if (eina_list_count(st->touched) == 0)
- { /* Report END only at last release event */
- ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
- &st->info, EINA_FALSE);
- consume_event(wd, event_info, event_type, ev_flag);
- }
- }
- else
- { /* Stop test, user lifts finger before long-start */
- if (st->timeout) ecore_timer_del(st->timeout);
- st->timeout = NULL;
- ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
- &st->info, EINA_FALSE);
- consume_event(wd, event_info, event_type, ev_flag);
- }
+ { /* Report END only for gesture that STARTed */
+ if (eina_list_count(st->touched) == 0)
+ { /* Report END only at last release event */
+ ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
+ &st->info, EINA_FALSE);
+ consume_event(wd, event_info, event_type, ev_flag);
+ }
+ }
+ else
+ { /* Stop test, user lifts finger before long-start */
+ if (st->timeout) ecore_timer_del(st->timeout);
+ st->timeout = NULL;
+ ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
+ &st->info, EINA_FALSE);
+ consume_event(wd, event_info, event_type, ev_flag);
+ }
- break;
+ break;
case EVAS_CALLBACK_MULTI_MOVE:
case EVAS_CALLBACK_MOUSE_MOVE:
- if(st->info.n &&
- ((gesture->state == ELM_GESTURE_STATE_START) ||
- (gesture->state == ELM_GESTURE_STATE_MOVE)))
- { /* Report MOVE only if STARTED */
- _compute_taps_center(st, pe);
- /* Report MOVE if gesture started */
- ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
- &st->info, EINA_TRUE);
- consume_event(wd, event_info, event_type, ev_flag);
- }
- break;
+ if(st->info.n &&
+ ((gesture->state == ELM_GESTURE_STATE_START) ||
+ (gesture->state == ELM_GESTURE_STATE_MOVE)))
+ { /* Report MOVE only if STARTED */
+ Evas_Coord x = 0;
+ Evas_Coord y = 0;
+ Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
+
+ _compute_taps_center(st, &x, &y, pe);
+ /* ABORT if user moved fingers out of tap area */
+#if defined(DEBUG_GESTURE_LAYER)
+ printf("%s x,y=(%d,%d) st->info.x,st->info.y=(%d,%d)\n",__func__,x,y,st->info.x,st->info.y);
+#endif
+ if (!_inside(x, y, st->center_x, st->center_y))
+ state_to_report = ELM_GESTURE_STATE_ABORT;
+
+ /* Report MOVE if gesture started */
+ ev_flag = _set_state(gesture, state_to_report,
+ &st->info, EINA_TRUE);
+ consume_event(wd, event_info, event_type, ev_flag);
+ }
+ break;
default:
- return;
+ return;
}
}
if (!gesture ) return;
Momentum_Type *st = gesture->data;
- Elm_Gesture_State state_to_report;
+ Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
if (!st)
{ /* Allocated once on first time */
st = calloc(1, sizeof(Momentum_Type));
if (!pe)
return;
+ /* 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 */
+ unsigned int cnt = 1; /* We start counter counting current pe event */
+ EINA_LIST_FOREACH(wd->touched, l, p)
+ if (p->device != pe_local.device)
+ {
+ pe_local.x += p->x;
+ pe_local.y += p->y;
+ cnt++;
+ }
+
+
+ /* Compute avarage to get center point */
+ pe_local.x /= cnt;
+ pe_local.y /= cnt;
+
+ /* If user added finger - reset gesture */
+ if ((st->info.n) && (st->info.n < cnt))
+ state_to_report = ELM_GESTURE_STATE_ABORT;
+
+ if (st->info.n < cnt)
+ st->info.n = cnt;
+
Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
switch (event_type)
{
case EVAS_CALLBACK_MOUSE_DOWN:
+ case EVAS_CALLBACK_MULTI_DOWN:
case EVAS_CALLBACK_MOUSE_MOVE:
+ case EVAS_CALLBACK_MULTI_MOVE:
if (!st->t_st_x)
{
if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
+ (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
(wd->glayer_continues_enable)) /* start also on MOVE */
{ /* We start on MOVE when cont-enabled only */
- st->line_st.x = st->line_end.x = pe->x;
- st->line_st.y = st->line_end.y = pe->y;
- st->t_st_x = st->t_st_y = st->t_end = pe->timestamp;
+ st->line_st.x = st->line_end.x = pe_local.x;
+ st->line_st.y = st->line_end.y = pe_local.y;
+ st->t_st_x = st->t_st_y = st->t_end = pe_local.timestamp;
st->xdir = st->ydir = 0;
- st->info.x2 = st->info.x1 = pe->x;
- st->info.y2 = st->info.y1 = pe->y;
- st->info.tx = st->info.ty = pe->timestamp;
+ st->info.x2 = st->info.x1 = pe_local.x;
+ st->info.y2 = st->info.y1 = pe_local.y;
+ st->info.tx = st->info.ty = pe_local.timestamp;
ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
&st->info, EINA_FALSE);
consume_event(wd, event_info, event_type, ev_flag);
-
}
return;
}
- state_to_report = ELM_GESTURE_STATE_MOVE;
- if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
+
+ /* ABORT gesture if got DOWN or MOVE event after UP+timeout */
+ if ((st->t_up) &&
+ ((st->t_up + ELM_GESTURE_MULTI_TIMEOUT) < pe_local.timestamp))
+ state_to_report = ELM_GESTURE_STATE_ABORT;
+
+ if ((pe_local.timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
{ /* Too long of a wait, reset all values */
- st->line_st.x = pe->x;
- st->line_st.y = pe->y;
- st->t_st_y = st->t_st_x = pe->timestamp;
+ st->line_st.x = pe_local.x;
+ st->line_st.y = pe_local.y;
+ st->t_st_y = st->t_st_x = pe_local.timestamp;
st->info.tx = st->t_st_x;
st->info.ty = st->t_st_y;
st->xdir = st->ydir = 0;
else
{
int xdir, ydir;
- xdir = _get_direction(st->line_st.x, pe->x);
- ydir = _get_direction(st->line_st.y, pe->y);
+ xdir = _get_direction(st->line_st.x, pe_local.x);
+ ydir = _get_direction(st->line_st.y, pe_local.y);
if (!xdir || (xdir == (-st->xdir)))
{
st->line_st.x = st->line_end.x;
}
}
- st->info.x2 = st->line_end.x = pe->x;
- st->info.y2 = st->line_end.y = pe->y;
- st->t_end = pe->timestamp;
- _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
- st->t_st_x, st->t_st_y, pe->timestamp);
+ st->info.x2 = st->line_end.x = pe_local.x;
+ st->info.y2 = st->line_end.y = pe_local.y;
+ st->t_end = pe_local.timestamp;
+ _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, state_to_report, &st->info,
EINA_TRUE);
consume_event(wd, event_info, event_type, ev_flag);
case EVAS_CALLBACK_MOUSE_UP:
- /* IGNORE if line info was cleared, like long press, move */
- if (!st->t_st_x)
+ case EVAS_CALLBACK_MULTI_UP:
+ st->t_up = pe_local.timestamp; /* Record recent up event time */
+ if ((cnt > 1) || /* Ignore if more fingers touch surface */
+ (!st->t_st_x)) /* IGNORE if info was cleared, long press,move */
return;
- state_to_report = ELM_GESTURE_STATE_END;
- if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
+ if ((pe_local.timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
{ /* Too long of a wait, reset all values */
- st->line_st.x = pe->x;
- st->line_st.y = pe->y;
- st->t_st_y = st->t_st_x = pe->timestamp;
+ st->line_st.x = pe_local.x;
+ st->line_st.y = pe_local.y;
+ st->t_st_y = st->t_st_x = pe_local.timestamp;
st->xdir = st->ydir = 0;
}
- st->info.x2 = pe->x;
- st->info.y2 = pe->y;
- st->line_end.x = pe->x;
- st->line_end.y = pe->y;
- st->t_end = pe->timestamp;
-
- _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
- st->t_st_x, st->t_st_y, pe->timestamp);
-
- ev_flag = _set_state(gesture, state_to_report, &st->info,
- EINA_FALSE);
- consume_event(wd, event_info, event_type, ev_flag);
+ st->info.x2 = pe_local.x;
+ st->info.y2 = pe_local.y;
+ st->line_end.x = pe_local.x;
+ st->line_end.y = pe_local.y;
+ st->t_end = pe_local.timestamp;
- return;
+ _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);
- case EVAS_CALLBACK_MULTI_UP:
- ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
+ ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END, &st->info,
EINA_FALSE);
consume_event(wd, event_info, event_type, ev_flag);
return;
}
}
- st->info.n = started;
+ st->info.momentum.n = started;
if (ended &&
if (!wd->gesture[g_type]) return;
Gesture_Info *gesture = wd->gesture[g_type];
- Rotate_Type *st = gesture->data;
+ Rotate_Type *st;
if (gesture)
{
st = gesture->data;
Widget_Data *wd = elm_widget_data_get(data);
if (!wd) return EINA_FALSE;
+ memset(pe, '\0', sizeof(*pe));
switch (event_type)
{
case EVAS_CALLBACK_MOUSE_DOWN:
/* Run through events to restart gestures */
Gesture_Info *g;
- Eina_Bool n_lines, n_flicks, zoom, rotate;
+ Eina_Bool n_momentum, n_lines, n_flicks, zoom, rotate;
/* We turn-on flag for finished, aborted, not-started gestures */
+ g = wd->gesture[ELM_GESTURE_MOMENTUM];
+ n_momentum = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
+ && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
+ if (n_momentum)
+ {
+ _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
+ _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
+ SET_TEST_BIT(g);
+ }
+
g = wd->gesture[ELM_GESTURE_N_LINES];
n_lines = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
&& (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
if (_make_pointer_event(data, event_info, event_type, &_pe))
pe = &_pe;
+ if (!pe) return;
+
if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
_n_long_tap_test(data, pe, event_info, event_type,
ELM_GESTURE_N_LONG_TAPS);
if (IS_TESTED(ELM_GESTURE_N_FLICKS))
_n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_FLICKS);
- if (IS_TESTED(ELM_GESTURE_ZOOM))
+ if (_elm_config->glayer_zoom_finger_enable && IS_TESTED(ELM_GESTURE_ZOOM))
_zoom_test(data, pe, event_info, event_type, ELM_GESTURE_ZOOM);
if (IS_TESTED(ELM_GESTURE_ZOOM))
_zoom_with_wheel_test(data, event_info, event_type, ELM_GESTURE_ZOOM);
- if (IS_TESTED(ELM_GESTURE_ROTATE))
+ if (_elm_config->glayer_rotate_finger_enable && IS_TESTED(ELM_GESTURE_ROTATE))
_rotate_test(data, pe, event_info, event_type, ELM_GESTURE_ROTATE);
if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
}
}
- /* Log event to restart gestures */
- wd->recent_device_event = _add_recent_device_event(wd->recent_device_event, &_pe);
-
/* we maintain list of touched devices */
/* We also use move to track current device x.y pos */
if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
Evas *e;
Widget_Data *wd;
- EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
+ ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
- wd = ELM_NEW(Widget_Data);
- e = evas_object_evas_get(parent);
- if (!e) return NULL;
- obj = elm_widget_add(e);
ELM_SET_WIDTYPE(widtype, "gesture_layer");
elm_widget_type_set(obj, "gesture_layer");
elm_widget_sub_object_add(parent, obj);
wd->flick_time_limit_ms = _elm_config->glayer_flick_time_limit_ms;
wd->long_tap_start_timeout = _elm_config->glayer_long_tap_start_timeout;
wd->repeat_events = EINA_TRUE;
- wd->glayer_continues_enable = EINA_FALSE;//_elm_config->glayer_continues_enable;
+ wd->glayer_continues_enable = _elm_config->glayer_continues_enable;
#if defined(DEBUG_GESTURE_LAYER)
printf("size of Gestures = <%d>\n", sizeof(wd->gesture));