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 st->info.n = st->count_ups;
1331 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1332 &st->info, EINA_FALSE);
1333 consume_event(wd, event_info, event_type, ev_flag);
1340 case EVAS_CALLBACK_MULTI_MOVE:
1341 case EVAS_CALLBACK_MOUSE_MOVE:
1342 /* Get first event in first list, this has to be a Mouse Down event */
1343 /* and verify that user didn't move out of this area before next tap */
1344 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1347 pe_down = eina_list_data_get(pe_list);
1348 if (!_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1350 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1351 &st->info, EINA_FALSE);
1352 consume_event(wd, event_info, event_type, ev_flag);
1365 * This function computes center-point for long-tap gesture
1367 * @param st Long Tap gesture info pointer
1368 * @param pe The recent input event as stored in pe struct.
1370 * @ingroup Elm_Gesture_Layer
1373 _compute_taps_center(Long_Tap_Type *st, Pointer_Event *pe)
1375 if(!eina_list_count(st->touched))
1380 Evas_Coord x = 0, y = 0;
1381 EINA_LIST_FOREACH(st->touched, l, p)
1382 { /* Accumulate all then take avarage */
1383 if (p->device == pe->device)
1384 { /* This will take care of values coming from MOVE event */
1395 st->info.x = x / eina_list_count(st->touched);
1396 st->info.y = y / eina_list_count(st->touched);
1402 * This function checks N long-tap gesture.
1404 * @param obj The gesture-layer object.
1405 * @param pe The recent input event as stored in pe struct.
1406 * @param event_info Original input event pointer.
1407 * @param event_type Type of original input event.
1408 * @param g_type what Gesture we are testing.
1409 * @param taps How many click/taps we test for.
1411 * @ingroup Elm_Gesture_Layer
1414 _n_long_tap_test(Evas_Object *obj, Pointer_Event *pe,
1415 void *event_info, Evas_Callback_Type event_type,
1416 Elm_Gesture_Types g_type)
1417 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1418 Widget_Data *wd = elm_widget_data_get(obj);
1421 if (!pe) /* this happens when unhandled event arrived */
1422 return; /* see _make_pointer_event function */
1424 Gesture_Info *gesture = wd->gesture[g_type];
1425 if (!gesture ) return;
1427 Long_Tap_Type *st = gesture->data;
1429 { /* Allocated once on first time */
1430 st = calloc(1, sizeof(Long_Tap_Type));
1432 _n_long_tap_test_reset(gesture);
1435 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1436 switch (pe->event_type)
1438 case EVAS_CALLBACK_MULTI_DOWN:
1439 case EVAS_CALLBACK_MOUSE_DOWN:
1440 if (st->info.n > eina_list_count(st->touched))
1441 { /* ABORT: user lifts finger then back before completing gesgure */
1442 if (st->timeout) ecore_timer_del(st->timeout);
1444 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1445 &st->info, EINA_FALSE);
1448 st->touched = _add_touched_device(st->touched, pe);
1449 st->info.n = eina_list_count(st->touched);
1450 if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
1451 { /* This is the first mouse down we got */
1452 st->info.timestamp = pe->timestamp;
1454 /* To test long tap */
1455 /* When this timer expires, gesture STARTED */
1457 st->timeout = ecore_timer_add(wd->long_tap_start_timeout, _long_tap_timeout,
1461 consume_event(wd, event_info, event_type, ev_flag);
1462 _compute_taps_center(st, pe);
1465 case EVAS_CALLBACK_MULTI_UP:
1466 case EVAS_CALLBACK_MOUSE_UP:
1467 st->touched = _remove_touched_device(st->touched, pe);
1469 ((gesture->state == ELM_GESTURE_STATE_START) ||
1470 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1471 { /* Report END only for gesture that STARTed */
1472 if (eina_list_count(st->touched) == 0)
1473 { /* Report END only at last release event */
1474 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1475 &st->info, EINA_FALSE);
1476 consume_event(wd, event_info, event_type, ev_flag);
1481 case EVAS_CALLBACK_MULTI_MOVE:
1482 case EVAS_CALLBACK_MOUSE_MOVE:
1484 ((gesture->state == ELM_GESTURE_STATE_START) ||
1485 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1486 { /* Report MOVE only if STARTED */
1487 _compute_taps_center(st, pe);
1488 /* Report MOVE if gesture started */
1489 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
1490 &st->info, EINA_TRUE);
1491 consume_event(wd, event_info, event_type, ev_flag);
1503 * This function computes momentum for MOMENTUM, LINE and FLICK gestures
1504 * This momentum value will be sent to widget when gesture is completed.
1506 * @param momentum pointer to buffer where we record momentum value.
1507 * @param x1 x coord where user started gesture.
1508 * @param y1 y coord where user started gesture.
1509 * @param x2 x coord where user completed gesture.
1510 * @param y2 y coord where user completed gesture.
1511 * @param t1x timestamp for X, when user started gesture.
1512 * @param t1y timestamp for Y, when user started gesture.
1513 * @param t2 timestamp when user completed gesture.
1515 * @ingroup Elm_Gesture_Layer
1518 _set_momentum(Elm_Gesture_Momentum_Info *momentum, Evas_Coord x1, Evas_Coord y1,
1519 Evas_Coord x2, Evas_Coord y2, unsigned int t1x, unsigned int t1y,
1522 Evas_Coord velx = 0, vely = 0, vel;
1523 Evas_Coord dx = x2 - x1;
1524 Evas_Coord dy = y2 - y1;
1528 velx = (dx * 1000) / dtx;
1531 vely = (dy * 1000) / dty;
1533 vel = sqrt((velx * velx) + (vely * vely));
1535 if ((_elm_config->thumbscroll_friction > 0.0) &&
1536 (vel > _elm_config->thumbscroll_momentum_threshold))
1537 { /* report momentum */
1538 momentum->mx = velx;
1539 momentum->my = vely;
1551 * This function is used for computing rotation angle (DEG).
1553 * @param x1 first finger x location.
1554 * @param y1 first finger y location.
1555 * @param x2 second finger x location.
1556 * @param y2 second finger y location.
1558 * @return angle of the line between (x1,y1), (x2,y2) in Radians.
1560 * @ingroup Elm_Gesture_Layer
1563 get_angle(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
1569 if (((int) xx) && ((int) yy))
1576 return RAD_360DEG - a;
1587 return RAD_180DEG + a;
1591 return RAD_180DEG - a;
1597 { /* Horizontal line */
1622 * This function is used for computing the magnitude and direction
1623 * of vector between two points.
1625 * @param x1 first finger x location.
1626 * @param y1 first finger y location.
1627 * @param x2 second finger x location.
1628 * @param y2 second finger y location.
1629 * @param l length computed (output)
1630 * @param a angle computed (output)
1632 * @ingroup Elm_Gesture_Layer
1635 get_vector(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2,
1636 Evas_Coord *l, double *a)
1641 *l = (Evas_Coord) sqrt(xx*xx + yy*yy);
1642 *a = get_angle(x1, y1, x2, y2);
1646 _get_direction(Evas_Coord x1, Evas_Coord x2)
1658 * This function tests momentum gesture.
1659 * @param obj The gesture-layer object.
1660 * @param pe The recent input event as stored in pe struct.
1661 * @param event_info recent input event.
1662 * @param event_type recent event type.
1663 * @param g_type what Gesture we are testing.
1665 * @ingroup Elm_Gesture_Layer
1668 _momentum_test(Evas_Object *obj, Pointer_Event *pe,
1669 void *event_info, Evas_Callback_Type event_type,
1670 Elm_Gesture_Types g_type)
1672 Widget_Data *wd = elm_widget_data_get(obj);
1674 Gesture_Info *gesture = wd->gesture[g_type];
1675 if (!gesture ) return;
1677 Momentum_Type *st = gesture->data;
1678 Elm_Gesture_State state_to_report;
1680 { /* Allocated once on first time */
1681 st = calloc(1, sizeof(Momentum_Type));
1683 _momentum_test_reset(gesture);
1689 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1692 case EVAS_CALLBACK_MOUSE_DOWN:
1693 case EVAS_CALLBACK_MOUSE_MOVE:
1696 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1697 (wd->glayer_continues_enable)) /* start also on MOVE */
1698 { /* We start on MOVE when cont-enabled only */
1699 st->line_st.x = st->line_end.x = pe->x;
1700 st->line_st.y = st->line_end.y = pe->y;
1701 st->t_st_x = st->t_st_y = st->t_end = pe->timestamp;
1702 st->xdir = st->ydir = 0;
1703 st->info.x2 = st->info.x1 = pe->x;
1704 st->info.y2 = st->info.y1 = pe->y;
1705 st->info.tx = st->info.ty = pe->timestamp;
1706 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1707 &st->info, EINA_FALSE);
1708 consume_event(wd, event_info, event_type, ev_flag);
1715 state_to_report = ELM_GESTURE_STATE_MOVE;
1716 if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1717 { /* Too long of a wait, reset all values */
1718 st->line_st.x = pe->x;
1719 st->line_st.y = pe->y;
1720 st->t_st_y = st->t_st_x = pe->timestamp;
1721 st->info.tx = st->t_st_x;
1722 st->info.ty = st->t_st_y;
1723 st->xdir = st->ydir = 0;
1728 xdir = _get_direction(st->line_st.x, pe->x);
1729 ydir = _get_direction(st->line_st.y, pe->y);
1730 if (!xdir || (xdir == (-st->xdir)))
1732 st->line_st.x = st->line_end.x;
1733 st->info.tx = st->t_st_x = st->t_end;
1737 if (!ydir || (ydir == (-st->ydir)))
1739 st->line_st.y = st->line_end.y;
1740 st->info.ty = st->t_st_y = st->t_end;
1745 st->info.x2 = st->line_end.x = pe->x;
1746 st->info.y2 = st->line_end.y = pe->y;
1747 st->t_end = pe->timestamp;
1748 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
1749 st->t_st_x, st->t_st_y, pe->timestamp);
1750 ev_flag = _set_state(gesture, state_to_report, &st->info,
1752 consume_event(wd, event_info, event_type, ev_flag);
1756 case EVAS_CALLBACK_MOUSE_UP:
1757 /* IGNORE if line info was cleared, like long press, move */
1760 state_to_report = ELM_GESTURE_STATE_END;
1762 if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1763 { /* Too long of a wait, reset all values */
1764 st->line_st.x = pe->x;
1765 st->line_st.y = pe->y;
1766 st->t_st_y = st->t_st_x = pe->timestamp;
1767 st->xdir = st->ydir = 0;
1770 st->info.x2 = pe->x;
1771 st->info.y2 = pe->y;
1772 st->line_end.x = pe->x;
1773 st->line_end.y = pe->y;
1774 st->t_end = pe->timestamp;
1776 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
1777 st->t_st_x, st->t_st_y, pe->timestamp);
1779 ev_flag = _set_state(gesture, state_to_report, &st->info,
1781 consume_event(wd, event_info, event_type, ev_flag);
1785 case EVAS_CALLBACK_MULTI_UP:
1786 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
1788 consume_event(wd, event_info, event_type, ev_flag);
1797 compare_line_device(const void *data1, const void *data2)
1798 { /* Compare device component of line struct */
1799 const Line_Data *ln1 = data1;
1800 const int *device = data2;
1802 if (ln1->t_st) /* Compare only with lines that started */
1803 return (ln1->device - (*device));
1811 * This function construct line struct from input.
1812 * @param info pointer to store line momentum.
1813 * @param st line info to store input data.
1814 * @param pe The recent input event as stored in pe struct.
1816 * @ingroup Elm_Gesture_Layer
1819 _single_line_process(Elm_Gesture_Line_Info *info, Line_Data *st,
1820 Pointer_Event *pe, Evas_Callback_Type event_type)
1821 { /* Record events and set momentum for line pointed by st */
1827 case EVAS_CALLBACK_MOUSE_DOWN:
1828 case EVAS_CALLBACK_MOUSE_MOVE:
1829 case EVAS_CALLBACK_MULTI_DOWN:
1830 case EVAS_CALLBACK_MULTI_MOVE:
1832 { /* This happens only when line starts */
1833 st->line_st.x = pe->x;
1834 st->line_st.y = pe->y;
1835 st->t_st = pe->timestamp;
1836 st->device = pe->device;
1837 info->momentum.x1 = pe->x;
1838 info->momentum.y1 = pe->y;
1839 info->momentum.tx = pe->timestamp;
1840 info->momentum.ty = pe->timestamp;
1847 case EVAS_CALLBACK_MOUSE_UP:
1848 case EVAS_CALLBACK_MULTI_UP:
1849 /* IGNORE if line info was cleared, like long press, move */
1853 st->line_end.x = pe->x;
1854 st->line_end.y = pe->y;
1855 st->t_end = pe->timestamp;
1864 _line_data_reset(st);
1868 info->momentum.x2 = pe->x;
1869 info->momentum.y2 = pe->y;
1870 _set_momentum(&info->momentum, st->line_st.x, st->line_st.y, pe->x, pe->y,
1871 st->t_st, st->t_st, pe->timestamp);
1879 * This function test for (n) line gesture.
1880 * @param obj The gesture-layer object.
1881 * @param pe The recent input event as stored in pe struct.
1882 * @param event_info Original input event pointer.
1883 * @param event_type Type of original input event.
1884 * @param g_type what Gesture we are testing.
1886 * @ingroup Elm_Gesture_Layer
1889 _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
1890 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
1894 Widget_Data *wd = elm_widget_data_get(obj);
1896 Gesture_Info *gesture = wd->gesture[g_type];
1897 if (!gesture ) return;
1899 Line_Type *st = gesture->data;
1902 st = calloc(1, sizeof(Line_Type));
1906 Line_Data *line = NULL;
1907 Eina_List *list = st->list;
1908 unsigned cnt = eina_list_count(list);
1911 { /* list is not empty, locate this device on list */
1912 line = (Line_Data *) eina_list_search_unsorted(st->list,
1913 compare_line_device, &pe->device);
1917 { /* List is empty or device not found, new line-struct on START only */
1918 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1919 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
1920 ((wd->glayer_continues_enable) && /* START on MOVE also */
1921 ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
1922 (event_type == EVAS_CALLBACK_MULTI_MOVE))))
1923 { /* Allocate new item on START only */
1924 line = calloc(1, sizeof(Line_Data));
1925 _line_data_reset(line);
1926 list = eina_list_append(list, line);
1931 if (!line) /* This may happen on MOVE that comes before DOWN */
1932 return; /* No line-struct to work with, can't continue testing */
1934 if (_single_line_process(&st->info, line, pe, event_type)) /* update st with input */
1935 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1937 /* Get direction and magnitude of the line */
1939 get_vector(line->line_st.x, line->line_st.y, pe->x, pe->y,
1940 &line->line_length, &angle);
1942 /* These are used later to compare lines length */
1943 Evas_Coord shortest_line_len = line->line_length;
1944 Evas_Coord longest_line_len = line->line_length;
1945 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1947 /* Now update line-state */
1949 { /* Analyze line only if line started */
1950 if (line->line_angle >= 0.0)
1951 { /* if line direction was set, we test if broke tolerance */
1952 double a = fabs(angle - line->line_angle);
1954 double d = (tan(a)) * line->line_length; /* Distance from line */
1955 #if defined(DEBUG_GESTURE_LAYER)
1956 printf("%s a=<%f> d=<%f>\n", __func__, (a * 57.295779513), d);
1958 if ((d > wd->line_distance_tolerance) || (a > wd->line_angular_tolerance))
1959 { /* Broke tolerance: abort line and start a new one */
1960 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1961 &st->info, EINA_FALSE);
1962 consume_event(wd, event_info, event_type, ev_flag);
1966 if (wd->glayer_continues_enable)
1967 { /* We may finish line if momentum is zero */
1968 /* This is for continues-gesture */
1969 if ((!st->info.momentum.mx) && (!st->info.momentum.my))
1970 { /* Finish line on zero momentum for continues gesture */
1971 line->line_end.x = pe->x;
1972 line->line_end.y = pe->y;
1973 line->t_end = pe->timestamp;
1978 { /* Record the line angle as it broke minimum length for line */
1979 if (line->line_length >= wd->line_min_length)
1980 st->info.angle = line->line_angle = angle;
1986 if (line->line_angle < 0.0)
1987 { /* it's not a line, too short more close to a tap */
1988 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1989 &st->info, EINA_FALSE);
1990 consume_event(wd, event_info, event_type, ev_flag);
1996 /* Count how many lines already started / ended */
1999 unsigned int tm_start = pe->timestamp;
2000 unsigned int tm_end = pe->timestamp;
2003 double base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
2004 Eina_Bool lines_parallel = EINA_TRUE;
2005 EINA_LIST_FOREACH(list, l, t_line)
2008 base_angle = t_line->line_angle;
2011 if (t_line->line_angle >= 0)
2012 { /* Compare angle only with lines with direction defined */
2013 if (fabs(base_angle - t_line->line_angle) >
2014 wd->line_angular_tolerance)
2015 lines_parallel = EINA_FALSE;
2019 if (t_line->line_length)
2020 { /* update only if this line is used */
2021 if (shortest_line_len > t_line->line_length)
2022 shortest_line_len = t_line->line_length;
2024 if (longest_line_len < t_line->line_length)
2025 longest_line_len = t_line->line_length;
2031 if (t_line->t_st < tm_start)
2032 tm_start = t_line->t_st;
2038 if (t_line->t_end < tm_end)
2039 tm_end = t_line->t_end;
2043 st->info.n = started;
2047 ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2048 (event_type == EVAS_CALLBACK_MULTI_DOWN)))
2049 { /* user lift one finger then starts again without line-end - ABORT */
2050 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2052 consume_event(wd, event_info, event_type, ev_flag);
2056 if (!lines_parallel)
2057 { /* Lines are NOT at same direction, abort this gesture */
2058 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2060 consume_event(wd, event_info, event_type, ev_flag);
2065 /* We report ABORT if lines length are NOT matching when fingers are up */
2066 if ((longest_line_len - shortest_line_len) > (elm_finger_size_get()*2))
2068 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2070 consume_event(wd, event_info, event_type, ev_flag);
2074 if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > wd->flick_time_limit_ms))
2075 { /* We consider FLICK as a fast line.ABORT if take too long to finish */
2076 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2078 consume_event(wd, event_info, event_type, ev_flag);
2084 case EVAS_CALLBACK_MOUSE_UP:
2085 case EVAS_CALLBACK_MULTI_UP:
2086 if ((started) && (started == ended))
2088 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2089 &st->info, EINA_FALSE);
2090 consume_event(wd, event_info, event_type, ev_flag);
2095 case EVAS_CALLBACK_MOUSE_DOWN:
2096 case EVAS_CALLBACK_MULTI_DOWN:
2097 case EVAS_CALLBACK_MOUSE_MOVE:
2098 case EVAS_CALLBACK_MULTI_MOVE:
2101 if (wd->glayer_continues_enable && (started == ended))
2102 { /* For continues gesture */
2103 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2104 &st->info, EINA_FALSE);
2105 consume_event(wd, event_info, event_type, ev_flag);
2108 { /* When continues, may START on MOVE event too */
2109 Elm_Gesture_State s = ELM_GESTURE_STATE_MOVE;
2111 /* This happens when: on n > 1 lines then one finger up */
2112 /* caused abort, then put finger down. */
2113 /* This will stop line from starting again. */
2114 /* Number of lines, MUST match touched-device in list */
2115 if ((!wd->glayer_continues_enable) &&
2116 (eina_list_count(st->list) < eina_list_count(wd->touched)))
2117 s = ELM_GESTURE_STATE_ABORT;
2119 if (gesture->state == ELM_GESTURE_STATE_UNDEFINED)
2120 s = ELM_GESTURE_STATE_START;
2122 ev_flag = _set_state(gesture, s, &st->info, EINA_TRUE);
2123 consume_event(wd, event_info, event_type, ev_flag);
2129 return; /* Unhandeld event type */
2136 * This function is used to check if rotation gesture started.
2137 * @param st Contains current rotation values from user input.
2138 * @return TRUE/FALSE if we need to set rotation START.
2140 * @ingroup Elm_Gesture_Layer
2143 rotation_broke_tolerance(Rotate_Type *st)
2145 if (st->info.base_angle < 0)
2146 return EINA_FALSE; /* Angle has to be computed first */
2148 if (st->rotate_angular_tolerance < 0)
2151 double low = st->info.base_angle - st->rotate_angular_tolerance;
2152 double high = st->info.base_angle + st->rotate_angular_tolerance;
2153 double t = st->info.angle;
2166 if (high > RAD_360DEG)
2177 #if defined(DEBUG_GESTURE_LAYER)
2178 printf("%s angle=<%f> low=<%f> high=<%f>\n", __func__, t, low, high);
2180 if ((t < low) || (t > high))
2181 { /* This marks that roation action has started */
2182 st->rotate_angular_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
2183 st->info.base_angle = st->info.angle; /* Avoid jump in angle value */
2193 * This function is used for computing the gap between fingers.
2194 * It returns the length and center point between fingers.
2196 * @param x1 first finger x location.
2197 * @param y1 first finger y location.
2198 * @param x2 second finger x location.
2199 * @param y2 second finger y location.
2200 * @param x Gets center point x cord (output)
2201 * @param y Gets center point y cord (output)
2203 * @return length of the line between (x1,y1), (x2,y2) in pixels.
2205 * @ingroup Elm_Gesture_Layer
2208 get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
2209 Evas_Coord y2, Evas_Coord *x, Evas_Coord *y)
2211 double a, b, xx, yy, gap;
2214 gap = sqrt(xx*xx + yy*yy);
2216 /* START - Compute zoom center point */
2217 /* The triangle defined as follows:
2225 * http://en.wikipedia.org/wiki/Trigonometric_functions
2226 *************************************/
2227 if (((int) xx) && ((int) yy))
2229 double A = atan((yy / xx));
2230 #if defined(DEBUG_GESTURE_LAYER)
2231 printf("xx=<%f> yy=<%f> A=<%f>\n", xx, yy, A);
2233 a = (Evas_Coord) ((gap / 2) * sin(A));
2234 b = (Evas_Coord) ((gap / 2) * cos(A));
2235 *x = (Evas_Coord) ((x2 > x1) ? (x1 + b) : (x2 + b));
2236 *y = (Evas_Coord) ((y2 > y1) ? (y1 + a) : (y2 + a));
2241 { /* horiz line, take half width */
2242 #if defined(DEBUG_GESTURE_LAYER)
2243 printf("==== HORIZ ====\n");
2245 *x = (Evas_Coord) (xx / 2);
2246 *y = (Evas_Coord) (y1);
2250 { /* vert line, take half width */
2251 #if defined(DEBUG_GESTURE_LAYER)
2252 printf("==== VERT ====\n");
2254 *x = (Evas_Coord) (x1);
2255 *y = (Evas_Coord) (yy / 2);
2258 /* END - Compute zoom center point */
2260 return (Evas_Coord) gap;
2266 * This function is used for computing zoom value.
2268 * @param st Pointer to zoom data based on user input.
2269 * @param x1 first finger x location.
2270 * @param y1 first finger y location.
2271 * @param x2 second finger x location.
2272 * @param y2 second finger y location.
2273 * @param factor zoom-factor, used to determine how fast zoom works.
2275 * @return zoom value, when 1.0 means no zoom, 0.5 half size...
2277 * @ingroup Elm_Gesture_Layer
2279 /* FIXME change float to double */
2281 compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2282 Evas_Coord x2, Evas_Coord y2, unsigned int tm2, double zoom_finger_factor)
2285 Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
2286 &st->info.x, &st->info.y);
2288 st->info.radius = diam / 2;
2292 st->zoom_base = diam;
2293 return st->info.zoom;
2296 if (st->zoom_distance_tolerance)
2297 { /* zoom tolerance <> ZERO, means zoom action NOT started yet */
2298 if (diam < (st->zoom_base - st->zoom_distance_tolerance))
2299 { /* avoid jump with zoom value when break tolerance */
2300 st->zoom_base -= st->zoom_distance_tolerance;
2301 st->zoom_distance_tolerance = 0;
2304 if (diam > (st->zoom_base + st->zoom_distance_tolerance))
2305 { /* avoid jump with zoom value when break tolerance */
2306 st->zoom_base += st->zoom_distance_tolerance;
2307 st->zoom_distance_tolerance = 0;
2313 /* We use factor only on the difference between gap-base */
2314 /* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
2315 rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
2316 (float) st->zoom_base) * zoom_finger_factor));
2319 /* Momentum: zoom per second: (NOT YET SUPPORTED) */
2320 st->info.momentum = (((rt - 1.0) * 1000) / (tm2 - tm1));
2331 * This function handles zoom with mouse wheel.
2332 * thats a combination of wheel + CTRL key.
2333 * @param obj The gesture-layer object.
2334 * @param event_info Original input event pointer.
2335 * @param event_type Type of original input event.
2336 * @param g_type what Gesture we are testing.
2338 * @ingroup Elm_Gesture_Layer
2341 _zoom_with_wheel_test(Evas_Object *obj, void *event_info,
2342 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2344 Widget_Data *wd = elm_widget_data_get(obj);
2346 if (!wd->gesture[g_type]) return;
2348 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2349 Zoom_Type *st = gesture_zoom->data;
2350 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2352 { /* Allocated once on first time, used for zoom intermediate data */
2353 st = calloc(1, sizeof(Zoom_Type));
2354 gesture_zoom->data = st;
2355 _zoom_test_reset(gesture_zoom);
2360 case EVAS_CALLBACK_KEY_UP:
2362 Evas_Event_Key_Up *p = event_info;
2363 if ((!strcmp(p->keyname, "Control_L")) ||
2364 (!strcmp(p->keyname, "Control_R")))
2365 { /* Test if we ended a zoom gesture when releasing CTRL */
2366 if ((st->zoom_wheel) &&
2367 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2368 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2369 { /* User released CTRL after zooming */
2370 ev_flag = _set_state(gesture_zoom,
2371 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2372 consume_event(wd, event_info, event_type, ev_flag);
2380 case EVAS_CALLBACK_MOUSE_WHEEL:
2383 Elm_Gesture_State s;
2384 if (!evas_key_modifier_is_set(
2385 ((Evas_Event_Mouse_Wheel *) event_info)->modifiers,
2387 { /* if using wheel witout CTRL after starting zoom */
2388 if ((st->zoom_wheel) &&
2389 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2390 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2392 ev_flag = _set_state(gesture_zoom,
2393 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2394 consume_event(wd, event_info, event_type, ev_flag);
2399 return; /* Ignore mouse-wheel without control */
2402 /* Using mouse wheel with CTRL for zoom */
2403 if (st->zoom_wheel || (st->zoom_distance_tolerance == 0))
2404 { /* when (zoom_wheel == NULL) and (zoom_distance_tolerance == 0)
2405 we continue a zoom gesture */
2407 s = ELM_GESTURE_STATE_MOVE;
2410 { /* On first wheel event, report START */
2411 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
2412 evas_object_evas_get(wd->target), "Control");
2414 s = ELM_GESTURE_STATE_START;
2415 if (!evas_object_key_grab(wd->target, "Control_L", mask, 0, EINA_FALSE))
2416 ERR("Failed to Grabbed CTRL_L");
2417 if (!evas_object_key_grab(wd->target, "Control_R", mask, 0, EINA_FALSE))
2418 ERR("Failed to Grabbed CTRL_R");
2421 st->zoom_distance_tolerance = 0; /* Cancel tolerance */
2422 st->zoom_wheel = (Evas_Event_Mouse_Wheel *) event_info;
2423 st->info.x = st->zoom_wheel->canvas.x;
2424 st->info.y = st->zoom_wheel->canvas.y;
2426 if (st->zoom_wheel->z < 0) /* zoom in */
2427 st->info.zoom += (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2429 if (st->zoom_wheel->z > 0) /* zoom out */
2430 st->info.zoom -= (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2432 if (st->info.zoom < 0.0)
2433 st->info.zoom = 0.0;
2435 ev_flag = _set_state(gesture_zoom, s, &st->info, force);
2436 consume_event(wd, event_info, event_type, ev_flag);
2448 * This function is used to test zoom gesture.
2449 * user may combine zoom, rotation together.
2450 * so its possible that both will be detected from input.
2451 * (both are two-finger movement-oriented gestures)
2453 * @param obj The gesture-layer object.
2454 * @param event_info Pointer to recent input event.
2455 * @param event_type Recent input event type.
2456 * @param g_type what Gesture we are testing.
2458 * @ingroup Elm_Gesture_Layer
2461 _zoom_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2462 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2466 Widget_Data *wd = elm_widget_data_get(obj);
2468 if (!wd->gesture[g_type]) return;
2470 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2471 Zoom_Type *st = gesture_zoom->data;
2474 { /* Allocated once on first time, used for zoom data */
2475 st = calloc(1, sizeof(Zoom_Type));
2476 gesture_zoom->data = st;
2477 _zoom_test_reset(gesture_zoom);
2481 /* Start - new zoom testing, letting all fingers start */
2482 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2485 case EVAS_CALLBACK_MOUSE_MOVE:
2486 case EVAS_CALLBACK_MULTI_MOVE:
2487 /* if non-continues mode and gesture NOT started, ignore MOVE */
2488 if ((!wd->glayer_continues_enable) &&
2489 (!st->zoom_st.timestamp))
2492 case EVAS_CALLBACK_MOUSE_DOWN:
2493 case EVAS_CALLBACK_MULTI_DOWN:
2494 { /* Here we take care of zoom-start and zoom move */
2498 if(eina_list_count(wd->touched) > 2)
2499 { /* Process zoom only when 2 fingers on surface */
2500 ev_flag = _set_state(gesture_zoom,
2501 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2502 consume_event(wd, event_info, event_type, ev_flag);
2507 if (!st->zoom_st.timestamp)
2508 { /* Now scan touched-devices list and find other finger */
2509 EINA_LIST_FOREACH(wd->touched, l, p)
2510 { /* Device of other finger <> pe device */
2511 if (p->device != pe->device)
2515 if (!p) /* Single finger on touch */
2518 /* Record down fingers */
2519 consume_event(wd, event_info, event_type, ev_flag);
2520 memcpy(&st->zoom_st, pe, sizeof(Pointer_Event));
2521 memcpy(&st->zoom_st1, p, sizeof(Pointer_Event));
2523 /* Set mv field as well to be ready for MOVE events */
2524 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2525 memcpy(&st->zoom_mv1, p, sizeof(Pointer_Event));
2527 /* Here we have zoom_st, zoom_st1 set, report START */
2528 /* Set zoom-base after BOTH down events recorded */
2529 /* Compute length of line between fingers zoom start */
2530 st->info.zoom = 1.0;
2531 st->zoom_base = get_finger_gap_length(st->zoom_st1.x,
2532 st->zoom_st1.y, st->zoom_st.x, st->zoom_st.y,
2533 &st->info.x, &st->info.y);
2535 st->info.radius = st->zoom_base / 2;
2537 if ((gesture_zoom->state != ELM_GESTURE_STATE_START) &&
2538 (gesture_zoom->state != ELM_GESTURE_STATE_MOVE))
2539 { /* zoom started with mouse-wheel, don't report twice */
2540 ev_flag = _set_state(gesture_zoom,
2541 ELM_GESTURE_STATE_START, &st->info, EINA_FALSE);
2542 consume_event(wd, event_info, event_type, ev_flag);
2545 return; /* Zoom started */
2546 } /* End of ZOOM_START handling */
2549 /* if we got here, we have (exacally) two fingers on surfce */
2550 /* we also after START, report MOVE */
2551 /* First detect which finger moved */
2552 if (pe->device == st->zoom_mv.device)
2553 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2554 else if (pe->device == st->zoom_mv1.device)
2555 memcpy(&st->zoom_mv1, pe, sizeof(Pointer_Event));
2557 /* Compute change in zoom as fingers move */
2558 st->info.zoom = compute_zoom(st,
2559 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2560 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2561 wd->zoom_finger_factor);
2563 if (!st->zoom_distance_tolerance)
2564 { /* Zoom broke tolerance, report move */
2565 double d = st->info.zoom - st->next_step;
2569 if (d >= wd->zoom_step)
2570 { /* Report move in steps */
2571 st->next_step = st->info.zoom;
2573 ev_flag = _set_state(gesture_zoom,
2574 ELM_GESTURE_STATE_MOVE,
2575 &st->info, EINA_TRUE);
2576 consume_event(wd, event_info, event_type, ev_flag);
2578 } /* End of ZOOM_MOVE handling */
2583 case EVAS_CALLBACK_MOUSE_UP:
2584 case EVAS_CALLBACK_MULTI_UP:
2585 /* Reset timestamp of finger-up.This is used later
2586 by _zoom_test_reset() to retain finger-down data */
2587 consume_event(wd, event_info, event_type, ev_flag);
2588 if (((st->zoom_wheel) || (st->zoom_base)) &&
2589 (st->zoom_distance_tolerance == 0))
2591 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
2592 &st->info, EINA_FALSE);
2593 consume_event(wd, event_info, event_type, ev_flag);
2598 /* if we got here not a ZOOM */
2599 if (gesture_zoom->state != ELM_GESTURE_STATE_UNDEFINED)
2600 { /* Must be != undefined, if gesture started */
2601 ev_flag = _set_state(gesture_zoom,
2602 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2603 consume_event(wd, event_info, event_type, ev_flag);
2606 _zoom_test_reset(gesture_zoom);
2616 _get_rotate_properties(Rotate_Type *st,
2617 Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2618 Evas_Coord x2, Evas_Coord y2, unsigned int tm2,
2621 st->info.radius = get_finger_gap_length(x1, y1, x2, y2,
2622 &st->info.x, &st->info.y) / 2;
2624 *angle = get_angle(x1, y1, x2, y2);
2625 #if 0 /* (NOT YET SUPPORTED) */
2626 if (angle == &st->info.angle)
2627 { /* Compute momentum: TODO: bug when breaking 0, 360 values */
2628 st->info.momentum = (((*angle) - st->info.base_angle) /
2629 (fabs(tm2 - tm1))) * 1000;
2632 st->info.momentum = 0;
2642 * This function is used to test rotation gesture.
2643 * user may combine zoom, rotation together.
2644 * so its possible that both will be detected from input.
2645 * (both are two-finger movement-oriented gestures)
2647 * @param obj The gesture-layer object.
2648 * @param event_info Pointer to recent input event.
2649 * @param event_type Recent input event type.
2650 * @param g_type what Gesture we are testing.
2652 * @ingroup Elm_Gesture_Layer
2655 _rotate_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2656 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2661 Widget_Data *wd = elm_widget_data_get(obj);
2663 if (!wd->gesture[g_type]) return;
2665 Gesture_Info *gesture = wd->gesture[g_type];
2666 Rotate_Type *st = gesture->data;
2671 { /* Allocated once on first time */
2672 st = calloc(1, sizeof(Rotate_Type));
2674 _rotate_test_reset(gesture);
2678 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2681 case EVAS_CALLBACK_MOUSE_MOVE:
2682 case EVAS_CALLBACK_MULTI_MOVE:
2683 /* if non-continues mode and gesture NOT started, ignore MOVE */
2684 if ((!wd->glayer_continues_enable) &&
2685 (!st->rotate_st.timestamp))
2688 case EVAS_CALLBACK_MOUSE_DOWN:
2689 case EVAS_CALLBACK_MULTI_DOWN:
2690 { /* Here we take care of rotate-start and rotate move */
2694 if(eina_list_count(wd->touched) > 2)
2695 { /* Process rotate only when 2 fingers on surface */
2696 ev_flag = _set_state(gesture,
2697 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2698 consume_event(wd, event_info, event_type, ev_flag);
2703 if (!st->rotate_st.timestamp)
2704 { /* Now scan touched-devices list and find other finger */
2705 EINA_LIST_FOREACH(wd->touched, l, p)
2706 { /* Device of other finger <> pe device */
2707 if (p->device != pe->device)
2712 return; /* Single finger on touch */
2714 /* Record down fingers */
2715 consume_event(wd, event_info, event_type, ev_flag);
2716 memcpy(&st->rotate_st, pe, sizeof(Pointer_Event));
2717 memcpy(&st->rotate_st1, p, sizeof(Pointer_Event));
2719 /* Set mv field as well to be ready for MOVE events */
2720 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2721 memcpy(&st->rotate_mv1, p, sizeof(Pointer_Event));
2723 /* Here we have rotate_st, rotate_st1 set, report START */
2724 /* Set rotate-base after BOTH down events recorded */
2725 /* Compute length of line between fingers rotate start */
2726 _get_rotate_properties(st,
2727 st->rotate_st.x, st->rotate_st.y,
2728 st->rotate_st.timestamp,
2729 st->rotate_st1.x, st->rotate_st1.y,
2730 st->rotate_st1.timestamp, &st->info.base_angle);
2732 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
2733 &st->info, EINA_FALSE);
2734 consume_event(wd, event_info, event_type, ev_flag);
2736 return; /* Rotate started */
2737 } /* End of ROTATE_START handling */
2740 /* if we got here, we have (exacally) two fingers on surfce */
2741 /* we also after START, report MOVE */
2742 /* First detect which finger moved */
2743 if (pe->device == st->rotate_mv.device)
2744 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2745 else if (pe->device == st->rotate_mv1.device)
2746 memcpy(&st->rotate_mv1, pe, sizeof(Pointer_Event));
2748 /* Compute change in rotate as fingers move */
2749 _get_rotate_properties(st,
2750 st->rotate_mv.x, st->rotate_mv.y,
2751 st->rotate_mv.timestamp,
2752 st->rotate_mv1.x, st->rotate_mv1.y,
2753 st->rotate_mv1.timestamp, &st->info.angle);
2755 if (rotation_broke_tolerance(st))
2756 { /* Rotation broke tolerance, report move */
2757 double d = st->info.angle - st->next_step;
2761 if (d >= wd->rotate_step)
2762 { /* Report move in steps */
2763 st->next_step = st->info.angle;
2765 ev_flag = _set_state(gesture,
2766 ELM_GESTURE_STATE_MOVE, &st->info, EINA_TRUE);
2767 consume_event(wd, event_info, event_type, ev_flag);
2769 } /* End of ROTATE_MOVE handling */
2774 case EVAS_CALLBACK_MOUSE_UP:
2775 case EVAS_CALLBACK_MULTI_UP:
2776 consume_event(wd, event_info, event_type, ev_flag);
2777 /* Reset timestamp of finger-up.This is used later
2778 by rotate_test_reset() to retain finger-down data */
2779 if (st->rotate_angular_tolerance < 0)
2781 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2782 &st->info, EINA_FALSE);
2783 consume_event(wd, event_info, event_type, ev_flag);
2788 if (gesture->state != ELM_GESTURE_STATE_UNDEFINED)
2789 { /* Must be != undefined, if gesture started */
2790 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2791 &st->info, EINA_FALSE);
2792 consume_event(wd, event_info, event_type, ev_flag);
2795 _rotate_test_reset(gesture);
2806 * This function is used to save input events in an abstract struct
2807 * to be used later by getsure-testing functions.
2809 * @param data The gesture-layer object.
2810 * @param event_info Pointer to recent input event.
2811 * @param event_type Recent input event type.
2812 * @param pe The abstract data-struct (output).
2814 * @ingroup Elm_Gesture_Layer
2817 _make_pointer_event(void *data, void *event_info,
2818 Evas_Callback_Type event_type, Pointer_Event *pe)
2820 Widget_Data *wd = elm_widget_data_get(data);
2821 if (!wd) return EINA_FALSE;
2825 case EVAS_CALLBACK_MOUSE_DOWN:
2826 pe->x = ((Evas_Event_Mouse_Down *) event_info)->canvas.x;
2827 pe->y = ((Evas_Event_Mouse_Down *) event_info)->canvas.y;
2828 pe->timestamp = ((Evas_Event_Mouse_Down *) event_info)->timestamp;
2829 pe->device = ELM_MOUSE_DEVICE;
2832 case EVAS_CALLBACK_MOUSE_UP:
2833 pe->x = ((Evas_Event_Mouse_Up *) event_info)->canvas.x;
2834 pe->y = ((Evas_Event_Mouse_Up *) event_info)->canvas.y;
2835 pe->timestamp = ((Evas_Event_Mouse_Up *) event_info)->timestamp;
2836 pe->device = ELM_MOUSE_DEVICE;
2839 case EVAS_CALLBACK_MOUSE_MOVE:
2840 pe->x = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.x;
2841 pe->y = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.y;
2842 pe->timestamp = ((Evas_Event_Mouse_Move *) event_info)->timestamp;
2843 pe->device = ELM_MOUSE_DEVICE;
2846 case EVAS_CALLBACK_MULTI_DOWN:
2847 pe->x = ((Evas_Event_Multi_Down *) event_info)->canvas.x;
2848 pe->y = ((Evas_Event_Multi_Down *) event_info)->canvas.y;
2849 pe->timestamp = ((Evas_Event_Multi_Down *) event_info)->timestamp;
2850 pe->device = ((Evas_Event_Multi_Down *) event_info)->device;
2853 case EVAS_CALLBACK_MULTI_UP:
2854 pe->x = ((Evas_Event_Multi_Up *) event_info)->canvas.x;
2855 pe->y = ((Evas_Event_Multi_Up *) event_info)->canvas.y;
2856 pe->timestamp = ((Evas_Event_Multi_Up *) event_info)->timestamp;
2857 pe->device = ((Evas_Event_Multi_Up *) event_info)->device;
2860 case EVAS_CALLBACK_MULTI_MOVE:
2861 pe->x = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.x;
2862 pe->y = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.y;
2863 pe->timestamp = ((Evas_Event_Multi_Move *) event_info)->timestamp;
2864 pe->device = ((Evas_Event_Multi_Move *) event_info)->device;
2871 pe->event_type = event_type;
2878 * This function restartes line, flick, zoom and rotate gestures
2879 * when gesture-layer continues-gestures enabled.
2880 * Example of continues-gesture:
2881 * When doing a line, user stops moving finger but keeps fingers on touch.
2882 * This will cause line-end, then as user continues moving his finger
2883 * it re-starts line gesture.
2884 * When continue mode is disabled, user has to lift finger from touch
2885 * to end a gesture. Them touch-again to start a new one.
2887 * @param data The gesture-layer object.
2888 * @param wd gesture layer widget data.
2889 * @param states_reset flag that marks gestures were reset in history clear.
2891 * @ingroup Elm_Gesture_Layer
2893 void continues_gestures_restart(void *data, Eina_Bool states_reset)
2895 Widget_Data *wd = elm_widget_data_get(data);
2898 /* Run through events to restart gestures */
2900 Eina_Bool n_lines, n_flicks, zoom, rotate;
2901 #if defined(DEBUG_GESTURE_LAYER)
2903 printf("Gesture | State | is tested\n");
2904 for(i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
2908 printf(" %d %d %d\n", i, g->state, g->test);
2911 /* We turn-on flag for finished, aborted, not-started gestures */
2912 g = wd->gesture[ELM_GESTURE_N_LINES];
2913 n_lines = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2914 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2917 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
2918 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2922 g = wd->gesture[ELM_GESTURE_N_FLICKS];
2923 n_flicks = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2924 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2927 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
2928 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2932 g = wd->gesture[ELM_GESTURE_ZOOM];
2933 zoom = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2934 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2937 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
2938 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2942 g = wd->gesture[ELM_GESTURE_ROTATE];
2943 rotate = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2944 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2947 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
2948 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2956 * This function the core-function where input handling is done.
2957 * Here we get user input and stream it to gesture testing.
2958 * We notify user about any gestures with new state:
2960 * START - gesture started.
2961 * MOVE - gesture is ongoing.
2962 * END - gesture was completed.
2963 * ABORT - gesture was aborted after START, MOVE (will NOT be completed)
2965 * We also check if a gesture was detected, then reset event history
2966 * If no gestures were found we reset gesture test flag
2967 * after streaming event-history to widget.
2968 * (stream to the widget all events not consumed as a gesture)
2970 * @param data The gesture-layer object.
2971 * @param event_info Pointer to recent input event.
2972 * @param event_type Recent input event type.
2974 * @ingroup Elm_Gesture_Layer
2977 _event_process(void *data, Evas_Object *obj __UNUSED__,
2978 void *event_info, Evas_Callback_Type event_type)
2981 Pointer_Event *pe = NULL;
2982 Widget_Data *wd = elm_widget_data_get(data);
2985 /* Start testing candidate gesture from here */
2986 if (_make_pointer_event(data, event_info, event_type, &_pe))
2989 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
2990 _n_long_tap_test(data, pe, event_info, event_type,
2991 ELM_GESTURE_N_LONG_TAPS);
2993 if (IS_TESTED(ELM_GESTURE_N_TAPS))
2994 _dbl_click_test(data, pe, event_info, event_type,
2995 ELM_GESTURE_N_TAPS, 1);
2997 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
2998 _dbl_click_test(data, pe, event_info, event_type,
2999 ELM_GESTURE_N_DOUBLE_TAPS, 2);
3001 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
3002 _dbl_click_test(data, pe, event_info, event_type,
3003 ELM_GESTURE_N_TRIPLE_TAPS, 3);
3005 if (IS_TESTED(ELM_GESTURE_MOMENTUM))
3006 _momentum_test(data, pe, event_info, event_type,
3007 ELM_GESTURE_MOMENTUM);
3009 if (IS_TESTED(ELM_GESTURE_N_LINES))
3010 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_LINES);
3012 if (IS_TESTED(ELM_GESTURE_N_FLICKS))
3013 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_FLICKS);
3015 if (IS_TESTED(ELM_GESTURE_ZOOM))
3016 _zoom_test(data, pe, event_info, event_type, ELM_GESTURE_ZOOM);
3018 if (IS_TESTED(ELM_GESTURE_ZOOM))
3019 _zoom_with_wheel_test(data, event_info, event_type, ELM_GESTURE_ZOOM);
3021 if (IS_TESTED(ELM_GESTURE_ROTATE))
3022 _rotate_test(data, pe, event_info, event_type, ELM_GESTURE_ROTATE);
3024 if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
3025 _event_history_add(data, event_info, event_type);
3026 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3027 (event_type == EVAS_CALLBACK_MULTI_UP))
3029 Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type);
3032 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD);
3033 _event_history_add(data, event_info, event_type);
3037 /* Log event to restart gestures */
3038 wd->recent_device_event = _add_recent_device_event(wd->recent_device_event, &_pe);
3040 /* we maintain list of touched devices */
3041 /* We also use move to track current device x.y pos */
3042 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
3043 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
3044 (event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
3045 (event_type == EVAS_CALLBACK_MULTI_MOVE))
3047 wd->touched = _add_touched_device(wd->touched, pe);
3049 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3050 (event_type == EVAS_CALLBACK_MULTI_UP))
3052 wd->touched = _remove_touched_device(wd->touched, pe);
3055 /* Report current states and clear history if needed */
3056 Eina_Bool states_reset = _clear_if_finished(data);
3057 if (wd->glayer_continues_enable)
3058 continues_gestures_restart(data, states_reset);
3063 * For all _mouse_* / multi_* functions wethen send this event to
3064 * _event_process function.
3066 * @param data The gesture-layer object.
3067 * @param event_info Pointer to recent input event.
3069 * @ingroup Elm_Gesture_Layer
3072 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3075 Widget_Data *wd = elm_widget_data_get(data);
3077 if (((Evas_Event_Mouse_Down *) event_info)->button != 1)
3078 return; /* We only process left-click at the moment */
3080 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_DOWN);
3084 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3087 Widget_Data *wd = elm_widget_data_get(data);
3090 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_MOVE);
3094 _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3097 Widget_Data *wd = elm_widget_data_get(data);
3100 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_DOWN);
3104 _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3107 Widget_Data *wd = elm_widget_data_get(data);
3110 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_UP);
3114 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3117 Widget_Data *wd = elm_widget_data_get(data);
3120 if (((Evas_Event_Mouse_Up *) event_info)->button != 1)
3121 return; /* We only process left-click at the moment */
3123 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_UP);
3127 _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3130 Widget_Data *wd = elm_widget_data_get(data);
3133 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_WHEEL);
3137 _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3140 Widget_Data *wd = elm_widget_data_get(data);
3143 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_DOWN);
3147 _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3150 Widget_Data *wd = elm_widget_data_get(data);
3153 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_MOVE);
3157 _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3160 Widget_Data *wd = elm_widget_data_get(data);
3163 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_UP);
3167 elm_gesture_layer_hold_events_get(Evas_Object *obj)
3169 Widget_Data *wd = elm_widget_data_get(obj);
3170 if (!wd) return EINA_FALSE;
3172 return !wd->repeat_events;
3176 elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool r)
3178 Widget_Data *wd = elm_widget_data_get(obj);
3181 wd->repeat_events = !r;
3185 elm_gesture_layer_zoom_step_set(Evas_Object *obj, double s)
3187 Widget_Data *wd = elm_widget_data_get(obj);
3197 elm_gesture_layer_rotate_step_set(Evas_Object *obj, double s)
3199 Widget_Data *wd = elm_widget_data_get(obj);
3205 wd->rotate_step = s;
3209 elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *t)
3211 Widget_Data *wd = elm_widget_data_get(obj);
3212 if (!wd) return EINA_FALSE;
3217 /* if was attached before, unregister callbacks first */
3219 _unregister_callbacks(obj);
3223 _register_callbacks(obj);
3228 elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Types idx,
3229 Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data)
3231 Widget_Data *wd = elm_widget_data_get(obj);
3235 if (!wd->gesture[idx])
3236 wd->gesture[idx] = calloc(1, sizeof(Gesture_Info));
3237 if (!wd->gesture[idx]) return;
3239 p = wd->gesture[idx];
3242 p->fn[cb_type].cb = cb;
3243 p->fn[cb_type].user_data = data;
3244 p->state = ELM_GESTURE_STATE_UNDEFINED;
3249 _disable_hook(Evas_Object *obj)
3251 if (elm_widget_disabled_get(obj))
3252 _unregister_callbacks(obj);
3254 _register_callbacks(obj);
3258 elm_gesture_layer_add(Evas_Object *parent)
3264 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
3266 wd = ELM_NEW(Widget_Data);
3267 e = evas_object_evas_get(parent);
3268 if (!e) return NULL;
3269 obj = elm_widget_add(e);
3270 ELM_SET_WIDTYPE(widtype, "gesture_layer");
3271 elm_widget_type_set(obj, "gesture_layer");
3272 elm_widget_sub_object_add(parent, obj);
3273 elm_widget_data_set(obj, wd);
3274 elm_widget_del_hook_set(obj, _del_hook);
3275 elm_widget_disable_hook_set(obj, _disable_hook);
3278 wd->line_min_length =_elm_config->glayer_line_min_length * elm_finger_size_get();
3279 wd->zoom_distance_tolerance = _elm_config->glayer_zoom_distance_tolerance * elm_finger_size_get();
3280 wd->line_distance_tolerance = _elm_config->glayer_line_distance_tolerance * elm_finger_size_get();
3281 wd->zoom_finger_factor = _elm_config->glayer_zoom_finger_factor;
3282 wd->zoom_wheel_factor = _elm_config->glayer_zoom_wheel_factor; /* mouse wheel zoom steps */
3283 wd->rotate_angular_tolerance = _elm_config->glayer_rotate_angular_tolerance;
3284 wd->line_angular_tolerance = _elm_config->glayer_line_angular_tolerance;
3285 wd->flick_time_limit_ms = _elm_config->glayer_flick_time_limit_ms;
3286 wd->long_tap_start_timeout = _elm_config->glayer_long_tap_start_timeout;
3287 wd->repeat_events = EINA_TRUE;
3288 wd->glayer_continues_enable = _elm_config->glayer_continues_enable;
3290 #if defined(DEBUG_GESTURE_LAYER)
3291 printf("size of Gestures = <%d>\n", sizeof(wd->gesture));
3292 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);
3294 memset(wd->gesture, 0, sizeof(wd->gesture));