1 #include <Elementary.h>
3 /** @defgroup Elm_Gesture_Layer Gesture Layer */
6 #define ELM_MOUSE_DEVICE 0
7 /* ELM_GESTURE_NEGATIVE_ANGLE - magic number says we didn't compute this yet */
8 #define ELM_GESTURE_NEGATIVE_ANGLE (-1.0) /* Magic number */
9 #define ELM_GESTURE_MOMENTUM_TIMEOUT 50
11 /* Some Trigo values */
12 #define RAD_90DEG M_PI_2
13 #define RAD_180DEG M_PI
14 #define RAD_270DEG (M_PI_2 * 3)
15 #define RAD_360DEG (M_PI * 2)
16 /* #define DEBUG_GESTURE_LAYER 1 */
19 _glayer_bufdup(void *buf, size_t size)
26 #define COPY_EVENT_INFO(EV) _glayer_bufdup(EV, sizeof(*EV))
29 #define SET_TEST_BIT(P) do { \
30 P->test = P->fn[ELM_GESTURE_STATE_START].cb || P->fn[ELM_GESTURE_STATE_MOVE].cb || P->fn[ELM_GESTURE_STATE_END].cb || P->fn[ELM_GESTURE_STATE_ABORT].cb; \
33 #define IS_TESTED(T) ((wd->gesture[T]) ? wd->gesture[T]->test : EINA_FALSE)
39 * Struct holds callback information.
41 * @ingroup Elm_Gesture_Layer
45 void *user_data; /**< Holds user data to CB (like sd) */
46 Elm_Gesture_Event_Cb cb;
53 * type for callback information
55 * @ingroup Elm_Gesture_Layer
57 typedef struct _Func_Data Func_Data;
62 * @struct _Gesture_Info
63 * Struct holds gesture info
65 * @ingroup Elm_Gesture_Layer
70 void *data; /**< Holds gesture intemidiate processing data */
71 Func_Data fn[ELM_GESTURE_STATE_ABORT + 1]; /**< Callback info for states */
72 Elm_Gesture_Types g_type; /**< gesture type */
73 Elm_Gesture_State state; /**< gesture state */
74 void *info; /**< Data for the state callback */
75 Eina_Bool test; /**< if true this gesture should be tested on input */
81 * @typedef Gesture_Info
82 * Type for _Gesture_Info
84 * @ingroup Elm_Gesture_Layer
86 typedef struct _Gesture_Info Gesture_Info;
91 * @struct _Event_History
92 * Struct holds event history.
93 * These events are repeated if no gesture found.
95 * @ingroup Elm_Gesture_Layer
101 Evas_Callback_Type event_type;
107 * @typedef Event_History
108 * Type for _Event_History
110 * @ingroup Elm_Gesture_Layer
112 typedef struct _Event_History Event_History;
117 * @struct _Pointer_Event
118 * Struct holds pointer-event info
119 * This is a generic pointer event structure
121 * @ingroup Elm_Gesture_Layer
123 struct _Pointer_Event
126 unsigned int timestamp;
128 Evas_Callback_Type event_type;
134 * @typedef Pointer_Event
135 * Type for generic pointer event structure
137 * @ingroup Elm_Gesture_Layer
139 typedef struct _Pointer_Event Pointer_Event;
141 /* All *Type structs hold result for the user in 'info' field
142 * The rest is gesture processing intermediate data.
143 * NOTE: info field must be FIRST in the struct.
144 * This is used when reporting ABORT in event_history_clear() */
147 Elm_Gesture_Taps_Info info;
148 unsigned int count_ups;
154 typedef struct _Taps_Type Taps_Type;
156 struct _Long_Tap_Type
158 Elm_Gesture_Taps_Info info;
159 unsigned int center_x;
160 unsigned int center_y;
162 Ecore_Timer *timeout; /* When this expires, long tap STARTed */
165 typedef struct _Long_Tap_Type Long_Tap_Type;
167 struct _Momentum_Type
168 { /* Fields used by _line_test() */
169 Elm_Gesture_Momentum_Info info;
170 Evas_Coord_Point line_st;
171 Evas_Coord_Point line_end;
172 unsigned int t_st_x; /* Time start on X */
173 unsigned int t_st_y; /* Time start on Y */
174 unsigned int t_end; /* Time end */
177 typedef struct _Momentum_Type Momentum_Type;
181 Evas_Coord_Point line_st;
182 Evas_Coord_Point line_end;
183 Evas_Coord line_length;
184 unsigned int t_st; /* Time start */
185 unsigned int t_end; /* Time end */
187 double line_angle; /* Current angle of line */
189 typedef struct _Line_Data Line_Data;
192 { /* Fields used by _line_test() */
193 Elm_Gesture_Line_Info info;
194 Eina_List *list; /* List of Line_Data */
196 typedef struct _Line_Type Line_Type;
199 { /* Fields used by _zoom_test() */
200 Elm_Gesture_Zoom_Info info;
201 Pointer_Event zoom_st;
202 Pointer_Event zoom_mv;
203 Pointer_Event zoom_st1;
204 Pointer_Event zoom_mv1;
205 Evas_Event_Mouse_Wheel *zoom_wheel;
206 Evas_Coord zoom_base; /* Holds gap between fingers on zoom-start */
207 Evas_Coord zoom_distance_tolerance;
208 Elm_Gesture_Momentum_Info momentum1; /* For continues gesture */
209 Elm_Gesture_Momentum_Info momentum2; /* For continues gesture */
212 typedef struct _Zoom_Type Zoom_Type;
215 { /* Fields used by _rotation_test() */
216 Elm_Gesture_Rotate_Info info;
217 Pointer_Event rotate_st;
218 Pointer_Event rotate_mv;
219 Pointer_Event rotate_st1;
220 Pointer_Event rotate_mv1;
221 double rotate_angular_tolerance;
223 Elm_Gesture_Momentum_Info momentum1; /* For continues gesture */
224 Elm_Gesture_Momentum_Info momentum2; /* For continues gesture */
226 typedef struct _Rotate_Type Rotate_Type;
230 Evas_Object *target; /* Target Widget */
231 Event_History *event_history_list;
234 Evas_Coord zoom_distance_tolerance;
235 Evas_Coord line_distance_tolerance;
236 double line_angular_tolerance;
237 double zoom_wheel_factor; /* mouse wheel zoom steps */
238 double zoom_finger_factor; /* used for zoom factor */
239 double rotate_angular_tolerance;
240 unsigned int flick_time_limit_ms;
241 double long_tap_start_timeout;
246 Gesture_Info *gesture[ELM_GESTURE_LAST];
247 Ecore_Timer *dbl_timeout; /* When this expires, dbl click/taps ABORTed */
248 Eina_List *pending; /* List of devices need to refeed *UP event */
249 Eina_List *touched; /* Information of touched devices */
250 Eina_List *recent_device_event; /* Information of recent pe event of each device */
252 Eina_Bool repeat_events : 1;
254 typedef struct _Widget_Data Widget_Data;
256 static const char *widtype = NULL;
257 static void _del_hook(Evas_Object *obj);
259 static Eina_Bool _event_history_clear(Evas_Object *obj);
260 static void _reset_states(Widget_Data *wd);
261 static void _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
262 static void _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
263 static void _zoom_with_wheel_test(Evas_Object *obj, void *event_info, Evas_Callback_Type event_type, Elm_Gesture_Types g_type);
264 static void _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
265 static void _mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
266 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
267 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
269 static void _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
270 static void _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
271 static void _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
273 /* START - Functions to manage touched-device list */
276 * This function is used to find if device is touched
278 * @ingroup Elm_Gesture_Layer
281 compare_device(const void *data1, const void *data2)
282 { /* Compare the two device numbers */
283 return (((Pointer_Event *) data1)->device -((Pointer_Event *) data2)->device);
289 * Recoed Pointer Event in touched device list
290 * Note: This fuction allocates memory for PE event
291 * This memory is released in _remove_touched_device()
292 * @param list Pointer to touched device list.
293 * @param Pointer_Event Pointer to PE.
295 * @ingroup Elm_Gesture_Layer
298 _add_touched_device(Eina_List *list, Pointer_Event *pe)
300 if (eina_list_search_unsorted_list(list, compare_device, pe))
303 Pointer_Event *p = malloc(sizeof(Pointer_Event ));
304 memcpy(p, pe, sizeof(Pointer_Event)); /* Freed in _remove_touched_device() */
305 return eina_list_append(list, p);
311 * Remove Pointer Event from touched device list
312 * @param list Pointer to touched device list.
313 * @param Pointer_Event Pointer to PE.
315 * @ingroup Elm_Gesture_Layer
318 _remove_touched_device(Eina_List *list, Pointer_Event *pe)
320 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
324 return eina_list_remove(list, p);
329 /* END - Functions to manage touched-device list */
331 /* START - Functions to manage recent device event list */
332 /* This list holds the recent-event for each device */
333 /* it will hold a single recent-event for each device */
334 /* We are using those PE events of this list to */
335 /* send them later to test funcs to restart gestures */
336 /* We only keep DOWN, MOVE events in this list. */
337 /* So when no touch this list is empty. */
341 * Recoed Pointer Event in touched device list
342 * Note: This fuction allocates memory for PE event
343 * This memory is released here when device untouched
345 * @param list Pointer to touched device list.
346 * @param Pointer_Event Pointer to PE.
348 * @ingroup Elm_Gesture_Layer
351 _add_recent_device_event(Eina_List *list, Pointer_Event *pe)
353 void *data = eina_list_search_sorted(list, compare_device, pe);
355 Pointer_Event *p = NULL;
356 if(data) /* First remove recent event for this device */
357 l = eina_list_remove(list, data);
360 switch(pe->event_type)
362 case EVAS_CALLBACK_MOUSE_DOWN:
363 case EVAS_CALLBACK_MOUSE_MOVE:
364 case EVAS_CALLBACK_MULTI_DOWN:
365 case EVAS_CALLBACK_MULTI_MOVE:
366 p = malloc(sizeof(Pointer_Event));
367 memcpy(p, pe, sizeof(Pointer_Event)); /* Freed in here or on cleanup */
368 l = eina_list_sorted_insert(l, compare_device, p);
371 /* Kept those cases for referance */
372 case EVAS_CALLBACK_MOUSE_IN:
373 case EVAS_CALLBACK_MOUSE_OUT:
374 case EVAS_CALLBACK_MOUSE_WHEEL:
375 case EVAS_CALLBACK_MOUSE_UP:
376 case EVAS_CALLBACK_MULTI_UP:
377 case EVAS_CALLBACK_KEY_DOWN:
378 case EVAS_CALLBACK_KEY_UP:
387 /* END - Functions to manage recent device event list */
393 * @param event_info pointer to event.
395 * @ingroup Elm_Gesture_Layer
397 static Evas_Event_Flags
398 _get_event_flag(void *event_info, Evas_Callback_Type event_type)
402 case EVAS_CALLBACK_MOUSE_IN:
403 return ((Evas_Event_Mouse_In *) event_info)->event_flags;
404 case EVAS_CALLBACK_MOUSE_OUT:
405 return ((Evas_Event_Mouse_Out *) event_info)->event_flags;
406 case EVAS_CALLBACK_MOUSE_DOWN:
407 return ((Evas_Event_Mouse_Down *) event_info)->event_flags;
408 case EVAS_CALLBACK_MOUSE_MOVE:
409 return ((Evas_Event_Mouse_Move *) event_info)->event_flags;
410 case EVAS_CALLBACK_MOUSE_UP:
411 return ((Evas_Event_Mouse_Up *) event_info)->event_flags;
412 case EVAS_CALLBACK_MOUSE_WHEEL:
413 return ((Evas_Event_Mouse_Wheel *) event_info)->event_flags;
414 case EVAS_CALLBACK_MULTI_DOWN:
415 return ((Evas_Event_Multi_Down *) event_info)->event_flags;
416 case EVAS_CALLBACK_MULTI_MOVE:
417 return ((Evas_Event_Multi_Move *) event_info)->event_flags;
418 case EVAS_CALLBACK_MULTI_UP:
419 return ((Evas_Event_Multi_Up *) event_info)->event_flags;
420 case EVAS_CALLBACK_KEY_DOWN:
421 return ((Evas_Event_Key_Down *) event_info)->event_flags;
422 case EVAS_CALLBACK_KEY_UP:
423 return ((Evas_Event_Key_Up *) event_info)->event_flags;
425 return EVAS_EVENT_FLAG_NONE;
432 * Sets event flag to value returned from user callback
433 * @param wd Widget Data
434 * @param event_info pointer to event.
435 * @param event_type what type was ev (mouse down, etc...)
436 * @param ev_flags event flags
438 * @ingroup Elm_Gesture_Layer
441 consume_event(Widget_Data *wd, void *event_info,
442 Evas_Callback_Type event_type, Evas_Event_Flags ev_flags)
443 { /* Mark EVAS_EVENT_FLAG_ON_HOLD on events that are used by gesture layer */
444 /* ev_flags != EVAS_EVENT_FLAG_NONE means target used event and g-layer */
445 /* should not refeed this event. */
447 return; /* This happens when restarting gestures */
449 if ((ev_flags) || (!wd->repeat_events))
453 case EVAS_CALLBACK_MOUSE_DOWN:
454 ((Evas_Event_Mouse_Down *) event_info)->event_flags |= ev_flags;
456 case EVAS_CALLBACK_MOUSE_MOVE:
457 ((Evas_Event_Mouse_Move *) event_info)->event_flags |= ev_flags;
459 case EVAS_CALLBACK_MOUSE_UP:
460 ((Evas_Event_Mouse_Up *) event_info)->event_flags |= ev_flags;
462 case EVAS_CALLBACK_MOUSE_WHEEL:
463 ((Evas_Event_Mouse_Wheel *) event_info)->event_flags |= ev_flags;
465 case EVAS_CALLBACK_MULTI_DOWN:
466 ((Evas_Event_Multi_Down *) event_info)->event_flags |= ev_flags;
468 case EVAS_CALLBACK_MULTI_MOVE:
469 ((Evas_Event_Multi_Move *) event_info)->event_flags |= ev_flags;
471 case EVAS_CALLBACK_MULTI_UP:
472 ((Evas_Event_Multi_Up *) event_info)->event_flags |= ev_flags;
474 case EVAS_CALLBACK_KEY_DOWN:
475 ((Evas_Event_Key_Down *) event_info)->event_flags |= ev_flags;
477 case EVAS_CALLBACK_KEY_UP:
478 ((Evas_Event_Key_Up *) event_info)->event_flags |= ev_flags;
489 * Report current state of a gesture by calling user callback.
490 * @param gesture what gesture state we report.
491 * @param info inforamtion for user callback
493 * @ingroup Elm_Gesture_Layer
495 static Evas_Event_Flags
496 _report_state(Gesture_Info *gesture, void *info)
497 { /* We report current state (START, MOVE, END, ABORT), once */
498 #if defined(DEBUG_GESTURE_LAYER)
499 printf("%s reporting gesture=<%d> state=<%d>\n" , __func__, gesture->g_type,
502 if ((gesture->state != ELM_GESTURE_STATE_UNDEFINED) &&
503 (gesture->fn[gesture->state].cb))
504 { /* Fill state-info struct and send ptr to user callback */
505 return gesture->fn[gesture->state].cb(
506 gesture->fn[gesture->state].user_data, info);
509 return EVAS_EVENT_FLAG_NONE;
515 * Update state for a given gesture.
516 * We may update gesture state to:
517 * UNDEFINED - current input did not start gesure yet.
518 * START - gesture started according to input.
519 * MOVE - gusture in progress.
520 * END - gesture completed according to input.
521 * ABORT - input does not matches gesure.
522 * note that we may move from UNDEFINED to ABORT
523 * because we may detect that gesture will not START
524 * with a given input.
526 * @param g given gesture to change state.
527 * @param s gesure new state.
528 * @param info buffer to be sent to user callback on report_state.
529 * @param force makes report_state to report the new-state even
530 * if its same as current state. Works for MOVE - gesture in progress.
532 * @ingroup Elm_Gesture_Layer
534 static Evas_Event_Flags
535 _set_state(Gesture_Info *g, Elm_Gesture_State s,
536 void *info, Eina_Bool force)
538 Elm_Gesture_State old_state;
539 if ((g->state == s) && (!force))
540 return EVAS_EVENT_FLAG_NONE;
542 old_state = g->state;
545 g->info = info; /* Information for user callback */
546 if ((g->state == ELM_GESTURE_STATE_ABORT) ||
547 (g->state == ELM_GESTURE_STATE_END))
548 g->test = EINA_FALSE;
550 if ((g->state != ELM_GESTURE_STATE_UNDEFINED) &&
551 (!((old_state == ELM_GESTURE_STATE_UNDEFINED) &&
552 (s == ELM_GESTURE_STATE_ABORT))))
553 return _report_state(g, g->info);
555 return EVAS_EVENT_FLAG_NONE;
561 * This resets all gesture states and sets test-bit.
562 * this is used for restarting gestures to listen to input.
563 * happens after we complete a gesture or no gesture was detected.
564 * @param wd Widget data of the gesture-layer object.
566 * @ingroup Elm_Gesture_Layer
569 _reset_states(Widget_Data *wd)
573 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
578 _set_state(p, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
587 * if gesture was NOT detected AND we only have gestures in ABORT state
588 * we clear history immediately to be ready for input.
590 * @param obj The gesture-layer object.
591 * @return TRUE on event history_clear
593 * @ingroup Elm_Gesture_Layer
596 _clear_if_finished(Evas_Object *obj)
598 Widget_Data *wd = elm_widget_data_get(obj);
599 if (!wd) return EINA_FALSE;
602 /* Clear history if all we have aborted gestures */
603 Eina_Bool reset_s = EINA_TRUE, all_undefined = EINA_TRUE;
604 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
605 { /* If no gesture started and all we have aborted gestures, reset all */
606 Gesture_Info *p = wd->gesture[i];
607 if ((p) && (p->state != ELM_GESTURE_STATE_UNDEFINED))
609 if ((p->state == ELM_GESTURE_STATE_START) ||
610 (p->state == ELM_GESTURE_STATE_MOVE))
611 reset_s = EINA_FALSE;
613 all_undefined = EINA_FALSE;
617 // if ((!wd->touched) || (reset_s && !all_undefined))
618 /* (!wd->touched && reset_s) - don't stop zoom with mouse-wheel */
619 if (reset_s && (/* !eina_list_count(wd->touched) || */ !all_undefined)) /* Aharon */
620 return _event_history_clear(obj);
626 _inside(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
628 int w = elm_finger_size_get() >> 1; /* Finger size devided by 2 */
644 /* All *test_reset() funcs are called to clear
645 * gesture intermediate data.
646 * This happens when we need to reset our tests.
647 * for example when gesture is detected or all ABORTed. */
649 _dbl_click_test_reset(Gesture_Info *gesture)
654 Widget_Data *wd = elm_widget_data_get(gesture->obj);
655 if (wd->dbl_timeout) ecore_timer_del(wd->dbl_timeout);
656 wd->dbl_timeout = NULL;
663 EINA_LIST_FREE(((Taps_Type *) gesture->data)->l, data)
664 EINA_LIST_FREE(data, pe)
667 memset(gesture->data, 0, sizeof(Taps_Type));
670 /* All *test_reset() funcs are called to clear
671 * gesture intermediate data.
672 * This happens when we need to reset our tests.
673 * for example when gesture is detected or all ABORTed. */
675 _n_long_tap_test_reset(Gesture_Info *gesture)
683 Long_Tap_Type *st = gesture->data;
684 if (st->timeout) ecore_timer_del(st->timeout);
687 EINA_LIST_FOREACH(st->touched, l, p)
690 eina_list_free(st->touched);
691 memset(gesture->data, 0, sizeof(Long_Tap_Type));
695 _momentum_test_reset(Gesture_Info *gesture)
703 memset(gesture->data, 0, sizeof(Momentum_Type));
707 _line_data_reset(Line_Data *st)
712 memset(st, 0, sizeof(Line_Data));
713 st->line_angle = ELM_GESTURE_NEGATIVE_ANGLE;
717 _line_test_reset(Gesture_Info *gesture)
725 Line_Type *st = gesture->data;
726 Eina_List *list = st->list;
729 EINA_LIST_FOREACH(list, l, t_line)
732 eina_list_free(list);
737 _zoom_test_reset(Gesture_Info *gesture)
745 Widget_Data *wd = elm_widget_data_get(gesture->obj);
746 Zoom_Type *st = gesture->data;
747 Pointer_Event pe, pe1;
748 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
749 evas_object_evas_get(wd->target), "Control");
750 evas_object_key_ungrab(wd->target, "Control_L", mask, 0);
751 evas_object_key_ungrab(wd->target, "Control_R", mask, 0);
753 pe.timestamp = pe1.timestamp = 0;
755 if (eina_list_search_unsorted_list(wd->touched, compare_device,
757 memcpy(&pe, &st->zoom_st, sizeof(Pointer_Event));
759 if (eina_list_search_unsorted_list(wd->touched, compare_device,
761 memcpy(&pe1, &st->zoom_st1, sizeof(Pointer_Event));
763 memset(st, 0, sizeof(Zoom_Type));
765 /* If user released one finger only, restore down-info */
766 if (pe.timestamp && (!pe1.timestamp))
767 memcpy(&st->zoom_st, &pe, sizeof(Pointer_Event));
769 if (pe1.timestamp && (!pe.timestamp))
770 memcpy(&st->zoom_st1, &pe1, sizeof(Pointer_Event));
772 st->zoom_distance_tolerance = wd->zoom_distance_tolerance;
777 _rotate_test_reset(Gesture_Info *gesture)
785 Widget_Data *wd = elm_widget_data_get(gesture->obj);
786 Rotate_Type *st = gesture->data;
787 Pointer_Event pe, pe1;
789 pe.timestamp = pe1.timestamp = 0;
791 if (eina_list_search_unsorted_list(wd->touched, compare_device,
793 memcpy(&pe, &st->rotate_st, sizeof(Pointer_Event));
795 if (eina_list_search_unsorted_list(wd->touched, compare_device,
797 memcpy(&pe1, &st->rotate_st1, sizeof(Pointer_Event));
799 memset(st, 0, sizeof(Rotate_Type));
801 /* If user released one finger only, restore down-info */
802 if (pe.timestamp && (!pe1.timestamp))
803 memcpy(&st->rotate_st, &pe, sizeof(Pointer_Event));
805 if (pe1.timestamp && (!pe.timestamp))
806 memcpy(&st->rotate_st1, &pe1, sizeof(Pointer_Event));
809 st->info.base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
810 st->rotate_angular_tolerance = wd->rotate_angular_tolerance;
817 * We register callbacks when gesture layer is attached to an object
818 * or when its enabled after disable.
820 * @param obj The gesture-layer object.
822 * @ingroup Elm_Gesture_Layer
825 _register_callbacks(Evas_Object *obj)
827 Widget_Data *wd = elm_widget_data_get(obj);
832 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
834 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
836 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_UP,
839 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
842 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_DOWN,
844 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_MOVE,
846 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_UP,
849 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_DOWN,
851 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_UP,
859 * We unregister callbacks when gesture layer is disabled.
861 * @param obj The gesture-layer object.
863 * @ingroup Elm_Gesture_Layer
866 _unregister_callbacks(Evas_Object *obj)
868 Widget_Data *wd = elm_widget_data_get(obj);
873 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
875 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
877 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_UP,
880 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
883 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_DOWN,
886 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_MOVE,
889 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_UP,
892 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_DOWN,
894 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_UP,
899 /* START - Event history list handling functions */
902 * This function is used to find if device number
903 * is found in a list of devices.
904 * The list contains devices for refeeding *UP event
906 * @ingroup Elm_Gesture_Layer
909 device_in_pending_list(const void *data1, const void *data2)
910 { /* Compare the two device numbers */
911 return (((intptr_t) data1) - ((intptr_t) data2));
917 * This functions adds device to refeed-pending device list
918 * @ingroup Elm_Gesture_Layer
921 _add_device_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
923 int device = ELM_MOUSE_DEVICE;
926 case EVAS_CALLBACK_MOUSE_DOWN:
928 case EVAS_CALLBACK_MULTI_DOWN:
929 device = ((Evas_Event_Multi_Down *) event)->device;
935 if (!eina_list_search_unsorted_list(list, device_in_pending_list,
938 return eina_list_append(list, (intptr_t*) device);
947 * This functions returns pending-device node
948 * @ingroup Elm_Gesture_Layer
951 _device_is_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
953 int device = ELM_MOUSE_DEVICE;
956 case EVAS_CALLBACK_MOUSE_UP:
958 case EVAS_CALLBACK_MULTI_UP:
959 device = ((Evas_Event_Multi_Up *) event)->device;
965 return eina_list_search_unsorted_list(list, device_in_pending_list,
966 (intptr_t *) device);
972 * This function reports ABORT to all none-detected gestures
973 * Then resets test bits for all desired gesures
974 * and clears input-events history.
975 * note: if no gesture was detected, events from history list
976 * are streamed to the widget because it's unused by layer.
977 * user may cancel refeed of events by setting repeat events.
979 * @param obj The gesture-layer object.
981 * @ingroup Elm_Gesture_Layer
984 _event_history_clear(Evas_Object *obj)
986 Widget_Data *wd = elm_widget_data_get(obj);
987 if (!wd) return EINA_FALSE;
991 Evas *e = evas_object_evas_get(obj);
992 Eina_Bool gesture_found = EINA_FALSE;
993 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
998 if (p->state == ELM_GESTURE_STATE_END)
999 gesture_found = EINA_TRUE;
1001 { /* Report ABORT to all gestures that still not finished */
1002 _set_state(p, ELM_GESTURE_STATE_ABORT, wd->gesture[i]->info,
1008 _reset_states(wd); /* we are ready to start testing for gestures again */
1010 /* Clear all gestures intermediate date */
1011 _n_long_tap_test_reset(wd->gesture[ELM_GESTURE_N_LONG_TAPS]);
1012 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_TAPS]);
1013 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
1014 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
1015 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
1016 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
1017 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
1018 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
1019 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
1021 /* Disable gesture layer so refeeded events won't be consumed by it */
1022 _unregister_callbacks(obj);
1023 while (wd->event_history_list)
1026 t = wd->event_history_list;
1027 Eina_List *pending = _device_is_pending(wd->pending,
1028 wd->event_history_list->event,
1029 wd->event_history_list->event_type);
1031 /* Refeed events if no gesture matched input */
1032 if (pending || ((!gesture_found) && (!wd->repeat_events)))
1034 evas_event_refeed_event(e, wd->event_history_list->event,
1035 wd->event_history_list->event_type);
1039 wd->pending = eina_list_remove_list(wd->pending, pending);
1040 int device = ELM_MOUSE_DEVICE;
1041 if (wd->event_history_list->event_type == EVAS_CALLBACK_MULTI_UP)
1042 device = ((Evas_Event_Multi_Up *)
1043 (wd->event_history_list->event))->device;
1046 wd->pending = _add_device_pending(wd->pending,
1047 wd->event_history_list->event,
1048 wd->event_history_list->event_type);
1051 free(wd->event_history_list->event);
1052 wd->event_history_list = (Event_History *) eina_inlist_remove(
1053 EINA_INLIST_GET(wd->event_history_list),
1054 EINA_INLIST_GET(wd->event_history_list));
1057 _register_callbacks(obj);
1058 printf("%s\n", __func__);
1065 * This function copies input events.
1066 * We copy event info before adding it to history.
1067 * The memory is freed when we clear history.
1069 * @param event the event to copy
1070 * @param event_type event type to copy
1072 * @ingroup Elm_Gesture_Layer
1075 _copy_event_info(void *event, Evas_Callback_Type event_type)
1079 case EVAS_CALLBACK_MOUSE_DOWN:
1080 return COPY_EVENT_INFO((Evas_Event_Mouse_Down *) event);
1082 case EVAS_CALLBACK_MOUSE_MOVE:
1083 return COPY_EVENT_INFO((Evas_Event_Mouse_Move *) event);
1085 case EVAS_CALLBACK_MOUSE_UP:
1086 return COPY_EVENT_INFO((Evas_Event_Mouse_Up *) event);
1088 case EVAS_CALLBACK_MOUSE_WHEEL:
1089 return COPY_EVENT_INFO((Evas_Event_Mouse_Wheel *) event);
1091 case EVAS_CALLBACK_MULTI_DOWN:
1092 return COPY_EVENT_INFO((Evas_Event_Multi_Down *) event);
1094 case EVAS_CALLBACK_MULTI_MOVE:
1095 return COPY_EVENT_INFO((Evas_Event_Multi_Move *) event);
1097 case EVAS_CALLBACK_MULTI_UP:
1098 return COPY_EVENT_INFO((Evas_Event_Multi_Up *) event);
1100 case EVAS_CALLBACK_KEY_DOWN:
1101 return COPY_EVENT_INFO((Evas_Event_Key_Down *) event);
1103 case EVAS_CALLBACK_KEY_UP:
1104 return COPY_EVENT_INFO((Evas_Event_Key_Up *) event);
1112 _event_history_add(Evas_Object *obj, void *event, Evas_Callback_Type event_type)
1114 Widget_Data *wd = elm_widget_data_get(obj);
1116 if (!wd) return EINA_FALSE;
1118 ev = malloc(sizeof(Event_History));
1119 ev->event = _copy_event_info(event, event_type); /* Freed on event_history_clear */
1120 ev->event_type = event_type;
1121 wd->event_history_list = (Event_History *) eina_inlist_append(
1122 EINA_INLIST_GET(wd->event_history_list), EINA_INLIST_GET(ev));
1126 /* END - Event history list handling functions */
1129 _del_hook(Evas_Object *obj)
1131 Widget_Data *wd = elm_widget_data_get(obj);
1134 _event_history_clear(obj);
1135 eina_list_free(wd->pending);
1137 Pointer_Event *data;
1138 EINA_LIST_FREE(wd->touched, data)
1141 EINA_LIST_FREE(wd->recent_device_event, data)
1144 if (!elm_widget_disabled_get(obj))
1145 _unregister_callbacks(obj);
1147 /* Free all gestures internal data structures */
1149 for (i = 0; i < ELM_GESTURE_LAST; i++)
1152 if (wd->gesture[i]->data)
1153 free(wd->gesture[i]->data);
1155 free(wd->gesture[i]);
1162 compare_match_fingers(const void *data1, const void *data2)
1163 { /* Compare coords of first item in list to cur coords */
1164 const Pointer_Event *pe1 = eina_list_data_get(data1);
1165 const Pointer_Event *pe2 = data2;
1167 if (_inside(pe1->x, pe1->y, pe2->x, pe2->y))
1169 else if (pe1->x < pe2->x)
1173 if (pe1->x == pe2->x)
1174 return pe1->y - pe2->y;
1181 compare_pe_device(const void *data1, const void *data2)
1182 { /* Compare coords of first item in list to cur coords */
1183 const Pointer_Event *pe1 = eina_list_data_get(eina_list_last(data1));
1184 const Pointer_Event *pe2 = data2;
1186 /* Only match if last was a down event */
1187 if ((pe1->event_type != EVAS_CALLBACK_MULTI_DOWN) &&
1188 (pe1->event_type != EVAS_CALLBACK_MOUSE_DOWN))
1192 if (pe1->device == pe2->device)
1194 else if (pe1->device < pe2->device)
1201 _record_pointer_event(Taps_Type *st, Eina_List *pe_list, Pointer_Event *pe,
1202 Widget_Data *wd, void *event_info, Evas_Callback_Type event_type)
1203 { /* Keep copy of pe and record it in list */
1204 Pointer_Event *p = malloc(sizeof(Pointer_Event));
1205 memcpy(p, pe, sizeof(Pointer_Event));
1206 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1212 /* This will also update middle-point to report to user later */
1213 st->info.x = st->sum_x / st->n_taps;
1214 st->info.y = st->sum_y / st->n_taps;
1215 st->info.timestamp = pe->timestamp;
1219 pe_list = eina_list_append(pe_list, p);
1220 st->l = eina_list_append(st->l, pe_list);
1223 pe_list = eina_list_append(pe_list, p);
1231 * when this timer expires we ABORT double click gesture.
1233 * @param data The gesture-layer object.
1234 * @return cancles callback for this timer.
1236 * @ingroup Elm_Gesture_Layer
1239 _dbl_click_timeout(void *data)
1241 Gesture_Info *gesture = data;
1242 Widget_Data *wd = elm_widget_data_get(gesture->obj);
1244 wd->dbl_timeout = NULL;
1245 _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1246 gesture->info, EINA_FALSE);
1248 _dbl_click_test_reset(gesture);
1249 _clear_if_finished(gesture->obj);
1250 return ECORE_CALLBACK_CANCEL;
1256 * when this timer expires we START long tap gesture
1258 * @param data The gesture-layer object.
1259 * @return cancles callback for this timer.
1261 * @ingroup Elm_Gesture_Layer
1264 _long_tap_timeout(void *data)
1266 Gesture_Info *gesture = data;
1267 Long_Tap_Type *st = gesture->data;
1270 _set_state(gesture, ELM_GESTURE_STATE_START,
1271 gesture->data, EINA_FALSE);
1273 return ECORE_CALLBACK_CANCEL;
1279 * This function checks all click/tap and double/triple taps
1281 * @param obj The gesture-layer object.
1282 * @param pe The recent input event as stored in pe struct.
1283 * @param event_info Original input event pointer.
1284 * @param event_type Type of original input event.
1285 * @param g_type what Gesture we are testing.
1286 * @param taps How many click/taps we test for.
1288 * @ingroup Elm_Gesture_Layer
1291 _dbl_click_test(Evas_Object *obj, Pointer_Event *pe,
1292 void *event_info, Evas_Callback_Type event_type,
1293 Elm_Gesture_Types g_type, int taps)
1294 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1295 Widget_Data *wd = elm_widget_data_get(obj);
1298 if (!pe) /* this happens when unhandled event arrived */
1299 return; /* see _make_pointer_event function */
1301 Gesture_Info *gesture = wd->gesture[g_type];
1302 if (!gesture ) return;
1304 if ((gesture->state == ELM_GESTURE_STATE_UNDEFINED) &&
1305 eina_list_count(wd->touched))
1306 return; /* user left a finger on device, do NOT start */
1308 Taps_Type *st = gesture->data;
1310 { /* Allocated once on first time */
1311 st = calloc(1, sizeof(Taps_Type));
1313 _dbl_click_test_reset(gesture);
1316 Eina_List *pe_list = NULL;
1317 Pointer_Event *pe_down = NULL;
1318 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1319 switch (pe->event_type)
1321 case EVAS_CALLBACK_MULTI_DOWN:
1322 case EVAS_CALLBACK_MOUSE_DOWN:
1323 pe_list = eina_list_search_unsorted(st->l, compare_match_fingers, pe);
1324 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1325 if ((pe->device == 0) && (eina_list_count(pe_list) == 1))
1326 { /* This is the first mouse down we got */
1327 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1328 &st->info, EINA_FALSE);
1329 consume_event(wd, event_info, event_type, ev_flag);
1331 /* To test dbl_click/dbl_tap */
1332 /* When this timer expires, gesture ABORTed if not completed */
1333 if (!wd->dbl_timeout && (taps > 1))
1334 wd->dbl_timeout = ecore_timer_add(0.4, _dbl_click_timeout,
1341 case EVAS_CALLBACK_MULTI_UP:
1342 case EVAS_CALLBACK_MOUSE_UP:
1343 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1345 return; /* Got only first mouse_down and mouse_up */
1347 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1349 if (eina_list_count(pe_list) <= (unsigned int) ((taps - 1) * 2))
1350 return; /* Got only first mouse_down and mouse_up */
1352 /* Get first event in first list, this has to be Mouse Down event */
1353 pe_down = eina_list_data_get(pe_list);
1355 if (_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1361 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1362 &st->info, EINA_FALSE);
1363 consume_event(wd, event_info, event_type, ev_flag);
1367 if (st->count_ups == eina_list_count(st->l))
1369 /* Abort if we found a single click */
1370 if ((taps == 1) && (st->count_ups == 1))
1372 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1373 &st->info, EINA_FALSE);
1374 consume_event(wd, event_info, event_type, ev_flag);
1377 st->info.n = st->count_ups;
1378 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1379 &st->info, EINA_FALSE);
1380 consume_event(wd, event_info, event_type, ev_flag);
1387 case EVAS_CALLBACK_MULTI_MOVE:
1388 case EVAS_CALLBACK_MOUSE_MOVE:
1389 /* Get first event in first list, this has to be a Mouse Down event */
1390 /* and verify that user didn't move out of this area before next tap */
1391 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1394 pe_down = eina_list_data_get(pe_list);
1395 if (!_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1397 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1398 &st->info, EINA_FALSE);
1399 consume_event(wd, event_info, event_type, ev_flag);
1412 * This function computes center-point for long-tap gesture
1414 * @param st Long Tap gesture info pointer
1415 * @param pe The recent input event as stored in pe struct.
1417 * @ingroup Elm_Gesture_Layer
1420 _compute_taps_center(Long_Tap_Type *st, Pointer_Event *pe)
1422 if(!eina_list_count(st->touched))
1427 Evas_Coord x = 0, y = 0;
1428 EINA_LIST_FOREACH(st->touched, l, p)
1429 { /* Accumulate all then take avarage */
1430 if (p->device == pe->device)
1431 { /* This will take care of values coming from MOVE event */
1442 st->info.x = x / eina_list_count(st->touched);
1443 st->info.y = y / eina_list_count(st->touched);
1449 * This function checks N long-tap gesture.
1451 * @param obj The gesture-layer object.
1452 * @param pe The recent input event as stored in pe struct.
1453 * @param event_info Original input event pointer.
1454 * @param event_type Type of original input event.
1455 * @param g_type what Gesture we are testing.
1456 * @param taps How many click/taps we test for.
1458 * @ingroup Elm_Gesture_Layer
1461 _n_long_tap_test(Evas_Object *obj, Pointer_Event *pe,
1462 void *event_info, Evas_Callback_Type event_type,
1463 Elm_Gesture_Types g_type)
1464 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1465 Widget_Data *wd = elm_widget_data_get(obj);
1468 if (!pe) /* this happens when unhandled event arrived */
1469 return; /* see _make_pointer_event function */
1471 Gesture_Info *gesture = wd->gesture[g_type];
1472 if (!gesture ) return;
1474 Long_Tap_Type *st = gesture->data;
1476 { /* Allocated once on first time */
1477 st = calloc(1, sizeof(Long_Tap_Type));
1479 _n_long_tap_test_reset(gesture);
1482 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1483 switch (pe->event_type)
1485 case EVAS_CALLBACK_MULTI_DOWN:
1486 case EVAS_CALLBACK_MOUSE_DOWN:
1487 if (st->info.n > eina_list_count(st->touched))
1488 { /* ABORT: user lifts finger then back before completing gesgure */
1489 if (st->timeout) ecore_timer_del(st->timeout);
1491 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1492 &st->info, EINA_FALSE);
1495 st->touched = _add_touched_device(st->touched, pe);
1496 st->info.n = eina_list_count(st->touched);
1497 if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
1498 { /* This is the first mouse down we got */
1499 st->info.timestamp = pe->timestamp;
1501 /* To test long tap */
1502 /* When this timer expires, gesture STARTED */
1504 st->timeout = ecore_timer_add(wd->long_tap_start_timeout, _long_tap_timeout,
1508 consume_event(wd, event_info, event_type, ev_flag);
1509 _compute_taps_center(st, pe);
1512 case EVAS_CALLBACK_MULTI_UP:
1513 case EVAS_CALLBACK_MOUSE_UP:
1514 st->touched = _remove_touched_device(st->touched, pe);
1516 ((gesture->state == ELM_GESTURE_STATE_START) ||
1517 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1518 { /* Report END only for gesture that STARTed */
1519 if (eina_list_count(st->touched) == 0)
1520 { /* Report END only at last release event */
1521 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1522 &st->info, EINA_FALSE);
1523 consume_event(wd, event_info, event_type, ev_flag);
1528 case EVAS_CALLBACK_MULTI_MOVE:
1529 case EVAS_CALLBACK_MOUSE_MOVE:
1531 ((gesture->state == ELM_GESTURE_STATE_START) ||
1532 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1533 { /* Report MOVE only if STARTED */
1534 _compute_taps_center(st, pe);
1535 /* Report MOVE if gesture started */
1536 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
1537 &st->info, EINA_TRUE);
1538 consume_event(wd, event_info, event_type, ev_flag);
1550 * This function computes momentum for MOMENTUM, LINE and FLICK gestures
1551 * This momentum value will be sent to widget when gesture is completed.
1553 * @param momentum pointer to buffer where we record momentum value.
1554 * @param x1 x coord where user started gesture.
1555 * @param y1 y coord where user started gesture.
1556 * @param x2 x coord where user completed gesture.
1557 * @param y2 y coord where user completed gesture.
1558 * @param t1x timestamp for X, when user started gesture.
1559 * @param t1y timestamp for Y, when user started gesture.
1560 * @param t2 timestamp when user completed gesture.
1562 * @ingroup Elm_Gesture_Layer
1565 _set_momentum(Elm_Gesture_Momentum_Info *momentum, Evas_Coord x1, Evas_Coord y1,
1566 Evas_Coord x2, Evas_Coord y2, unsigned int t1x, unsigned int t1y,
1569 Evas_Coord velx = 0, vely = 0, vel;
1570 Evas_Coord dx = x2 - x1;
1571 Evas_Coord dy = y2 - y1;
1575 velx = (dx * 1000) / dtx;
1578 vely = (dy * 1000) / dty;
1580 vel = sqrt((velx * velx) + (vely * vely));
1582 if ((_elm_config->thumbscroll_friction > 0.0) &&
1583 (vel > _elm_config->thumbscroll_momentum_threshold))
1584 { /* report momentum */
1585 momentum->mx = velx;
1586 momentum->my = vely;
1598 * This function is used for computing rotation angle (DEG).
1600 * @param x1 first finger x location.
1601 * @param y1 first finger y location.
1602 * @param x2 second finger x location.
1603 * @param y2 second finger y location.
1605 * @return angle of the line between (x1,y1), (x2,y2) in Radians.
1607 * @ingroup Elm_Gesture_Layer
1610 get_angle(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
1616 if (((int) xx) && ((int) yy))
1623 return RAD_360DEG - a;
1634 return RAD_180DEG + a;
1638 return RAD_180DEG - a;
1644 { /* Horizontal line */
1669 * This function is used for computing the magnitude and direction
1670 * of vector between two points.
1672 * @param x1 first finger x location.
1673 * @param y1 first finger y location.
1674 * @param x2 second finger x location.
1675 * @param y2 second finger y location.
1676 * @param l length computed (output)
1677 * @param a angle computed (output)
1679 * @ingroup Elm_Gesture_Layer
1682 get_vector(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2,
1683 Evas_Coord *l, double *a)
1688 *l = (Evas_Coord) sqrt(xx*xx + yy*yy);
1689 *a = get_angle(x1, y1, x2, y2);
1693 _get_direction(Evas_Coord x1, Evas_Coord x2)
1706 * This function tests momentum gesture.
1707 * @param obj The gesture-layer object.
1708 * @param pe The recent input event as stored in pe struct.
1709 * @param event_info recent input event.
1710 * @param event_type recent event type.
1711 * @param g_type what Gesture we are testing.
1713 * @ingroup Elm_Gesture_Layer
1716 _momentum_test(Evas_Object *obj, Pointer_Event *pe,
1717 void *event_info, Evas_Callback_Type event_type,
1718 Elm_Gesture_Types g_type)
1720 Widget_Data *wd = elm_widget_data_get(obj);
1722 Gesture_Info *gesture = wd->gesture[g_type];
1723 if (!gesture ) return;
1725 if ((gesture->state == ELM_GESTURE_STATE_UNDEFINED) &&
1726 eina_list_count(wd->touched))
1727 return; /* user left a finger on device, do NOT start */
1729 Momentum_Type *st = gesture->data;
1730 Elm_Gesture_State state_to_report;
1732 { /* Allocated once on first time */
1733 st = calloc(1, sizeof(Momentum_Type));
1735 _momentum_test_reset(gesture);
1741 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1744 case EVAS_CALLBACK_MOUSE_DOWN:
1745 st->line_st.x = st->line_end.x = pe->x;
1746 st->line_st.y = st->line_end.y = pe->y;
1747 st->t_st_x = st->t_st_y = st->t_end = pe->timestamp;
1748 st->xdir = st->ydir = 0;
1749 st->info.x2 = st->info.x1 = pe->x;
1750 st->info.y2 = st->info.y1 = pe->y;
1751 st->info.tx = st->info.ty = pe->timestamp;
1752 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1753 &st->info, EINA_FALSE);
1754 consume_event(wd, event_info, event_type, ev_flag);
1757 case EVAS_CALLBACK_MOUSE_UP:
1758 /* IGNORE if line info was cleared, like long press, move */
1761 state_to_report = ELM_GESTURE_STATE_END;
1763 if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1765 /* Too long of a wait, reset all values */
1766 st->line_st.x = pe->x;
1767 st->line_st.y = pe->y;
1768 st->t_st_y = st->t_st_x = pe->timestamp;
1769 st->xdir = st->ydir = 0;
1770 state_to_report = ELM_GESTURE_STATE_ABORT;
1773 st->info.x2 = pe->x;
1774 st->info.y2 = pe->y;
1775 st->line_end.x = pe->x;
1776 st->line_end.y = pe->y;
1777 st->t_end = pe->timestamp;
1779 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
1780 st->t_st_x, st->t_st_y, pe->timestamp);
1782 ev_flag = _set_state(gesture, state_to_report, &st->info,
1784 consume_event(wd, event_info, event_type, ev_flag);
1788 case EVAS_CALLBACK_MOUSE_MOVE:
1789 /* IGNORE if line info was cleared, like long press, move */
1793 state_to_report = ELM_GESTURE_STATE_MOVE;
1794 if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1796 /* Too long of a wait, reset all values */
1797 st->line_st.x = pe->x;
1798 st->line_st.y = pe->y;
1799 st->t_st_y = st->t_st_x = pe->timestamp;
1800 st->info.tx = st->t_st_x;
1801 st->info.ty = st->t_st_y;
1802 st->xdir = st->ydir = 0;
1803 state_to_report = ELM_GESTURE_STATE_ABORT;
1808 xdir = _get_direction(st->line_end.x, pe->x);
1809 ydir = _get_direction(st->line_end.y, pe->y);
1810 if (!xdir || (xdir == (-st->xdir)))
1812 st->line_st.x = st->line_end.x;
1813 st->info.tx = st->t_st_x = st->t_end;
1817 if (!ydir || (ydir == (-st->ydir)))
1819 st->line_st.y = st->line_end.y;
1820 st->info.ty = st->t_st_y = st->t_end;
1825 st->info.x2 = st->line_end.x = pe->x;
1826 st->info.y2 = st->line_end.y = pe->y;
1827 st->t_end = pe->timestamp;
1828 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
1829 st->t_st_x, st->t_st_y, pe->timestamp);
1830 ev_flag = _set_state(gesture, state_to_report, &st->info,
1832 consume_event(wd, event_info, event_type, ev_flag);
1835 case EVAS_CALLBACK_MULTI_UP:
1836 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
1838 consume_event(wd, event_info, event_type, ev_flag);
1847 compare_line_device(const void *data1, const void *data2)
1848 { /* Compare device component of line struct */
1849 const Line_Data *ln1 = data1;
1850 const int *device = data2;
1852 if (ln1->t_st) /* Compare only with lines that started */
1853 return (ln1->device - (*device));
1861 * This function construct line struct from input.
1862 * @param info pointer to store line momentum.
1863 * @param st line info to store input data.
1864 * @param pe The recent input event as stored in pe struct.
1866 * @ingroup Elm_Gesture_Layer
1869 _single_line_process(Elm_Gesture_Line_Info *info, Line_Data *st,
1870 Pointer_Event *pe, Evas_Callback_Type event_type)
1871 { /* Record events and set momentum for line pointed by st */
1877 case EVAS_CALLBACK_MOUSE_DOWN:
1878 case EVAS_CALLBACK_MULTI_DOWN:
1879 st->line_st.x = pe->x;
1880 st->line_st.y = pe->y;
1881 st->t_st = pe->timestamp;
1882 st->device = pe->device;
1883 info->momentum.x1 = pe->x;
1884 info->momentum.y1 = pe->y;
1885 info->momentum.tx = pe->timestamp;
1886 info->momentum.ty = pe->timestamp;
1891 case EVAS_CALLBACK_MOUSE_UP:
1892 case EVAS_CALLBACK_MULTI_UP:
1893 /* IGNORE if line info was cleared, like long press, move */
1897 st->line_end.x = pe->x;
1898 st->line_end.y = pe->y;
1899 st->t_end = pe->timestamp;
1902 case EVAS_CALLBACK_MOUSE_MOVE:
1903 case EVAS_CALLBACK_MULTI_MOVE:
1904 /* IGNORE if line info was cleared, like long press, move */
1915 _line_data_reset(st);
1919 info->momentum.x2 = pe->x;
1920 info->momentum.y2 = pe->y;
1921 _set_momentum(&info->momentum, st->line_st.x, st->line_st.y, pe->x, pe->y,
1922 st->t_st, st->t_st, pe->timestamp);
1930 * This function test for (n) line gesture.
1931 * @param obj The gesture-layer object.
1932 * @param pe The recent input event as stored in pe struct.
1933 * @param event_info Original input event pointer.
1934 * @param event_type Type of original input event.
1935 * @param g_type what Gesture we are testing.
1937 * @ingroup Elm_Gesture_Layer
1940 _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
1941 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
1945 Widget_Data *wd = elm_widget_data_get(obj);
1947 Gesture_Info *gesture = wd->gesture[g_type];
1948 if (!gesture ) return;
1950 if ((gesture->state == ELM_GESTURE_STATE_UNDEFINED) &&
1951 eina_list_count(wd->touched))
1952 return; user left a finger on device, do NOT start
1954 Line_Type *st = gesture->data;
1957 st = calloc(1, sizeof(Line_Type));
1961 Line_Data *line = NULL;
1962 Eina_List *list = st->list;
1963 unsigned int i, cnt = eina_list_count(list);
1966 { /* list is not empty, locate this device on list */
1967 line = (Line_Data *) eina_list_search_unsorted(st->list,
1968 compare_line_device, &pe->device);
1971 { /* Try to locate an empty-node */
1972 for (i = 0; i < cnt; i++)
1974 line = eina_list_nth(list, i);
1976 break; /* Found a free node */
1984 { /* List is empty or device not found, new line-struct on START only */
1985 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1986 (event_type == EVAS_CALLBACK_MULTI_DOWN))
1987 { /* Allocate new item on START */
1988 line = calloc(1, sizeof(Line_Data));
1989 _line_data_reset(line);
1990 list = eina_list_append(list, line);
1995 if (!line) /* This may happen on MOVE that comes before DOWN */
1996 return; /* No line-struct to work with, can't continue testing */
1998 if (_single_line_process(&st->info, line, pe, event_type)) /* update st with input */
1999 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
2001 /* Get direction and magnitude of the line */
2003 get_vector(line->line_st.x, line->line_st.y, pe->x, pe->y,
2004 &line->line_length, &angle);
2006 /* These are used later to compare lines length */
2007 Evas_Coord shortest_line_len = line->line_length;
2008 Evas_Coord longest_line_len = line->line_length;
2009 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2011 /* Now update line-state */
2013 { /* Analyze line only if line started */
2014 if (line->line_angle >= 0.0)
2015 { /* if line direction was set, we test if broke tolerance */
2016 double a = fabs(angle - line->line_angle);
2018 double d = (tan(a)) * line->line_length; /* Distance from line */
2019 #if defined(DEBUG_GESTURE_LAYER)
2020 printf("%s a=<%f> d=<%f>\n", __func__, (a * 57.295779513), d);
2022 if ((d > wd->line_distance_tolerance) || (a > wd->line_angular_tolerance))
2023 { /* Broke tolerance: abort line and start a new one */
2024 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2025 &st->info, EINA_FALSE);
2026 consume_event(wd, event_info, event_type, ev_flag);
2030 /* We may finish line if momentum is zero */
2031 /* This is for continues-gesture */
2032 if ((!st->info.momentum.mx) && (!st->info.momentum.my))
2033 { /* Finish line on zero momentum for continues gesture */
2034 line->line_end.x = pe->x;
2035 line->line_end.y = pe->y;
2036 line->t_end = pe->timestamp;
2041 { /* Record the line angle as it broke minimum length for line */
2042 if (line->line_length >= wd->line_min_length)
2043 st->info.angle = line->line_angle = angle;
2049 if (line->line_angle < 0.0)
2050 { /* it's not a line, too short more close to a tap */
2051 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2052 &st->info, EINA_FALSE);
2053 consume_event(wd, event_info, event_type, ev_flag);
2059 /* Count how many lines already started / ended */
2062 unsigned int tm_start = pe->timestamp;
2063 unsigned int tm_end = pe->timestamp;
2066 double base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
2067 Eina_Bool lines_parallel = EINA_TRUE;
2068 EINA_LIST_FOREACH(list, l, t_line)
2071 base_angle = t_line->line_angle;
2074 if (t_line->line_angle >= 0)
2075 { /* Compare angle only with lines with direction defined */
2076 if (fabs(base_angle - t_line->line_angle) >
2077 wd->line_angular_tolerance)
2078 lines_parallel = EINA_FALSE;
2082 if (t_line->line_length)
2083 { /* update only if this line is used */
2084 if (shortest_line_len > t_line->line_length)
2085 shortest_line_len = t_line->line_length;
2087 if (longest_line_len < t_line->line_length)
2088 longest_line_len = t_line->line_length;
2094 if (t_line->t_st < tm_start)
2095 tm_start = t_line->t_st;
2101 if (t_line->t_end < tm_end)
2102 tm_end = t_line->t_end;
2106 st->info.n = started;
2110 ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2111 (event_type == EVAS_CALLBACK_MULTI_DOWN)))
2112 { /* user lift one finger then starts again without line-end - ABORT */
2113 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2115 consume_event(wd, event_info, event_type, ev_flag);
2119 if (!lines_parallel)
2120 { /* Lines are NOT at same direction, abort this gesture */
2121 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2123 consume_event(wd, event_info, event_type, ev_flag);
2128 /* We report ABORT if lines length are NOT matching when fingers are up */
2129 if ((longest_line_len - shortest_line_len) > (elm_finger_size_get()*2))
2131 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2133 consume_event(wd, event_info, event_type, ev_flag);
2137 if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > wd->flick_time_limit_ms))
2138 { /* We consider FLICK as a fast line.ABORT if take too long to finish */
2139 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2141 consume_event(wd, event_info, event_type, ev_flag);
2147 case EVAS_CALLBACK_MOUSE_UP:
2148 case EVAS_CALLBACK_MULTI_UP:
2149 if ((started) && (started == ended))
2151 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2152 &st->info, EINA_FALSE);
2153 consume_event(wd, event_info, event_type, ev_flag);
2158 case EVAS_CALLBACK_MOUSE_DOWN:
2159 case EVAS_CALLBACK_MULTI_DOWN:
2162 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
2163 &st->info, EINA_TRUE);
2164 consume_event(wd, event_info, event_type, ev_flag);
2169 case EVAS_CALLBACK_MOUSE_MOVE:
2170 case EVAS_CALLBACK_MULTI_MOVE:
2173 if (started == ended)
2174 { /* For continues gesture */
2175 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2176 &st->info, EINA_FALSE);
2177 consume_event(wd, event_info, event_type, ev_flag);
2181 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
2182 &st->info, EINA_TRUE);
2183 consume_event(wd, event_info, event_type, ev_flag);
2189 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
2190 &st->info, EINA_TRUE);
2191 consume_event(wd, event_info, event_type, ev_flag);
2197 return; /* Unhandeld event type */
2204 * This function is used to check if rotation gesture started.
2205 * @param st Contains current rotation values from user input.
2206 * @return TRUE/FALSE if we need to set rotation START.
2208 * @ingroup Elm_Gesture_Layer
2211 rotation_broke_tolerance(Rotate_Type *st)
2213 if (st->info.base_angle < 0)
2214 return EINA_FALSE; /* Angle has to be computed first */
2216 if (st->rotate_angular_tolerance < 0)
2219 double low = st->info.base_angle - st->rotate_angular_tolerance;
2220 double high = st->info.base_angle + st->rotate_angular_tolerance;
2221 double t = st->info.angle;
2234 if (high > RAD_360DEG)
2245 #if defined(DEBUG_GESTURE_LAYER)
2246 printf("%s angle=<%f> low=<%f> high=<%f>\n", __func__, t, low, high);
2248 if ((t < low) || (t > high))
2249 { /* This marks that roation action has started */
2250 st->rotate_angular_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
2251 st->info.base_angle = st->info.angle; /* Avoid jump in angle value */
2261 * This function is used for computing the gap between fingers.
2262 * It returns the length and center point between fingers.
2264 * @param x1 first finger x location.
2265 * @param y1 first finger y location.
2266 * @param x2 second finger x location.
2267 * @param y2 second finger y location.
2268 * @param x Gets center point x cord (output)
2269 * @param y Gets center point y cord (output)
2271 * @return length of the line between (x1,y1), (x2,y2) in pixels.
2273 * @ingroup Elm_Gesture_Layer
2276 get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
2277 Evas_Coord y2, Evas_Coord *x, Evas_Coord *y)
2279 double a, b, xx, yy, gap;
2282 gap = sqrt(xx*xx + yy*yy);
2284 /* START - Compute zoom center point */
2285 /* The triangle defined as follows:
2293 * http://en.wikipedia.org/wiki/Trigonometric_functions
2294 *************************************/
2295 if (((int) xx) && ((int) yy))
2297 double A = atan((yy / xx));
2298 #if defined(DEBUG_GESTURE_LAYER)
2299 printf("xx=<%f> yy=<%f> A=<%f>\n", xx, yy, A);
2301 a = (Evas_Coord) ((gap / 2) * sin(A));
2302 b = (Evas_Coord) ((gap / 2) * cos(A));
2303 *x = (Evas_Coord) ((x2 > x1) ? (x1 + b) : (x2 + b));
2304 *y = (Evas_Coord) ((y2 > y1) ? (y1 + a) : (y2 + a));
2309 { /* horiz line, take half width */
2310 #if defined(DEBUG_GESTURE_LAYER)
2311 printf("==== HORIZ ====\n");
2313 *x = (Evas_Coord) (xx / 2);
2314 *y = (Evas_Coord) (y1);
2318 { /* vert line, take half width */
2319 #if defined(DEBUG_GESTURE_LAYER)
2320 printf("==== VERT ====\n");
2322 *x = (Evas_Coord) (x1);
2323 *y = (Evas_Coord) (yy / 2);
2326 /* END - Compute zoom center point */
2328 return (Evas_Coord) gap;
2334 * This function is used for computing zoom value.
2336 * @param st Pointer to zoom data based on user input.
2337 * @param x1 first finger x location.
2338 * @param y1 first finger y location.
2339 * @param x2 second finger x location.
2340 * @param y2 second finger y location.
2341 * @param factor zoom-factor, used to determine how fast zoom works.
2343 * @return zoom value, when 1.0 means no zoom, 0.5 half size...
2345 * @ingroup Elm_Gesture_Layer
2347 /* FIXME change float to double */
2349 compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2350 Evas_Coord x2, Evas_Coord y2, unsigned int tm2, double zoom_finger_factor)
2353 Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
2354 &st->info.x, &st->info.y);
2356 st->info.radius = diam / 2;
2360 st->zoom_base = diam;
2361 return st->info.zoom;
2364 if (st->zoom_distance_tolerance)
2365 { /* zoom tolerance <> ZERO, means zoom action NOT started yet */
2366 if (diam < (st->zoom_base - st->zoom_distance_tolerance))
2367 { /* avoid jump with zoom value when break tolerance */
2368 st->zoom_base -= st->zoom_distance_tolerance;
2369 st->zoom_distance_tolerance = 0;
2372 if (diam > (st->zoom_base + st->zoom_distance_tolerance))
2373 { /* avoid jump with zoom value when break tolerance */
2374 st->zoom_base += st->zoom_distance_tolerance;
2375 st->zoom_distance_tolerance = 0;
2381 /* We use factor only on the difference between gap-base */
2382 /* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
2383 rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
2384 (float) st->zoom_base) * zoom_finger_factor));
2387 /* Momentum: zoom per second: (NOT YET SUPPORTED) */
2388 st->info.momentum = (((rt - 1.0) * 1000) / (tm2 - tm1));
2399 * This function handles zoom with mouse wheel.
2400 * thats a combination of wheel + CTRL key.
2401 * @param obj The gesture-layer object.
2402 * @param event_info Original input event pointer.
2403 * @param event_type Type of original input event.
2404 * @param g_type what Gesture we are testing.
2406 * @ingroup Elm_Gesture_Layer
2409 _zoom_with_wheel_test(Evas_Object *obj, void *event_info,
2410 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2412 Widget_Data *wd = elm_widget_data_get(obj);
2414 if (!wd->gesture[g_type]) return;
2416 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2417 Zoom_Type *st = gesture_zoom->data;
2418 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2420 { /* Allocated once on first time, used for zoom intermediate data */
2421 st = calloc(1, sizeof(Zoom_Type));
2422 gesture_zoom->data = st;
2423 _zoom_test_reset(gesture_zoom);
2428 case EVAS_CALLBACK_KEY_UP:
2430 Evas_Event_Key_Up *p = event_info;
2431 if ((!strcmp(p->keyname, "Control_L")) ||
2432 (!strcmp(p->keyname, "Control_R")))
2433 { /* Test if we ended a zoom gesture when releasing CTRL */
2434 if ((st->zoom_wheel) &&
2435 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2436 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2437 { /* User released CTRL after zooming */
2438 ev_flag = _set_state(gesture_zoom,
2439 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2440 consume_event(wd, event_info, event_type, ev_flag);
2448 case EVAS_CALLBACK_MOUSE_WHEEL:
2451 Elm_Gesture_State s;
2452 if (!evas_key_modifier_is_set(
2453 ((Evas_Event_Mouse_Wheel *) event_info)->modifiers,
2455 { /* if using wheel witout CTRL after starting zoom */
2456 if ((st->zoom_wheel) &&
2457 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2458 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2460 ev_flag = _set_state(gesture_zoom,
2461 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2462 consume_event(wd, event_info, event_type, ev_flag);
2467 return; /* Ignore mouse-wheel without control */
2470 /* Using mouse wheel with CTRL for zoom */
2471 if (st->zoom_wheel || (st->zoom_distance_tolerance == 0))
2472 { /* when (zoom_wheel == NULL) and (zoom_distance_tolerance == 0)
2473 we continue a zoom gesture */
2475 s = ELM_GESTURE_STATE_MOVE;
2478 { /* On first wheel event, report START */
2479 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
2480 evas_object_evas_get(wd->target), "Control");
2482 s = ELM_GESTURE_STATE_START;
2483 if (!evas_object_key_grab(wd->target, "Control_L", mask, 0, EINA_FALSE))
2484 ERR("Failed to Grabbed CTRL_L");
2485 if (!evas_object_key_grab(wd->target, "Control_R", mask, 0, EINA_FALSE))
2486 ERR("Failed to Grabbed CTRL_R");
2489 st->zoom_distance_tolerance = 0; /* Cancel tolerance */
2490 st->zoom_wheel = (Evas_Event_Mouse_Wheel *) event_info;
2491 st->info.x = st->zoom_wheel->canvas.x;
2492 st->info.y = st->zoom_wheel->canvas.y;
2494 if (st->zoom_wheel->z < 0) /* zoom in */
2495 st->info.zoom += (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2497 if (st->zoom_wheel->z > 0) /* zoom out */
2498 st->info.zoom -= (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2500 if (st->info.zoom < 0.0)
2501 st->info.zoom = 0.0;
2503 ev_flag = _set_state(gesture_zoom, s, &st->info, force);
2504 consume_event(wd, event_info, event_type, ev_flag);
2516 * This function is used to test zoom gesture.
2517 * user may combine zoom, rotation together.
2518 * so its possible that both will be detected from input.
2519 * (both are two-finger movement-oriented gestures)
2521 * @param obj The gesture-layer object.
2522 * @param event_info Pointer to recent input event.
2523 * @param event_type Recent input event type.
2524 * @param g_type what Gesture we are testing.
2526 * @ingroup Elm_Gesture_Layer
2529 _zoom_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2530 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2534 Widget_Data *wd = elm_widget_data_get(obj);
2536 if (!wd->gesture[g_type]) return;
2538 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2539 Zoom_Type *st = gesture_zoom->data;
2542 { /* Allocated once on first time, used for zoom data */
2543 st = calloc(1, sizeof(Zoom_Type));
2544 gesture_zoom->data = st;
2545 _zoom_test_reset(gesture_zoom);
2548 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2551 case EVAS_CALLBACK_MOUSE_DOWN:
2552 consume_event(wd, event_info, event_type, ev_flag);
2553 memcpy(&st->zoom_st, pe, sizeof(Pointer_Event));
2557 case EVAS_CALLBACK_MOUSE_MOVE:
2558 consume_event(wd, event_info, event_type, ev_flag);
2559 if (!st->zoom_st.timestamp)
2560 return; /* we got move event before down event.Ignore it */
2562 consume_event(wd, event_info, event_type, ev_flag);
2563 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2565 /* We match this point to previous multi-move or multi-down event */
2566 if (st->zoom_mv1.timestamp)
2568 st->info.zoom = compute_zoom(st,
2569 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2570 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2571 wd->zoom_finger_factor);
2575 if (st->zoom_st1.timestamp)
2577 st->info.zoom = compute_zoom(st,
2578 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2579 st->zoom_st1.x, st->zoom_st1.y, st->zoom_st1.timestamp,
2580 wd->zoom_finger_factor);
2586 case EVAS_CALLBACK_MULTI_MOVE:
2587 if (!st->zoom_st1.timestamp)
2588 return; /* We get move event before down event.Ignore it */
2590 consume_event(wd, event_info, event_type, ev_flag);
2591 if (st->zoom_mv1.timestamp)
2593 if (st->zoom_mv1.device !=
2594 ((Evas_Event_Multi_Move *) event_info)->device)
2595 { /* A third finger on screen, abort zoom */
2596 ev_flag = _set_state(gesture_zoom,
2597 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2598 consume_event(wd, event_info, event_type, ev_flag);
2604 memcpy(&st->zoom_mv1, pe, sizeof(Pointer_Event));
2606 /* Match this point to previous mouse-move or mouse-down event */
2607 if (st->zoom_mv.timestamp)
2609 st->info.zoom = compute_zoom(st,
2610 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2611 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2612 wd->zoom_finger_factor);
2616 if (st->zoom_st.timestamp)
2618 st->info.zoom = compute_zoom(st,
2619 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2620 st->zoom_st.x, st->zoom_st.y, st->zoom_st.timestamp,
2621 wd->zoom_finger_factor);
2627 case EVAS_CALLBACK_MULTI_DOWN:
2628 consume_event(wd, event_info, event_type, ev_flag);
2629 memcpy(&st->zoom_st1, pe, sizeof(Pointer_Event));
2632 case EVAS_CALLBACK_MOUSE_UP:
2633 case EVAS_CALLBACK_MULTI_UP:
2634 /* Reset timestamp of finger-up.This is used later
2635 by _zoom_test_reset() to retain finger-down data */
2636 consume_event(wd, event_info, event_type, ev_flag);
2637 if (((st->zoom_wheel) || (st->zoom_base)) &&
2638 (st->zoom_distance_tolerance == 0))
2640 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
2641 &st->info, EINA_FALSE);
2642 consume_event(wd, event_info, event_type, ev_flag);
2647 /* if we got here not a ZOOM */
2648 if (gesture_zoom->state != ELM_GESTURE_STATE_UNDEFINED)
2649 { /* Must be != undefined, if gesture started */
2650 ev_flag = _set_state(gesture_zoom,
2651 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2652 consume_event(wd, event_info, event_type, ev_flag);
2655 _zoom_test_reset(gesture_zoom);
2664 if (!st->zoom_distance_tolerance)
2665 if ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
2666 (event_type == EVAS_CALLBACK_MULTI_MOVE))
2668 { /* Zoom broke tolerance, report move */
2669 double d = st->info.zoom - st->next_step;
2673 /* START For contiunues gesture: compute momentum */
2674 _set_momentum(&st->momentum1, st->zoom_st.x, st->zoom_st.y,
2675 st->zoom_mv.x, st->zoom_mv.y,st->zoom_st.timestamp, st->zoom_st.timestamp,
2676 st->zoom_mv.timestamp);
2678 _set_momentum(&st->momentum2, st->zoom_st1.x, st->zoom_st1.y,
2679 st->zoom_mv1.x, st->zoom_mv1.y,st->zoom_st1.timestamp, st->zoom_st1.timestamp,
2680 st->zoom_mv1.timestamp);
2682 if (!(st->momentum1.mx + st->momentum1.my + st->momentum2.mx + st->momentum2.my))
2684 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
2685 &st->info, EINA_FALSE);
2688 /* END For contiunues gesture: compute momentum */
2691 if (d >= wd->zoom_step)
2692 { /* Report move in steps */
2693 st->next_step = st->info.zoom;
2695 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_MOVE,
2696 &st->info, EINA_TRUE);
2697 consume_event(wd, event_info, event_type, ev_flag);
2704 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2705 (event_type == EVAS_CALLBACK_MULTI_DOWN))
2706 { /* report zoom start finger location is zoom-center temporarly */
2707 /* Zoom may have started with mouse-wheel, don't report START */
2708 if ((st->zoom_st.timestamp) && (st->zoom_st1.timestamp))
2709 { /* Set zoom-base after BOTH down events were recorded */
2710 /* Compute length of line between fingers on zoom start */
2711 st->info.zoom = 1.0;
2712 st->zoom_base = get_finger_gap_length(st->zoom_st1.x,
2713 st->zoom_st1.y, st->zoom_st.x, st->zoom_st.y,
2714 &st->info.x, &st->info.y);
2716 st->info.radius = st->zoom_base / 2;
2718 if ((gesture_zoom->state != ELM_GESTURE_STATE_START) &&
2719 (gesture_zoom->state != ELM_GESTURE_STATE_MOVE))
2720 { /* Report START only when two fingers touching */
2721 ev_flag = _set_state(gesture_zoom,
2722 ELM_GESTURE_STATE_START, &st->info, EINA_FALSE);
2723 consume_event(wd, event_info, event_type, ev_flag);
2732 _get_rotate_properties(Rotate_Type *st,
2733 Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2734 Evas_Coord x2, Evas_Coord y2, unsigned int tm2,
2737 st->info.radius = get_finger_gap_length(x1, y1, x2, y2,
2738 &st->info.x, &st->info.y) / 2;
2740 *angle = get_angle(x1, y1, x2, y2);
2741 #if 0 /* (NOT YET SUPPORTED) */
2742 if (angle == &st->info.angle)
2743 { /* Compute momentum: TODO: bug when breaking 0, 360 values */
2744 st->info.momentum = (((*angle) - st->info.base_angle) /
2745 (fabs(tm2 - tm1))) * 1000;
2748 st->info.momentum = 0;
2758 * This function is used to test rotation gesture.
2759 * user may combine zoom, rotation together.
2760 * so its possible that both will be detected from input.
2761 * (both are two-finger movement-oriented gestures)
2763 * @param obj The gesture-layer object.
2764 * @param event_info Pointer to recent input event.
2765 * @param event_type Recent input event type.
2766 * @param g_type what Gesture we are testing.
2768 * @ingroup Elm_Gesture_Layer
2771 _rotate_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2772 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2777 Widget_Data *wd = elm_widget_data_get(obj);
2779 if (!wd->gesture[g_type]) return;
2781 Gesture_Info *gesture = wd->gesture[g_type];
2782 Rotate_Type *st = gesture->data;
2787 { /* Allocated once on first time */
2788 st = calloc(1, sizeof(Rotate_Type));
2790 _rotate_test_reset(gesture);
2794 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2798 case EVAS_CALLBACK_MOUSE_DOWN:
2799 consume_event(wd, event_info, event_type, ev_flag);
2800 memcpy(&st->rotate_st, pe, sizeof(Pointer_Event));
2804 case EVAS_CALLBACK_MOUSE_MOVE:
2805 if (!st->rotate_st.timestamp)
2806 break; /* We got move event before down event.Ignore it */
2808 consume_event(wd, event_info, event_type, ev_flag);
2809 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2811 /* Match this point to previous multi-move or multi-down event */
2812 if (st->rotate_mv1.timestamp)
2813 { /* Compute rotation angle and report to user */
2814 _get_rotate_properties(st,
2815 st->rotate_mv.x, st->rotate_mv.y, st->rotate_mv.timestamp,
2816 st->rotate_mv1.x, st->rotate_mv1.y, st->rotate_mv1.timestamp,
2821 if (st->rotate_st1.timestamp)
2822 { /* Compute rotation angle and report to user */
2823 _get_rotate_properties(st,
2824 st->rotate_mv.x, st->rotate_mv.y, st->rotate_mv.timestamp,
2825 st->rotate_st1.x, st->rotate_st1.y, st->rotate_st1.timestamp,
2832 case EVAS_CALLBACK_MULTI_MOVE:
2833 if (!st->rotate_st1.timestamp)
2834 break; /* We got move event before down event.Ignore it */
2836 consume_event(wd, event_info, event_type, ev_flag);
2837 if (st->rotate_mv1.timestamp)
2839 if (st->rotate_mv1.device !=
2840 ((Evas_Event_Multi_Move *) event_info)->device)
2841 { /* A third finger on screen, abort rotate */
2842 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2843 &st->info, EINA_FALSE);
2844 consume_event(wd, event_info, event_type, ev_flag);
2850 memcpy(&st->rotate_mv1, pe, sizeof(Pointer_Event));
2852 /* Match this point to previous mouse-move or mouse-down event */
2853 if (st->rotate_mv.timestamp)
2854 { /* Compute rotation angle and report to user */
2855 _get_rotate_properties(st,
2856 st->rotate_mv.x, st->rotate_mv.y, st->rotate_mv.timestamp,
2857 st->rotate_mv1.x, st->rotate_mv1.y, st->rotate_mv1.timestamp,
2862 if (st->rotate_st.timestamp)
2863 { /* Compute rotation angle and report to user */
2864 _get_rotate_properties(st,
2865 st->rotate_st.x, st->rotate_st.y, st->rotate_st.timestamp,
2866 st->rotate_mv1.x, st->rotate_mv1.y, st->rotate_mv1.timestamp,
2873 case EVAS_CALLBACK_MULTI_DOWN:
2874 consume_event(wd, event_info, event_type, ev_flag);
2875 memcpy(&st->rotate_st1, pe, sizeof(Pointer_Event));
2876 _get_rotate_properties(st,
2877 st->rotate_st.x, st->rotate_st.y, st->rotate_st.timestamp,
2878 st->rotate_st1.x, st->rotate_st1.y, st->rotate_st1.timestamp,
2882 case EVAS_CALLBACK_MOUSE_UP:
2883 case EVAS_CALLBACK_MULTI_UP:
2884 consume_event(wd, event_info, event_type, ev_flag);
2885 /* Reset timestamp of finger-up.This is used later
2886 by rotate_test_reset() to retain finger-down data */
2887 if (st->rotate_angular_tolerance < 0)
2889 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2890 &st->info, EINA_FALSE);
2891 consume_event(wd, event_info, event_type, ev_flag);
2896 if (gesture->state != ELM_GESTURE_STATE_UNDEFINED)
2897 { /* Must be != undefined, if gesture started */
2898 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2899 &st->info, EINA_FALSE);
2900 consume_event(wd, event_info, event_type, ev_flag);
2903 _rotate_test_reset(gesture);
2910 if ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
2911 (event_type == EVAS_CALLBACK_MULTI_MOVE))
2912 { /* Report MOVE or ABORT for *MOVE event */
2913 if (rotation_broke_tolerance(st))
2914 { /* Rotation broke tolerance, report move */
2915 double d = st->info.angle - st->next_step;
2919 /* START For contiunues gesture: compute momentum */
2920 _set_momentum(&st->momentum1, st->rotate_st.x, st->rotate_st.y,
2921 st->rotate_mv.x, st->rotate_mv.y,st->rotate_st.timestamp, st->rotate_st.timestamp,
2922 st->rotate_mv.timestamp);
2924 _set_momentum(&st->momentum2, st->rotate_st1.x, st->rotate_st1.y,
2925 st->rotate_mv1.x, st->rotate_mv1.y,st->rotate_st1.timestamp, st->rotate_st1.timestamp,
2926 st->rotate_mv1.timestamp);
2928 if (!(st->momentum1.mx + st->momentum1.my + st->momentum2.mx + st->momentum2.my))
2930 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2931 &st->info, EINA_FALSE);
2934 /* END For contiunues gesture: compute momentum */
2936 if (d >= wd->rotate_step)
2937 { /* Report move in steps */
2938 st->next_step = st->info.angle;
2940 ev_flag = _set_state(gesture,
2941 ELM_GESTURE_STATE_MOVE, &st->info, EINA_TRUE);
2942 consume_event(wd, event_info, event_type, ev_flag);
2949 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2950 (event_type == EVAS_CALLBACK_MULTI_DOWN))
2952 if ((st->rotate_st.timestamp) && (st->rotate_st1.timestamp))
2953 { /* two-fingers on touch screen - report rotate start */
2954 /* Set base angle, then report start. */
2955 _get_rotate_properties(st,
2956 st->rotate_st.x, st->rotate_st.y, st->rotate_st.timestamp,
2957 st->rotate_st1.x, st->rotate_st1.y, st->rotate_st1.timestamp,
2958 &st->info.base_angle);
2960 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
2961 &st->info, EINA_FALSE);
2962 consume_event(wd, event_info, event_type, ev_flag);
2972 * This function is used to save input events in an abstract struct
2973 * to be used later by getsure-testing functions.
2975 * @param data The gesture-layer object.
2976 * @param event_info Pointer to recent input event.
2977 * @param event_type Recent input event type.
2978 * @param pe The abstract data-struct (output).
2980 * @ingroup Elm_Gesture_Layer
2983 _make_pointer_event(void *data, void *event_info,
2984 Evas_Callback_Type event_type, Pointer_Event *pe)
2986 Widget_Data *wd = elm_widget_data_get(data);
2987 if (!wd) return EINA_FALSE;
2991 case EVAS_CALLBACK_MOUSE_DOWN:
2992 pe->x = ((Evas_Event_Mouse_Down *) event_info)->canvas.x;
2993 pe->y = ((Evas_Event_Mouse_Down *) event_info)->canvas.y;
2994 pe->timestamp = ((Evas_Event_Mouse_Down *) event_info)->timestamp;
2995 pe->device = ELM_MOUSE_DEVICE;
2998 case EVAS_CALLBACK_MOUSE_UP:
2999 pe->x = ((Evas_Event_Mouse_Up *) event_info)->canvas.x;
3000 pe->y = ((Evas_Event_Mouse_Up *) event_info)->canvas.y;
3001 pe->timestamp = ((Evas_Event_Mouse_Up *) event_info)->timestamp;
3002 pe->device = ELM_MOUSE_DEVICE;
3005 case EVAS_CALLBACK_MOUSE_MOVE:
3006 pe->x = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.x;
3007 pe->y = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.y;
3008 pe->timestamp = ((Evas_Event_Mouse_Move *) event_info)->timestamp;
3009 pe->device = ELM_MOUSE_DEVICE;
3012 case EVAS_CALLBACK_MULTI_DOWN:
3013 pe->x = ((Evas_Event_Multi_Down *) event_info)->canvas.x;
3014 pe->y = ((Evas_Event_Multi_Down *) event_info)->canvas.y;
3015 pe->timestamp = ((Evas_Event_Multi_Down *) event_info)->timestamp;
3016 pe->device = ((Evas_Event_Multi_Down *) event_info)->device;
3019 case EVAS_CALLBACK_MULTI_UP:
3020 pe->x = ((Evas_Event_Multi_Up *) event_info)->canvas.x;
3021 pe->y = ((Evas_Event_Multi_Up *) event_info)->canvas.y;
3022 pe->timestamp = ((Evas_Event_Multi_Up *) event_info)->timestamp;
3023 pe->device = ((Evas_Event_Multi_Up *) event_info)->device;
3026 case EVAS_CALLBACK_MULTI_MOVE:
3027 pe->x = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.x;
3028 pe->y = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.y;
3029 pe->timestamp = ((Evas_Event_Multi_Move *) event_info)->timestamp;
3030 pe->device = ((Evas_Event_Multi_Move *) event_info)->device;
3037 pe->event_type = event_type;
3044 * This function the core-function where input handling is done.
3045 * Here we get user input and stream it to gesture testing.
3046 * We notify user about any gestures with new state:
3048 * START - gesture started.
3049 * MOVE - gesture is ongoing.
3050 * END - gesture was completed.
3051 * ABORT - gesture was aborted after START, MOVE (will NOT be completed)
3053 * We also check if a gesture was detected, then reset event history
3054 * If no gestures were found we reset gesture test flag
3055 * after streaming event-history to widget.
3056 * (stream to the widget all events not consumed as a gesture)
3058 * @param data The gesture-layer object.
3059 * @param event_info Pointer to recent input event.
3060 * @param event_type Recent input event type.
3062 * @ingroup Elm_Gesture_Layer
3065 _event_process(void *data, Evas_Object *obj __UNUSED__,
3066 void *event_info, Evas_Callback_Type event_type)
3069 Pointer_Event *pe = NULL;
3070 Widget_Data *wd = elm_widget_data_get(data);
3073 /* Start testing candidate gesture from here */
3074 if (_make_pointer_event(data, event_info, event_type, &_pe))
3077 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
3078 _n_long_tap_test(data, pe, event_info, event_type,
3079 ELM_GESTURE_N_LONG_TAPS);
3081 if (IS_TESTED(ELM_GESTURE_N_TAPS))
3082 _dbl_click_test(data, pe, event_info, event_type,
3083 ELM_GESTURE_N_TAPS, 1);
3085 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
3086 _dbl_click_test(data, pe, event_info, event_type,
3087 ELM_GESTURE_N_DOUBLE_TAPS, 2);
3089 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
3090 _dbl_click_test(data, pe, event_info, event_type,
3091 ELM_GESTURE_N_TRIPLE_TAPS, 3);
3093 if (IS_TESTED(ELM_GESTURE_MOMENTUM))
3094 _momentum_test(data, pe, event_info, event_type,
3095 ELM_GESTURE_MOMENTUM);
3097 if (IS_TESTED(ELM_GESTURE_N_LINES))
3098 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_LINES);
3100 if (IS_TESTED(ELM_GESTURE_N_FLICKS))
3101 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_FLICKS);
3103 if (IS_TESTED(ELM_GESTURE_ZOOM))
3104 _zoom_test(data, pe, event_info, event_type, ELM_GESTURE_ZOOM);
3106 if (IS_TESTED(ELM_GESTURE_ZOOM))
3107 _zoom_with_wheel_test(data, event_info, event_type, ELM_GESTURE_ZOOM);
3109 if (IS_TESTED(ELM_GESTURE_ROTATE))
3110 _rotate_test(data, pe, event_info, event_type, ELM_GESTURE_ROTATE);
3112 if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
3113 _event_history_add(data, event_info, event_type);
3114 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3115 (event_type == EVAS_CALLBACK_MULTI_UP))
3117 Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type);
3120 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD);
3121 _event_history_add(data, event_info, event_type);
3125 /* Log event to restart gestures */
3126 wd->recent_device_event = _add_recent_device_event(wd->recent_device_event, &_pe);
3128 /* we maintain list of touched devices*/
3129 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
3130 (event_type == EVAS_CALLBACK_MULTI_DOWN))
3132 wd->touched = _add_touched_device(wd->touched, pe);
3134 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3135 (event_type == EVAS_CALLBACK_MULTI_UP))
3137 wd->touched = _remove_touched_device(wd->touched, pe);
3140 /* Report current states and clear history if needed */
3141 Eina_Bool states_reset = _clear_if_finished(data);
3144 /* Run through events to restart gestures */
3146 Eina_Bool n_lines, n_flicks, zoom, rotate;
3149 printf("Gesture | State | tested\n");
3150 for(i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
3154 printf(" %d %d %d\n", i, g->state, g->test);
3157 /* We turn-on flag for finished, aborted, not-started gestures */
3158 g = wd->gesture[ELM_GESTURE_N_LINES];
3159 n_lines = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3160 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3163 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
3164 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3168 g = wd->gesture[ELM_GESTURE_N_FLICKS];
3169 n_flicks = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3170 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3173 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
3174 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3178 g = wd->gesture[ELM_GESTURE_ZOOM];
3179 zoom = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3180 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3183 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
3184 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3189 g = wd->gesture[ELM_GESTURE_ROTATE];
3190 rotate = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3191 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3194 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
3195 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3201 EINA_LIST_FOREACH(wd->recent_device_event, l, p)
3202 { /* Generate a DOWN event */
3203 Evas_Callback_Type e_type = p->event_type;
3204 if(p->event_type == EVAS_CALLBACK_MULTI_MOVE)
3205 e_type = EVAS_CALLBACK_MULTI_DOWN;
3207 if(p->event_type == EVAS_CALLBACK_MOUSE_MOVE)
3208 e_type = EVAS_CALLBACK_MOUSE_DOWN;
3211 if (n_lines && (IS_TESTED(ELM_GESTURE_N_LINES)))
3212 _n_line_test(data, p, NULL, e_type, ELM_GESTURE_N_LINES);
3214 if (n_flicks && (IS_TESTED(ELM_GESTURE_N_FLICKS)))
3215 _n_line_test(data, p, NULL, e_type, ELM_GESTURE_N_FLICKS);
3217 if (zoom && (IS_TESTED(ELM_GESTURE_ZOOM)))
3218 _zoom_test(data, p, NULL, e_type, ELM_GESTURE_ZOOM);
3220 if (rotate && (IS_TESTED(ELM_GESTURE_ROTATE)))
3221 _rotate_test(data, p, NULL, e_type, ELM_GESTURE_ROTATE);
3227 * For all _mouse_* / multi_* functions wethen send this event to
3228 * _event_process function.
3230 * @param data The gesture-layer object.
3231 * @param event_info Pointer to recent input event.
3233 * @ingroup Elm_Gesture_Layer
3236 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3239 Widget_Data *wd = elm_widget_data_get(data);
3241 if (((Evas_Event_Mouse_Down *) event_info)->button != 1)
3242 return; /* We only process left-click at the moment */
3244 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_DOWN);
3248 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3251 Widget_Data *wd = elm_widget_data_get(data);
3254 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_MOVE);
3258 _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3261 Widget_Data *wd = elm_widget_data_get(data);
3264 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_DOWN);
3268 _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3271 Widget_Data *wd = elm_widget_data_get(data);
3274 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_UP);
3278 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3281 Widget_Data *wd = elm_widget_data_get(data);
3284 if (((Evas_Event_Mouse_Up *) event_info)->button != 1)
3285 return; /* We only process left-click at the moment */
3287 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_UP);
3291 _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3294 Widget_Data *wd = elm_widget_data_get(data);
3297 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_WHEEL);
3301 _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3304 Widget_Data *wd = elm_widget_data_get(data);
3307 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_DOWN);
3311 _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3314 Widget_Data *wd = elm_widget_data_get(data);
3317 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_MOVE);
3321 _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3324 Widget_Data *wd = elm_widget_data_get(data);
3327 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_UP);
3331 elm_gesture_layer_hold_events_get(Evas_Object *obj)
3333 Widget_Data *wd = elm_widget_data_get(obj);
3334 if (!wd) return EINA_FALSE;
3336 return !wd->repeat_events;
3340 elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool r)
3342 Widget_Data *wd = elm_widget_data_get(obj);
3345 wd->repeat_events = !r;
3349 elm_gesture_layer_zoom_step_set(Evas_Object *obj, double s)
3351 Widget_Data *wd = elm_widget_data_get(obj);
3361 elm_gesture_layer_rotate_step_set(Evas_Object *obj, double s)
3363 Widget_Data *wd = elm_widget_data_get(obj);
3369 wd->rotate_step = s;
3373 elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *t)
3375 Widget_Data *wd = elm_widget_data_get(obj);
3376 if (!wd) return EINA_FALSE;
3381 /* if was attached before, unregister callbacks first */
3383 _unregister_callbacks(obj);
3387 _register_callbacks(obj);
3392 elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Types idx,
3393 Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data)
3395 Widget_Data *wd = elm_widget_data_get(obj);
3399 if (!wd->gesture[idx])
3400 wd->gesture[idx] = calloc(1, sizeof(Gesture_Info));
3401 if (!wd->gesture[idx]) return;
3403 p = wd->gesture[idx];
3406 p->fn[cb_type].cb = cb;
3407 p->fn[cb_type].user_data = data;
3408 p->state = ELM_GESTURE_STATE_UNDEFINED;
3413 _disable_hook(Evas_Object *obj)
3415 if (elm_widget_disabled_get(obj))
3416 _unregister_callbacks(obj);
3418 _register_callbacks(obj);
3422 elm_gesture_layer_add(Evas_Object *parent)
3428 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
3430 wd = ELM_NEW(Widget_Data);
3431 e = evas_object_evas_get(parent);
3432 if (!e) return NULL;
3433 obj = elm_widget_add(e);
3434 ELM_SET_WIDTYPE(widtype, "gesture_layer");
3435 elm_widget_type_set(obj, "gesture_layer");
3436 elm_widget_sub_object_add(parent, obj);
3437 elm_widget_data_set(obj, wd);
3438 elm_widget_del_hook_set(obj, _del_hook);
3439 elm_widget_disable_hook_set(obj, _disable_hook);
3442 wd->line_min_length =_elm_config->glayer_line_min_length * elm_finger_size_get();
3443 wd->zoom_distance_tolerance = _elm_config->glayer_zoom_distance_tolerance * elm_finger_size_get();
3444 wd->line_distance_tolerance = _elm_config->glayer_line_distance_tolerance * elm_finger_size_get();
3445 wd->zoom_finger_factor = _elm_config->glayer_zoom_finger_factor;
3446 wd->zoom_wheel_factor = _elm_config->glayer_zoom_wheel_factor; /* mouse wheel zoom steps */
3447 wd->rotate_angular_tolerance = _elm_config->glayer_rotate_angular_tolerance;
3448 wd->line_angular_tolerance = _elm_config->glayer_line_angular_tolerance;
3449 wd->flick_time_limit_ms = _elm_config->glayer_flick_time_limit_ms;
3450 wd->long_tap_start_timeout = _elm_config->glayer_long_tap_start_timeout;
3451 wd->repeat_events = EINA_TRUE;
3453 #if defined(DEBUG_GESTURE_LAYER)
3454 printf("size of Gestures = <%d>\n", sizeof(wd->gesture));
3455 printf("initial values:\n\tzoom_finger_factor=<%f>\n\tzoom_distance_tolerance=<%d>\n\tline_min_length=<%d>\n\tline_distance_tolerance=<%d>\n\tzoom_wheel_factor=<%f>\n\trotate_angular_tolerance=<%f>\n\twd->line_angular_tolerance=<%f>\n\twd->flick_time_limit_ms=<%d>\n\twd->long_tap_start_timeout=<%f>\n\twd->zoom_step=<%f>\n\twd->rotate_step=<%f>\n", wd->zoom_finger_factor, wd->zoom_distance_tolerance, wd->line_min_length, wd->line_distance_tolerance, wd->zoom_wheel_factor, wd->rotate_angular_tolerance, wd->line_angular_tolerance, wd->flick_time_limit_ms, wd->long_tap_start_timeout, wd->zoom_step, wd->rotate_step);
3457 memset(wd->gesture, 0, sizeof(wd->gesture));