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;
242 Eina_Bool glayer_continues_enable;
247 Gesture_Info *gesture[ELM_GESTURE_LAST];
248 Ecore_Timer *dbl_timeout; /* When this expires, dbl click/taps ABORTed */
249 Eina_List *pending; /* List of devices need to refeed *UP event */
250 Eina_List *touched; /* Information of touched devices */
251 Eina_List *recent_device_event; /* Information of recent pe event of each device */
253 Eina_Bool repeat_events : 1;
255 typedef struct _Widget_Data Widget_Data;
257 static const char *widtype = NULL;
258 static void _del_hook(Evas_Object *obj);
260 static Eina_Bool _event_history_clear(Evas_Object *obj);
261 static void _reset_states(Widget_Data *wd);
262 static void _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
263 static void _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
264 static void _zoom_with_wheel_test(Evas_Object *obj, void *event_info, Evas_Callback_Type event_type, Elm_Gesture_Types g_type);
265 static void _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
266 static void _mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
267 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
268 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
270 static void _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
271 static void _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
272 static void _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
274 /* START - Functions to manage touched-device list */
277 * This function is used to find if device is touched
279 * @ingroup Elm_Gesture_Layer
282 compare_device(const void *data1, const void *data2)
283 { /* Compare the two device numbers */
284 return (((Pointer_Event *) data1)->device -((Pointer_Event *) data2)->device);
290 * Remove Pointer Event from touched device list
291 * @param list Pointer to touched device list.
292 * @param Pointer_Event Pointer to PE.
294 * @ingroup Elm_Gesture_Layer
297 _remove_touched_device(Eina_List *list, Pointer_Event *pe)
299 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
303 return eina_list_remove(list, p);
312 * Recoed Pointer Event in touched device list
313 * Note: This fuction allocates memory for PE event
314 * This memory is released in _remove_touched_device()
315 * @param list Pointer to touched device list.
316 * @param Pointer_Event Pointer to PE.
318 * @ingroup Elm_Gesture_Layer
321 _add_touched_device(Eina_List *list, Pointer_Event *pe)
323 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
325 { /* We like to track device touch-position, overwrite info */
326 memcpy(p, pe, sizeof(Pointer_Event));
330 p = malloc(sizeof(Pointer_Event));
331 memcpy(p, pe, sizeof(Pointer_Event)); /* Freed in _remove_touched_device() */
332 return eina_list_append(list, p);
334 /* END - Functions to manage touched-device list */
336 /* START - Functions to manage recent device event list */
337 /* This list holds the recent-event for each device */
338 /* it will hold a single recent-event for each device */
339 /* We are using those PE events of this list to */
340 /* send them later to test funcs to restart gestures */
341 /* We only keep DOWN, MOVE events in this list. */
342 /* So when no touch this list is empty. */
346 * Recoed Pointer Event in touched device list
347 * Note: This fuction allocates memory for PE event
348 * This memory is released here when device untouched
350 * @param list Pointer to touched device list.
351 * @param Pointer_Event Pointer to PE.
353 * @ingroup Elm_Gesture_Layer
356 _add_recent_device_event(Eina_List *list, Pointer_Event *pe)
358 void *data = eina_list_search_sorted(list, compare_device, pe);
360 Pointer_Event *p = NULL;
361 if(data) /* First remove recent event for this device */
362 l = eina_list_remove(list, data);
365 switch(pe->event_type)
367 case EVAS_CALLBACK_MOUSE_DOWN:
368 case EVAS_CALLBACK_MOUSE_MOVE:
369 case EVAS_CALLBACK_MULTI_DOWN:
370 case EVAS_CALLBACK_MULTI_MOVE:
371 p = malloc(sizeof(Pointer_Event));
372 memcpy(p, pe, sizeof(Pointer_Event)); /* Freed in here or on cleanup */
373 l = eina_list_sorted_insert(l, compare_device, p);
376 /* Kept those cases for referance */
377 case EVAS_CALLBACK_MOUSE_IN:
378 case EVAS_CALLBACK_MOUSE_OUT:
379 case EVAS_CALLBACK_MOUSE_WHEEL:
380 case EVAS_CALLBACK_MOUSE_UP:
381 case EVAS_CALLBACK_MULTI_UP:
382 case EVAS_CALLBACK_KEY_DOWN:
383 case EVAS_CALLBACK_KEY_UP:
392 /* END - Functions to manage recent device event list */
398 * @param event_info pointer to event.
400 * @ingroup Elm_Gesture_Layer
402 static Evas_Event_Flags
403 _get_event_flag(void *event_info, Evas_Callback_Type event_type)
407 case EVAS_CALLBACK_MOUSE_IN:
408 return ((Evas_Event_Mouse_In *) event_info)->event_flags;
409 case EVAS_CALLBACK_MOUSE_OUT:
410 return ((Evas_Event_Mouse_Out *) event_info)->event_flags;
411 case EVAS_CALLBACK_MOUSE_DOWN:
412 return ((Evas_Event_Mouse_Down *) event_info)->event_flags;
413 case EVAS_CALLBACK_MOUSE_MOVE:
414 return ((Evas_Event_Mouse_Move *) event_info)->event_flags;
415 case EVAS_CALLBACK_MOUSE_UP:
416 return ((Evas_Event_Mouse_Up *) event_info)->event_flags;
417 case EVAS_CALLBACK_MOUSE_WHEEL:
418 return ((Evas_Event_Mouse_Wheel *) event_info)->event_flags;
419 case EVAS_CALLBACK_MULTI_DOWN:
420 return ((Evas_Event_Multi_Down *) event_info)->event_flags;
421 case EVAS_CALLBACK_MULTI_MOVE:
422 return ((Evas_Event_Multi_Move *) event_info)->event_flags;
423 case EVAS_CALLBACK_MULTI_UP:
424 return ((Evas_Event_Multi_Up *) event_info)->event_flags;
425 case EVAS_CALLBACK_KEY_DOWN:
426 return ((Evas_Event_Key_Down *) event_info)->event_flags;
427 case EVAS_CALLBACK_KEY_UP:
428 return ((Evas_Event_Key_Up *) event_info)->event_flags;
430 return EVAS_EVENT_FLAG_NONE;
437 * Sets event flag to value returned from user callback
438 * @param wd Widget Data
439 * @param event_info pointer to event.
440 * @param event_type what type was ev (mouse down, etc...)
441 * @param ev_flags event flags
443 * @ingroup Elm_Gesture_Layer
446 consume_event(Widget_Data *wd, void *event_info,
447 Evas_Callback_Type event_type, Evas_Event_Flags ev_flags)
448 { /* Mark EVAS_EVENT_FLAG_ON_HOLD on events that are used by gesture layer */
449 /* ev_flags != EVAS_EVENT_FLAG_NONE means target used event and g-layer */
450 /* should not refeed this event. */
452 return; /* This happens when restarting gestures */
454 if ((ev_flags) || (!wd->repeat_events))
458 case EVAS_CALLBACK_MOUSE_DOWN:
459 ((Evas_Event_Mouse_Down *) event_info)->event_flags |= ev_flags;
461 case EVAS_CALLBACK_MOUSE_MOVE:
462 ((Evas_Event_Mouse_Move *) event_info)->event_flags |= ev_flags;
464 case EVAS_CALLBACK_MOUSE_UP:
465 ((Evas_Event_Mouse_Up *) event_info)->event_flags |= ev_flags;
467 case EVAS_CALLBACK_MOUSE_WHEEL:
468 ((Evas_Event_Mouse_Wheel *) event_info)->event_flags |= ev_flags;
470 case EVAS_CALLBACK_MULTI_DOWN:
471 ((Evas_Event_Multi_Down *) event_info)->event_flags |= ev_flags;
473 case EVAS_CALLBACK_MULTI_MOVE:
474 ((Evas_Event_Multi_Move *) event_info)->event_flags |= ev_flags;
476 case EVAS_CALLBACK_MULTI_UP:
477 ((Evas_Event_Multi_Up *) event_info)->event_flags |= ev_flags;
479 case EVAS_CALLBACK_KEY_DOWN:
480 ((Evas_Event_Key_Down *) event_info)->event_flags |= ev_flags;
482 case EVAS_CALLBACK_KEY_UP:
483 ((Evas_Event_Key_Up *) event_info)->event_flags |= ev_flags;
494 * Report current state of a gesture by calling user callback.
495 * @param gesture what gesture state we report.
496 * @param info inforamtion for user callback
498 * @ingroup Elm_Gesture_Layer
500 static Evas_Event_Flags
501 _report_state(Gesture_Info *gesture, void *info)
502 { /* We report current state (START, MOVE, END, ABORT), once */
503 #if defined(DEBUG_GESTURE_LAYER)
504 printf("%s reporting gesture=<%d> state=<%d>\n" , __func__, gesture->g_type,
507 if ((gesture->state != ELM_GESTURE_STATE_UNDEFINED) &&
508 (gesture->fn[gesture->state].cb))
509 { /* Fill state-info struct and send ptr to user callback */
510 return gesture->fn[gesture->state].cb(
511 gesture->fn[gesture->state].user_data, info);
514 return EVAS_EVENT_FLAG_NONE;
520 * Update state for a given gesture.
521 * We may update gesture state to:
522 * UNDEFINED - current input did not start gesure yet.
523 * START - gesture started according to input.
524 * MOVE - gusture in progress.
525 * END - gesture completed according to input.
526 * ABORT - input does not matches gesure.
527 * note that we may move from UNDEFINED to ABORT
528 * because we may detect that gesture will not START
529 * with a given input.
531 * @param g given gesture to change state.
532 * @param s gesure new state.
533 * @param info buffer to be sent to user callback on report_state.
534 * @param force makes report_state to report the new-state even
535 * if its same as current state. Works for MOVE - gesture in progress.
537 * @ingroup Elm_Gesture_Layer
539 static Evas_Event_Flags
540 _set_state(Gesture_Info *g, Elm_Gesture_State s,
541 void *info, Eina_Bool force)
543 Elm_Gesture_State old_state;
544 if ((g->state == s) && (!force))
545 return EVAS_EVENT_FLAG_NONE;
547 old_state = g->state;
550 g->info = info; /* Information for user callback */
551 if ((g->state == ELM_GESTURE_STATE_ABORT) ||
552 (g->state == ELM_GESTURE_STATE_END))
553 g->test = EINA_FALSE;
555 if ((g->state != ELM_GESTURE_STATE_UNDEFINED) &&
556 (!((old_state == ELM_GESTURE_STATE_UNDEFINED) &&
557 (s == ELM_GESTURE_STATE_ABORT))))
558 return _report_state(g, g->info);
560 return EVAS_EVENT_FLAG_NONE;
566 * This resets all gesture states and sets test-bit.
567 * this is used for restarting gestures to listen to input.
568 * happens after we complete a gesture or no gesture was detected.
569 * @param wd Widget data of the gesture-layer object.
571 * @ingroup Elm_Gesture_Layer
574 _reset_states(Widget_Data *wd)
578 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
583 _set_state(p, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
592 * if gesture was NOT detected AND we only have gestures in ABORT state
593 * we clear history immediately to be ready for input.
595 * @param obj The gesture-layer object.
596 * @return TRUE on event history_clear
598 * @ingroup Elm_Gesture_Layer
601 _clear_if_finished(Evas_Object *obj)
603 Widget_Data *wd = elm_widget_data_get(obj);
604 if (!wd) return EINA_FALSE;
607 /* Clear history if all we have aborted gestures */
608 Eina_Bool reset_s = EINA_TRUE, all_undefined = EINA_TRUE;
609 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
610 { /* If no gesture started and all we have aborted gestures, reset all */
611 Gesture_Info *p = wd->gesture[i];
612 if ((p) && (p->state != ELM_GESTURE_STATE_UNDEFINED))
614 if ((p->state == ELM_GESTURE_STATE_START) ||
615 (p->state == ELM_GESTURE_STATE_MOVE))
616 reset_s = EINA_FALSE;
618 all_undefined = EINA_FALSE;
622 // if ((!wd->touched) || (reset_s && !all_undefined))
623 /* (!wd->touched && reset_s) - don't stop zoom with mouse-wheel */
624 if (reset_s && (!all_undefined))
625 return _event_history_clear(obj);
631 _inside(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
633 int w = elm_finger_size_get() >> 1; /* Finger size devided by 2 */
649 /* All *test_reset() funcs are called to clear
650 * gesture intermediate data.
651 * This happens when we need to reset our tests.
652 * for example when gesture is detected or all ABORTed. */
654 _dbl_click_test_reset(Gesture_Info *gesture)
659 Widget_Data *wd = elm_widget_data_get(gesture->obj);
660 if (wd->dbl_timeout) ecore_timer_del(wd->dbl_timeout);
661 wd->dbl_timeout = NULL;
668 EINA_LIST_FREE(((Taps_Type *) gesture->data)->l, data)
669 EINA_LIST_FREE(data, pe)
672 memset(gesture->data, 0, sizeof(Taps_Type));
675 /* All *test_reset() funcs are called to clear
676 * gesture intermediate data.
677 * This happens when we need to reset our tests.
678 * for example when gesture is detected or all ABORTed. */
680 _n_long_tap_test_reset(Gesture_Info *gesture)
688 Long_Tap_Type *st = gesture->data;
689 if (st->timeout) ecore_timer_del(st->timeout);
692 EINA_LIST_FOREACH(st->touched, l, p)
695 eina_list_free(st->touched);
696 memset(gesture->data, 0, sizeof(Long_Tap_Type));
700 _momentum_test_reset(Gesture_Info *gesture)
708 memset(gesture->data, 0, sizeof(Momentum_Type));
712 _line_data_reset(Line_Data *st)
717 memset(st, 0, sizeof(Line_Data));
718 st->line_angle = ELM_GESTURE_NEGATIVE_ANGLE;
722 _line_test_reset(Gesture_Info *gesture)
730 Line_Type *st = gesture->data;
731 Eina_List *list = st->list;
734 EINA_LIST_FOREACH(list, l, t_line)
737 eina_list_free(list);
742 _zoom_test_reset(Gesture_Info *gesture)
750 Widget_Data *wd = elm_widget_data_get(gesture->obj);
751 Zoom_Type *st = gesture->data;
752 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
753 evas_object_evas_get(wd->target), "Control");
754 evas_object_key_ungrab(wd->target, "Control_L", mask, 0);
755 evas_object_key_ungrab(wd->target, "Control_R", mask, 0);
757 memset(st, 0, sizeof(Zoom_Type));
758 st->zoom_distance_tolerance = wd->zoom_distance_tolerance;
763 _rotate_test_reset(Gesture_Info *gesture)
771 Widget_Data *wd = elm_widget_data_get(gesture->obj);
772 Rotate_Type *st = gesture->data;
774 memset(st, 0, sizeof(Rotate_Type));
775 st->info.base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
776 st->rotate_angular_tolerance = wd->rotate_angular_tolerance;
783 * We register callbacks when gesture layer is attached to an object
784 * or when its enabled after disable.
786 * @param obj The gesture-layer object.
788 * @ingroup Elm_Gesture_Layer
791 _register_callbacks(Evas_Object *obj)
793 Widget_Data *wd = elm_widget_data_get(obj);
798 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
800 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
802 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_UP,
805 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
808 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_DOWN,
810 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_MOVE,
812 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_UP,
815 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_DOWN,
817 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_UP,
825 * We unregister callbacks when gesture layer is disabled.
827 * @param obj The gesture-layer object.
829 * @ingroup Elm_Gesture_Layer
832 _unregister_callbacks(Evas_Object *obj)
834 Widget_Data *wd = elm_widget_data_get(obj);
839 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
841 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
843 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_UP,
846 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
849 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_DOWN,
852 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_MOVE,
855 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_UP,
858 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_DOWN,
860 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_UP,
865 /* START - Event history list handling functions */
868 * This function is used to find if device number
869 * is found in a list of devices.
870 * The list contains devices for refeeding *UP event
872 * @ingroup Elm_Gesture_Layer
875 device_in_pending_list(const void *data1, const void *data2)
876 { /* Compare the two device numbers */
877 return (((intptr_t) data1) - ((intptr_t) data2));
883 * This functions adds device to refeed-pending device list
884 * @ingroup Elm_Gesture_Layer
887 _add_device_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
889 int device = ELM_MOUSE_DEVICE;
892 case EVAS_CALLBACK_MOUSE_DOWN:
894 case EVAS_CALLBACK_MULTI_DOWN:
895 device = ((Evas_Event_Multi_Down *) event)->device;
901 if (!eina_list_search_unsorted_list(list, device_in_pending_list,
904 return eina_list_append(list, (intptr_t*) device);
913 * This functions returns pending-device node
914 * @ingroup Elm_Gesture_Layer
917 _device_is_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
919 int device = ELM_MOUSE_DEVICE;
922 case EVAS_CALLBACK_MOUSE_UP:
924 case EVAS_CALLBACK_MULTI_UP:
925 device = ((Evas_Event_Multi_Up *) event)->device;
931 return eina_list_search_unsorted_list(list, device_in_pending_list,
932 (intptr_t *) device);
938 * This function reports ABORT to all none-detected gestures
939 * Then resets test bits for all desired gesures
940 * and clears input-events history.
941 * note: if no gesture was detected, events from history list
942 * are streamed to the widget because it's unused by layer.
943 * user may cancel refeed of events by setting repeat events.
945 * @param obj The gesture-layer object.
947 * @ingroup Elm_Gesture_Layer
950 _event_history_clear(Evas_Object *obj)
952 Widget_Data *wd = elm_widget_data_get(obj);
953 if (!wd) return EINA_FALSE;
957 Evas *e = evas_object_evas_get(obj);
958 Eina_Bool gesture_found = EINA_FALSE;
959 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
964 if (p->state == ELM_GESTURE_STATE_END)
965 gesture_found = EINA_TRUE;
967 { /* Report ABORT to all gestures that still not finished */
968 _set_state(p, ELM_GESTURE_STATE_ABORT, wd->gesture[i]->info,
974 _reset_states(wd); /* we are ready to start testing for gestures again */
976 /* Clear all gestures intermediate date */
977 _n_long_tap_test_reset(wd->gesture[ELM_GESTURE_N_LONG_TAPS]);
978 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_TAPS]);
979 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
980 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
981 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
982 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
983 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
984 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
985 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
987 /* Disable gesture layer so refeeded events won't be consumed by it */
988 _unregister_callbacks(obj);
989 while (wd->event_history_list)
992 t = wd->event_history_list;
993 Eina_List *pending = _device_is_pending(wd->pending,
994 wd->event_history_list->event,
995 wd->event_history_list->event_type);
997 /* Refeed events if no gesture matched input */
998 if (pending || ((!gesture_found) && (!wd->repeat_events)))
1000 evas_event_refeed_event(e, wd->event_history_list->event,
1001 wd->event_history_list->event_type);
1005 wd->pending = eina_list_remove_list(wd->pending, pending);
1006 int device = ELM_MOUSE_DEVICE;
1007 if (wd->event_history_list->event_type == EVAS_CALLBACK_MULTI_UP)
1008 device = ((Evas_Event_Multi_Up *)
1009 (wd->event_history_list->event))->device;
1012 wd->pending = _add_device_pending(wd->pending,
1013 wd->event_history_list->event,
1014 wd->event_history_list->event_type);
1017 free(wd->event_history_list->event);
1018 wd->event_history_list = (Event_History *) eina_inlist_remove(
1019 EINA_INLIST_GET(wd->event_history_list),
1020 EINA_INLIST_GET(wd->event_history_list));
1023 _register_callbacks(obj);
1030 * This function copies input events.
1031 * We copy event info before adding it to history.
1032 * The memory is freed when we clear history.
1034 * @param event the event to copy
1035 * @param event_type event type to copy
1037 * @ingroup Elm_Gesture_Layer
1040 _copy_event_info(void *event, Evas_Callback_Type event_type)
1044 case EVAS_CALLBACK_MOUSE_DOWN:
1045 return COPY_EVENT_INFO((Evas_Event_Mouse_Down *) event);
1047 case EVAS_CALLBACK_MOUSE_MOVE:
1048 return COPY_EVENT_INFO((Evas_Event_Mouse_Move *) event);
1050 case EVAS_CALLBACK_MOUSE_UP:
1051 return COPY_EVENT_INFO((Evas_Event_Mouse_Up *) event);
1053 case EVAS_CALLBACK_MOUSE_WHEEL:
1054 return COPY_EVENT_INFO((Evas_Event_Mouse_Wheel *) event);
1056 case EVAS_CALLBACK_MULTI_DOWN:
1057 return COPY_EVENT_INFO((Evas_Event_Multi_Down *) event);
1059 case EVAS_CALLBACK_MULTI_MOVE:
1060 return COPY_EVENT_INFO((Evas_Event_Multi_Move *) event);
1062 case EVAS_CALLBACK_MULTI_UP:
1063 return COPY_EVENT_INFO((Evas_Event_Multi_Up *) event);
1065 case EVAS_CALLBACK_KEY_DOWN:
1066 return COPY_EVENT_INFO((Evas_Event_Key_Down *) event);
1068 case EVAS_CALLBACK_KEY_UP:
1069 return COPY_EVENT_INFO((Evas_Event_Key_Up *) event);
1077 _event_history_add(Evas_Object *obj, void *event, Evas_Callback_Type event_type)
1079 Widget_Data *wd = elm_widget_data_get(obj);
1081 if (!wd) return EINA_FALSE;
1083 ev = malloc(sizeof(Event_History));
1084 ev->event = _copy_event_info(event, event_type); /* Freed on event_history_clear */
1085 ev->event_type = event_type;
1086 wd->event_history_list = (Event_History *) eina_inlist_append(
1087 EINA_INLIST_GET(wd->event_history_list), EINA_INLIST_GET(ev));
1091 /* END - Event history list handling functions */
1094 _del_hook(Evas_Object *obj)
1096 Widget_Data *wd = elm_widget_data_get(obj);
1099 _event_history_clear(obj);
1100 eina_list_free(wd->pending);
1102 Pointer_Event *data;
1103 EINA_LIST_FREE(wd->touched, data)
1106 EINA_LIST_FREE(wd->recent_device_event, data)
1109 if (!elm_widget_disabled_get(obj))
1110 _unregister_callbacks(obj);
1112 /* Free all gestures internal data structures */
1114 for (i = 0; i < ELM_GESTURE_LAST; i++)
1117 if (wd->gesture[i]->data)
1118 free(wd->gesture[i]->data);
1120 free(wd->gesture[i]);
1127 compare_match_fingers(const void *data1, const void *data2)
1128 { /* Compare coords of first item in list to cur coords */
1129 const Pointer_Event *pe1 = eina_list_data_get(data1);
1130 const Pointer_Event *pe2 = data2;
1132 if (_inside(pe1->x, pe1->y, pe2->x, pe2->y))
1134 else if (pe1->x < pe2->x)
1138 if (pe1->x == pe2->x)
1139 return pe1->y - pe2->y;
1146 compare_pe_device(const void *data1, const void *data2)
1147 { /* Compare coords of first item in list to cur coords */
1148 const Pointer_Event *pe1 = eina_list_data_get(eina_list_last(data1));
1149 const Pointer_Event *pe2 = data2;
1151 /* Only match if last was a down event */
1152 if ((pe1->event_type != EVAS_CALLBACK_MULTI_DOWN) &&
1153 (pe1->event_type != EVAS_CALLBACK_MOUSE_DOWN))
1157 if (pe1->device == pe2->device)
1159 else if (pe1->device < pe2->device)
1166 _record_pointer_event(Taps_Type *st, Eina_List *pe_list, Pointer_Event *pe,
1167 Widget_Data *wd, void *event_info, Evas_Callback_Type event_type)
1168 { /* Keep copy of pe and record it in list */
1169 Pointer_Event *p = malloc(sizeof(Pointer_Event));
1170 memcpy(p, pe, sizeof(Pointer_Event));
1171 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1177 /* This will also update middle-point to report to user later */
1178 st->info.x = st->sum_x / st->n_taps;
1179 st->info.y = st->sum_y / st->n_taps;
1180 st->info.timestamp = pe->timestamp;
1184 pe_list = eina_list_append(pe_list, p);
1185 st->l = eina_list_append(st->l, pe_list);
1188 pe_list = eina_list_append(pe_list, p);
1196 * when this timer expires we ABORT double click gesture.
1198 * @param data The gesture-layer object.
1199 * @return cancles callback for this timer.
1201 * @ingroup Elm_Gesture_Layer
1204 _dbl_click_timeout(void *data)
1206 Gesture_Info *gesture = data;
1207 Widget_Data *wd = elm_widget_data_get(gesture->obj);
1209 wd->dbl_timeout = NULL;
1210 _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1211 gesture->info, EINA_FALSE);
1213 _dbl_click_test_reset(gesture);
1214 _clear_if_finished(gesture->obj);
1215 return ECORE_CALLBACK_CANCEL;
1221 * when this timer expires we START long tap gesture
1223 * @param data The gesture-layer object.
1224 * @return cancles callback for this timer.
1226 * @ingroup Elm_Gesture_Layer
1229 _long_tap_timeout(void *data)
1231 Gesture_Info *gesture = data;
1232 Long_Tap_Type *st = gesture->data;
1235 _set_state(gesture, ELM_GESTURE_STATE_START,
1236 gesture->data, EINA_FALSE);
1238 return ECORE_CALLBACK_CANCEL;
1244 * This function checks all click/tap and double/triple taps
1246 * @param obj The gesture-layer object.
1247 * @param pe The recent input event as stored in pe struct.
1248 * @param event_info Original input event pointer.
1249 * @param event_type Type of original input event.
1250 * @param g_type what Gesture we are testing.
1251 * @param taps How many click/taps we test for.
1253 * @ingroup Elm_Gesture_Layer
1256 _dbl_click_test(Evas_Object *obj, Pointer_Event *pe,
1257 void *event_info, Evas_Callback_Type event_type,
1258 Elm_Gesture_Types g_type, int taps)
1259 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1260 Widget_Data *wd = elm_widget_data_get(obj);
1263 if (!pe) /* this happens when unhandled event arrived */
1264 return; /* see _make_pointer_event function */
1266 Gesture_Info *gesture = wd->gesture[g_type];
1267 if (!gesture ) return;
1269 Taps_Type *st = gesture->data;
1271 { /* Allocated once on first time */
1272 st = calloc(1, sizeof(Taps_Type));
1274 _dbl_click_test_reset(gesture);
1277 Eina_List *pe_list = NULL;
1278 Pointer_Event *pe_down = NULL;
1279 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1280 switch (pe->event_type)
1282 case EVAS_CALLBACK_MULTI_DOWN:
1283 case EVAS_CALLBACK_MOUSE_DOWN:
1284 pe_list = eina_list_search_unsorted(st->l, compare_match_fingers, pe);
1285 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1286 if ((pe->device == 0) && (eina_list_count(pe_list) == 1))
1287 { /* This is the first mouse down we got */
1288 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1289 &st->info, EINA_FALSE);
1290 consume_event(wd, event_info, event_type, ev_flag);
1292 /* To test dbl_click/dbl_tap */
1293 /* When this timer expires, gesture ABORTed if not completed */
1294 if (!wd->dbl_timeout && (taps > 1))
1295 wd->dbl_timeout = ecore_timer_add(0.4, _dbl_click_timeout,
1302 case EVAS_CALLBACK_MULTI_UP:
1303 case EVAS_CALLBACK_MOUSE_UP:
1304 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1306 return; /* Got only first mouse_down and mouse_up */
1308 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1310 if (eina_list_count(pe_list) <= (unsigned int) ((taps - 1) * 2))
1311 return; /* Got only first mouse_down and mouse_up */
1313 /* Get first event in first list, this has to be Mouse Down event */
1314 pe_down = eina_list_data_get(pe_list);
1316 if (_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1322 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1323 &st->info, EINA_FALSE);
1324 consume_event(wd, event_info, event_type, ev_flag);
1328 if (st->count_ups == eina_list_count(st->l))
1330 /* Abort if we found a single click */
1331 if ((taps == 1) && (st->count_ups == 1))
1333 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1334 &st->info, EINA_FALSE);
1335 consume_event(wd, event_info, event_type, ev_flag);
1338 st->info.n = st->count_ups;
1339 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1340 &st->info, EINA_FALSE);
1341 consume_event(wd, event_info, event_type, ev_flag);
1348 case EVAS_CALLBACK_MULTI_MOVE:
1349 case EVAS_CALLBACK_MOUSE_MOVE:
1350 /* Get first event in first list, this has to be a Mouse Down event */
1351 /* and verify that user didn't move out of this area before next tap */
1352 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1355 pe_down = eina_list_data_get(pe_list);
1356 if (!_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1358 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1359 &st->info, EINA_FALSE);
1360 consume_event(wd, event_info, event_type, ev_flag);
1373 * This function computes center-point for long-tap gesture
1375 * @param st Long Tap gesture info pointer
1376 * @param pe The recent input event as stored in pe struct.
1378 * @ingroup Elm_Gesture_Layer
1381 _compute_taps_center(Long_Tap_Type *st, Pointer_Event *pe)
1383 if(!eina_list_count(st->touched))
1388 Evas_Coord x = 0, y = 0;
1389 EINA_LIST_FOREACH(st->touched, l, p)
1390 { /* Accumulate all then take avarage */
1391 if (p->device == pe->device)
1392 { /* This will take care of values coming from MOVE event */
1403 st->info.x = x / eina_list_count(st->touched);
1404 st->info.y = y / eina_list_count(st->touched);
1410 * This function checks N long-tap gesture.
1412 * @param obj The gesture-layer object.
1413 * @param pe The recent input event as stored in pe struct.
1414 * @param event_info Original input event pointer.
1415 * @param event_type Type of original input event.
1416 * @param g_type what Gesture we are testing.
1417 * @param taps How many click/taps we test for.
1419 * @ingroup Elm_Gesture_Layer
1422 _n_long_tap_test(Evas_Object *obj, Pointer_Event *pe,
1423 void *event_info, Evas_Callback_Type event_type,
1424 Elm_Gesture_Types g_type)
1425 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1426 Widget_Data *wd = elm_widget_data_get(obj);
1429 if (!pe) /* this happens when unhandled event arrived */
1430 return; /* see _make_pointer_event function */
1432 Gesture_Info *gesture = wd->gesture[g_type];
1433 if (!gesture ) return;
1435 Long_Tap_Type *st = gesture->data;
1437 { /* Allocated once on first time */
1438 st = calloc(1, sizeof(Long_Tap_Type));
1440 _n_long_tap_test_reset(gesture);
1443 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1444 switch (pe->event_type)
1446 case EVAS_CALLBACK_MULTI_DOWN:
1447 case EVAS_CALLBACK_MOUSE_DOWN:
1448 if (st->info.n > eina_list_count(st->touched))
1449 { /* ABORT: user lifts finger then back before completing gesgure */
1450 if (st->timeout) ecore_timer_del(st->timeout);
1452 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1453 &st->info, EINA_FALSE);
1456 st->touched = _add_touched_device(st->touched, pe);
1457 st->info.n = eina_list_count(st->touched);
1458 if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
1459 { /* This is the first mouse down we got */
1460 st->info.timestamp = pe->timestamp;
1462 /* To test long tap */
1463 /* When this timer expires, gesture STARTED */
1465 st->timeout = ecore_timer_add(wd->long_tap_start_timeout, _long_tap_timeout,
1469 consume_event(wd, event_info, event_type, ev_flag);
1470 _compute_taps_center(st, pe);
1473 case EVAS_CALLBACK_MULTI_UP:
1474 case EVAS_CALLBACK_MOUSE_UP:
1475 st->touched = _remove_touched_device(st->touched, pe);
1477 ((gesture->state == ELM_GESTURE_STATE_START) ||
1478 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1479 { /* Report END only for gesture that STARTed */
1480 if (eina_list_count(st->touched) == 0)
1481 { /* Report END only at last release event */
1482 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1483 &st->info, EINA_FALSE);
1484 consume_event(wd, event_info, event_type, ev_flag);
1489 case EVAS_CALLBACK_MULTI_MOVE:
1490 case EVAS_CALLBACK_MOUSE_MOVE:
1492 ((gesture->state == ELM_GESTURE_STATE_START) ||
1493 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1494 { /* Report MOVE only if STARTED */
1495 _compute_taps_center(st, pe);
1496 /* Report MOVE if gesture started */
1497 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
1498 &st->info, EINA_TRUE);
1499 consume_event(wd, event_info, event_type, ev_flag);
1511 * This function computes momentum for MOMENTUM, LINE and FLICK gestures
1512 * This momentum value will be sent to widget when gesture is completed.
1514 * @param momentum pointer to buffer where we record momentum value.
1515 * @param x1 x coord where user started gesture.
1516 * @param y1 y coord where user started gesture.
1517 * @param x2 x coord where user completed gesture.
1518 * @param y2 y coord where user completed gesture.
1519 * @param t1x timestamp for X, when user started gesture.
1520 * @param t1y timestamp for Y, when user started gesture.
1521 * @param t2 timestamp when user completed gesture.
1523 * @ingroup Elm_Gesture_Layer
1526 _set_momentum(Elm_Gesture_Momentum_Info *momentum, Evas_Coord x1, Evas_Coord y1,
1527 Evas_Coord x2, Evas_Coord y2, unsigned int t1x, unsigned int t1y,
1530 Evas_Coord velx = 0, vely = 0, vel;
1531 Evas_Coord dx = x2 - x1;
1532 Evas_Coord dy = y2 - y1;
1536 velx = (dx * 1000) / dtx;
1539 vely = (dy * 1000) / dty;
1541 vel = sqrt((velx * velx) + (vely * vely));
1543 if ((_elm_config->thumbscroll_friction > 0.0) &&
1544 (vel > _elm_config->thumbscroll_momentum_threshold))
1545 { /* report momentum */
1546 momentum->mx = velx;
1547 momentum->my = vely;
1559 * This function is used for computing rotation angle (DEG).
1561 * @param x1 first finger x location.
1562 * @param y1 first finger y location.
1563 * @param x2 second finger x location.
1564 * @param y2 second finger y location.
1566 * @return angle of the line between (x1,y1), (x2,y2) in Radians.
1568 * @ingroup Elm_Gesture_Layer
1571 get_angle(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
1577 if (((int) xx) && ((int) yy))
1584 return RAD_360DEG - a;
1595 return RAD_180DEG + a;
1599 return RAD_180DEG - a;
1605 { /* Horizontal line */
1630 * This function is used for computing the magnitude and direction
1631 * of vector between two points.
1633 * @param x1 first finger x location.
1634 * @param y1 first finger y location.
1635 * @param x2 second finger x location.
1636 * @param y2 second finger y location.
1637 * @param l length computed (output)
1638 * @param a angle computed (output)
1640 * @ingroup Elm_Gesture_Layer
1643 get_vector(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2,
1644 Evas_Coord *l, double *a)
1649 *l = (Evas_Coord) sqrt(xx*xx + yy*yy);
1650 *a = get_angle(x1, y1, x2, y2);
1654 _get_direction(Evas_Coord x1, Evas_Coord x2)
1666 * This function tests momentum gesture.
1667 * @param obj The gesture-layer object.
1668 * @param pe The recent input event as stored in pe struct.
1669 * @param event_info recent input event.
1670 * @param event_type recent event type.
1671 * @param g_type what Gesture we are testing.
1673 * @ingroup Elm_Gesture_Layer
1676 _momentum_test(Evas_Object *obj, Pointer_Event *pe,
1677 void *event_info, Evas_Callback_Type event_type,
1678 Elm_Gesture_Types g_type)
1680 Widget_Data *wd = elm_widget_data_get(obj);
1682 Gesture_Info *gesture = wd->gesture[g_type];
1683 if (!gesture ) return;
1685 Momentum_Type *st = gesture->data;
1686 Elm_Gesture_State state_to_report;
1688 { /* Allocated once on first time */
1689 st = calloc(1, sizeof(Momentum_Type));
1691 _momentum_test_reset(gesture);
1697 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1700 case EVAS_CALLBACK_MOUSE_DOWN:
1701 case EVAS_CALLBACK_MOUSE_MOVE:
1704 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1705 (wd->glayer_continues_enable)) /* start also on MOVE */
1706 { /* We start on MOVE when cont-enabled only */
1707 st->line_st.x = st->line_end.x = pe->x;
1708 st->line_st.y = st->line_end.y = pe->y;
1709 st->t_st_x = st->t_st_y = st->t_end = pe->timestamp;
1710 st->xdir = st->ydir = 0;
1711 st->info.x2 = st->info.x1 = pe->x;
1712 st->info.y2 = st->info.y1 = pe->y;
1713 st->info.tx = st->info.ty = pe->timestamp;
1714 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1715 &st->info, EINA_FALSE);
1716 consume_event(wd, event_info, event_type, ev_flag);
1723 state_to_report = ELM_GESTURE_STATE_MOVE;
1724 if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1725 { /* Too long of a wait, reset all values */
1726 st->line_st.x = pe->x;
1727 st->line_st.y = pe->y;
1728 st->t_st_y = st->t_st_x = pe->timestamp;
1729 st->info.tx = st->t_st_x;
1730 st->info.ty = st->t_st_y;
1731 st->xdir = st->ydir = 0;
1736 xdir = _get_direction(st->line_st.x, pe->x);
1737 ydir = _get_direction(st->line_st.y, pe->y);
1738 if (!xdir || (xdir == (-st->xdir)))
1740 st->line_st.x = st->line_end.x;
1741 st->info.tx = st->t_st_x = st->t_end;
1745 if (!ydir || (ydir == (-st->ydir)))
1747 st->line_st.y = st->line_end.y;
1748 st->info.ty = st->t_st_y = st->t_end;
1753 st->info.x2 = st->line_end.x = pe->x;
1754 st->info.y2 = st->line_end.y = pe->y;
1755 st->t_end = pe->timestamp;
1756 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
1757 st->t_st_x, st->t_st_y, pe->timestamp);
1758 ev_flag = _set_state(gesture, state_to_report, &st->info,
1760 consume_event(wd, event_info, event_type, ev_flag);
1764 case EVAS_CALLBACK_MOUSE_UP:
1765 /* IGNORE if line info was cleared, like long press, move */
1768 state_to_report = ELM_GESTURE_STATE_END;
1770 if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1771 { /* Too long of a wait, reset all values */
1772 st->line_st.x = pe->x;
1773 st->line_st.y = pe->y;
1774 st->t_st_y = st->t_st_x = pe->timestamp;
1775 st->xdir = st->ydir = 0;
1778 st->info.x2 = pe->x;
1779 st->info.y2 = pe->y;
1780 st->line_end.x = pe->x;
1781 st->line_end.y = pe->y;
1782 st->t_end = pe->timestamp;
1784 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
1785 st->t_st_x, st->t_st_y, pe->timestamp);
1787 ev_flag = _set_state(gesture, state_to_report, &st->info,
1789 consume_event(wd, event_info, event_type, ev_flag);
1793 case EVAS_CALLBACK_MULTI_UP:
1794 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
1796 consume_event(wd, event_info, event_type, ev_flag);
1805 compare_line_device(const void *data1, const void *data2)
1806 { /* Compare device component of line struct */
1807 const Line_Data *ln1 = data1;
1808 const int *device = data2;
1810 if (ln1->t_st) /* Compare only with lines that started */
1811 return (ln1->device - (*device));
1819 * This function construct line struct from input.
1820 * @param info pointer to store line momentum.
1821 * @param st line info to store input data.
1822 * @param pe The recent input event as stored in pe struct.
1824 * @ingroup Elm_Gesture_Layer
1827 _single_line_process(Elm_Gesture_Line_Info *info, Line_Data *st,
1828 Pointer_Event *pe, Evas_Callback_Type event_type)
1829 { /* Record events and set momentum for line pointed by st */
1835 case EVAS_CALLBACK_MOUSE_DOWN:
1836 case EVAS_CALLBACK_MOUSE_MOVE:
1837 case EVAS_CALLBACK_MULTI_DOWN:
1838 case EVAS_CALLBACK_MULTI_MOVE:
1840 { /* This happens only when line starts */
1841 st->line_st.x = pe->x;
1842 st->line_st.y = pe->y;
1843 st->t_st = pe->timestamp;
1844 st->device = pe->device;
1845 info->momentum.x1 = pe->x;
1846 info->momentum.y1 = pe->y;
1847 info->momentum.tx = pe->timestamp;
1848 info->momentum.ty = pe->timestamp;
1855 case EVAS_CALLBACK_MOUSE_UP:
1856 case EVAS_CALLBACK_MULTI_UP:
1857 /* IGNORE if line info was cleared, like long press, move */
1861 st->line_end.x = pe->x;
1862 st->line_end.y = pe->y;
1863 st->t_end = pe->timestamp;
1872 _line_data_reset(st);
1876 info->momentum.x2 = pe->x;
1877 info->momentum.y2 = pe->y;
1878 _set_momentum(&info->momentum, st->line_st.x, st->line_st.y, pe->x, pe->y,
1879 st->t_st, st->t_st, pe->timestamp);
1887 * This function test for (n) line gesture.
1888 * @param obj The gesture-layer object.
1889 * @param pe The recent input event as stored in pe struct.
1890 * @param event_info Original input event pointer.
1891 * @param event_type Type of original input event.
1892 * @param g_type what Gesture we are testing.
1894 * @ingroup Elm_Gesture_Layer
1897 _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
1898 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
1902 Widget_Data *wd = elm_widget_data_get(obj);
1904 Gesture_Info *gesture = wd->gesture[g_type];
1905 if (!gesture ) return;
1907 Line_Type *st = gesture->data;
1910 st = calloc(1, sizeof(Line_Type));
1914 Line_Data *line = NULL;
1915 Eina_List *list = st->list;
1916 unsigned cnt = eina_list_count(list);
1919 { /* list is not empty, locate this device on list */
1920 line = (Line_Data *) eina_list_search_unsorted(st->list,
1921 compare_line_device, &pe->device);
1925 { /* List is empty or device not found, new line-struct on START only */
1926 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1927 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
1928 ((wd->glayer_continues_enable) && /* START on MOVE also */
1929 ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
1930 (event_type == EVAS_CALLBACK_MULTI_MOVE))))
1931 { /* Allocate new item on START only */
1932 line = calloc(1, sizeof(Line_Data));
1933 _line_data_reset(line);
1934 list = eina_list_append(list, line);
1939 if (!line) /* This may happen on MOVE that comes before DOWN */
1940 return; /* No line-struct to work with, can't continue testing */
1942 if (_single_line_process(&st->info, line, pe, event_type)) /* update st with input */
1943 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1945 /* Get direction and magnitude of the line */
1947 get_vector(line->line_st.x, line->line_st.y, pe->x, pe->y,
1948 &line->line_length, &angle);
1950 /* These are used later to compare lines length */
1951 Evas_Coord shortest_line_len = line->line_length;
1952 Evas_Coord longest_line_len = line->line_length;
1953 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1955 /* Now update line-state */
1957 { /* Analyze line only if line started */
1958 if (line->line_angle >= 0.0)
1959 { /* if line direction was set, we test if broke tolerance */
1960 double a = fabs(angle - line->line_angle);
1962 double d = (tan(a)) * line->line_length; /* Distance from line */
1963 #if defined(DEBUG_GESTURE_LAYER)
1964 printf("%s a=<%f> d=<%f>\n", __func__, (a * 57.295779513), d);
1966 if ((d > wd->line_distance_tolerance) || (a > wd->line_angular_tolerance))
1967 { /* Broke tolerance: abort line and start a new one */
1968 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1969 &st->info, EINA_FALSE);
1970 consume_event(wd, event_info, event_type, ev_flag);
1974 if (wd->glayer_continues_enable)
1975 { /* We may finish line if momentum is zero */
1976 /* This is for continues-gesture */
1977 if ((!st->info.momentum.mx) && (!st->info.momentum.my))
1978 { /* Finish line on zero momentum for continues gesture */
1979 line->line_end.x = pe->x;
1980 line->line_end.y = pe->y;
1981 line->t_end = pe->timestamp;
1986 { /* Record the line angle as it broke minimum length for line */
1987 if (line->line_length >= wd->line_min_length)
1988 st->info.angle = line->line_angle = angle;
1994 if (line->line_angle < 0.0)
1995 { /* it's not a line, too short more close to a tap */
1996 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1997 &st->info, EINA_FALSE);
1998 consume_event(wd, event_info, event_type, ev_flag);
2004 /* Count how many lines already started / ended */
2007 unsigned int tm_start = pe->timestamp;
2008 unsigned int tm_end = pe->timestamp;
2011 double base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
2012 Eina_Bool lines_parallel = EINA_TRUE;
2013 EINA_LIST_FOREACH(list, l, t_line)
2016 base_angle = t_line->line_angle;
2019 if (t_line->line_angle >= 0)
2020 { /* Compare angle only with lines with direction defined */
2021 if (fabs(base_angle - t_line->line_angle) >
2022 wd->line_angular_tolerance)
2023 lines_parallel = EINA_FALSE;
2027 if (t_line->line_length)
2028 { /* update only if this line is used */
2029 if (shortest_line_len > t_line->line_length)
2030 shortest_line_len = t_line->line_length;
2032 if (longest_line_len < t_line->line_length)
2033 longest_line_len = t_line->line_length;
2039 if (t_line->t_st < tm_start)
2040 tm_start = t_line->t_st;
2046 if (t_line->t_end < tm_end)
2047 tm_end = t_line->t_end;
2051 st->info.n = started;
2055 ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2056 (event_type == EVAS_CALLBACK_MULTI_DOWN)))
2057 { /* user lift one finger then starts again without line-end - ABORT */
2058 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2060 consume_event(wd, event_info, event_type, ev_flag);
2064 if (!lines_parallel)
2065 { /* Lines are NOT at same direction, abort this gesture */
2066 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2068 consume_event(wd, event_info, event_type, ev_flag);
2073 /* We report ABORT if lines length are NOT matching when fingers are up */
2074 if ((longest_line_len - shortest_line_len) > (elm_finger_size_get()*2))
2076 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2078 consume_event(wd, event_info, event_type, ev_flag);
2082 if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > wd->flick_time_limit_ms))
2083 { /* We consider FLICK as a fast line.ABORT if take too long to finish */
2084 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2086 consume_event(wd, event_info, event_type, ev_flag);
2092 case EVAS_CALLBACK_MOUSE_UP:
2093 case EVAS_CALLBACK_MULTI_UP:
2094 if ((started) && (started == ended))
2096 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2097 &st->info, EINA_FALSE);
2098 consume_event(wd, event_info, event_type, ev_flag);
2103 case EVAS_CALLBACK_MOUSE_DOWN:
2104 case EVAS_CALLBACK_MULTI_DOWN:
2105 case EVAS_CALLBACK_MOUSE_MOVE:
2106 case EVAS_CALLBACK_MULTI_MOVE:
2109 if (wd->glayer_continues_enable && (started == ended))
2110 { /* For continues gesture */
2111 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2112 &st->info, EINA_FALSE);
2113 consume_event(wd, event_info, event_type, ev_flag);
2116 { /* When continues, may START on MOVE event too */
2117 Elm_Gesture_State s = ELM_GESTURE_STATE_MOVE;
2119 /* This happens when: on n > 1 lines then one finger up */
2120 /* caused abort, then put finger down. */
2121 /* This will stop line from starting again. */
2122 /* Number of lines, MUST match touched-device in list */
2123 if ((!wd->glayer_continues_enable) &&
2124 (eina_list_count(st->list) < eina_list_count(wd->touched)))
2125 s = ELM_GESTURE_STATE_ABORT;
2127 if (gesture->state == ELM_GESTURE_STATE_UNDEFINED)
2128 s = ELM_GESTURE_STATE_START;
2130 ev_flag = _set_state(gesture, s, &st->info, EINA_TRUE);
2131 consume_event(wd, event_info, event_type, ev_flag);
2137 return; /* Unhandeld event type */
2144 * This function is used to check if rotation gesture started.
2145 * @param st Contains current rotation values from user input.
2146 * @return TRUE/FALSE if we need to set rotation START.
2148 * @ingroup Elm_Gesture_Layer
2151 rotation_broke_tolerance(Rotate_Type *st)
2153 if (st->info.base_angle < 0)
2154 return EINA_FALSE; /* Angle has to be computed first */
2156 if (st->rotate_angular_tolerance < 0)
2159 double low = st->info.base_angle - st->rotate_angular_tolerance;
2160 double high = st->info.base_angle + st->rotate_angular_tolerance;
2161 double t = st->info.angle;
2174 if (high > RAD_360DEG)
2185 #if defined(DEBUG_GESTURE_LAYER)
2186 printf("%s angle=<%f> low=<%f> high=<%f>\n", __func__, t, low, high);
2188 if ((t < low) || (t > high))
2189 { /* This marks that roation action has started */
2190 st->rotate_angular_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
2191 st->info.base_angle = st->info.angle; /* Avoid jump in angle value */
2201 * This function is used for computing the gap between fingers.
2202 * It returns the length and center point between fingers.
2204 * @param x1 first finger x location.
2205 * @param y1 first finger y location.
2206 * @param x2 second finger x location.
2207 * @param y2 second finger y location.
2208 * @param x Gets center point x cord (output)
2209 * @param y Gets center point y cord (output)
2211 * @return length of the line between (x1,y1), (x2,y2) in pixels.
2213 * @ingroup Elm_Gesture_Layer
2216 get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
2217 Evas_Coord y2, Evas_Coord *x, Evas_Coord *y)
2219 double a, b, xx, yy, gap;
2222 gap = sqrt(xx*xx + yy*yy);
2224 /* START - Compute zoom center point */
2225 /* The triangle defined as follows:
2233 * http://en.wikipedia.org/wiki/Trigonometric_functions
2234 *************************************/
2235 if (((int) xx) && ((int) yy))
2237 double A = atan((yy / xx));
2238 #if defined(DEBUG_GESTURE_LAYER)
2239 printf("xx=<%f> yy=<%f> A=<%f>\n", xx, yy, A);
2241 a = (Evas_Coord) ((gap / 2) * sin(A));
2242 b = (Evas_Coord) ((gap / 2) * cos(A));
2243 *x = (Evas_Coord) ((x2 > x1) ? (x1 + b) : (x2 + b));
2244 *y = (Evas_Coord) ((y2 > y1) ? (y1 + a) : (y2 + a));
2249 { /* horiz line, take half width */
2250 #if defined(DEBUG_GESTURE_LAYER)
2251 printf("==== HORIZ ====\n");
2253 *x = (Evas_Coord) (xx / 2);
2254 *y = (Evas_Coord) (y1);
2258 { /* vert line, take half width */
2259 #if defined(DEBUG_GESTURE_LAYER)
2260 printf("==== VERT ====\n");
2262 *x = (Evas_Coord) (x1);
2263 *y = (Evas_Coord) (yy / 2);
2266 /* END - Compute zoom center point */
2268 return (Evas_Coord) gap;
2274 * This function is used for computing zoom value.
2276 * @param st Pointer to zoom data based on user input.
2277 * @param x1 first finger x location.
2278 * @param y1 first finger y location.
2279 * @param x2 second finger x location.
2280 * @param y2 second finger y location.
2281 * @param factor zoom-factor, used to determine how fast zoom works.
2283 * @return zoom value, when 1.0 means no zoom, 0.5 half size...
2285 * @ingroup Elm_Gesture_Layer
2287 /* FIXME change float to double */
2289 compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2290 Evas_Coord x2, Evas_Coord y2, unsigned int tm2, double zoom_finger_factor)
2293 Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
2294 &st->info.x, &st->info.y);
2296 st->info.radius = diam / 2;
2300 st->zoom_base = diam;
2301 return st->info.zoom;
2304 if (st->zoom_distance_tolerance)
2305 { /* zoom tolerance <> ZERO, means zoom action NOT started yet */
2306 if (diam < (st->zoom_base - st->zoom_distance_tolerance))
2307 { /* avoid jump with zoom value when break tolerance */
2308 st->zoom_base -= st->zoom_distance_tolerance;
2309 st->zoom_distance_tolerance = 0;
2312 if (diam > (st->zoom_base + st->zoom_distance_tolerance))
2313 { /* avoid jump with zoom value when break tolerance */
2314 st->zoom_base += st->zoom_distance_tolerance;
2315 st->zoom_distance_tolerance = 0;
2321 /* We use factor only on the difference between gap-base */
2322 /* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
2323 rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
2324 (float) st->zoom_base) * zoom_finger_factor));
2327 /* Momentum: zoom per second: (NOT YET SUPPORTED) */
2328 st->info.momentum = (((rt - 1.0) * 1000) / (tm2 - tm1));
2339 * This function handles zoom with mouse wheel.
2340 * thats a combination of wheel + CTRL key.
2341 * @param obj The gesture-layer object.
2342 * @param event_info Original input event pointer.
2343 * @param event_type Type of original input event.
2344 * @param g_type what Gesture we are testing.
2346 * @ingroup Elm_Gesture_Layer
2349 _zoom_with_wheel_test(Evas_Object *obj, void *event_info,
2350 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2352 Widget_Data *wd = elm_widget_data_get(obj);
2354 if (!wd->gesture[g_type]) return;
2356 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2357 Zoom_Type *st = gesture_zoom->data;
2358 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2360 { /* Allocated once on first time, used for zoom intermediate data */
2361 st = calloc(1, sizeof(Zoom_Type));
2362 gesture_zoom->data = st;
2363 _zoom_test_reset(gesture_zoom);
2368 case EVAS_CALLBACK_KEY_UP:
2370 Evas_Event_Key_Up *p = event_info;
2371 if ((!strcmp(p->keyname, "Control_L")) ||
2372 (!strcmp(p->keyname, "Control_R")))
2373 { /* Test if we ended a zoom gesture when releasing CTRL */
2374 if ((st->zoom_wheel) &&
2375 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2376 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2377 { /* User released CTRL after zooming */
2378 ev_flag = _set_state(gesture_zoom,
2379 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2380 consume_event(wd, event_info, event_type, ev_flag);
2388 case EVAS_CALLBACK_MOUSE_WHEEL:
2391 Elm_Gesture_State s;
2392 if (!evas_key_modifier_is_set(
2393 ((Evas_Event_Mouse_Wheel *) event_info)->modifiers,
2395 { /* if using wheel witout CTRL after starting zoom */
2396 if ((st->zoom_wheel) &&
2397 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2398 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2400 ev_flag = _set_state(gesture_zoom,
2401 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2402 consume_event(wd, event_info, event_type, ev_flag);
2407 return; /* Ignore mouse-wheel without control */
2410 /* Using mouse wheel with CTRL for zoom */
2411 if (st->zoom_wheel || (st->zoom_distance_tolerance == 0))
2412 { /* when (zoom_wheel == NULL) and (zoom_distance_tolerance == 0)
2413 we continue a zoom gesture */
2415 s = ELM_GESTURE_STATE_MOVE;
2418 { /* On first wheel event, report START */
2419 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
2420 evas_object_evas_get(wd->target), "Control");
2422 s = ELM_GESTURE_STATE_START;
2423 if (!evas_object_key_grab(wd->target, "Control_L", mask, 0, EINA_FALSE))
2424 ERR("Failed to Grabbed CTRL_L");
2425 if (!evas_object_key_grab(wd->target, "Control_R", mask, 0, EINA_FALSE))
2426 ERR("Failed to Grabbed CTRL_R");
2429 st->zoom_distance_tolerance = 0; /* Cancel tolerance */
2430 st->zoom_wheel = (Evas_Event_Mouse_Wheel *) event_info;
2431 st->info.x = st->zoom_wheel->canvas.x;
2432 st->info.y = st->zoom_wheel->canvas.y;
2434 if (st->zoom_wheel->z < 0) /* zoom in */
2435 st->info.zoom += (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2437 if (st->zoom_wheel->z > 0) /* zoom out */
2438 st->info.zoom -= (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2440 if (st->info.zoom < 0.0)
2441 st->info.zoom = 0.0;
2443 ev_flag = _set_state(gesture_zoom, s, &st->info, force);
2444 consume_event(wd, event_info, event_type, ev_flag);
2456 * This function is used to test zoom gesture.
2457 * user may combine zoom, rotation together.
2458 * so its possible that both will be detected from input.
2459 * (both are two-finger movement-oriented gestures)
2461 * @param obj The gesture-layer object.
2462 * @param event_info Pointer to recent input event.
2463 * @param event_type Recent input event type.
2464 * @param g_type what Gesture we are testing.
2466 * @ingroup Elm_Gesture_Layer
2469 _zoom_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2470 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2474 Widget_Data *wd = elm_widget_data_get(obj);
2476 if (!wd->gesture[g_type]) return;
2478 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2479 Zoom_Type *st = gesture_zoom->data;
2482 { /* Allocated once on first time, used for zoom data */
2483 st = calloc(1, sizeof(Zoom_Type));
2484 gesture_zoom->data = st;
2485 _zoom_test_reset(gesture_zoom);
2489 /* Start - new zoom testing, letting all fingers start */
2490 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2493 case EVAS_CALLBACK_MOUSE_MOVE:
2494 case EVAS_CALLBACK_MULTI_MOVE:
2495 /* if non-continues mode and gesture NOT started, ignore MOVE */
2496 if ((!wd->glayer_continues_enable) &&
2497 (!st->zoom_st.timestamp))
2500 case EVAS_CALLBACK_MOUSE_DOWN:
2501 case EVAS_CALLBACK_MULTI_DOWN:
2502 { /* Here we take care of zoom-start and zoom move */
2506 if(eina_list_count(wd->touched) > 2)
2507 { /* Process zoom only when 2 fingers on surface */
2508 ev_flag = _set_state(gesture_zoom,
2509 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2510 consume_event(wd, event_info, event_type, ev_flag);
2515 if (!st->zoom_st.timestamp)
2516 { /* Now scan touched-devices list and find other finger */
2517 EINA_LIST_FOREACH(wd->touched, l, p)
2518 { /* Device of other finger <> pe device */
2519 if (p->device != pe->device)
2523 if (!p) /* Single finger on touch */
2526 /* Record down fingers */
2527 consume_event(wd, event_info, event_type, ev_flag);
2528 memcpy(&st->zoom_st, pe, sizeof(Pointer_Event));
2529 memcpy(&st->zoom_st1, p, sizeof(Pointer_Event));
2531 /* Set mv field as well to be ready for MOVE events */
2532 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2533 memcpy(&st->zoom_mv1, p, sizeof(Pointer_Event));
2535 /* Here we have zoom_st, zoom_st1 set, report START */
2536 /* Set zoom-base after BOTH down events recorded */
2537 /* Compute length of line between fingers zoom start */
2538 st->info.zoom = 1.0;
2539 st->zoom_base = get_finger_gap_length(st->zoom_st1.x,
2540 st->zoom_st1.y, st->zoom_st.x, st->zoom_st.y,
2541 &st->info.x, &st->info.y);
2543 st->info.radius = st->zoom_base / 2;
2545 if ((gesture_zoom->state != ELM_GESTURE_STATE_START) &&
2546 (gesture_zoom->state != ELM_GESTURE_STATE_MOVE))
2547 { /* zoom started with mouse-wheel, don't report twice */
2548 ev_flag = _set_state(gesture_zoom,
2549 ELM_GESTURE_STATE_START, &st->info, EINA_FALSE);
2550 consume_event(wd, event_info, event_type, ev_flag);
2553 return; /* Zoom started */
2554 } /* End of ZOOM_START handling */
2557 /* if we got here, we have (exacally) two fingers on surfce */
2558 /* we also after START, report MOVE */
2559 /* First detect which finger moved */
2560 if (pe->device == st->zoom_mv.device)
2561 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2562 else if (pe->device == st->zoom_mv1.device)
2563 memcpy(&st->zoom_mv1, pe, sizeof(Pointer_Event));
2565 /* Compute change in zoom as fingers move */
2566 st->info.zoom = compute_zoom(st,
2567 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2568 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2569 wd->zoom_finger_factor);
2571 if (!st->zoom_distance_tolerance)
2572 { /* Zoom broke tolerance, report move */
2573 double d = st->info.zoom - st->next_step;
2577 if (d >= wd->zoom_step)
2578 { /* Report move in steps */
2579 st->next_step = st->info.zoom;
2581 ev_flag = _set_state(gesture_zoom,
2582 ELM_GESTURE_STATE_MOVE,
2583 &st->info, EINA_TRUE);
2584 consume_event(wd, event_info, event_type, ev_flag);
2586 } /* End of ZOOM_MOVE handling */
2591 case EVAS_CALLBACK_MOUSE_UP:
2592 case EVAS_CALLBACK_MULTI_UP:
2593 /* Reset timestamp of finger-up.This is used later
2594 by _zoom_test_reset() to retain finger-down data */
2595 consume_event(wd, event_info, event_type, ev_flag);
2596 if (((st->zoom_wheel) || (st->zoom_base)) &&
2597 (st->zoom_distance_tolerance == 0))
2599 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
2600 &st->info, EINA_FALSE);
2601 consume_event(wd, event_info, event_type, ev_flag);
2606 /* if we got here not a ZOOM */
2607 if (gesture_zoom->state != ELM_GESTURE_STATE_UNDEFINED)
2608 { /* Must be != undefined, if gesture started */
2609 ev_flag = _set_state(gesture_zoom,
2610 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2611 consume_event(wd, event_info, event_type, ev_flag);
2614 _zoom_test_reset(gesture_zoom);
2624 _get_rotate_properties(Rotate_Type *st,
2625 Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2626 Evas_Coord x2, Evas_Coord y2, unsigned int tm2,
2629 st->info.radius = get_finger_gap_length(x1, y1, x2, y2,
2630 &st->info.x, &st->info.y) / 2;
2632 *angle = get_angle(x1, y1, x2, y2);
2633 #if 0 /* (NOT YET SUPPORTED) */
2634 if (angle == &st->info.angle)
2635 { /* Compute momentum: TODO: bug when breaking 0, 360 values */
2636 st->info.momentum = (((*angle) - st->info.base_angle) /
2637 (fabs(tm2 - tm1))) * 1000;
2640 st->info.momentum = 0;
2650 * This function is used to test rotation gesture.
2651 * user may combine zoom, rotation together.
2652 * so its possible that both will be detected from input.
2653 * (both are two-finger movement-oriented gestures)
2655 * @param obj The gesture-layer object.
2656 * @param event_info Pointer to recent input event.
2657 * @param event_type Recent input event type.
2658 * @param g_type what Gesture we are testing.
2660 * @ingroup Elm_Gesture_Layer
2663 _rotate_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2664 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2669 Widget_Data *wd = elm_widget_data_get(obj);
2671 if (!wd->gesture[g_type]) return;
2673 Gesture_Info *gesture = wd->gesture[g_type];
2674 Rotate_Type *st = gesture->data;
2679 { /* Allocated once on first time */
2680 st = calloc(1, sizeof(Rotate_Type));
2682 _rotate_test_reset(gesture);
2686 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2689 case EVAS_CALLBACK_MOUSE_MOVE:
2690 case EVAS_CALLBACK_MULTI_MOVE:
2691 /* if non-continues mode and gesture NOT started, ignore MOVE */
2692 if ((!wd->glayer_continues_enable) &&
2693 (!st->rotate_st.timestamp))
2696 case EVAS_CALLBACK_MOUSE_DOWN:
2697 case EVAS_CALLBACK_MULTI_DOWN:
2698 { /* Here we take care of rotate-start and rotate move */
2702 if(eina_list_count(wd->touched) > 2)
2703 { /* Process rotate only when 2 fingers on surface */
2704 ev_flag = _set_state(gesture,
2705 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2706 consume_event(wd, event_info, event_type, ev_flag);
2711 if (!st->rotate_st.timestamp)
2712 { /* Now scan touched-devices list and find other finger */
2713 EINA_LIST_FOREACH(wd->touched, l, p)
2714 { /* Device of other finger <> pe device */
2715 if (p->device != pe->device)
2720 return; /* Single finger on touch */
2722 /* Record down fingers */
2723 consume_event(wd, event_info, event_type, ev_flag);
2724 memcpy(&st->rotate_st, pe, sizeof(Pointer_Event));
2725 memcpy(&st->rotate_st1, p, sizeof(Pointer_Event));
2727 /* Set mv field as well to be ready for MOVE events */
2728 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2729 memcpy(&st->rotate_mv1, p, sizeof(Pointer_Event));
2731 /* Here we have rotate_st, rotate_st1 set, report START */
2732 /* Set rotate-base after BOTH down events recorded */
2733 /* Compute length of line between fingers rotate start */
2734 _get_rotate_properties(st,
2735 st->rotate_st.x, st->rotate_st.y,
2736 st->rotate_st.timestamp,
2737 st->rotate_st1.x, st->rotate_st1.y,
2738 st->rotate_st1.timestamp, &st->info.base_angle);
2740 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
2741 &st->info, EINA_FALSE);
2742 consume_event(wd, event_info, event_type, ev_flag);
2744 return; /* Rotate started */
2745 } /* End of ROTATE_START handling */
2748 /* if we got here, we have (exacally) two fingers on surfce */
2749 /* we also after START, report MOVE */
2750 /* First detect which finger moved */
2751 if (pe->device == st->rotate_mv.device)
2752 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2753 else if (pe->device == st->rotate_mv1.device)
2754 memcpy(&st->rotate_mv1, pe, sizeof(Pointer_Event));
2756 /* Compute change in rotate as fingers move */
2757 _get_rotate_properties(st,
2758 st->rotate_mv.x, st->rotate_mv.y,
2759 st->rotate_mv.timestamp,
2760 st->rotate_mv1.x, st->rotate_mv1.y,
2761 st->rotate_mv1.timestamp, &st->info.angle);
2763 if (rotation_broke_tolerance(st))
2764 { /* Rotation broke tolerance, report move */
2765 double d = st->info.angle - st->next_step;
2769 if (d >= wd->rotate_step)
2770 { /* Report move in steps */
2771 st->next_step = st->info.angle;
2773 ev_flag = _set_state(gesture,
2774 ELM_GESTURE_STATE_MOVE, &st->info, EINA_TRUE);
2775 consume_event(wd, event_info, event_type, ev_flag);
2777 } /* End of ROTATE_MOVE handling */
2782 case EVAS_CALLBACK_MOUSE_UP:
2783 case EVAS_CALLBACK_MULTI_UP:
2784 consume_event(wd, event_info, event_type, ev_flag);
2785 /* Reset timestamp of finger-up.This is used later
2786 by rotate_test_reset() to retain finger-down data */
2787 if (st->rotate_angular_tolerance < 0)
2789 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2790 &st->info, EINA_FALSE);
2791 consume_event(wd, event_info, event_type, ev_flag);
2796 if (gesture->state != ELM_GESTURE_STATE_UNDEFINED)
2797 { /* Must be != undefined, if gesture started */
2798 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2799 &st->info, EINA_FALSE);
2800 consume_event(wd, event_info, event_type, ev_flag);
2803 _rotate_test_reset(gesture);
2814 * This function is used to save input events in an abstract struct
2815 * to be used later by getsure-testing functions.
2817 * @param data The gesture-layer object.
2818 * @param event_info Pointer to recent input event.
2819 * @param event_type Recent input event type.
2820 * @param pe The abstract data-struct (output).
2822 * @ingroup Elm_Gesture_Layer
2825 _make_pointer_event(void *data, void *event_info,
2826 Evas_Callback_Type event_type, Pointer_Event *pe)
2828 Widget_Data *wd = elm_widget_data_get(data);
2829 if (!wd) return EINA_FALSE;
2833 case EVAS_CALLBACK_MOUSE_DOWN:
2834 pe->x = ((Evas_Event_Mouse_Down *) event_info)->canvas.x;
2835 pe->y = ((Evas_Event_Mouse_Down *) event_info)->canvas.y;
2836 pe->timestamp = ((Evas_Event_Mouse_Down *) event_info)->timestamp;
2837 pe->device = ELM_MOUSE_DEVICE;
2840 case EVAS_CALLBACK_MOUSE_UP:
2841 pe->x = ((Evas_Event_Mouse_Up *) event_info)->canvas.x;
2842 pe->y = ((Evas_Event_Mouse_Up *) event_info)->canvas.y;
2843 pe->timestamp = ((Evas_Event_Mouse_Up *) event_info)->timestamp;
2844 pe->device = ELM_MOUSE_DEVICE;
2847 case EVAS_CALLBACK_MOUSE_MOVE:
2848 pe->x = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.x;
2849 pe->y = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.y;
2850 pe->timestamp = ((Evas_Event_Mouse_Move *) event_info)->timestamp;
2851 pe->device = ELM_MOUSE_DEVICE;
2854 case EVAS_CALLBACK_MULTI_DOWN:
2855 pe->x = ((Evas_Event_Multi_Down *) event_info)->canvas.x;
2856 pe->y = ((Evas_Event_Multi_Down *) event_info)->canvas.y;
2857 pe->timestamp = ((Evas_Event_Multi_Down *) event_info)->timestamp;
2858 pe->device = ((Evas_Event_Multi_Down *) event_info)->device;
2861 case EVAS_CALLBACK_MULTI_UP:
2862 pe->x = ((Evas_Event_Multi_Up *) event_info)->canvas.x;
2863 pe->y = ((Evas_Event_Multi_Up *) event_info)->canvas.y;
2864 pe->timestamp = ((Evas_Event_Multi_Up *) event_info)->timestamp;
2865 pe->device = ((Evas_Event_Multi_Up *) event_info)->device;
2868 case EVAS_CALLBACK_MULTI_MOVE:
2869 pe->x = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.x;
2870 pe->y = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.y;
2871 pe->timestamp = ((Evas_Event_Multi_Move *) event_info)->timestamp;
2872 pe->device = ((Evas_Event_Multi_Move *) event_info)->device;
2879 pe->event_type = event_type;
2886 * This function restartes line, flick, zoom and rotate gestures
2887 * when gesture-layer continues-gestures enabled.
2888 * Example of continues-gesture:
2889 * When doing a line, user stops moving finger but keeps fingers on touch.
2890 * This will cause line-end, then as user continues moving his finger
2891 * it re-starts line gesture.
2892 * When continue mode is disabled, user has to lift finger from touch
2893 * to end a gesture. Them touch-again to start a new one.
2895 * @param data The gesture-layer object.
2896 * @param wd gesture layer widget data.
2897 * @param states_reset flag that marks gestures were reset in history clear.
2899 * @ingroup Elm_Gesture_Layer
2901 void continues_gestures_restart(void *data, Eina_Bool states_reset)
2903 Widget_Data *wd = elm_widget_data_get(data);
2906 /* Run through events to restart gestures */
2908 Eina_Bool n_lines, n_flicks, zoom, rotate;
2909 #if defined(DEBUG_GESTURE_LAYER)
2911 printf("Gesture | State | is tested\n");
2912 for(i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
2916 printf(" %d %d %d\n", i, g->state, g->test);
2919 /* We turn-on flag for finished, aborted, not-started gestures */
2920 g = wd->gesture[ELM_GESTURE_N_LINES];
2921 n_lines = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2922 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2925 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
2926 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2930 g = wd->gesture[ELM_GESTURE_N_FLICKS];
2931 n_flicks = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2932 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2935 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
2936 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2940 g = wd->gesture[ELM_GESTURE_ZOOM];
2941 zoom = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2942 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2945 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
2946 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2950 g = wd->gesture[ELM_GESTURE_ROTATE];
2951 rotate = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2952 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2955 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
2956 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2964 * This function the core-function where input handling is done.
2965 * Here we get user input and stream it to gesture testing.
2966 * We notify user about any gestures with new state:
2968 * START - gesture started.
2969 * MOVE - gesture is ongoing.
2970 * END - gesture was completed.
2971 * ABORT - gesture was aborted after START, MOVE (will NOT be completed)
2973 * We also check if a gesture was detected, then reset event history
2974 * If no gestures were found we reset gesture test flag
2975 * after streaming event-history to widget.
2976 * (stream to the widget all events not consumed as a gesture)
2978 * @param data The gesture-layer object.
2979 * @param event_info Pointer to recent input event.
2980 * @param event_type Recent input event type.
2982 * @ingroup Elm_Gesture_Layer
2985 _event_process(void *data, Evas_Object *obj __UNUSED__,
2986 void *event_info, Evas_Callback_Type event_type)
2989 Pointer_Event *pe = NULL;
2990 Widget_Data *wd = elm_widget_data_get(data);
2993 /* Start testing candidate gesture from here */
2994 if (_make_pointer_event(data, event_info, event_type, &_pe))
2997 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
2998 _n_long_tap_test(data, pe, event_info, event_type,
2999 ELM_GESTURE_N_LONG_TAPS);
3001 if (IS_TESTED(ELM_GESTURE_N_TAPS))
3002 _dbl_click_test(data, pe, event_info, event_type,
3003 ELM_GESTURE_N_TAPS, 1);
3005 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
3006 _dbl_click_test(data, pe, event_info, event_type,
3007 ELM_GESTURE_N_DOUBLE_TAPS, 2);
3009 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
3010 _dbl_click_test(data, pe, event_info, event_type,
3011 ELM_GESTURE_N_TRIPLE_TAPS, 3);
3013 if (IS_TESTED(ELM_GESTURE_MOMENTUM))
3014 _momentum_test(data, pe, event_info, event_type,
3015 ELM_GESTURE_MOMENTUM);
3017 if (IS_TESTED(ELM_GESTURE_N_LINES))
3018 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_LINES);
3020 if (IS_TESTED(ELM_GESTURE_N_FLICKS))
3021 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_FLICKS);
3023 if (IS_TESTED(ELM_GESTURE_ZOOM))
3024 _zoom_test(data, pe, event_info, event_type, ELM_GESTURE_ZOOM);
3026 if (IS_TESTED(ELM_GESTURE_ZOOM))
3027 _zoom_with_wheel_test(data, event_info, event_type, ELM_GESTURE_ZOOM);
3029 if (IS_TESTED(ELM_GESTURE_ROTATE))
3030 _rotate_test(data, pe, event_info, event_type, ELM_GESTURE_ROTATE);
3032 if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
3033 _event_history_add(data, event_info, event_type);
3034 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3035 (event_type == EVAS_CALLBACK_MULTI_UP))
3037 Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type);
3040 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD);
3041 _event_history_add(data, event_info, event_type);
3045 /* Log event to restart gestures */
3046 wd->recent_device_event = _add_recent_device_event(wd->recent_device_event, &_pe);
3048 /* we maintain list of touched devices */
3049 /* We also use move to track current device x.y pos */
3050 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
3051 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
3052 (event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
3053 (event_type == EVAS_CALLBACK_MULTI_MOVE))
3055 wd->touched = _add_touched_device(wd->touched, pe);
3057 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3058 (event_type == EVAS_CALLBACK_MULTI_UP))
3060 wd->touched = _remove_touched_device(wd->touched, pe);
3063 /* Report current states and clear history if needed */
3064 Eina_Bool states_reset = _clear_if_finished(data);
3065 if (wd->glayer_continues_enable)
3066 continues_gestures_restart(data, states_reset);
3071 * For all _mouse_* / multi_* functions wethen send this event to
3072 * _event_process function.
3074 * @param data The gesture-layer object.
3075 * @param event_info Pointer to recent input event.
3077 * @ingroup Elm_Gesture_Layer
3080 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3083 Widget_Data *wd = elm_widget_data_get(data);
3085 if (((Evas_Event_Mouse_Down *) event_info)->button != 1)
3086 return; /* We only process left-click at the moment */
3088 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_DOWN);
3092 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3095 Widget_Data *wd = elm_widget_data_get(data);
3098 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_MOVE);
3102 _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3105 Widget_Data *wd = elm_widget_data_get(data);
3108 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_DOWN);
3112 _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3115 Widget_Data *wd = elm_widget_data_get(data);
3118 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_UP);
3122 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3125 Widget_Data *wd = elm_widget_data_get(data);
3128 if (((Evas_Event_Mouse_Up *) event_info)->button != 1)
3129 return; /* We only process left-click at the moment */
3131 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_UP);
3135 _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3138 Widget_Data *wd = elm_widget_data_get(data);
3141 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_WHEEL);
3145 _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3148 Widget_Data *wd = elm_widget_data_get(data);
3151 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_DOWN);
3155 _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3158 Widget_Data *wd = elm_widget_data_get(data);
3161 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_MOVE);
3165 _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3168 Widget_Data *wd = elm_widget_data_get(data);
3171 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_UP);
3175 elm_gesture_layer_hold_events_get(Evas_Object *obj)
3177 Widget_Data *wd = elm_widget_data_get(obj);
3178 if (!wd) return EINA_FALSE;
3180 return !wd->repeat_events;
3184 elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool r)
3186 Widget_Data *wd = elm_widget_data_get(obj);
3189 wd->repeat_events = !r;
3193 elm_gesture_layer_zoom_step_set(Evas_Object *obj, double s)
3195 Widget_Data *wd = elm_widget_data_get(obj);
3205 elm_gesture_layer_rotate_step_set(Evas_Object *obj, double s)
3207 Widget_Data *wd = elm_widget_data_get(obj);
3213 wd->rotate_step = s;
3217 elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *t)
3219 Widget_Data *wd = elm_widget_data_get(obj);
3220 if (!wd) return EINA_FALSE;
3225 /* if was attached before, unregister callbacks first */
3227 _unregister_callbacks(obj);
3231 _register_callbacks(obj);
3236 elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Types idx,
3237 Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data)
3239 Widget_Data *wd = elm_widget_data_get(obj);
3243 if (!wd->gesture[idx])
3244 wd->gesture[idx] = calloc(1, sizeof(Gesture_Info));
3245 if (!wd->gesture[idx]) return;
3247 p = wd->gesture[idx];
3250 p->fn[cb_type].cb = cb;
3251 p->fn[cb_type].user_data = data;
3252 p->state = ELM_GESTURE_STATE_UNDEFINED;
3257 _disable_hook(Evas_Object *obj)
3259 if (elm_widget_disabled_get(obj))
3260 _unregister_callbacks(obj);
3262 _register_callbacks(obj);
3266 elm_gesture_layer_add(Evas_Object *parent)
3272 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
3274 wd = ELM_NEW(Widget_Data);
3275 e = evas_object_evas_get(parent);
3276 if (!e) return NULL;
3277 obj = elm_widget_add(e);
3278 ELM_SET_WIDTYPE(widtype, "gesture_layer");
3279 elm_widget_type_set(obj, "gesture_layer");
3280 elm_widget_sub_object_add(parent, obj);
3281 elm_widget_data_set(obj, wd);
3282 elm_widget_del_hook_set(obj, _del_hook);
3283 elm_widget_disable_hook_set(obj, _disable_hook);
3286 wd->line_min_length =_elm_config->glayer_line_min_length * elm_finger_size_get();
3287 wd->zoom_distance_tolerance = _elm_config->glayer_zoom_distance_tolerance * elm_finger_size_get();
3288 wd->line_distance_tolerance = _elm_config->glayer_line_distance_tolerance * elm_finger_size_get();
3289 wd->zoom_finger_factor = _elm_config->glayer_zoom_finger_factor;
3290 wd->zoom_wheel_factor = _elm_config->glayer_zoom_wheel_factor; /* mouse wheel zoom steps */
3291 wd->rotate_angular_tolerance = _elm_config->glayer_rotate_angular_tolerance;
3292 wd->line_angular_tolerance = _elm_config->glayer_line_angular_tolerance;
3293 wd->flick_time_limit_ms = _elm_config->glayer_flick_time_limit_ms;
3294 wd->long_tap_start_timeout = _elm_config->glayer_long_tap_start_timeout;
3295 wd->repeat_events = EINA_TRUE;
3296 wd->glayer_continues_enable = _elm_config->glayer_continues_enable;
3298 #if defined(DEBUG_GESTURE_LAYER)
3299 printf("size of Gestures = <%d>\n", sizeof(wd->gesture));
3300 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\twd->glayer_continues_enable=<%d>\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, wd->glayer_continues_enable);
3302 memset(wd->gesture, 0, sizeof(wd->gesture));