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
10 #define ELM_GESTURE_MULTI_TIMEOUT 50
11 #define ELM_GESTURE_MINIMUM_MOMENTUM 0.001
13 /* Some Trigo values */
14 #define RAD_90DEG M_PI_2
15 #define RAD_180DEG M_PI
16 #define RAD_270DEG (M_PI_2 * 3)
17 #define RAD_360DEG (M_PI * 2)
18 /* #define DEBUG_GESTURE_LAYER 1 */
21 _glayer_bufdup(void *buf, size_t size)
28 #define COPY_EVENT_INFO(EV) _glayer_bufdup(EV, sizeof(*EV))
31 #define SET_TEST_BIT(P) do { \
32 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; \
35 #define IS_TESTED(T) ((wd->gesture[T]) ? wd->gesture[T]->test : EINA_FALSE)
41 * Struct holds callback information.
43 * @ingroup Elm_Gesture_Layer
47 void *user_data; /**< Holds user data to CB (like sd) */
48 Elm_Gesture_Event_Cb cb;
55 * type for callback information
57 * @ingroup Elm_Gesture_Layer
59 typedef struct _Func_Data Func_Data;
64 * @struct _Gesture_Info
65 * Struct holds gesture info
67 * @ingroup Elm_Gesture_Layer
72 void *data; /**< Holds gesture intemidiate processing data */
73 Func_Data fn[ELM_GESTURE_STATE_ABORT + 1]; /**< Callback info for states */
74 Elm_Gesture_Types g_type; /**< gesture type */
75 Elm_Gesture_State state; /**< gesture state */
76 void *info; /**< Data for the state callback */
77 Eina_Bool test; /**< if true this gesture should be tested on input */
83 * @typedef Gesture_Info
84 * Type for _Gesture_Info
86 * @ingroup Elm_Gesture_Layer
88 typedef struct _Gesture_Info Gesture_Info;
93 * @struct _Event_History
94 * Struct holds event history.
95 * These events are repeated if no gesture found.
97 * @ingroup Elm_Gesture_Layer
103 Evas_Callback_Type event_type;
109 * @typedef Event_History
110 * Type for _Event_History
112 * @ingroup Elm_Gesture_Layer
114 typedef struct _Event_History Event_History;
119 * @struct _Pointer_Event
120 * Struct holds pointer-event info
121 * This is a generic pointer event structure
123 * @ingroup Elm_Gesture_Layer
125 struct _Pointer_Event
128 unsigned int timestamp;
130 Evas_Callback_Type event_type;
136 * @typedef Pointer_Event
137 * Type for generic pointer event structure
139 * @ingroup Elm_Gesture_Layer
141 typedef struct _Pointer_Event Pointer_Event;
143 /* All *Type structs hold result for the user in 'info' field
144 * The rest is gesture processing intermediate data.
145 * NOTE: info field must be FIRST in the struct.
146 * This is used when reporting ABORT in event_history_clear() */
149 Elm_Gesture_Taps_Info info;
152 unsigned int n_taps_needed;
156 typedef struct _Taps_Type Taps_Type;
158 struct _Long_Tap_Type
160 Elm_Gesture_Taps_Info info;
163 unsigned int max_touched;
164 Ecore_Timer *timeout; /* When this expires, long tap STARTed */
167 typedef struct _Long_Tap_Type Long_Tap_Type;
169 struct _Momentum_Type
170 { /* Fields used by _line_test() */
171 Elm_Gesture_Momentum_Info info;
172 Evas_Coord_Point line_st;
173 Evas_Coord_Point line_end;
174 unsigned int t_st_x; /* Time start on X */
175 unsigned int t_st_y; /* Time start on Y */
176 unsigned int t_end; /* Time end */
177 unsigned int t_up; /* Recent up event time */
180 typedef struct _Momentum_Type Momentum_Type;
184 Evas_Coord_Point line_st;
185 Evas_Coord_Point line_end;
186 Evas_Coord line_length;
187 unsigned int t_st; /* Time start */
188 unsigned int t_end; /* Time end */
190 double line_angle; /* Current angle of line */
192 typedef struct _Line_Data Line_Data;
195 { /* Fields used by _line_test() */
196 Elm_Gesture_Line_Info info;
197 Eina_List *list; /* List of Line_Data */
199 typedef struct _Line_Type Line_Type;
202 { /* Fields used by _zoom_test() */
203 Elm_Gesture_Zoom_Info info;
204 Pointer_Event zoom_st;
205 Pointer_Event zoom_mv;
206 Pointer_Event zoom_st1;
207 Pointer_Event zoom_mv1;
208 Evas_Event_Mouse_Wheel *zoom_wheel;
209 Evas_Coord zoom_base; /* Holds gap between fingers on zoom-start */
210 Evas_Coord zoom_distance_tolerance;
211 Elm_Gesture_Momentum_Info momentum1; /* For continues gesture */
212 Elm_Gesture_Momentum_Info momentum2; /* For continues gesture */
215 typedef struct _Zoom_Type Zoom_Type;
218 { /* Fields used by _rotation_test() */
219 Elm_Gesture_Rotate_Info info;
220 Pointer_Event rotate_st;
221 Pointer_Event rotate_mv;
222 Pointer_Event rotate_st1;
223 Pointer_Event rotate_mv1;
224 double rotate_angular_tolerance;
226 Elm_Gesture_Momentum_Info momentum1; /* For continues gesture */
227 Elm_Gesture_Momentum_Info momentum2; /* For continues gesture */
229 typedef struct _Rotate_Type Rotate_Type;
233 Evas_Object *target; /* Target Widget */
234 Event_History *event_history_list;
237 Evas_Coord zoom_distance_tolerance;
238 Evas_Coord line_distance_tolerance;
239 double line_angular_tolerance;
240 double zoom_wheel_factor; /* mouse wheel zoom steps */
241 double zoom_finger_factor; /* used for zoom factor */
242 double rotate_angular_tolerance;
243 unsigned int flick_time_limit_ms;
244 double long_tap_start_timeout;
245 Eina_Bool glayer_continues_enable;
250 Gesture_Info *gesture[ELM_GESTURE_LAST];
251 Ecore_Timer *dbl_timeout; /* When this expires, dbl click/taps ABORTed */
252 Eina_List *pending; /* List of devices need to refeed *UP event */
253 Eina_List *touched; /* Information of touched devices */
255 Eina_Bool repeat_events : 1;
257 typedef struct _Widget_Data Widget_Data;
259 static const char *widtype = NULL;
260 static void _del_hook(Evas_Object *obj);
262 static Eina_Bool _event_history_clear(Evas_Object *obj);
263 static void _reset_states(Widget_Data *wd);
264 static void _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
265 static void _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
266 static void _zoom_with_wheel_test(Evas_Object *obj, void *event_info, Evas_Callback_Type event_type, Elm_Gesture_Types g_type);
267 static void _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
268 static void _mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
269 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
270 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
272 static void _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
273 static void _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
274 static void _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
276 /* START - Functions to manage touched-device list */
279 * This function is used to find if device is touched
281 * @ingroup Elm_Gesture_Layer
284 compare_device(const void *data1, const void *data2)
285 { /* Compare the two device numbers */
286 return (((Pointer_Event *) data1)->device -((Pointer_Event *) data2)->device);
292 * Remove Pointer Event from touched device list
293 * @param list Pointer to touched device list.
294 * @param Pointer_Event Pointer to PE.
296 * @ingroup Elm_Gesture_Layer
299 _remove_touched_device(Eina_List *list, Pointer_Event *pe)
301 Eina_List *lst = NULL;
302 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
305 lst = eina_list_remove(list, p);
316 * Recoed Pointer Event in touched device list
317 * Note: This fuction allocates memory for PE event
318 * This memory is released in _remove_touched_device()
319 * @param list Pointer to touched device list.
320 * @param Pointer_Event Pointer to PE.
322 * @ingroup Elm_Gesture_Layer
325 _add_touched_device(Eina_List *list, Pointer_Event *pe)
327 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
329 { /* We like to track device touch-position, overwrite info */
330 memcpy(p, pe, sizeof(Pointer_Event));
334 if ((pe->event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
335 (pe->event_type == EVAS_CALLBACK_MULTI_DOWN))
336 { /* Add touched device on DOWN event only */
337 p = malloc(sizeof(Pointer_Event));
338 /* Freed in _remove_touched_device() */
339 memcpy(p, pe, sizeof(Pointer_Event));
340 return eina_list_append(list, p);
345 /* END - Functions to manage touched-device list */
351 * @param event_info pointer to event.
353 * @ingroup Elm_Gesture_Layer
355 static Evas_Event_Flags
356 _get_event_flag(void *event_info, Evas_Callback_Type event_type)
360 case EVAS_CALLBACK_MOUSE_IN:
361 return ((Evas_Event_Mouse_In *) event_info)->event_flags;
362 case EVAS_CALLBACK_MOUSE_OUT:
363 return ((Evas_Event_Mouse_Out *) event_info)->event_flags;
364 case EVAS_CALLBACK_MOUSE_DOWN:
365 return ((Evas_Event_Mouse_Down *) event_info)->event_flags;
366 case EVAS_CALLBACK_MOUSE_MOVE:
367 return ((Evas_Event_Mouse_Move *) event_info)->event_flags;
368 case EVAS_CALLBACK_MOUSE_UP:
369 return ((Evas_Event_Mouse_Up *) event_info)->event_flags;
370 case EVAS_CALLBACK_MOUSE_WHEEL:
371 return ((Evas_Event_Mouse_Wheel *) event_info)->event_flags;
372 case EVAS_CALLBACK_MULTI_DOWN:
373 return ((Evas_Event_Multi_Down *) event_info)->event_flags;
374 case EVAS_CALLBACK_MULTI_MOVE:
375 return ((Evas_Event_Multi_Move *) event_info)->event_flags;
376 case EVAS_CALLBACK_MULTI_UP:
377 return ((Evas_Event_Multi_Up *) event_info)->event_flags;
378 case EVAS_CALLBACK_KEY_DOWN:
379 return ((Evas_Event_Key_Down *) event_info)->event_flags;
380 case EVAS_CALLBACK_KEY_UP:
381 return ((Evas_Event_Key_Up *) event_info)->event_flags;
383 return EVAS_EVENT_FLAG_NONE;
390 * Sets event flag to value returned from user callback
391 * @param wd Widget Data
392 * @param event_info pointer to event.
393 * @param event_type what type was ev (mouse down, etc...)
394 * @param ev_flags event flags
396 * @ingroup Elm_Gesture_Layer
399 consume_event(Widget_Data *wd, void *event_info,
400 Evas_Callback_Type event_type, Evas_Event_Flags ev_flags)
401 { /* Mark EVAS_EVENT_FLAG_ON_HOLD on events that are used by gesture layer */
402 /* ev_flags != EVAS_EVENT_FLAG_NONE means target used event and g-layer */
403 /* should not refeed this event. */
405 return; /* This happens when restarting gestures */
407 if ((ev_flags) || (!wd->repeat_events))
411 case EVAS_CALLBACK_MOUSE_DOWN:
412 ((Evas_Event_Mouse_Down *) event_info)->event_flags |= ev_flags;
414 case EVAS_CALLBACK_MOUSE_MOVE:
415 ((Evas_Event_Mouse_Move *) event_info)->event_flags |= ev_flags;
417 case EVAS_CALLBACK_MOUSE_UP:
418 ((Evas_Event_Mouse_Up *) event_info)->event_flags |= ev_flags;
420 case EVAS_CALLBACK_MOUSE_WHEEL:
421 ((Evas_Event_Mouse_Wheel *) event_info)->event_flags |= ev_flags;
423 case EVAS_CALLBACK_MULTI_DOWN:
424 ((Evas_Event_Multi_Down *) event_info)->event_flags |= ev_flags;
426 case EVAS_CALLBACK_MULTI_MOVE:
427 ((Evas_Event_Multi_Move *) event_info)->event_flags |= ev_flags;
429 case EVAS_CALLBACK_MULTI_UP:
430 ((Evas_Event_Multi_Up *) event_info)->event_flags |= ev_flags;
432 case EVAS_CALLBACK_KEY_DOWN:
433 ((Evas_Event_Key_Down *) event_info)->event_flags |= ev_flags;
435 case EVAS_CALLBACK_KEY_UP:
436 ((Evas_Event_Key_Up *) event_info)->event_flags |= ev_flags;
447 * Report current state of a gesture by calling user callback.
448 * @param gesture what gesture state we report.
449 * @param info inforamtion for user callback
451 * @ingroup Elm_Gesture_Layer
453 static Evas_Event_Flags
454 _report_state(Gesture_Info *gesture, void *info)
455 { /* We report current state (START, MOVE, END, ABORT), once */
456 #if defined(DEBUG_GESTURE_LAYER)
457 printf("%s reporting gesture=<%d> state=<%d>\n" , __func__, gesture->g_type,
460 if ((gesture->state != ELM_GESTURE_STATE_UNDEFINED) &&
461 (gesture->fn[gesture->state].cb))
462 { /* Fill state-info struct and send ptr to user callback */
463 return gesture->fn[gesture->state].cb(
464 gesture->fn[gesture->state].user_data, info);
467 return EVAS_EVENT_FLAG_NONE;
473 * Update state for a given gesture.
474 * We may update gesture state to:
475 * UNDEFINED - current input did not start gesure yet.
476 * START - gesture started according to input.
477 * MOVE - gusture in progress.
478 * END - gesture completed according to input.
479 * ABORT - input does not matches gesure.
480 * note that we may move from UNDEFINED to ABORT
481 * because we may detect that gesture will not START
482 * with a given input.
484 * @param g given gesture to change state.
485 * @param s gesure new state.
486 * @param info buffer to be sent to user callback on report_state.
487 * @param force makes report_state to report the new-state even
488 * if its same as current state. Works for MOVE - gesture in progress.
490 * @ingroup Elm_Gesture_Layer
492 static Evas_Event_Flags
493 _set_state(Gesture_Info *g, Elm_Gesture_State s,
494 void *info, Eina_Bool force)
496 Elm_Gesture_State old_state;
497 if ((g->state == s) && (!force))
498 return EVAS_EVENT_FLAG_NONE;
500 old_state = g->state;
503 g->info = info; /* Information for user callback */
504 if ((g->state == ELM_GESTURE_STATE_ABORT) ||
505 (g->state == ELM_GESTURE_STATE_END))
506 g->test = EINA_FALSE;
508 if ((g->state != ELM_GESTURE_STATE_UNDEFINED) &&
509 (!((old_state == ELM_GESTURE_STATE_UNDEFINED) &&
510 (s == ELM_GESTURE_STATE_ABORT))))
511 return _report_state(g, g->info);
513 return EVAS_EVENT_FLAG_NONE;
519 * This resets all gesture states and sets test-bit.
520 * this is used for restarting gestures to listen to input.
521 * happens after we complete a gesture or no gesture was detected.
522 * @param wd Widget data of the gesture-layer object.
524 * @ingroup Elm_Gesture_Layer
527 _reset_states(Widget_Data *wd)
531 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
536 _set_state(p, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
545 * if gesture was NOT detected AND we only have gestures in ABORT state
546 * we clear history immediately to be ready for input.
548 * @param obj The gesture-layer object.
549 * @return TRUE on event history_clear
551 * @ingroup Elm_Gesture_Layer
554 _clear_if_finished(Evas_Object *obj)
556 Widget_Data *wd = elm_widget_data_get(obj);
557 if (!wd) return EINA_FALSE;
560 /* Clear history if all we have aborted gestures */
561 Eina_Bool reset_s = EINA_TRUE, all_undefined = EINA_TRUE;
562 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
563 { /* If no gesture started and all we have aborted gestures, reset all */
564 Gesture_Info *p = wd->gesture[i];
565 if ((p) && (p->state != ELM_GESTURE_STATE_UNDEFINED))
567 if ((p->state == ELM_GESTURE_STATE_START) ||
568 (p->state == ELM_GESTURE_STATE_MOVE))
569 reset_s = EINA_FALSE;
571 all_undefined = EINA_FALSE;
575 if (reset_s && (!all_undefined))
576 return _event_history_clear(obj);
582 _inside(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
584 int w = elm_finger_size_get() >> 1; /* Finger size devided by 2 */
600 /* All *test_reset() funcs are called to clear
601 * gesture intermediate data.
602 * This happens when we need to reset our tests.
603 * for example when gesture is detected or all ABORTed. */
605 _tap_gestures_test_reset(Gesture_Info *gesture)
610 Widget_Data *wd = elm_widget_data_get(gesture->obj);
611 wd->dbl_timeout = NULL;
618 EINA_LIST_FREE(((Taps_Type *) gesture->data)->l, data)
619 EINA_LIST_FREE(data, pe)
622 memset(gesture->data, 0, sizeof(Taps_Type));
625 /* All *test_reset() funcs are called to clear
626 * gesture intermediate data.
627 * This happens when we need to reset our tests.
628 * for example when gesture is detected or all ABORTed. */
630 _n_long_tap_test_reset(Gesture_Info *gesture)
638 Long_Tap_Type *st = gesture->data;
641 EINA_LIST_FOREACH(st->touched, l, p)
644 eina_list_free(st->touched);
645 if (st->timeout) ecore_timer_del(st->timeout);
646 memset(gesture->data, 0, sizeof(Long_Tap_Type));
650 _momentum_test_reset(Gesture_Info *gesture)
658 memset(gesture->data, 0, sizeof(Momentum_Type));
662 _line_data_reset(Line_Data *st)
667 memset(st, 0, sizeof(Line_Data));
668 st->line_angle = ELM_GESTURE_NEGATIVE_ANGLE;
672 _line_test_reset(Gesture_Info *gesture)
680 Line_Type *st = gesture->data;
681 Eina_List *list = st->list;
684 EINA_LIST_FOREACH(list, l, t_line)
687 eina_list_free(list);
692 _zoom_test_reset(Gesture_Info *gesture)
700 Widget_Data *wd = elm_widget_data_get(gesture->obj);
701 Zoom_Type *st = gesture->data;
702 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
703 evas_object_evas_get(wd->target), "Control");
704 evas_object_key_ungrab(wd->target, "Control_L", mask, 0);
705 evas_object_key_ungrab(wd->target, "Control_R", mask, 0);
707 memset(st, 0, sizeof(Zoom_Type));
708 st->zoom_distance_tolerance = wd->zoom_distance_tolerance;
713 _rotate_test_reset(Gesture_Info *gesture)
721 Widget_Data *wd = elm_widget_data_get(gesture->obj);
722 Rotate_Type *st = gesture->data;
724 memset(st, 0, sizeof(Rotate_Type));
725 st->info.base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
726 st->rotate_angular_tolerance = wd->rotate_angular_tolerance;
733 * We register callbacks when gesture layer is attached to an object
734 * or when its enabled after disable.
736 * @param obj The gesture-layer object.
738 * @ingroup Elm_Gesture_Layer
741 _register_callbacks(Evas_Object *obj)
743 Widget_Data *wd = elm_widget_data_get(obj);
748 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
750 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
752 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_UP,
755 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
758 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_DOWN,
760 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_MOVE,
762 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_UP,
765 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_DOWN,
767 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_UP,
775 * We unregister callbacks when gesture layer is disabled.
777 * @param obj The gesture-layer object.
779 * @ingroup Elm_Gesture_Layer
782 _unregister_callbacks(Evas_Object *obj)
784 Widget_Data *wd = elm_widget_data_get(obj);
789 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
791 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
793 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_UP,
796 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
799 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_DOWN,
802 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_MOVE,
805 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_UP,
808 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_DOWN,
810 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_UP,
815 /* START - Event history list handling functions */
818 * This function is used to find if device number
819 * is found in a list of devices.
820 * The list contains devices for refeeding *UP event
822 * @ingroup Elm_Gesture_Layer
825 device_in_pending_list(const void *data1, const void *data2)
826 { /* Compare the two device numbers */
827 return (((intptr_t) data1) - ((intptr_t) data2));
833 * This functions adds device to refeed-pending device list
834 * @ingroup Elm_Gesture_Layer
837 _add_device_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
839 int device = ELM_MOUSE_DEVICE;
842 case EVAS_CALLBACK_MOUSE_DOWN:
844 case EVAS_CALLBACK_MULTI_DOWN:
845 device = ((Evas_Event_Multi_Down *) event)->device;
851 if (!eina_list_search_unsorted_list(list, device_in_pending_list,
854 return eina_list_append(list, (intptr_t*) device);
863 * This functions returns pending-device node
864 * @ingroup Elm_Gesture_Layer
867 _device_is_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
869 int device = ELM_MOUSE_DEVICE;
872 case EVAS_CALLBACK_MOUSE_UP:
874 case EVAS_CALLBACK_MULTI_UP:
875 device = ((Evas_Event_Multi_Up *) event)->device;
881 return eina_list_search_unsorted_list(list, device_in_pending_list,
882 (intptr_t *) device);
888 * This function reports ABORT to all none-detected gestures
889 * Then resets test bits for all desired gesures
890 * and clears input-events history.
891 * note: if no gesture was detected, events from history list
892 * are streamed to the widget because it's unused by layer.
893 * user may cancel refeed of events by setting repeat events.
895 * @param obj The gesture-layer object.
897 * @ingroup Elm_Gesture_Layer
900 _event_history_clear(Evas_Object *obj)
902 Widget_Data *wd = elm_widget_data_get(obj);
903 if (!wd) return EINA_FALSE;
907 Evas *e = evas_object_evas_get(obj);
908 Eina_Bool gesture_found = EINA_FALSE;
909 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
914 if (p->state == ELM_GESTURE_STATE_END)
915 gesture_found = EINA_TRUE;
917 { /* Report ABORT to all gestures that still not finished */
918 _set_state(p, ELM_GESTURE_STATE_ABORT, wd->gesture[i]->info,
924 _reset_states(wd); /* we are ready to start testing for gestures again */
926 /* Clear all gestures intermediate data */
927 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
928 { /* We do not clear a long-tap gesture if fingers still on surface */
929 /* and gesture timer still pending to test gesture state */
930 Long_Tap_Type *st = wd->gesture[ELM_GESTURE_N_LONG_TAPS]->data;
931 if ((st) && /* st not allocated if clear occurs before 1st input */
932 ((!eina_list_count(st->touched)) || (!st->timeout)))
933 _n_long_tap_test_reset(wd->gesture[ELM_GESTURE_N_LONG_TAPS]);
938 ecore_timer_del(wd->dbl_timeout);
939 wd->dbl_timeout = NULL;
942 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_TAPS]);
943 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
944 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
945 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
946 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
947 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
948 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
949 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
951 /* Disable gesture layer so refeeded events won't be consumed by it */
952 _unregister_callbacks(obj);
953 while (wd->event_history_list)
956 t = wd->event_history_list;
957 Eina_List *pending = _device_is_pending(wd->pending,
958 wd->event_history_list->event,
959 wd->event_history_list->event_type);
961 /* Refeed events if no gesture matched input */
962 if (pending || ((!gesture_found) && (!wd->repeat_events)))
964 evas_event_refeed_event(e, wd->event_history_list->event,
965 wd->event_history_list->event_type);
969 wd->pending = eina_list_remove_list(wd->pending, pending);
973 wd->pending = _add_device_pending(wd->pending,
974 wd->event_history_list->event,
975 wd->event_history_list->event_type);
979 free(wd->event_history_list->event);
980 wd->event_history_list = (Event_History *) eina_inlist_remove(
981 EINA_INLIST_GET(wd->event_history_list),
982 EINA_INLIST_GET(wd->event_history_list));
985 _register_callbacks(obj);
992 * This function copies input events.
993 * We copy event info before adding it to history.
994 * The memory is freed when we clear history.
996 * @param event the event to copy
997 * @param event_type event type to copy
999 * @ingroup Elm_Gesture_Layer
1002 _copy_event_info(void *event, Evas_Callback_Type event_type)
1006 case EVAS_CALLBACK_MOUSE_DOWN:
1007 return COPY_EVENT_INFO((Evas_Event_Mouse_Down *) event);
1009 case EVAS_CALLBACK_MOUSE_MOVE:
1010 return COPY_EVENT_INFO((Evas_Event_Mouse_Move *) event);
1012 case EVAS_CALLBACK_MOUSE_UP:
1013 return COPY_EVENT_INFO((Evas_Event_Mouse_Up *) event);
1015 case EVAS_CALLBACK_MOUSE_WHEEL:
1016 return COPY_EVENT_INFO((Evas_Event_Mouse_Wheel *) event);
1018 case EVAS_CALLBACK_MULTI_DOWN:
1019 return COPY_EVENT_INFO((Evas_Event_Multi_Down *) event);
1021 case EVAS_CALLBACK_MULTI_MOVE:
1022 return COPY_EVENT_INFO((Evas_Event_Multi_Move *) event);
1024 case EVAS_CALLBACK_MULTI_UP:
1025 return COPY_EVENT_INFO((Evas_Event_Multi_Up *) event);
1027 case EVAS_CALLBACK_KEY_DOWN:
1028 return COPY_EVENT_INFO((Evas_Event_Key_Down *) event);
1030 case EVAS_CALLBACK_KEY_UP:
1031 return COPY_EVENT_INFO((Evas_Event_Key_Up *) event);
1039 _event_history_add(Evas_Object *obj, void *event, Evas_Callback_Type event_type)
1041 Widget_Data *wd = elm_widget_data_get(obj);
1043 if (!wd) return EINA_FALSE;
1045 ev = malloc(sizeof(Event_History));
1046 ev->event = _copy_event_info(event, event_type); /* Freed on event_history_clear */
1047 ev->event_type = event_type;
1048 wd->event_history_list = (Event_History *) eina_inlist_append(
1049 EINA_INLIST_GET(wd->event_history_list), EINA_INLIST_GET(ev));
1053 /* END - Event history list handling functions */
1056 _del_hook(Evas_Object *obj)
1058 Widget_Data *wd = elm_widget_data_get(obj);
1061 _event_history_clear(obj);
1062 eina_list_free(wd->pending);
1064 Pointer_Event *data;
1065 EINA_LIST_FREE(wd->touched, data)
1068 if (!elm_widget_disabled_get(obj))
1069 _unregister_callbacks(obj);
1071 /* Free all gestures internal data structures */
1073 for (i = 0; i < ELM_GESTURE_LAST; i++)
1076 if (wd->gesture[i]->data)
1077 free(wd->gesture[i]->data);
1079 free(wd->gesture[i]);
1086 compare_match_fingers(const void *data1, const void *data2)
1087 { /* Compare coords of first item in list to cur coords */
1088 const Pointer_Event *pe1 = eina_list_data_get(data1);
1089 const Pointer_Event *pe2 = data2;
1091 if (_inside(pe1->x, pe1->y, pe2->x, pe2->y))
1093 else if (pe1->x < pe2->x)
1097 if (pe1->x == pe2->x)
1098 return pe1->y - pe2->y;
1105 compare_pe_device(const void *data1, const void *data2)
1106 { /* Compare device of first item in list to our pe device */
1107 const Pointer_Event *pe1 = eina_list_data_get(data1);
1108 const Pointer_Event *pe2 = data2;
1110 /* Only match if last was a down event */
1111 if ((pe1->event_type != EVAS_CALLBACK_MULTI_DOWN) &&
1112 (pe1->event_type != EVAS_CALLBACK_MOUSE_DOWN))
1116 if (pe1->device == pe2->device)
1118 else if (pe1->device < pe2->device)
1125 _record_pointer_event(Taps_Type *st, Eina_List *pe_list, Pointer_Event *pe,
1126 Widget_Data *wd, void *event_info, Evas_Callback_Type event_type)
1127 { /* Keep copy of pe and record it in list */
1128 Pointer_Event *p = malloc(sizeof(Pointer_Event));
1129 memcpy(p, pe, sizeof(Pointer_Event));
1130 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1136 /* This will also update middle-point to report to user later */
1137 st->info.x = st->sum_x / st->n_taps;
1138 st->info.y = st->sum_y / st->n_taps;
1139 st->info.timestamp = pe->timestamp;
1143 pe_list = eina_list_append(pe_list, p);
1144 st->l = eina_list_append(st->l, pe_list);
1147 pe_list = eina_list_append(pe_list, p);
1155 * This function sets state a tap-gesture to END or ABORT
1157 * @param data gesture info pointer
1159 * @ingroup Elm_Gesture_Layer
1162 _tap_gesture_finish(void *data)
1163 { /* This function will test each tap gesture when timer expires */
1164 Gesture_Info *gesture = data;
1165 Elm_Gesture_State s = ELM_GESTURE_STATE_END;
1166 /* Here we check if taps-gesture was completed successfuly */
1167 /* Count how many taps were recieved on each device then */
1168 /* determine if it matches n_taps_needed defined on START */
1169 Taps_Type *st = gesture->data;
1172 EINA_LIST_FOREACH(st->l, l, pe_list)
1174 if (eina_list_count(pe_list) != st->n_taps_needed)
1175 { /* No match taps number on device, ABORT */
1176 s = ELM_GESTURE_STATE_ABORT;
1181 st->info.n = eina_list_count(st->l);
1182 _set_state(gesture, s, gesture->info, EINA_FALSE);
1183 _tap_gestures_test_reset(gesture);
1189 * when this timer expires we finish tap gestures.
1191 * @param data The gesture-layer object.
1192 * @return cancles callback for this timer.
1194 * @ingroup Elm_Gesture_Layer
1197 _multi_tap_timeout(void *data)
1199 Widget_Data *wd = elm_widget_data_get(data);
1200 if (!wd) return EINA_FALSE;
1202 if (IS_TESTED(ELM_GESTURE_N_TAPS))
1203 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TAPS]);
1205 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
1206 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
1208 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
1209 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
1211 _clear_if_finished(data);
1212 wd->dbl_timeout = NULL;
1213 return ECORE_CALLBACK_CANCEL;
1219 * when this timer expires we START long tap gesture
1221 * @param data The gesture-layer object.
1222 * @return cancles callback for this timer.
1224 * @ingroup Elm_Gesture_Layer
1227 _long_tap_timeout(void *data)
1229 Gesture_Info *gesture = data;
1230 Long_Tap_Type *st = gesture->data;
1233 _set_state(gesture, ELM_GESTURE_STATE_START,
1234 gesture->data, EINA_FALSE);
1236 return ECORE_CALLBACK_CANCEL;
1243 * This function checks if a tap gesture should start
1245 * @param wd Gesture Layer Widget Data.
1246 * @param pe The recent input event as stored in pe struct.
1247 * @param event_info Original input event pointer.
1248 * @param event_type Type of original input event.
1249 * @param gesture what gesture is tested
1250 * @param how many taps for this gesture (1, 2 or 3)
1252 * @return Flag to determine if we need to set a timer for finish
1254 * @ingroup Elm_Gesture_Layer
1257 _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe,
1258 void *event_info, Evas_Callback_Type event_type,
1259 Gesture_Info *gesture, int taps)
1260 { /* Here we fill Tap struct */
1261 Taps_Type *st = gesture->data;
1263 { /* Allocated once on first time */
1264 st = calloc(1, sizeof(Taps_Type));
1266 _tap_gestures_test_reset(gesture);
1269 Eina_List *pe_list = NULL;
1270 Pointer_Event *pe_down = NULL;
1271 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1272 switch (pe->event_type)
1274 case EVAS_CALLBACK_MULTI_DOWN:
1275 case EVAS_CALLBACK_MOUSE_DOWN:
1276 /* Check if got tap on same cord was tapped before */
1277 pe_list = eina_list_search_unsorted(st->l, compare_match_fingers, pe);
1280 eina_list_search_unsorted(st->l, compare_pe_device, pe))
1281 { /* This device was touched in other cord before completion */
1282 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1283 &st->info, EINA_FALSE);
1284 consume_event(wd, event_info, event_type, ev_flag);
1289 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1290 if ((pe->device == 0) && (eina_list_count(pe_list) == 1))
1291 { /* This is the first mouse down we got */
1292 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1293 &st->info, EINA_FALSE);
1294 consume_event(wd, event_info, event_type, ev_flag);
1296 st->n_taps_needed = taps * 2; /* count DOWN and UP */
1303 case EVAS_CALLBACK_MULTI_UP:
1304 case EVAS_CALLBACK_MOUSE_UP:
1305 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1309 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1312 case EVAS_CALLBACK_MULTI_MOVE:
1313 case EVAS_CALLBACK_MOUSE_MOVE:
1314 /* Get first event in first list, this has to be a Mouse Down event */
1315 /* and verify that user didn't move out of this area before next tap */
1316 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1319 pe_down = eina_list_data_get(pe_list);
1320 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);
1340 * This function checks all click/tap and double/triple taps
1342 * @param obj The gesture-layer object.
1343 * @param pe The recent input event as stored in pe struct.
1344 * @param event_info Original input event pointer.
1345 * @param event_type Type of original input event.
1347 * @ingroup Elm_Gesture_Layer
1350 _tap_gestures_test(Evas_Object *obj, Pointer_Event *pe,
1351 void *event_info, Evas_Callback_Type event_type)
1352 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1353 Eina_Bool need_timer = EINA_FALSE;
1354 Widget_Data *wd = elm_widget_data_get(obj);
1357 if (!pe) /* this happens when unhandled event arrived */
1358 return; /* see _make_pointer_event function */
1360 if (IS_TESTED(ELM_GESTURE_N_TAPS))
1361 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1362 wd->gesture[ELM_GESTURE_N_TAPS], 1);
1364 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
1365 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1366 wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS], 2);
1368 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
1369 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1370 wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS], 3);
1372 if ((need_timer) && (!wd->dbl_timeout))
1373 { /* Set a timer to finish these gestures */
1374 wd->dbl_timeout = ecore_timer_add(0.4, _multi_tap_timeout,
1382 * This function computes center-point for long-tap gesture
1384 * @param st Long Tap gesture info pointer
1385 * @param pe The recent input event as stored in pe struct.
1387 * @ingroup Elm_Gesture_Layer
1390 _compute_taps_center(Long_Tap_Type *st,
1391 Evas_Coord *x_out, Evas_Coord *y_out, Pointer_Event *pe)
1393 if(!eina_list_count(st->touched))
1398 Evas_Coord x = 0, y = 0;
1399 EINA_LIST_FOREACH(st->touched, l, p)
1400 { /* Accumulate all then take avarage */
1401 if (p->device == pe->device)
1402 { /* This will take care of values coming from MOVE event */
1413 *x_out = x / eina_list_count(st->touched);
1414 *y_out = y / eina_list_count(st->touched);
1420 * This function checks N long-tap gesture.
1422 * @param obj The gesture-layer object.
1423 * @param pe The recent input event as stored in pe struct.
1424 * @param event_info Original input event pointer.
1425 * @param event_type Type of original input event.
1426 * @param g_type what Gesture we are testing.
1427 * @param taps How many click/taps we test for.
1429 * @ingroup Elm_Gesture_Layer
1432 _n_long_tap_test(Evas_Object *obj, Pointer_Event *pe,
1433 void *event_info, Evas_Callback_Type event_type,
1434 Elm_Gesture_Types g_type)
1435 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1436 Widget_Data *wd = elm_widget_data_get(obj);
1439 if (!pe) /* this happens when unhandled event arrived */
1440 return; /* see _make_pointer_event function */
1441 Gesture_Info *gesture = wd->gesture[g_type];
1442 if (!gesture) return;
1444 Long_Tap_Type *st = gesture->data;
1446 { /* Allocated once on first time */
1447 st = calloc(1, sizeof(Long_Tap_Type));
1449 _n_long_tap_test_reset(gesture);
1452 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1453 switch (pe->event_type)
1455 case EVAS_CALLBACK_MULTI_DOWN:
1456 case EVAS_CALLBACK_MOUSE_DOWN:
1457 st->touched = _add_touched_device(st->touched, pe);
1458 st->info.n = eina_list_count(st->touched);
1459 if (st->info.n > st->max_touched)
1460 st->max_touched = st->info.n;
1462 { /* User removed finger from touch, then put back - ABORT */
1463 if ((gesture->state == ELM_GESTURE_STATE_START) ||
1464 (gesture->state == ELM_GESTURE_STATE_MOVE))
1466 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1467 &st->info, EINA_FALSE);
1468 consume_event(wd, event_info, event_type, ev_flag);
1472 if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
1473 { /* This is the first mouse down we got */
1474 st->info.timestamp = pe->timestamp;
1476 /* To test long tap */
1477 /* When this timer expires, gesture STARTED */
1479 st->timeout = ecore_timer_add(wd->long_tap_start_timeout,
1480 _long_tap_timeout, gesture);
1483 consume_event(wd, event_info, event_type, ev_flag);
1484 _compute_taps_center(st, &st->info.x, &st->info.y, pe);
1485 st->center_x = st->info.x;
1486 st->center_y = st->info.y;
1489 case EVAS_CALLBACK_MULTI_UP:
1490 case EVAS_CALLBACK_MOUSE_UP:
1491 st->touched = _remove_touched_device(st->touched, pe);
1492 _compute_taps_center(st, &st->center_x, &st->center_y, pe);
1494 ((gesture->state == ELM_GESTURE_STATE_START) ||
1495 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1496 { /* Report END only for gesture that STARTed */
1497 if (eina_list_count(st->touched) == 0)
1498 { /* Report END only at last release event */
1499 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1500 &st->info, EINA_FALSE);
1501 consume_event(wd, event_info, event_type, ev_flag);
1505 { /* Stop test, user lifts finger before long-start */
1506 if (st->timeout) ecore_timer_del(st->timeout);
1508 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1509 &st->info, EINA_FALSE);
1510 consume_event(wd, event_info, event_type, ev_flag);
1515 case EVAS_CALLBACK_MULTI_MOVE:
1516 case EVAS_CALLBACK_MOUSE_MOVE:
1518 ((gesture->state == ELM_GESTURE_STATE_START) ||
1519 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1520 { /* Report MOVE only if STARTED */
1523 Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
1525 _compute_taps_center(st, &x, &y, pe);
1526 /* ABORT if user moved fingers out of tap area */
1527 #if defined(DEBUG_GESTURE_LAYER)
1528 printf("%s x,y=(%d,%d) st->info.x,st->info.y=(%d,%d)\n",__func__,x,y,st->info.x,st->info.y);
1530 if (!_inside(x, y, st->center_x, st->center_y))
1531 state_to_report = ELM_GESTURE_STATE_ABORT;
1533 /* Report MOVE if gesture started */
1534 ev_flag = _set_state(gesture, state_to_report,
1535 &st->info, EINA_TRUE);
1536 consume_event(wd, event_info, event_type, ev_flag);
1548 * This function computes momentum for MOMENTUM, LINE and FLICK gestures
1549 * This momentum value will be sent to widget when gesture is completed.
1551 * @param momentum pointer to buffer where we record momentum value.
1552 * @param x1 x coord where user started gesture.
1553 * @param y1 y coord where user started gesture.
1554 * @param x2 x coord where user completed gesture.
1555 * @param y2 y coord where user completed gesture.
1556 * @param t1x timestamp for X, when user started gesture.
1557 * @param t1y timestamp for Y, when user started gesture.
1558 * @param t2 timestamp when user completed gesture.
1560 * @ingroup Elm_Gesture_Layer
1563 _set_momentum(Elm_Gesture_Momentum_Info *momentum, Evas_Coord x1, Evas_Coord y1,
1564 Evas_Coord x2, Evas_Coord y2, unsigned int t1x, unsigned int t1y,
1567 Evas_Coord velx = 0, vely = 0, vel;
1568 Evas_Coord dx = x2 - x1;
1569 Evas_Coord dy = y2 - y1;
1573 velx = (dx * 1000) / dtx;
1576 vely = (dy * 1000) / dty;
1578 vel = sqrt((velx * velx) + (vely * vely));
1580 if ((_elm_config->thumbscroll_friction > 0.0) &&
1581 (vel > _elm_config->thumbscroll_momentum_threshold))
1582 { /* report momentum */
1583 momentum->mx = velx;
1584 momentum->my = vely;
1596 * This function is used for computing rotation angle (DEG).
1598 * @param x1 first finger x location.
1599 * @param y1 first finger y location.
1600 * @param x2 second finger x location.
1601 * @param y2 second finger y location.
1603 * @return angle of the line between (x1,y1), (x2,y2) in Radians.
1605 * @ingroup Elm_Gesture_Layer
1608 get_angle(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
1614 if (((int) xx) && ((int) yy))
1621 return RAD_360DEG - a;
1632 return RAD_180DEG + a;
1636 return RAD_180DEG - a;
1642 { /* Horizontal line */
1667 * This function is used for computing the magnitude and direction
1668 * of vector between two points.
1670 * @param x1 first finger x location.
1671 * @param y1 first finger y location.
1672 * @param x2 second finger x location.
1673 * @param y2 second finger y location.
1674 * @param l length computed (output)
1675 * @param a angle computed (output)
1677 * @ingroup Elm_Gesture_Layer
1680 get_vector(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2,
1681 Evas_Coord *l, double *a)
1686 *l = (Evas_Coord) sqrt(xx*xx + yy*yy);
1687 *a = get_angle(x1, y1, x2, y2);
1691 _get_direction(Evas_Coord x1, Evas_Coord x2)
1703 * This function tests momentum gesture.
1704 * @param obj The gesture-layer object.
1705 * @param pe The recent input event as stored in pe struct.
1706 * @param event_info recent input event.
1707 * @param event_type recent event type.
1708 * @param g_type what Gesture we are testing.
1710 * @ingroup Elm_Gesture_Layer
1713 _momentum_test(Evas_Object *obj, Pointer_Event *pe,
1714 void *event_info, Evas_Callback_Type event_type,
1715 Elm_Gesture_Types g_type)
1717 Widget_Data *wd = elm_widget_data_get(obj);
1719 Gesture_Info *gesture = wd->gesture[g_type];
1720 if (!gesture ) return;
1722 /* When continues enable = TRUE a gesture may START on MOVE event */
1723 /* We don't allow this to happen with the if-statement below. */
1724 /* When continues enable = FALSE a gesture may START on DOWN only */
1725 /* Therefor it would NOT start on MOVE event. */
1726 /* NOTE that touched list is updated AFTER this function returns */
1727 /* so (count == 0) when we get here on first touch on surface. */
1728 if ((wd->glayer_continues_enable) && (!eina_list_count(wd->touched)))
1729 return; /* Got move on mouse-over move */
1731 Momentum_Type *st = gesture->data;
1732 Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
1734 { /* Allocated once on first time */
1735 st = calloc(1, sizeof(Momentum_Type));
1737 _momentum_test_reset(gesture);
1743 /* First make avarage of all touched devices to determine center point */
1746 Pointer_Event pe_local = *pe; /* Copy pe event info to local */
1747 unsigned int cnt = 1; /* We start counter counting current pe event */
1748 EINA_LIST_FOREACH(wd->touched, l, p)
1749 if (p->device != pe_local.device)
1757 /* Compute avarage to get center point */
1761 /* If user added finger - reset gesture */
1762 if ((st->info.n) && (st->info.n < cnt))
1763 state_to_report = ELM_GESTURE_STATE_ABORT;
1765 if (st->info.n < cnt)
1768 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1771 case EVAS_CALLBACK_MOUSE_DOWN:
1772 case EVAS_CALLBACK_MULTI_DOWN:
1773 case EVAS_CALLBACK_MOUSE_MOVE:
1774 case EVAS_CALLBACK_MULTI_MOVE:
1777 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1778 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
1779 (wd->glayer_continues_enable)) /* start also on MOVE */
1780 { /* We start on MOVE when cont-enabled only */
1781 st->line_st.x = st->line_end.x = pe_local.x;
1782 st->line_st.y = st->line_end.y = pe_local.y;
1783 st->t_st_x = st->t_st_y = st->t_end = pe_local.timestamp;
1784 st->xdir = st->ydir = 0;
1785 st->info.x2 = st->info.x1 = pe_local.x;
1786 st->info.y2 = st->info.y1 = pe_local.y;
1787 st->info.tx = st->info.ty = pe_local.timestamp;
1788 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1789 &st->info, EINA_FALSE);
1790 consume_event(wd, event_info, event_type, ev_flag);
1797 /* ABORT gesture if got DOWN or MOVE event after UP+timeout */
1799 ((st->t_up + ELM_GESTURE_MULTI_TIMEOUT) < pe_local.timestamp))
1800 state_to_report = ELM_GESTURE_STATE_ABORT;
1802 if ((pe_local.timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1803 { /* Too long of a wait, reset all values */
1804 st->line_st.x = pe_local.x;
1805 st->line_st.y = pe_local.y;
1806 st->t_st_y = st->t_st_x = pe_local.timestamp;
1807 st->info.tx = st->t_st_x;
1808 st->info.ty = st->t_st_y;
1809 st->xdir = st->ydir = 0;
1814 xdir = _get_direction(st->line_st.x, pe_local.x);
1815 ydir = _get_direction(st->line_st.y, pe_local.y);
1816 if (!xdir || (xdir == (-st->xdir)))
1818 st->line_st.x = st->line_end.x;
1819 st->info.tx = st->t_st_x = st->t_end;
1823 if (!ydir || (ydir == (-st->ydir)))
1825 st->line_st.y = st->line_end.y;
1826 st->info.ty = st->t_st_y = st->t_end;
1831 st->info.x2 = st->line_end.x = pe_local.x;
1832 st->info.y2 = st->line_end.y = pe_local.y;
1833 st->t_end = pe_local.timestamp;
1834 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe_local.x, pe_local.y,
1835 st->t_st_x, st->t_st_y, pe_local.timestamp);
1836 ev_flag = _set_state(gesture, state_to_report, &st->info,
1838 consume_event(wd, event_info, event_type, ev_flag);
1842 case EVAS_CALLBACK_MOUSE_UP:
1843 case EVAS_CALLBACK_MULTI_UP:
1844 st->t_up = pe_local.timestamp; /* Record recent up event time */
1845 if ((cnt > 1) || /* Ignore if more fingers touch surface */
1846 (!st->t_st_x)) /* IGNORE if info was cleared, long press,move */
1849 if ((pe_local.timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1850 { /* Too long of a wait, reset all values */
1851 st->line_st.x = pe_local.x;
1852 st->line_st.y = pe_local.y;
1853 st->t_st_y = st->t_st_x = pe_local.timestamp;
1854 st->xdir = st->ydir = 0;
1857 st->info.x2 = pe_local.x;
1858 st->info.y2 = pe_local.y;
1859 st->line_end.x = pe_local.x;
1860 st->line_end.y = pe_local.y;
1861 st->t_end = pe_local.timestamp;
1863 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe_local.x, pe_local.y,
1864 st->t_st_x, st->t_st_y, pe_local.timestamp);
1866 if ((fabs(st->info.mx) > ELM_GESTURE_MINIMUM_MOMENTUM) ||
1867 (fabs(st->info.my) > ELM_GESTURE_MINIMUM_MOMENTUM))
1868 state_to_report = ELM_GESTURE_STATE_END;
1870 state_to_report = ELM_GESTURE_STATE_ABORT;
1872 ev_flag = _set_state(gesture, state_to_report, &st->info,
1874 consume_event(wd, event_info, event_type, ev_flag);
1883 compare_line_device(const void *data1, const void *data2)
1884 { /* Compare device component of line struct */
1885 const Line_Data *ln1 = data1;
1886 const int *device = data2;
1888 if (ln1->t_st) /* Compare only with lines that started */
1889 return (ln1->device - (*device));
1897 * This function construct line struct from input.
1898 * @param info pointer to store line momentum.
1899 * @param st line info to store input data.
1900 * @param pe The recent input event as stored in pe struct.
1902 * @ingroup Elm_Gesture_Layer
1905 _single_line_process(Elm_Gesture_Line_Info *info, Line_Data *st,
1906 Pointer_Event *pe, Evas_Callback_Type event_type)
1907 { /* Record events and set momentum for line pointed by st */
1913 case EVAS_CALLBACK_MOUSE_DOWN:
1914 case EVAS_CALLBACK_MOUSE_MOVE:
1915 case EVAS_CALLBACK_MULTI_DOWN:
1916 case EVAS_CALLBACK_MULTI_MOVE:
1918 { /* This happens only when line starts */
1919 st->line_st.x = pe->x;
1920 st->line_st.y = pe->y;
1921 st->t_st = pe->timestamp;
1922 st->device = pe->device;
1923 info->momentum.x1 = pe->x;
1924 info->momentum.y1 = pe->y;
1925 info->momentum.tx = pe->timestamp;
1926 info->momentum.ty = pe->timestamp;
1933 case EVAS_CALLBACK_MOUSE_UP:
1934 case EVAS_CALLBACK_MULTI_UP:
1935 /* IGNORE if line info was cleared, like long press, move */
1939 st->line_end.x = pe->x;
1940 st->line_end.y = pe->y;
1941 st->t_end = pe->timestamp;
1950 _line_data_reset(st);
1954 info->momentum.x2 = pe->x;
1955 info->momentum.y2 = pe->y;
1956 _set_momentum(&info->momentum, st->line_st.x, st->line_st.y, pe->x, pe->y,
1957 st->t_st, st->t_st, pe->timestamp);
1965 * This function test for (n) line gesture.
1966 * @param obj The gesture-layer object.
1967 * @param pe The recent input event as stored in pe struct.
1968 * @param event_info Original input event pointer.
1969 * @param event_type Type of original input event.
1970 * @param g_type what Gesture we are testing.
1972 * @ingroup Elm_Gesture_Layer
1975 _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
1976 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
1980 Widget_Data *wd = elm_widget_data_get(obj);
1982 Gesture_Info *gesture = wd->gesture[g_type];
1983 if (!gesture ) return;
1985 /* When continues enable = TRUE a gesture may START on MOVE event */
1986 /* We don't allow this to happen with the if-statement below. */
1987 /* When continues enable = FALSE a gesture may START on DOWN only */
1988 /* Therefor it would NOT start on MOVE event. */
1989 /* NOTE that touched list is updated AFTER this function returns */
1990 /* so (count == 0) when we get here on first touch on surface. */
1991 if ((wd->glayer_continues_enable) && (!eina_list_count(wd->touched)))
1992 return; /* Got move on mouse-over move */
1994 Line_Type *st = gesture->data;
1997 st = calloc(1, sizeof(Line_Type));
2001 Line_Data *line = NULL;
2002 Eina_List *list = st->list;
2003 unsigned cnt = eina_list_count(list);
2006 { /* list is not empty, locate this device on list */
2007 line = (Line_Data *) eina_list_search_unsorted(st->list,
2008 compare_line_device, &pe->device);
2012 { /* List is empty or device not found, new line-struct on START only */
2013 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2014 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
2015 ((wd->glayer_continues_enable) && /* START on MOVE also */
2016 ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
2017 (event_type == EVAS_CALLBACK_MULTI_MOVE))))
2018 { /* Allocate new item on START only */
2019 line = calloc(1, sizeof(Line_Data));
2020 _line_data_reset(line);
2021 list = eina_list_append(list, line);
2026 if (!line) /* This may happen on MOVE that comes before DOWN */
2027 return; /* No line-struct to work with, can't continue testing */
2029 if (_single_line_process(&st->info, line, pe, event_type)) /* update st with input */
2030 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
2032 /* Get direction and magnitude of the line */
2034 get_vector(line->line_st.x, line->line_st.y, pe->x, pe->y,
2035 &line->line_length, &angle);
2037 /* These are used later to compare lines length */
2038 Evas_Coord shortest_line_len = line->line_length;
2039 Evas_Coord longest_line_len = line->line_length;
2040 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2042 /* Now update line-state */
2044 { /* Analyze line only if line started */
2045 if (line->line_angle >= 0.0)
2046 { /* if line direction was set, we test if broke tolerance */
2047 double a = fabs(angle - line->line_angle);
2049 double d = (tan(a)) * line->line_length; /* Distance from line */
2050 #if defined(DEBUG_GESTURE_LAYER)
2051 printf("%s a=<%f> d=<%f>\n", __func__, (a * 57.295779513), d);
2053 if ((d > wd->line_distance_tolerance) || (a > wd->line_angular_tolerance))
2054 { /* Broke tolerance: abort line and start a new one */
2055 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2056 &st->info, EINA_FALSE);
2057 consume_event(wd, event_info, event_type, ev_flag);
2061 if (wd->glayer_continues_enable)
2062 { /* We may finish line if momentum is zero */
2063 /* This is for continues-gesture */
2064 if ((!st->info.momentum.mx) && (!st->info.momentum.my))
2065 { /* Finish line on zero momentum for continues gesture */
2066 line->line_end.x = pe->x;
2067 line->line_end.y = pe->y;
2068 line->t_end = pe->timestamp;
2073 { /* Record the line angle as it broke minimum length for line */
2074 if (line->line_length >= wd->line_min_length)
2075 st->info.angle = line->line_angle = angle;
2081 if (line->line_angle < 0.0)
2082 { /* it's not a line, too short more close to a tap */
2083 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2084 &st->info, EINA_FALSE);
2085 consume_event(wd, event_info, event_type, ev_flag);
2091 /* Count how many lines already started / ended */
2094 unsigned int tm_start = pe->timestamp;
2095 unsigned int tm_end = pe->timestamp;
2098 double base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
2099 Eina_Bool lines_parallel = EINA_TRUE;
2100 EINA_LIST_FOREACH(list, l, t_line)
2103 base_angle = t_line->line_angle;
2106 if (t_line->line_angle >= 0)
2107 { /* Compare angle only with lines with direction defined */
2108 if (fabs(base_angle - t_line->line_angle) >
2109 wd->line_angular_tolerance)
2110 lines_parallel = EINA_FALSE;
2114 if (t_line->line_length)
2115 { /* update only if this line is used */
2116 if (shortest_line_len > t_line->line_length)
2117 shortest_line_len = t_line->line_length;
2119 if (longest_line_len < t_line->line_length)
2120 longest_line_len = t_line->line_length;
2126 if (t_line->t_st < tm_start)
2127 tm_start = t_line->t_st;
2133 if (t_line->t_end < tm_end)
2134 tm_end = t_line->t_end;
2138 st->info.momentum.n = started;
2142 ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2143 (event_type == EVAS_CALLBACK_MULTI_DOWN)))
2144 { /* user lift one finger then starts again without line-end - ABORT */
2145 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2147 consume_event(wd, event_info, event_type, ev_flag);
2151 if (!lines_parallel)
2152 { /* Lines are NOT at same direction, abort this gesture */
2153 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2155 consume_event(wd, event_info, event_type, ev_flag);
2160 /* We report ABORT if lines length are NOT matching when fingers are up */
2161 if ((longest_line_len - shortest_line_len) > (elm_finger_size_get()*2))
2163 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2165 consume_event(wd, event_info, event_type, ev_flag);
2169 if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > wd->flick_time_limit_ms))
2170 { /* We consider FLICK as a fast line.ABORT if take too long to finish */
2171 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2173 consume_event(wd, event_info, event_type, ev_flag);
2179 case EVAS_CALLBACK_MOUSE_UP:
2180 case EVAS_CALLBACK_MULTI_UP:
2181 if ((started) && (started == ended))
2183 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2184 &st->info, EINA_FALSE);
2185 consume_event(wd, event_info, event_type, ev_flag);
2190 case EVAS_CALLBACK_MOUSE_DOWN:
2191 case EVAS_CALLBACK_MULTI_DOWN:
2192 case EVAS_CALLBACK_MOUSE_MOVE:
2193 case EVAS_CALLBACK_MULTI_MOVE:
2196 if (wd->glayer_continues_enable && (started == ended))
2197 { /* For continues gesture */
2198 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2199 &st->info, EINA_FALSE);
2200 consume_event(wd, event_info, event_type, ev_flag);
2203 { /* When continues, may START on MOVE event too */
2204 Elm_Gesture_State s = ELM_GESTURE_STATE_MOVE;
2206 /* This happens when: on n > 1 lines then one finger up */
2207 /* caused abort, then put finger down. */
2208 /* This will stop line from starting again. */
2209 /* Number of lines, MUST match touched-device in list */
2210 if ((!wd->glayer_continues_enable) &&
2211 (eina_list_count(st->list) < eina_list_count(wd->touched)))
2212 s = ELM_GESTURE_STATE_ABORT;
2214 if (gesture->state == ELM_GESTURE_STATE_UNDEFINED)
2215 s = ELM_GESTURE_STATE_START;
2217 ev_flag = _set_state(gesture, s, &st->info, EINA_TRUE);
2218 consume_event(wd, event_info, event_type, ev_flag);
2224 return; /* Unhandeld event type */
2231 * This function is used to check if rotation gesture started.
2232 * @param st Contains current rotation values from user input.
2233 * @return TRUE/FALSE if we need to set rotation START.
2235 * @ingroup Elm_Gesture_Layer
2238 rotation_broke_tolerance(Rotate_Type *st)
2240 if (st->info.base_angle < 0)
2241 return EINA_FALSE; /* Angle has to be computed first */
2243 if (st->rotate_angular_tolerance < 0)
2246 double low = st->info.base_angle - st->rotate_angular_tolerance;
2247 double high = st->info.base_angle + st->rotate_angular_tolerance;
2248 double t = st->info.angle;
2261 if (high > RAD_360DEG)
2272 #if defined(DEBUG_GESTURE_LAYER)
2273 printf("%s angle=<%f> low=<%f> high=<%f>\n", __func__, t, low, high);
2275 if ((t < low) || (t > high))
2276 { /* This marks that roation action has started */
2277 st->rotate_angular_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
2278 st->info.base_angle = st->info.angle; /* Avoid jump in angle value */
2288 * This function is used for computing the gap between fingers.
2289 * It returns the length and center point between fingers.
2291 * @param x1 first finger x location.
2292 * @param y1 first finger y location.
2293 * @param x2 second finger x location.
2294 * @param y2 second finger y location.
2295 * @param x Gets center point x cord (output)
2296 * @param y Gets center point y cord (output)
2298 * @return length of the line between (x1,y1), (x2,y2) in pixels.
2300 * @ingroup Elm_Gesture_Layer
2303 get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
2304 Evas_Coord y2, Evas_Coord *x, Evas_Coord *y)
2306 double a, b, xx, yy, gap;
2309 gap = sqrt(xx*xx + yy*yy);
2311 /* START - Compute zoom center point */
2312 /* The triangle defined as follows:
2320 * http://en.wikipedia.org/wiki/Trigonometric_functions
2321 *************************************/
2322 if (((int) xx) && ((int) yy))
2324 double A = atan((yy / xx));
2325 #if defined(DEBUG_GESTURE_LAYER)
2326 printf("xx=<%f> yy=<%f> A=<%f>\n", xx, yy, A);
2328 a = (Evas_Coord) ((gap / 2) * sin(A));
2329 b = (Evas_Coord) ((gap / 2) * cos(A));
2330 *x = (Evas_Coord) ((x2 > x1) ? (x1 + b) : (x2 + b));
2331 *y = (Evas_Coord) ((y2 > y1) ? (y1 + a) : (y2 + a));
2336 { /* horiz line, take half width */
2337 #if defined(DEBUG_GESTURE_LAYER)
2338 printf("==== HORIZ ====\n");
2340 *x = (Evas_Coord) (xx / 2);
2341 *y = (Evas_Coord) (y1);
2345 { /* vert line, take half width */
2346 #if defined(DEBUG_GESTURE_LAYER)
2347 printf("==== VERT ====\n");
2349 *x = (Evas_Coord) (x1);
2350 *y = (Evas_Coord) (yy / 2);
2353 /* END - Compute zoom center point */
2355 return (Evas_Coord) gap;
2361 * This function is used for computing zoom value.
2363 * @param st Pointer to zoom data based on user input.
2364 * @param x1 first finger x location.
2365 * @param y1 first finger y location.
2366 * @param x2 second finger x location.
2367 * @param y2 second finger y location.
2368 * @param factor zoom-factor, used to determine how fast zoom works.
2370 * @return zoom value, when 1.0 means no zoom, 0.5 half size...
2372 * @ingroup Elm_Gesture_Layer
2375 compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2376 Evas_Coord x2, Evas_Coord y2, unsigned int tm2, double zoom_finger_factor)
2379 Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
2380 &st->info.x, &st->info.y);
2382 st->info.radius = diam / 2;
2386 st->zoom_base = diam;
2387 return st->info.zoom;
2390 if (st->zoom_distance_tolerance)
2391 { /* zoom tolerance <> ZERO, means zoom action NOT started yet */
2392 if (diam < (st->zoom_base - st->zoom_distance_tolerance))
2393 { /* avoid jump with zoom value when break tolerance */
2394 st->zoom_base -= st->zoom_distance_tolerance;
2395 st->zoom_distance_tolerance = 0;
2398 if (diam > (st->zoom_base + st->zoom_distance_tolerance))
2399 { /* avoid jump with zoom value when break tolerance */
2400 st->zoom_base += st->zoom_distance_tolerance;
2401 st->zoom_distance_tolerance = 0;
2407 /* We use factor only on the difference between gap-base */
2408 /* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
2409 rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
2410 (float) st->zoom_base) * zoom_finger_factor));
2413 /* Momentum: zoom per second: (NOT YET SUPPORTED) */
2414 st->info.momentum = (((rt - 1.0) * 1000) / (tm2 - tm1));
2425 * This function handles zoom with mouse wheel.
2426 * thats a combination of wheel + CTRL key.
2427 * @param obj The gesture-layer object.
2428 * @param event_info Original input event pointer.
2429 * @param event_type Type of original input event.
2430 * @param g_type what Gesture we are testing.
2432 * @ingroup Elm_Gesture_Layer
2435 _zoom_with_wheel_test(Evas_Object *obj, void *event_info,
2436 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2438 Widget_Data *wd = elm_widget_data_get(obj);
2440 if (!wd->gesture[g_type]) return;
2442 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2443 Zoom_Type *st = gesture_zoom->data;
2444 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2446 { /* Allocated once on first time, used for zoom intermediate data */
2447 st = calloc(1, sizeof(Zoom_Type));
2448 gesture_zoom->data = st;
2449 _zoom_test_reset(gesture_zoom);
2454 case EVAS_CALLBACK_KEY_UP:
2456 Evas_Event_Key_Up *p = event_info;
2457 if ((!strcmp(p->keyname, "Control_L")) ||
2458 (!strcmp(p->keyname, "Control_R")))
2459 { /* Test if we ended a zoom gesture when releasing CTRL */
2460 if ((st->zoom_wheel) &&
2461 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2462 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2463 { /* User released CTRL after zooming */
2464 ev_flag = _set_state(gesture_zoom,
2465 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2466 consume_event(wd, event_info, event_type, ev_flag);
2474 case EVAS_CALLBACK_MOUSE_WHEEL:
2477 Elm_Gesture_State s;
2478 if (!evas_key_modifier_is_set(
2479 ((Evas_Event_Mouse_Wheel *) event_info)->modifiers,
2481 { /* if using wheel witout CTRL after starting zoom */
2482 if ((st->zoom_wheel) &&
2483 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2484 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2486 ev_flag = _set_state(gesture_zoom,
2487 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2488 consume_event(wd, event_info, event_type, ev_flag);
2493 return; /* Ignore mouse-wheel without control */
2496 /* Using mouse wheel with CTRL for zoom */
2497 if (st->zoom_wheel || (st->zoom_distance_tolerance == 0))
2498 { /* when (zoom_wheel == NULL) and (zoom_distance_tolerance == 0)
2499 we continue a zoom gesture */
2501 s = ELM_GESTURE_STATE_MOVE;
2504 { /* On first wheel event, report START */
2505 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
2506 evas_object_evas_get(wd->target), "Control");
2508 s = ELM_GESTURE_STATE_START;
2509 if (!evas_object_key_grab(wd->target, "Control_L", mask, 0, EINA_FALSE))
2510 ERR("Failed to Grabbed CTRL_L");
2511 if (!evas_object_key_grab(wd->target, "Control_R", mask, 0, EINA_FALSE))
2512 ERR("Failed to Grabbed CTRL_R");
2515 st->zoom_distance_tolerance = 0; /* Cancel tolerance */
2516 st->zoom_wheel = (Evas_Event_Mouse_Wheel *) event_info;
2517 st->info.x = st->zoom_wheel->canvas.x;
2518 st->info.y = st->zoom_wheel->canvas.y;
2520 if (st->zoom_wheel->z < 0) /* zoom in */
2521 st->info.zoom += (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2523 if (st->zoom_wheel->z > 0) /* zoom out */
2524 st->info.zoom -= (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2526 if (st->info.zoom < 0.0)
2527 st->info.zoom = 0.0;
2529 ev_flag = _set_state(gesture_zoom, s, &st->info, force);
2530 consume_event(wd, event_info, event_type, ev_flag);
2542 * This function is used to test zoom gesture.
2543 * user may combine zoom, rotation together.
2544 * so its possible that both will be detected from input.
2545 * (both are two-finger movement-oriented gestures)
2547 * @param obj The gesture-layer object.
2548 * @param event_info Pointer to recent input event.
2549 * @param event_type Recent input event type.
2550 * @param g_type what Gesture we are testing.
2552 * @ingroup Elm_Gesture_Layer
2555 _zoom_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2556 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2560 Widget_Data *wd = elm_widget_data_get(obj);
2562 if (!wd->gesture[g_type]) return;
2564 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2565 Zoom_Type *st = gesture_zoom->data;
2568 { /* Allocated once on first time, used for zoom data */
2569 st = calloc(1, sizeof(Zoom_Type));
2570 gesture_zoom->data = st;
2571 _zoom_test_reset(gesture_zoom);
2575 /* Start - new zoom testing, letting all fingers start */
2576 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2579 case EVAS_CALLBACK_MOUSE_MOVE:
2580 case EVAS_CALLBACK_MULTI_MOVE:
2581 /* if non-continues mode and gesture NOT started, ignore MOVE */
2582 if ((!wd->glayer_continues_enable) &&
2583 (!st->zoom_st.timestamp))
2586 case EVAS_CALLBACK_MOUSE_DOWN:
2587 case EVAS_CALLBACK_MULTI_DOWN:
2588 { /* Here we take care of zoom-start and zoom move */
2592 if(eina_list_count(wd->touched) > 2)
2593 { /* Process zoom only when 2 fingers on surface */
2594 ev_flag = _set_state(gesture_zoom,
2595 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2596 consume_event(wd, event_info, event_type, ev_flag);
2601 if (!st->zoom_st.timestamp)
2602 { /* Now scan touched-devices list and find other finger */
2603 EINA_LIST_FOREACH(wd->touched, l, p)
2604 { /* Device of other finger <> pe device */
2605 if (p->device != pe->device)
2609 if (!p) /* Single finger on touch */
2612 /* Record down fingers */
2613 consume_event(wd, event_info, event_type, ev_flag);
2614 memcpy(&st->zoom_st, pe, sizeof(Pointer_Event));
2615 memcpy(&st->zoom_st1, p, sizeof(Pointer_Event));
2617 /* Set mv field as well to be ready for MOVE events */
2618 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2619 memcpy(&st->zoom_mv1, p, sizeof(Pointer_Event));
2621 /* Here we have zoom_st, zoom_st1 set, report START */
2622 /* Set zoom-base after BOTH down events recorded */
2623 /* Compute length of line between fingers zoom start */
2624 st->info.zoom = 1.0;
2625 st->zoom_base = get_finger_gap_length(st->zoom_st1.x,
2626 st->zoom_st1.y, st->zoom_st.x, st->zoom_st.y,
2627 &st->info.x, &st->info.y);
2629 st->info.radius = st->zoom_base / 2;
2631 if ((gesture_zoom->state != ELM_GESTURE_STATE_START) &&
2632 (gesture_zoom->state != ELM_GESTURE_STATE_MOVE))
2633 { /* zoom started with mouse-wheel, don't report twice */
2634 ev_flag = _set_state(gesture_zoom,
2635 ELM_GESTURE_STATE_START, &st->info, EINA_FALSE);
2636 consume_event(wd, event_info, event_type, ev_flag);
2639 return; /* Zoom started */
2640 } /* End of ZOOM_START handling */
2643 /* if we got here, we have (exacally) two fingers on surfce */
2644 /* we also after START, report MOVE */
2645 /* First detect which finger moved */
2646 if (pe->device == st->zoom_mv.device)
2647 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2648 else if (pe->device == st->zoom_mv1.device)
2649 memcpy(&st->zoom_mv1, pe, sizeof(Pointer_Event));
2651 /* Compute change in zoom as fingers move */
2652 st->info.zoom = compute_zoom(st,
2653 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2654 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2655 wd->zoom_finger_factor);
2657 if (!st->zoom_distance_tolerance)
2658 { /* Zoom broke tolerance, report move */
2659 double d = st->info.zoom - st->next_step;
2663 if (d >= wd->zoom_step)
2664 { /* Report move in steps */
2665 st->next_step = st->info.zoom;
2667 ev_flag = _set_state(gesture_zoom,
2668 ELM_GESTURE_STATE_MOVE,
2669 &st->info, EINA_TRUE);
2670 consume_event(wd, event_info, event_type, ev_flag);
2672 } /* End of ZOOM_MOVE handling */
2677 case EVAS_CALLBACK_MOUSE_UP:
2678 case EVAS_CALLBACK_MULTI_UP:
2679 /* Reset timestamp of finger-up.This is used later
2680 by _zoom_test_reset() to retain finger-down data */
2681 consume_event(wd, event_info, event_type, ev_flag);
2682 if (((st->zoom_wheel) || (st->zoom_base)) &&
2683 (st->zoom_distance_tolerance == 0))
2685 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
2686 &st->info, EINA_FALSE);
2687 consume_event(wd, event_info, event_type, ev_flag);
2692 /* if we got here not a ZOOM */
2693 if (gesture_zoom->state != ELM_GESTURE_STATE_UNDEFINED)
2694 { /* Must be != undefined, if gesture started */
2695 ev_flag = _set_state(gesture_zoom,
2696 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2697 consume_event(wd, event_info, event_type, ev_flag);
2700 _zoom_test_reset(gesture_zoom);
2710 _get_rotate_properties(Rotate_Type *st,
2711 Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2712 Evas_Coord x2, Evas_Coord y2, unsigned int tm2,
2715 st->info.radius = get_finger_gap_length(x1, y1, x2, y2,
2716 &st->info.x, &st->info.y) / 2;
2718 *angle = get_angle(x1, y1, x2, y2);
2719 #if 0 /* (NOT YET SUPPORTED) */
2720 if (angle == &st->info.angle)
2721 { /* Compute momentum: TODO: bug when breaking 0, 360 values */
2722 st->info.momentum = (((*angle) - st->info.base_angle) /
2723 (fabs(tm2 - tm1))) * 1000;
2726 st->info.momentum = 0;
2736 * This function is used to test rotation gesture.
2737 * user may combine zoom, rotation together.
2738 * so its possible that both will be detected from input.
2739 * (both are two-finger movement-oriented gestures)
2741 * @param obj The gesture-layer object.
2742 * @param event_info Pointer to recent input event.
2743 * @param event_type Recent input event type.
2744 * @param g_type what Gesture we are testing.
2746 * @ingroup Elm_Gesture_Layer
2749 _rotate_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2750 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2755 Widget_Data *wd = elm_widget_data_get(obj);
2757 if (!wd->gesture[g_type]) return;
2759 Gesture_Info *gesture = wd->gesture[g_type];
2765 { /* Allocated once on first time */
2766 st = calloc(1, sizeof(Rotate_Type));
2768 _rotate_test_reset(gesture);
2772 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2775 case EVAS_CALLBACK_MOUSE_MOVE:
2776 case EVAS_CALLBACK_MULTI_MOVE:
2777 /* if non-continues mode and gesture NOT started, ignore MOVE */
2778 if ((!wd->glayer_continues_enable) &&
2779 (!st->rotate_st.timestamp))
2782 case EVAS_CALLBACK_MOUSE_DOWN:
2783 case EVAS_CALLBACK_MULTI_DOWN:
2784 { /* Here we take care of rotate-start and rotate move */
2788 if(eina_list_count(wd->touched) > 2)
2789 { /* Process rotate only when 2 fingers on surface */
2790 ev_flag = _set_state(gesture,
2791 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2792 consume_event(wd, event_info, event_type, ev_flag);
2797 if (!st->rotate_st.timestamp)
2798 { /* Now scan touched-devices list and find other finger */
2799 EINA_LIST_FOREACH(wd->touched, l, p)
2800 { /* Device of other finger <> pe device */
2801 if (p->device != pe->device)
2806 return; /* Single finger on touch */
2808 /* Record down fingers */
2809 consume_event(wd, event_info, event_type, ev_flag);
2810 memcpy(&st->rotate_st, pe, sizeof(Pointer_Event));
2811 memcpy(&st->rotate_st1, p, sizeof(Pointer_Event));
2813 /* Set mv field as well to be ready for MOVE events */
2814 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2815 memcpy(&st->rotate_mv1, p, sizeof(Pointer_Event));
2817 /* Here we have rotate_st, rotate_st1 set, report START */
2818 /* Set rotate-base after BOTH down events recorded */
2819 /* Compute length of line between fingers rotate start */
2820 _get_rotate_properties(st,
2821 st->rotate_st.x, st->rotate_st.y,
2822 st->rotate_st.timestamp,
2823 st->rotate_st1.x, st->rotate_st1.y,
2824 st->rotate_st1.timestamp, &st->info.base_angle);
2826 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
2827 &st->info, EINA_FALSE);
2828 consume_event(wd, event_info, event_type, ev_flag);
2830 return; /* Rotate started */
2831 } /* End of ROTATE_START handling */
2834 /* if we got here, we have (exacally) two fingers on surfce */
2835 /* we also after START, report MOVE */
2836 /* First detect which finger moved */
2837 if (pe->device == st->rotate_mv.device)
2838 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2839 else if (pe->device == st->rotate_mv1.device)
2840 memcpy(&st->rotate_mv1, pe, sizeof(Pointer_Event));
2842 /* Compute change in rotate as fingers move */
2843 _get_rotate_properties(st,
2844 st->rotate_mv.x, st->rotate_mv.y,
2845 st->rotate_mv.timestamp,
2846 st->rotate_mv1.x, st->rotate_mv1.y,
2847 st->rotate_mv1.timestamp, &st->info.angle);
2849 if (rotation_broke_tolerance(st))
2850 { /* Rotation broke tolerance, report move */
2851 double d = st->info.angle - st->next_step;
2855 if (d >= wd->rotate_step)
2856 { /* Report move in steps */
2857 st->next_step = st->info.angle;
2859 ev_flag = _set_state(gesture,
2860 ELM_GESTURE_STATE_MOVE, &st->info, EINA_TRUE);
2861 consume_event(wd, event_info, event_type, ev_flag);
2863 } /* End of ROTATE_MOVE handling */
2868 case EVAS_CALLBACK_MOUSE_UP:
2869 case EVAS_CALLBACK_MULTI_UP:
2870 consume_event(wd, event_info, event_type, ev_flag);
2871 /* Reset timestamp of finger-up.This is used later
2872 by rotate_test_reset() to retain finger-down data */
2873 if (st->rotate_angular_tolerance < 0)
2875 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2876 &st->info, EINA_FALSE);
2877 consume_event(wd, event_info, event_type, ev_flag);
2882 if (gesture->state != ELM_GESTURE_STATE_UNDEFINED)
2883 { /* Must be != undefined, if gesture started */
2884 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2885 &st->info, EINA_FALSE);
2886 consume_event(wd, event_info, event_type, ev_flag);
2889 _rotate_test_reset(gesture);
2900 * This function is used to save input events in an abstract struct
2901 * to be used later by getsure-testing functions.
2903 * @param data The gesture-layer object.
2904 * @param event_info Pointer to recent input event.
2905 * @param event_type Recent input event type.
2906 * @param pe The abstract data-struct (output).
2908 * @ingroup Elm_Gesture_Layer
2911 _make_pointer_event(void *data, void *event_info,
2912 Evas_Callback_Type event_type, Pointer_Event *pe)
2914 Widget_Data *wd = elm_widget_data_get(data);
2915 if (!wd) return EINA_FALSE;
2917 memset(pe, '\0', sizeof(*pe));
2920 case EVAS_CALLBACK_MOUSE_DOWN:
2921 pe->x = ((Evas_Event_Mouse_Down *) event_info)->canvas.x;
2922 pe->y = ((Evas_Event_Mouse_Down *) event_info)->canvas.y;
2923 pe->timestamp = ((Evas_Event_Mouse_Down *) event_info)->timestamp;
2924 pe->device = ELM_MOUSE_DEVICE;
2927 case EVAS_CALLBACK_MOUSE_UP:
2928 pe->x = ((Evas_Event_Mouse_Up *) event_info)->canvas.x;
2929 pe->y = ((Evas_Event_Mouse_Up *) event_info)->canvas.y;
2930 pe->timestamp = ((Evas_Event_Mouse_Up *) event_info)->timestamp;
2931 pe->device = ELM_MOUSE_DEVICE;
2934 case EVAS_CALLBACK_MOUSE_MOVE:
2935 pe->x = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.x;
2936 pe->y = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.y;
2937 pe->timestamp = ((Evas_Event_Mouse_Move *) event_info)->timestamp;
2938 pe->device = ELM_MOUSE_DEVICE;
2941 case EVAS_CALLBACK_MULTI_DOWN:
2942 pe->x = ((Evas_Event_Multi_Down *) event_info)->canvas.x;
2943 pe->y = ((Evas_Event_Multi_Down *) event_info)->canvas.y;
2944 pe->timestamp = ((Evas_Event_Multi_Down *) event_info)->timestamp;
2945 pe->device = ((Evas_Event_Multi_Down *) event_info)->device;
2948 case EVAS_CALLBACK_MULTI_UP:
2949 pe->x = ((Evas_Event_Multi_Up *) event_info)->canvas.x;
2950 pe->y = ((Evas_Event_Multi_Up *) event_info)->canvas.y;
2951 pe->timestamp = ((Evas_Event_Multi_Up *) event_info)->timestamp;
2952 pe->device = ((Evas_Event_Multi_Up *) event_info)->device;
2955 case EVAS_CALLBACK_MULTI_MOVE:
2956 pe->x = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.x;
2957 pe->y = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.y;
2958 pe->timestamp = ((Evas_Event_Multi_Move *) event_info)->timestamp;
2959 pe->device = ((Evas_Event_Multi_Move *) event_info)->device;
2966 pe->event_type = event_type;
2973 * This function restartes line, flick, zoom and rotate gestures
2974 * when gesture-layer continues-gestures enabled.
2975 * Example of continues-gesture:
2976 * When doing a line, user stops moving finger but keeps fingers on touch.
2977 * This will cause line-end, then as user continues moving his finger
2978 * it re-starts line gesture.
2979 * When continue mode is disabled, user has to lift finger from touch
2980 * to end a gesture. Them touch-again to start a new one.
2982 * @param data The gesture-layer object.
2983 * @param wd gesture layer widget data.
2984 * @param states_reset flag that marks gestures were reset in history clear.
2986 * @ingroup Elm_Gesture_Layer
2988 void continues_gestures_restart(void *data, Eina_Bool states_reset)
2990 Widget_Data *wd = elm_widget_data_get(data);
2993 /* Run through events to restart gestures */
2995 Eina_Bool n_momentum, n_lines, n_flicks, zoom, rotate;
2996 /* We turn-on flag for finished, aborted, not-started gestures */
2997 g = wd->gesture[ELM_GESTURE_MOMENTUM];
2998 n_momentum = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2999 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3002 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
3003 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3007 g = wd->gesture[ELM_GESTURE_N_LINES];
3008 n_lines = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3009 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3012 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
3013 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3017 g = wd->gesture[ELM_GESTURE_N_FLICKS];
3018 n_flicks = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3019 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3022 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
3023 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3027 g = wd->gesture[ELM_GESTURE_ZOOM];
3028 zoom = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3029 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3032 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
3033 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3037 g = wd->gesture[ELM_GESTURE_ROTATE];
3038 rotate = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3039 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3042 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
3043 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3051 * This function the core-function where input handling is done.
3052 * Here we get user input and stream it to gesture testing.
3053 * We notify user about any gestures with new state:
3055 * START - gesture started.
3056 * MOVE - gesture is ongoing.
3057 * END - gesture was completed.
3058 * ABORT - gesture was aborted after START, MOVE (will NOT be completed)
3060 * We also check if a gesture was detected, then reset event history
3061 * If no gestures were found we reset gesture test flag
3062 * after streaming event-history to widget.
3063 * (stream to the widget all events not consumed as a gesture)
3065 * @param data The gesture-layer object.
3066 * @param event_info Pointer to recent input event.
3067 * @param event_type Recent input event type.
3069 * @ingroup Elm_Gesture_Layer
3072 _event_process(void *data, Evas_Object *obj __UNUSED__,
3073 void *event_info, Evas_Callback_Type event_type)
3076 Pointer_Event *pe = NULL;
3077 Widget_Data *wd = elm_widget_data_get(data);
3080 #if defined(DEBUG_GESTURE_LAYER)
3083 printf("Gesture | State | is tested\n");
3084 for(i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
3088 printf(" %d %d %d\n", i, g->state, g->test);
3092 /* Start testing candidate gesture from here */
3093 if (_make_pointer_event(data, event_info, event_type, &_pe))
3096 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
3097 _n_long_tap_test(data, pe, event_info, event_type,
3098 ELM_GESTURE_N_LONG_TAPS);
3100 /* This takes care of single, double and tripple tap */
3101 _tap_gestures_test(data, pe, event_info, event_type);
3103 if (IS_TESTED(ELM_GESTURE_MOMENTUM))
3104 _momentum_test(data, pe, event_info, event_type,
3105 ELM_GESTURE_MOMENTUM);
3107 if (IS_TESTED(ELM_GESTURE_N_LINES))
3108 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_LINES);
3110 if (IS_TESTED(ELM_GESTURE_N_FLICKS))
3111 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_FLICKS);
3113 if (IS_TESTED(ELM_GESTURE_ZOOM))
3114 _zoom_test(data, pe, event_info, event_type, ELM_GESTURE_ZOOM);
3116 if (IS_TESTED(ELM_GESTURE_ZOOM))
3117 _zoom_with_wheel_test(data, event_info, event_type, ELM_GESTURE_ZOOM);
3119 if (IS_TESTED(ELM_GESTURE_ROTATE))
3120 _rotate_test(data, pe, event_info, event_type, ELM_GESTURE_ROTATE);
3122 if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
3123 _event_history_add(data, event_info, event_type);
3124 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3125 (event_type == EVAS_CALLBACK_MULTI_UP))
3127 Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type);
3130 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD);
3131 _event_history_add(data, event_info, event_type);
3135 /* we maintain list of touched devices */
3136 /* We also use move to track current device x.y pos */
3137 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
3138 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
3139 (event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
3140 (event_type == EVAS_CALLBACK_MULTI_MOVE))
3142 wd->touched = _add_touched_device(wd->touched, pe);
3144 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3145 (event_type == EVAS_CALLBACK_MULTI_UP))
3147 wd->touched = _remove_touched_device(wd->touched, pe);
3150 /* Report current states and clear history if needed */
3151 Eina_Bool states_reset = _clear_if_finished(data);
3152 if (wd->glayer_continues_enable)
3153 continues_gestures_restart(data, states_reset);
3158 * For all _mouse_* / multi_* functions wethen send this event to
3159 * _event_process function.
3161 * @param data The gesture-layer object.
3162 * @param event_info Pointer to recent input event.
3164 * @ingroup Elm_Gesture_Layer
3167 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3170 Widget_Data *wd = elm_widget_data_get(data);
3172 if (((Evas_Event_Mouse_Down *) event_info)->button != 1)
3173 return; /* We only process left-click at the moment */
3175 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_DOWN);
3179 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3182 Widget_Data *wd = elm_widget_data_get(data);
3185 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_MOVE);
3189 _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3192 Widget_Data *wd = elm_widget_data_get(data);
3195 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_DOWN);
3199 _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3202 Widget_Data *wd = elm_widget_data_get(data);
3205 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_UP);
3209 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3212 Widget_Data *wd = elm_widget_data_get(data);
3215 if (((Evas_Event_Mouse_Up *) event_info)->button != 1)
3216 return; /* We only process left-click at the moment */
3218 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_UP);
3222 _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3225 Widget_Data *wd = elm_widget_data_get(data);
3228 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_WHEEL);
3232 _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3235 Widget_Data *wd = elm_widget_data_get(data);
3238 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_DOWN);
3242 _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3245 Widget_Data *wd = elm_widget_data_get(data);
3248 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_MOVE);
3252 _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3255 Widget_Data *wd = elm_widget_data_get(data);
3258 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_UP);
3262 elm_gesture_layer_hold_events_get(Evas_Object *obj)
3264 Widget_Data *wd = elm_widget_data_get(obj);
3265 if (!wd) return EINA_FALSE;
3267 return !wd->repeat_events;
3271 elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool r)
3273 Widget_Data *wd = elm_widget_data_get(obj);
3276 wd->repeat_events = !r;
3280 elm_gesture_layer_zoom_step_set(Evas_Object *obj, double s)
3282 Widget_Data *wd = elm_widget_data_get(obj);
3292 elm_gesture_layer_rotate_step_set(Evas_Object *obj, double s)
3294 Widget_Data *wd = elm_widget_data_get(obj);
3300 wd->rotate_step = s;
3304 elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *t)
3306 Widget_Data *wd = elm_widget_data_get(obj);
3307 if (!wd) return EINA_FALSE;
3312 /* if was attached before, unregister callbacks first */
3314 _unregister_callbacks(obj);
3318 _register_callbacks(obj);
3323 elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Types idx,
3324 Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data)
3326 Widget_Data *wd = elm_widget_data_get(obj);
3330 if (!wd->gesture[idx])
3331 wd->gesture[idx] = calloc(1, sizeof(Gesture_Info));
3332 if (!wd->gesture[idx]) return;
3334 p = wd->gesture[idx];
3337 p->fn[cb_type].cb = cb;
3338 p->fn[cb_type].user_data = data;
3339 p->state = ELM_GESTURE_STATE_UNDEFINED;
3344 _disable_hook(Evas_Object *obj)
3346 if (elm_widget_disabled_get(obj))
3347 _unregister_callbacks(obj);
3349 _register_callbacks(obj);
3353 elm_gesture_layer_add(Evas_Object *parent)
3359 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3361 ELM_SET_WIDTYPE(widtype, "gesture_layer");
3362 elm_widget_type_set(obj, "gesture_layer");
3363 elm_widget_sub_object_add(parent, obj);
3364 elm_widget_data_set(obj, wd);
3365 elm_widget_del_hook_set(obj, _del_hook);
3366 elm_widget_disable_hook_set(obj, _disable_hook);
3369 wd->line_min_length =_elm_config->glayer_line_min_length * elm_finger_size_get();
3370 wd->zoom_distance_tolerance = _elm_config->glayer_zoom_distance_tolerance * elm_finger_size_get();
3371 wd->line_distance_tolerance = _elm_config->glayer_line_distance_tolerance * elm_finger_size_get();
3372 wd->zoom_finger_factor = _elm_config->glayer_zoom_finger_factor;
3373 wd->zoom_wheel_factor = _elm_config->glayer_zoom_wheel_factor; /* mouse wheel zoom steps */
3374 wd->rotate_angular_tolerance = _elm_config->glayer_rotate_angular_tolerance;
3375 wd->line_angular_tolerance = _elm_config->glayer_line_angular_tolerance;
3376 wd->flick_time_limit_ms = _elm_config->glayer_flick_time_limit_ms;
3377 wd->long_tap_start_timeout = _elm_config->glayer_long_tap_start_timeout;
3378 wd->repeat_events = EINA_TRUE;
3379 wd->glayer_continues_enable = _elm_config->glayer_continues_enable;
3381 #if defined(DEBUG_GESTURE_LAYER)
3382 printf("size of Gestures = <%d>\n", sizeof(wd->gesture));
3383 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);
3385 memset(wd->gesture, 0, sizeof(wd->gesture));