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_DELAY 25
10 #define ELM_GESTURE_MOMENTUM_TIMEOUT 50
11 #define ELM_GESTURE_MULTI_TIMEOUT 50
12 #define ELM_GESTURE_MINIMUM_MOMENTUM 0.001
14 /* Some Trigo values */
15 #define RAD_90DEG M_PI_2
16 #define RAD_180DEG M_PI
17 #define RAD_270DEG (M_PI_2 * 3)
18 #define RAD_360DEG (M_PI * 2)
19 /* #define DEBUG_GESTURE_LAYER 1 */
21 #define RAD2DEG(x) ((x) * 57.295779513)
22 #define DEG2RAD(x) ((x) / 57.295779513)
25 _glayer_bufdup(void *buf, size_t size)
32 #define COPY_EVENT_INFO(EV) _glayer_bufdup(EV, sizeof(*EV))
35 #define SET_TEST_BIT(P) do { \
36 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; \
39 #define IS_TESTED(T) ((wd->gesture[T]) ? wd->gesture[T]->test : EINA_FALSE)
45 * Struct holds callback information.
47 * @ingroup Elm_Gesture_Layer
51 void *user_data; /**< Holds user data to CB (like sd) */
52 Elm_Gesture_Event_Cb cb;
59 * type for callback information
61 * @ingroup Elm_Gesture_Layer
63 typedef struct _Func_Data Func_Data;
68 * @struct _Gesture_Info
69 * Struct holds gesture info
71 * @ingroup Elm_Gesture_Layer
76 void *data; /**< Holds gesture intemidiate processing data */
77 Func_Data fn[ELM_GESTURE_STATE_ABORT + 1]; /**< Callback info for states */
78 Elm_Gesture_Types g_type; /**< gesture type */
79 Elm_Gesture_State state; /**< gesture state */
80 void *info; /**< Data for the state callback */
81 Eina_Bool test; /**< if true this gesture should be tested on input */
87 * @typedef Gesture_Info
88 * Type for _Gesture_Info
90 * @ingroup Elm_Gesture_Layer
92 typedef struct _Gesture_Info Gesture_Info;
97 * @struct _Event_History
98 * Struct holds event history.
99 * These events are repeated if no gesture found.
101 * @ingroup Elm_Gesture_Layer
103 struct _Event_History
107 Evas_Callback_Type event_type;
113 * @typedef Event_History
114 * Type for _Event_History
116 * @ingroup Elm_Gesture_Layer
118 typedef struct _Event_History Event_History;
123 * @struct _Pointer_Event
124 * Struct holds pointer-event info
125 * This is a generic pointer event structure
127 * @ingroup Elm_Gesture_Layer
129 struct _Pointer_Event
132 unsigned int timestamp;
134 Evas_Callback_Type event_type;
140 * @typedef Pointer_Event
141 * Type for generic pointer event structure
143 * @ingroup Elm_Gesture_Layer
145 typedef struct _Pointer_Event Pointer_Event;
147 /* All *Type structs hold result for the user in 'info' field
148 * The rest is gesture processing intermediate data.
149 * NOTE: info field must be FIRST in the struct.
150 * This is used when reporting ABORT in event_history_clear() */
153 Elm_Gesture_Taps_Info info;
156 unsigned int n_taps_needed;
160 typedef struct _Taps_Type Taps_Type;
162 struct _Long_Tap_Type
164 Elm_Gesture_Taps_Info info;
167 unsigned int max_touched;
168 Ecore_Timer *timeout; /* When this expires, long tap STARTed */
171 typedef struct _Long_Tap_Type Long_Tap_Type;
173 struct _Momentum_Type
174 { /* Fields used by _line_test() */
175 Elm_Gesture_Momentum_Info info;
176 Evas_Coord_Point line_st;
177 Evas_Coord_Point line_end;
178 unsigned int t_st_x; /* Time start on X */
179 unsigned int t_st_y; /* Time start on Y */
180 unsigned int t_end; /* Time end */
181 unsigned int t_up; /* Recent up event time */
184 typedef struct _Momentum_Type Momentum_Type;
188 Evas_Coord_Point line_st;
189 Evas_Coord_Point line_end;
190 Evas_Coord line_length;
191 unsigned int t_st; /* Time start */
192 unsigned int t_end; /* Time end */
194 double line_angle; /* Current angle of line */
196 typedef struct _Line_Data Line_Data;
199 { /* Fields used by _line_test() */
200 Elm_Gesture_Line_Info info;
201 Eina_List *list; /* List of Line_Data */
203 typedef struct _Line_Type Line_Type;
206 { /* Fields used by _zoom_test() */
207 Elm_Gesture_Zoom_Info info;
208 Pointer_Event zoom_st;
209 Pointer_Event zoom_mv;
210 Pointer_Event zoom_st1;
211 Pointer_Event zoom_mv1;
212 Evas_Event_Mouse_Wheel *zoom_wheel;
213 Evas_Coord zoom_base; /* Holds gap between fingers on zoom-start */
214 Evas_Coord zoom_distance_tolerance;
215 unsigned int m_st_tm; /* momentum start time */
216 unsigned int m_prev_tm; /* momentum prev time */
217 int dir; /* Direction: 1=zoom-in, (-1)=zoom-out */
218 double m_base; /* zoom value when momentum starts */
221 typedef struct _Zoom_Type Zoom_Type;
224 { /* Fields used by _rotation_test() */
225 Elm_Gesture_Rotate_Info info;
226 Pointer_Event rotate_st;
227 Pointer_Event rotate_mv;
228 Pointer_Event rotate_st1;
229 Pointer_Event rotate_mv1;
230 unsigned int prev_momentum_tm; /* timestamp of prev_momentum */
231 double prev_momentum; /* Snapshot of momentum 0.01 sec ago */
232 double accum_momentum;
233 double rotate_angular_tolerance;
236 typedef struct _Rotate_Type Rotate_Type;
240 Evas_Object *target; /* Target Widget */
241 Event_History *event_history_list;
244 Evas_Coord zoom_distance_tolerance;
245 Evas_Coord line_distance_tolerance;
246 double line_angular_tolerance;
247 double zoom_wheel_factor; /* mouse wheel zoom steps */
248 double zoom_finger_factor; /* used for zoom factor */
249 double rotate_angular_tolerance;
250 unsigned int flick_time_limit_ms;
251 double long_tap_start_timeout;
252 Eina_Bool glayer_continues_enable;
257 Gesture_Info *gesture[ELM_GESTURE_LAST];
258 Ecore_Timer *dbl_timeout; /* When this expires, dbl click/taps ABORTed */
259 Eina_List *pending; /* List of devices need to refeed *UP event */
260 Eina_List *touched; /* Information of touched devices */
262 Eina_Bool repeat_events : 1;
264 typedef struct _Widget_Data Widget_Data;
266 static const char *widtype = NULL;
267 static void _del_hook(Evas_Object *obj);
269 static Eina_Bool _event_history_clear(Evas_Object *obj);
270 static void _reset_states(Widget_Data *wd);
271 static void _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
272 static void _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
273 static void _zoom_with_wheel_test(Evas_Object *obj, void *event_info, Evas_Callback_Type event_type, Elm_Gesture_Types g_type);
274 static void _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
275 static void _mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
276 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
277 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
279 static void _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
280 static void _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
281 static void _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
283 /* START - Functions to manage touched-device list */
286 * This function is used to find if device is touched
288 * @ingroup Elm_Gesture_Layer
291 compare_device(const void *data1, const void *data2)
292 { /* Compare the two device numbers */
293 return (((Pointer_Event *) data1)->device -((Pointer_Event *) data2)->device);
299 * Remove Pointer Event from touched device list
300 * @param list Pointer to touched device list.
301 * @param Pointer_Event Pointer to PE.
303 * @ingroup Elm_Gesture_Layer
306 _remove_touched_device(Eina_List *list, Pointer_Event *pe)
308 Eina_List *lst = NULL;
309 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
312 lst = eina_list_remove(list, p);
323 * Recoed Pointer Event in touched device list
324 * Note: This fuction allocates memory for PE event
325 * This memory is released in _remove_touched_device()
326 * @param list Pointer to touched device list.
327 * @param Pointer_Event Pointer to PE.
329 * @ingroup Elm_Gesture_Layer
332 _add_touched_device(Eina_List *list, Pointer_Event *pe)
334 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
336 { /* We like to track device touch-position, overwrite info */
337 memcpy(p, pe, sizeof(Pointer_Event));
341 if ((pe->event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
342 (pe->event_type == EVAS_CALLBACK_MULTI_DOWN))
343 { /* Add touched device on DOWN event only */
344 p = malloc(sizeof(Pointer_Event));
345 /* Freed in _remove_touched_device() */
346 memcpy(p, pe, sizeof(Pointer_Event));
347 return eina_list_append(list, p);
352 /* END - Functions to manage touched-device list */
358 * @param event_info pointer to event.
360 * @ingroup Elm_Gesture_Layer
362 static Evas_Event_Flags
363 _get_event_flag(void *event_info, Evas_Callback_Type event_type)
367 case EVAS_CALLBACK_MOUSE_IN:
368 return ((Evas_Event_Mouse_In *) event_info)->event_flags;
369 case EVAS_CALLBACK_MOUSE_OUT:
370 return ((Evas_Event_Mouse_Out *) event_info)->event_flags;
371 case EVAS_CALLBACK_MOUSE_DOWN:
372 return ((Evas_Event_Mouse_Down *) event_info)->event_flags;
373 case EVAS_CALLBACK_MOUSE_MOVE:
374 return ((Evas_Event_Mouse_Move *) event_info)->event_flags;
375 case EVAS_CALLBACK_MOUSE_UP:
376 return ((Evas_Event_Mouse_Up *) event_info)->event_flags;
377 case EVAS_CALLBACK_MOUSE_WHEEL:
378 return ((Evas_Event_Mouse_Wheel *) event_info)->event_flags;
379 case EVAS_CALLBACK_MULTI_DOWN:
380 return ((Evas_Event_Multi_Down *) event_info)->event_flags;
381 case EVAS_CALLBACK_MULTI_MOVE:
382 return ((Evas_Event_Multi_Move *) event_info)->event_flags;
383 case EVAS_CALLBACK_MULTI_UP:
384 return ((Evas_Event_Multi_Up *) event_info)->event_flags;
385 case EVAS_CALLBACK_KEY_DOWN:
386 return ((Evas_Event_Key_Down *) event_info)->event_flags;
387 case EVAS_CALLBACK_KEY_UP:
388 return ((Evas_Event_Key_Up *) event_info)->event_flags;
390 return EVAS_EVENT_FLAG_NONE;
397 * Sets event flag to value returned from user callback
398 * @param wd Widget Data
399 * @param event_info pointer to event.
400 * @param event_type what type was ev (mouse down, etc...)
401 * @param ev_flags event flags
403 * @ingroup Elm_Gesture_Layer
406 consume_event(Widget_Data *wd, void *event_info,
407 Evas_Callback_Type event_type, Evas_Event_Flags ev_flags)
408 { /* Mark EVAS_EVENT_FLAG_ON_HOLD on events that are used by gesture layer */
409 /* ev_flags != EVAS_EVENT_FLAG_NONE means target used event and g-layer */
410 /* should not refeed this event. */
412 return; /* This happens when restarting gestures */
414 if ((ev_flags) || (!wd->repeat_events))
418 case EVAS_CALLBACK_MOUSE_DOWN:
419 ((Evas_Event_Mouse_Down *) event_info)->event_flags |= ev_flags;
421 case EVAS_CALLBACK_MOUSE_MOVE:
422 ((Evas_Event_Mouse_Move *) event_info)->event_flags |= ev_flags;
424 case EVAS_CALLBACK_MOUSE_UP:
425 ((Evas_Event_Mouse_Up *) event_info)->event_flags |= ev_flags;
427 case EVAS_CALLBACK_MOUSE_WHEEL:
428 ((Evas_Event_Mouse_Wheel *) event_info)->event_flags |= ev_flags;
430 case EVAS_CALLBACK_MULTI_DOWN:
431 ((Evas_Event_Multi_Down *) event_info)->event_flags |= ev_flags;
433 case EVAS_CALLBACK_MULTI_MOVE:
434 ((Evas_Event_Multi_Move *) event_info)->event_flags |= ev_flags;
436 case EVAS_CALLBACK_MULTI_UP:
437 ((Evas_Event_Multi_Up *) event_info)->event_flags |= ev_flags;
439 case EVAS_CALLBACK_KEY_DOWN:
440 ((Evas_Event_Key_Down *) event_info)->event_flags |= ev_flags;
442 case EVAS_CALLBACK_KEY_UP:
443 ((Evas_Event_Key_Up *) event_info)->event_flags |= ev_flags;
454 * Report current state of a gesture by calling user callback.
455 * @param gesture what gesture state we report.
456 * @param info inforamtion for user callback
458 * @ingroup Elm_Gesture_Layer
460 static Evas_Event_Flags
461 _report_state(Gesture_Info *gesture, void *info)
462 { /* We report current state (START, MOVE, END, ABORT), once */
463 #if defined(DEBUG_GESTURE_LAYER)
464 printf("%s reporting gesture=<%d> state=<%d>\n" , __func__, gesture->g_type,
467 if ((gesture->state != ELM_GESTURE_STATE_UNDEFINED) &&
468 (gesture->fn[gesture->state].cb))
469 { /* Fill state-info struct and send ptr to user callback */
470 return gesture->fn[gesture->state].cb(
471 gesture->fn[gesture->state].user_data, info);
474 return EVAS_EVENT_FLAG_NONE;
480 * Update state for a given gesture.
481 * We may update gesture state to:
482 * UNDEFINED - current input did not start gesure yet.
483 * START - gesture started according to input.
484 * MOVE - gusture in progress.
485 * END - gesture completed according to input.
486 * ABORT - input does not matches gesure.
487 * note that we may move from UNDEFINED to ABORT
488 * because we may detect that gesture will not START
489 * with a given input.
491 * @param g given gesture to change state.
492 * @param s gesure new state.
493 * @param info buffer to be sent to user callback on report_state.
494 * @param force makes report_state to report the new-state even
495 * if its same as current state. Works for MOVE - gesture in progress.
497 * @ingroup Elm_Gesture_Layer
499 static Evas_Event_Flags
500 _set_state(Gesture_Info *g, Elm_Gesture_State s,
501 void *info, Eina_Bool force)
503 Elm_Gesture_State old_state;
504 if ((g->state == s) && (!force))
505 return EVAS_EVENT_FLAG_NONE;
507 old_state = g->state;
510 g->info = info; /* Information for user callback */
511 if ((g->state == ELM_GESTURE_STATE_ABORT) ||
512 (g->state == ELM_GESTURE_STATE_END))
513 g->test = EINA_FALSE;
515 if ((g->state != ELM_GESTURE_STATE_UNDEFINED) &&
516 (!((old_state == ELM_GESTURE_STATE_UNDEFINED) &&
517 (s == ELM_GESTURE_STATE_ABORT))))
518 return _report_state(g, g->info);
520 return EVAS_EVENT_FLAG_NONE;
526 * This resets all gesture states and sets test-bit.
527 * this is used for restarting gestures to listen to input.
528 * happens after we complete a gesture or no gesture was detected.
529 * @param wd Widget data of the gesture-layer object.
531 * @ingroup Elm_Gesture_Layer
534 _reset_states(Widget_Data *wd)
538 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
543 _set_state(p, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
552 * if gesture was NOT detected AND we only have gestures in ABORT state
553 * we clear history immediately to be ready for input.
555 * @param obj The gesture-layer object.
556 * @return TRUE on event history_clear
558 * @ingroup Elm_Gesture_Layer
561 _clear_if_finished(Evas_Object *obj)
563 Widget_Data *wd = elm_widget_data_get(obj);
564 if (!wd) return EINA_FALSE;
567 /* Clear history if all we have aborted gestures */
568 Eina_Bool reset_s = EINA_TRUE, all_undefined = EINA_TRUE;
569 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
570 { /* If no gesture started and all we have aborted gestures, reset all */
571 Gesture_Info *p = wd->gesture[i];
572 if ((p) && (p->state != ELM_GESTURE_STATE_UNDEFINED))
574 if ((p->state == ELM_GESTURE_STATE_START) ||
575 (p->state == ELM_GESTURE_STATE_MOVE))
576 reset_s = EINA_FALSE;
578 all_undefined = EINA_FALSE;
582 if (reset_s && (!all_undefined))
583 return _event_history_clear(obj);
589 _inside(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
591 int w = elm_finger_size_get() >> 1; /* Finger size devided by 2 */
607 /* All *test_reset() funcs are called to clear
608 * gesture intermediate data.
609 * This happens when we need to reset our tests.
610 * for example when gesture is detected or all ABORTed. */
612 _tap_gestures_test_reset(Gesture_Info *gesture)
617 Widget_Data *wd = elm_widget_data_get(gesture->obj);
618 wd->dbl_timeout = NULL;
625 EINA_LIST_FREE(((Taps_Type *) gesture->data)->l, data)
626 EINA_LIST_FREE(data, pe)
629 memset(gesture->data, 0, sizeof(Taps_Type));
632 /* All *test_reset() funcs are called to clear
633 * gesture intermediate data.
634 * This happens when we need to reset our tests.
635 * for example when gesture is detected or all ABORTed. */
637 _n_long_tap_test_reset(Gesture_Info *gesture)
645 Long_Tap_Type *st = gesture->data;
648 EINA_LIST_FOREACH(st->touched, l, p)
651 eina_list_free(st->touched);
652 if (st->timeout) ecore_timer_del(st->timeout);
653 memset(gesture->data, 0, sizeof(Long_Tap_Type));
657 _momentum_test_reset(Gesture_Info *gesture)
665 memset(gesture->data, 0, sizeof(Momentum_Type));
669 _line_data_reset(Line_Data *st)
674 memset(st, 0, sizeof(Line_Data));
675 st->line_angle = ELM_GESTURE_NEGATIVE_ANGLE;
679 _line_test_reset(Gesture_Info *gesture)
687 Line_Type *st = gesture->data;
688 Eina_List *list = st->list;
691 EINA_LIST_FOREACH(list, l, t_line)
694 eina_list_free(list);
699 _zoom_test_reset(Gesture_Info *gesture)
707 Widget_Data *wd = elm_widget_data_get(gesture->obj);
708 Zoom_Type *st = gesture->data;
709 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
710 evas_object_evas_get(wd->target), "Control");
711 evas_object_key_ungrab(wd->target, "Control_L", mask, 0);
712 evas_object_key_ungrab(wd->target, "Control_R", mask, 0);
714 memset(st, 0, sizeof(Zoom_Type));
715 st->zoom_distance_tolerance = wd->zoom_distance_tolerance;
720 _rotate_test_reset(Gesture_Info *gesture)
728 Widget_Data *wd = elm_widget_data_get(gesture->obj);
729 Rotate_Type *st = gesture->data;
731 memset(st, 0, sizeof(Rotate_Type));
732 st->info.base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
733 st->rotate_angular_tolerance = wd->rotate_angular_tolerance;
740 * We register callbacks when gesture layer is attached to an object
741 * or when its enabled after disable.
743 * @param obj The gesture-layer object.
745 * @ingroup Elm_Gesture_Layer
748 _register_callbacks(Evas_Object *obj)
750 Widget_Data *wd = elm_widget_data_get(obj);
755 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
757 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
759 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_UP,
762 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
765 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_DOWN,
767 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_MOVE,
769 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_UP,
772 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_DOWN,
774 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_UP,
782 * We unregister callbacks when gesture layer is disabled.
784 * @param obj The gesture-layer object.
786 * @ingroup Elm_Gesture_Layer
789 _unregister_callbacks(Evas_Object *obj)
791 Widget_Data *wd = elm_widget_data_get(obj);
796 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
798 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
800 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_UP,
803 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
806 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_DOWN,
809 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_MOVE,
812 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_UP,
815 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_DOWN,
817 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_UP,
822 /* START - Event history list handling functions */
825 * This function is used to find if device number
826 * is found in a list of devices.
827 * The list contains devices for refeeding *UP event
829 * @ingroup Elm_Gesture_Layer
832 device_in_pending_list(const void *data1, const void *data2)
833 { /* Compare the two device numbers */
834 return (((intptr_t) data1) - ((intptr_t) data2));
840 * This functions adds device to refeed-pending device list
841 * @ingroup Elm_Gesture_Layer
844 _add_device_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
846 int device = ELM_MOUSE_DEVICE;
849 case EVAS_CALLBACK_MOUSE_DOWN:
851 case EVAS_CALLBACK_MULTI_DOWN:
852 device = ((Evas_Event_Multi_Down *) event)->device;
858 if (!eina_list_search_unsorted_list(list, device_in_pending_list,
861 return eina_list_append(list, (intptr_t*) device);
870 * This functions returns pending-device node
871 * @ingroup Elm_Gesture_Layer
874 _device_is_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
876 int device = ELM_MOUSE_DEVICE;
879 case EVAS_CALLBACK_MOUSE_UP:
881 case EVAS_CALLBACK_MULTI_UP:
882 device = ((Evas_Event_Multi_Up *) event)->device;
888 return eina_list_search_unsorted_list(list, device_in_pending_list,
889 (intptr_t *) device);
895 * This function reports ABORT to all none-detected gestures
896 * Then resets test bits for all desired gesures
897 * and clears input-events history.
898 * note: if no gesture was detected, events from history list
899 * are streamed to the widget because it's unused by layer.
900 * user may cancel refeed of events by setting repeat events.
902 * @param obj The gesture-layer object.
904 * @ingroup Elm_Gesture_Layer
907 _event_history_clear(Evas_Object *obj)
909 Widget_Data *wd = elm_widget_data_get(obj);
910 if (!wd) return EINA_FALSE;
914 Evas *e = evas_object_evas_get(obj);
915 Eina_Bool gesture_found = EINA_FALSE;
916 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
921 if (p->state == ELM_GESTURE_STATE_END)
922 gesture_found = EINA_TRUE;
924 { /* Report ABORT to all gestures that still not finished */
925 _set_state(p, ELM_GESTURE_STATE_ABORT, wd->gesture[i]->info,
931 _reset_states(wd); /* we are ready to start testing for gestures again */
933 /* Clear all gestures intermediate data */
934 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
935 { /* We do not clear a long-tap gesture if fingers still on surface */
936 /* and gesture timer still pending to test gesture state */
937 Long_Tap_Type *st = wd->gesture[ELM_GESTURE_N_LONG_TAPS]->data;
938 if ((st) && /* st not allocated if clear occurs before 1st input */
939 ((!eina_list_count(st->touched)) || (!st->timeout)))
940 _n_long_tap_test_reset(wd->gesture[ELM_GESTURE_N_LONG_TAPS]);
945 ecore_timer_del(wd->dbl_timeout);
946 wd->dbl_timeout = NULL;
949 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_TAPS]);
950 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
951 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
952 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
953 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
954 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
955 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
956 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
958 /* Disable gesture layer so refeeded events won't be consumed by it */
959 _unregister_callbacks(obj);
960 while (wd->event_history_list)
963 t = wd->event_history_list;
964 Eina_List *pending = _device_is_pending(wd->pending,
965 wd->event_history_list->event,
966 wd->event_history_list->event_type);
968 /* Refeed events if no gesture matched input */
969 if (pending || ((!gesture_found) && (!wd->repeat_events)))
971 evas_event_refeed_event(e, wd->event_history_list->event,
972 wd->event_history_list->event_type);
976 wd->pending = eina_list_remove_list(wd->pending, pending);
980 wd->pending = _add_device_pending(wd->pending,
981 wd->event_history_list->event,
982 wd->event_history_list->event_type);
986 free(wd->event_history_list->event);
987 wd->event_history_list = (Event_History *) eina_inlist_remove(
988 EINA_INLIST_GET(wd->event_history_list),
989 EINA_INLIST_GET(wd->event_history_list));
992 _register_callbacks(obj);
999 * This function copies input events.
1000 * We copy event info before adding it to history.
1001 * The memory is freed when we clear history.
1003 * @param event the event to copy
1004 * @param event_type event type to copy
1006 * @ingroup Elm_Gesture_Layer
1009 _copy_event_info(void *event, Evas_Callback_Type event_type)
1013 case EVAS_CALLBACK_MOUSE_DOWN:
1014 return COPY_EVENT_INFO((Evas_Event_Mouse_Down *) event);
1016 case EVAS_CALLBACK_MOUSE_MOVE:
1017 return COPY_EVENT_INFO((Evas_Event_Mouse_Move *) event);
1019 case EVAS_CALLBACK_MOUSE_UP:
1020 return COPY_EVENT_INFO((Evas_Event_Mouse_Up *) event);
1022 case EVAS_CALLBACK_MOUSE_WHEEL:
1023 return COPY_EVENT_INFO((Evas_Event_Mouse_Wheel *) event);
1025 case EVAS_CALLBACK_MULTI_DOWN:
1026 return COPY_EVENT_INFO((Evas_Event_Multi_Down *) event);
1028 case EVAS_CALLBACK_MULTI_MOVE:
1029 return COPY_EVENT_INFO((Evas_Event_Multi_Move *) event);
1031 case EVAS_CALLBACK_MULTI_UP:
1032 return COPY_EVENT_INFO((Evas_Event_Multi_Up *) event);
1034 case EVAS_CALLBACK_KEY_DOWN:
1035 return COPY_EVENT_INFO((Evas_Event_Key_Down *) event);
1037 case EVAS_CALLBACK_KEY_UP:
1038 return COPY_EVENT_INFO((Evas_Event_Key_Up *) event);
1046 _event_history_add(Evas_Object *obj, void *event, Evas_Callback_Type event_type)
1048 Widget_Data *wd = elm_widget_data_get(obj);
1050 if (!wd) return EINA_FALSE;
1052 ev = malloc(sizeof(Event_History));
1053 ev->event = _copy_event_info(event, event_type); /* Freed on event_history_clear */
1054 ev->event_type = event_type;
1055 wd->event_history_list = (Event_History *) eina_inlist_append(
1056 EINA_INLIST_GET(wd->event_history_list), EINA_INLIST_GET(ev));
1060 /* END - Event history list handling functions */
1063 _del_hook(Evas_Object *obj)
1065 Widget_Data *wd = elm_widget_data_get(obj);
1068 _event_history_clear(obj);
1069 eina_list_free(wd->pending);
1071 Pointer_Event *data;
1072 EINA_LIST_FREE(wd->touched, data)
1075 if (!elm_widget_disabled_get(obj))
1076 _unregister_callbacks(obj);
1078 /* Free all gestures internal data structures */
1080 for (i = 0; i < ELM_GESTURE_LAST; i++)
1083 if (wd->gesture[i]->data)
1084 free(wd->gesture[i]->data);
1086 free(wd->gesture[i]);
1093 compare_match_fingers(const void *data1, const void *data2)
1094 { /* Compare coords of first item in list to cur coords */
1095 const Pointer_Event *pe1 = eina_list_data_get(data1);
1096 const Pointer_Event *pe2 = data2;
1098 if (_inside(pe1->x, pe1->y, pe2->x, pe2->y))
1100 else if (pe1->x < pe2->x)
1104 if (pe1->x == pe2->x)
1105 return pe1->y - pe2->y;
1112 compare_pe_device(const void *data1, const void *data2)
1113 { /* Compare device of first item in list to our pe device */
1114 const Pointer_Event *pe1 = eina_list_data_get(data1);
1115 const Pointer_Event *pe2 = data2;
1117 /* Only match if last was a down event */
1118 if ((pe1->event_type != EVAS_CALLBACK_MULTI_DOWN) &&
1119 (pe1->event_type != EVAS_CALLBACK_MOUSE_DOWN))
1123 if (pe1->device == pe2->device)
1125 else if (pe1->device < pe2->device)
1132 _record_pointer_event(Taps_Type *st, Eina_List *pe_list, Pointer_Event *pe,
1133 Widget_Data *wd, void *event_info, Evas_Callback_Type event_type)
1134 { /* Keep copy of pe and record it in list */
1135 Pointer_Event *p = malloc(sizeof(Pointer_Event));
1136 memcpy(p, pe, sizeof(Pointer_Event));
1137 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1143 /* This will also update middle-point to report to user later */
1144 st->info.x = st->sum_x / st->n_taps;
1145 st->info.y = st->sum_y / st->n_taps;
1146 st->info.timestamp = pe->timestamp;
1150 pe_list = eina_list_append(pe_list, p);
1151 st->l = eina_list_append(st->l, pe_list);
1154 pe_list = eina_list_append(pe_list, p);
1162 * This function sets state a tap-gesture to END or ABORT
1164 * @param data gesture info pointer
1166 * @ingroup Elm_Gesture_Layer
1169 _tap_gesture_finish(void *data)
1170 { /* This function will test each tap gesture when timer expires */
1171 Gesture_Info *gesture = data;
1172 Elm_Gesture_State s = ELM_GESTURE_STATE_END;
1173 /* Here we check if taps-gesture was completed successfuly */
1174 /* Count how many taps were recieved on each device then */
1175 /* determine if it matches n_taps_needed defined on START */
1176 Taps_Type *st = gesture->data;
1179 EINA_LIST_FOREACH(st->l, l, pe_list)
1181 if (eina_list_count(pe_list) != st->n_taps_needed)
1182 { /* No match taps number on device, ABORT */
1183 s = ELM_GESTURE_STATE_ABORT;
1188 st->info.n = eina_list_count(st->l);
1189 _set_state(gesture, s, gesture->info, EINA_FALSE);
1190 _tap_gestures_test_reset(gesture);
1196 * when this timer expires we finish tap gestures.
1198 * @param data The gesture-layer object.
1199 * @return cancles callback for this timer.
1201 * @ingroup Elm_Gesture_Layer
1204 _multi_tap_timeout(void *data)
1206 Widget_Data *wd = elm_widget_data_get(data);
1207 if (!wd) return EINA_FALSE;
1209 if (IS_TESTED(ELM_GESTURE_N_TAPS))
1210 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TAPS]);
1212 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
1213 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
1215 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
1216 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
1218 _clear_if_finished(data);
1219 wd->dbl_timeout = NULL;
1220 return ECORE_CALLBACK_CANCEL;
1226 * when this timer expires we START long tap gesture
1228 * @param data The gesture-layer object.
1229 * @return cancles callback for this timer.
1231 * @ingroup Elm_Gesture_Layer
1234 _long_tap_timeout(void *data)
1236 Gesture_Info *gesture = data;
1237 Long_Tap_Type *st = gesture->data;
1240 _set_state(gesture, ELM_GESTURE_STATE_START,
1241 gesture->data, EINA_FALSE);
1243 return ECORE_CALLBACK_CANCEL;
1250 * This function checks if a tap gesture should start
1252 * @param wd Gesture Layer Widget Data.
1253 * @param pe The recent input event as stored in pe struct.
1254 * @param event_info Original input event pointer.
1255 * @param event_type Type of original input event.
1256 * @param gesture what gesture is tested
1257 * @param how many taps for this gesture (1, 2 or 3)
1259 * @return Flag to determine if we need to set a timer for finish
1261 * @ingroup Elm_Gesture_Layer
1264 _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe,
1265 void *event_info, Evas_Callback_Type event_type,
1266 Gesture_Info *gesture, int taps)
1267 { /* Here we fill Tap struct */
1268 Taps_Type *st = gesture->data;
1270 { /* Allocated once on first time */
1271 st = calloc(1, sizeof(Taps_Type));
1273 _tap_gestures_test_reset(gesture);
1276 Eina_List *pe_list = NULL;
1277 Pointer_Event *pe_down = NULL;
1278 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1279 switch (pe->event_type)
1281 case EVAS_CALLBACK_MULTI_DOWN:
1282 case EVAS_CALLBACK_MOUSE_DOWN:
1283 /* Check if got tap on same cord was tapped before */
1284 pe_list = eina_list_search_unsorted(st->l, compare_match_fingers, pe);
1287 eina_list_search_unsorted(st->l, compare_pe_device, pe))
1288 { /* This device was touched in other cord before completion */
1289 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1290 &st->info, EINA_FALSE);
1291 consume_event(wd, event_info, event_type, ev_flag);
1296 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1297 if ((pe->device == 0) && (eina_list_count(pe_list) == 1))
1298 { /* This is the first mouse down we got */
1299 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1300 &st->info, EINA_FALSE);
1301 consume_event(wd, event_info, event_type, ev_flag);
1303 st->n_taps_needed = taps * 2; /* count DOWN and UP */
1310 case EVAS_CALLBACK_MULTI_UP:
1311 case EVAS_CALLBACK_MOUSE_UP:
1312 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1316 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1319 case EVAS_CALLBACK_MULTI_MOVE:
1320 case EVAS_CALLBACK_MOUSE_MOVE:
1321 /* Get first event in first list, this has to be a Mouse Down event */
1322 /* and verify that user didn't move out of this area before next tap */
1323 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1326 pe_down = eina_list_data_get(pe_list);
1327 if (!_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1329 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1330 &st->info, EINA_FALSE);
1331 consume_event(wd, event_info, event_type, ev_flag);
1347 * This function checks all click/tap and double/triple taps
1349 * @param obj The gesture-layer object.
1350 * @param pe The recent input event as stored in pe struct.
1351 * @param event_info Original input event pointer.
1352 * @param event_type Type of original input event.
1354 * @ingroup Elm_Gesture_Layer
1357 _tap_gestures_test(Evas_Object *obj, Pointer_Event *pe,
1358 void *event_info, Evas_Callback_Type event_type)
1359 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1360 Eina_Bool need_timer = EINA_FALSE;
1361 Widget_Data *wd = elm_widget_data_get(obj);
1364 if (!pe) /* this happens when unhandled event arrived */
1365 return; /* see _make_pointer_event function */
1367 if (IS_TESTED(ELM_GESTURE_N_TAPS))
1368 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1369 wd->gesture[ELM_GESTURE_N_TAPS], 1);
1371 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
1372 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1373 wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS], 2);
1375 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
1376 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1377 wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS], 3);
1379 if ((need_timer) && (!wd->dbl_timeout))
1380 { /* Set a timer to finish these gestures */
1381 wd->dbl_timeout = ecore_timer_add(0.4, _multi_tap_timeout,
1389 * This function computes center-point for long-tap gesture
1391 * @param st Long Tap gesture info pointer
1392 * @param pe The recent input event as stored in pe struct.
1394 * @ingroup Elm_Gesture_Layer
1397 _compute_taps_center(Long_Tap_Type *st,
1398 Evas_Coord *x_out, Evas_Coord *y_out, Pointer_Event *pe)
1400 if(!eina_list_count(st->touched))
1405 Evas_Coord x = 0, y = 0;
1406 EINA_LIST_FOREACH(st->touched, l, p)
1407 { /* Accumulate all then take avarage */
1408 if (p->device == pe->device)
1409 { /* This will take care of values coming from MOVE event */
1420 *x_out = x / eina_list_count(st->touched);
1421 *y_out = y / eina_list_count(st->touched);
1427 * This function checks N long-tap gesture.
1429 * @param obj The gesture-layer object.
1430 * @param pe The recent input event as stored in pe struct.
1431 * @param event_info Original input event pointer.
1432 * @param event_type Type of original input event.
1433 * @param g_type what Gesture we are testing.
1434 * @param taps How many click/taps we test for.
1436 * @ingroup Elm_Gesture_Layer
1439 _n_long_tap_test(Evas_Object *obj, Pointer_Event *pe,
1440 void *event_info, Evas_Callback_Type event_type,
1441 Elm_Gesture_Types g_type)
1442 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1443 Widget_Data *wd = elm_widget_data_get(obj);
1446 if (!pe) /* this happens when unhandled event arrived */
1447 return; /* see _make_pointer_event function */
1448 Gesture_Info *gesture = wd->gesture[g_type];
1449 if (!gesture) return;
1451 Long_Tap_Type *st = gesture->data;
1453 { /* Allocated once on first time */
1454 st = calloc(1, sizeof(Long_Tap_Type));
1456 _n_long_tap_test_reset(gesture);
1459 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1460 switch (pe->event_type)
1462 case EVAS_CALLBACK_MULTI_DOWN:
1463 case EVAS_CALLBACK_MOUSE_DOWN:
1464 st->touched = _add_touched_device(st->touched, pe);
1465 st->info.n = eina_list_count(st->touched);
1466 if (st->info.n > st->max_touched)
1467 st->max_touched = st->info.n;
1469 { /* User removed finger from touch, then put back - ABORT */
1470 if ((gesture->state == ELM_GESTURE_STATE_START) ||
1471 (gesture->state == ELM_GESTURE_STATE_MOVE))
1473 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1474 &st->info, EINA_FALSE);
1475 consume_event(wd, event_info, event_type, ev_flag);
1479 if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
1480 { /* This is the first mouse down we got */
1481 st->info.timestamp = pe->timestamp;
1483 /* To test long tap */
1484 /* When this timer expires, gesture STARTED */
1486 st->timeout = ecore_timer_add(wd->long_tap_start_timeout,
1487 _long_tap_timeout, gesture);
1490 consume_event(wd, event_info, event_type, ev_flag);
1491 _compute_taps_center(st, &st->info.x, &st->info.y, pe);
1492 st->center_x = st->info.x;
1493 st->center_y = st->info.y;
1496 case EVAS_CALLBACK_MULTI_UP:
1497 case EVAS_CALLBACK_MOUSE_UP:
1498 st->touched = _remove_touched_device(st->touched, pe);
1499 _compute_taps_center(st, &st->center_x, &st->center_y, pe);
1501 ((gesture->state == ELM_GESTURE_STATE_START) ||
1502 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1503 { /* Report END only for gesture that STARTed */
1504 if (eina_list_count(st->touched) == 0)
1505 { /* Report END only at last release event */
1506 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1507 &st->info, EINA_FALSE);
1508 consume_event(wd, event_info, event_type, ev_flag);
1512 { /* Stop test, user lifts finger before long-start */
1513 if (st->timeout) ecore_timer_del(st->timeout);
1515 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1516 &st->info, EINA_FALSE);
1517 consume_event(wd, event_info, event_type, ev_flag);
1522 case EVAS_CALLBACK_MULTI_MOVE:
1523 case EVAS_CALLBACK_MOUSE_MOVE:
1525 ((gesture->state == ELM_GESTURE_STATE_START) ||
1526 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1527 { /* Report MOVE only if STARTED */
1530 Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
1532 _compute_taps_center(st, &x, &y, pe);
1533 /* ABORT if user moved fingers out of tap area */
1534 #if defined(DEBUG_GESTURE_LAYER)
1535 printf("%s x,y=(%d,%d) st->info.x,st->info.y=(%d,%d)\n",__func__,x,y,st->info.x,st->info.y);
1537 if (!_inside(x, y, st->center_x, st->center_y))
1538 state_to_report = ELM_GESTURE_STATE_ABORT;
1540 /* Report MOVE if gesture started */
1541 ev_flag = _set_state(gesture, state_to_report,
1542 &st->info, EINA_TRUE);
1543 consume_event(wd, event_info, event_type, ev_flag);
1555 * This function computes momentum for MOMENTUM, LINE and FLICK gestures
1556 * This momentum value will be sent to widget when gesture is completed.
1558 * @param momentum pointer to buffer where we record momentum value.
1559 * @param x1 x coord where user started gesture.
1560 * @param y1 y coord where user started gesture.
1561 * @param x2 x coord where user completed gesture.
1562 * @param y2 y coord where user completed gesture.
1563 * @param t1x timestamp for X, when user started gesture.
1564 * @param t1y timestamp for Y, when user started gesture.
1565 * @param t2 timestamp when user completed gesture.
1567 * @ingroup Elm_Gesture_Layer
1570 _set_momentum(Elm_Gesture_Momentum_Info *momentum, Evas_Coord x1, Evas_Coord y1,
1571 Evas_Coord x2, Evas_Coord y2, unsigned int t1x, unsigned int t1y,
1574 Evas_Coord velx = 0, vely = 0, vel;
1575 Evas_Coord dx = x2 - x1;
1576 Evas_Coord dy = y2 - y1;
1580 velx = (dx * 1000) / dtx;
1583 vely = (dy * 1000) / dty;
1585 vel = sqrt((velx * velx) + (vely * vely));
1587 if ((_elm_config->thumbscroll_friction > 0.0) &&
1588 (vel > _elm_config->thumbscroll_momentum_threshold))
1589 { /* report momentum */
1590 momentum->mx = velx;
1591 momentum->my = vely;
1603 * This function is used for computing rotation angle (DEG).
1605 * @param x1 first finger x location.
1606 * @param y1 first finger y location.
1607 * @param x2 second finger x location.
1608 * @param y2 second finger y location.
1610 * @return angle of the line between (x1,y1), (x2,y2) in Deg.
1611 * Angles now are given in DEG, not RAD.
1612 * ZERO angle at 12-oclock, growing clockwise.
1614 * @ingroup Elm_Gesture_Layer
1617 get_angle(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
1619 double a, xx, yy, rt = (-1);
1623 if (((int) xx) && ((int) yy))
1625 rt = a = RAD2DEG(atan(yy / xx));
1651 { /* Do this only if rt is not set */
1653 { /* Horizontal line */
1664 { /* Vertical line */
1676 /* Now we want to change from:
1678 * original circle 180 0 We want: 270 90
1692 * This function is used for computing the magnitude and direction
1693 * of vector between two points.
1695 * @param x1 first finger x location.
1696 * @param y1 first finger y location.
1697 * @param x2 second finger x location.
1698 * @param y2 second finger y location.
1699 * @param l length computed (output)
1700 * @param a angle computed (output)
1702 * @ingroup Elm_Gesture_Layer
1705 get_vector(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2,
1706 Evas_Coord *l, double *a)
1711 *l = (Evas_Coord) sqrt(xx*xx + yy*yy);
1712 *a = get_angle(x1, y1, x2, y2);
1716 _get_direction(Evas_Coord x1, Evas_Coord x2)
1729 * This function tests momentum gesture.
1730 * @param obj The gesture-layer object.
1731 * @param pe The recent input event as stored in pe struct.
1732 * @param event_info recent input event.
1733 * @param event_type recent event type.
1734 * @param g_type what Gesture we are testing.
1736 * @ingroup Elm_Gesture_Layer
1739 _momentum_test(Evas_Object *obj, Pointer_Event *pe,
1740 void *event_info, Evas_Callback_Type event_type,
1741 Elm_Gesture_Types g_type)
1743 Widget_Data *wd = elm_widget_data_get(obj);
1745 Gesture_Info *gesture = wd->gesture[g_type];
1746 if (!gesture ) return;
1748 /* When continues enable = TRUE a gesture may START on MOVE event */
1749 /* We don't allow this to happen with the if-statement below. */
1750 /* When continues enable = FALSE a gesture may START on DOWN only */
1751 /* Therefor it would NOT start on MOVE event. */
1752 /* NOTE that touched list is updated AFTER this function returns */
1753 /* so (count == 0) when we get here on first touch on surface. */
1754 if ((wd->glayer_continues_enable) && (!eina_list_count(wd->touched)))
1755 return; /* Got move on mouse-over move */
1757 Momentum_Type *st = gesture->data;
1758 Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
1760 { /* Allocated once on first time */
1761 st = calloc(1, sizeof(Momentum_Type));
1763 _momentum_test_reset(gesture);
1769 /* First make avarage of all touched devices to determine center point */
1772 Pointer_Event pe_local = *pe; /* Copy pe event info to local */
1773 unsigned int cnt = 1; /* We start counter counting current pe event */
1774 EINA_LIST_FOREACH(wd->touched, l, p)
1775 if (p->device != pe_local.device)
1783 /* Compute avarage to get center point */
1787 /* If user added finger - reset gesture */
1788 if ((st->info.n) && (st->info.n < cnt))
1789 state_to_report = ELM_GESTURE_STATE_ABORT;
1791 if (st->info.n < cnt)
1794 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1797 case EVAS_CALLBACK_MOUSE_DOWN:
1798 case EVAS_CALLBACK_MULTI_DOWN:
1799 case EVAS_CALLBACK_MOUSE_MOVE:
1800 case EVAS_CALLBACK_MULTI_MOVE:
1803 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1804 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
1805 (wd->glayer_continues_enable)) /* start also on MOVE */
1806 { /* We start on MOVE when cont-enabled only */
1807 st->line_st.x = st->line_end.x = pe_local.x;
1808 st->line_st.y = st->line_end.y = pe_local.y;
1809 st->t_st_x = st->t_st_y = st->t_end = pe_local.timestamp;
1810 st->xdir = st->ydir = 0;
1811 st->info.x2 = st->info.x1 = pe_local.x;
1812 st->info.y2 = st->info.y1 = pe_local.y;
1813 st->info.tx = st->info.ty = pe_local.timestamp;
1814 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1815 &st->info, EINA_FALSE);
1816 consume_event(wd, event_info, event_type, ev_flag);
1823 /* ABORT gesture if got DOWN or MOVE event after UP+timeout */
1825 ((st->t_up + ELM_GESTURE_MULTI_TIMEOUT) < pe_local.timestamp))
1826 state_to_report = ELM_GESTURE_STATE_ABORT;
1828 if ((pe_local.timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1829 { /* Too long of a wait, reset all values */
1830 st->line_st.x = pe_local.x;
1831 st->line_st.y = pe_local.y;
1832 st->t_st_y = st->t_st_x = pe_local.timestamp;
1833 st->info.tx = st->t_st_x;
1834 st->info.ty = st->t_st_y;
1835 st->xdir = st->ydir = 0;
1840 xdir = _get_direction(st->line_end.x, pe_local.x);
1841 ydir = _get_direction(st->line_end.y, pe_local.y);
1842 if (xdir != st->xdir)
1844 st->line_st.x = st->line_end.x;
1845 st->info.tx = st->t_st_x = st->t_end;
1849 if (ydir != st->ydir)
1851 st->line_st.y = st->line_end.y;
1852 st->info.ty = st->t_st_y = st->t_end;
1857 st->info.x2 = st->line_end.x = pe_local.x;
1858 st->info.y2 = st->line_end.y = pe_local.y;
1859 st->t_end = pe_local.timestamp;
1860 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe_local.x, pe_local.y,
1861 st->t_st_x, st->t_st_y, pe_local.timestamp);
1862 ev_flag = _set_state(gesture, state_to_report, &st->info,
1864 consume_event(wd, event_info, event_type, ev_flag);
1868 case EVAS_CALLBACK_MOUSE_UP:
1869 case EVAS_CALLBACK_MULTI_UP:
1870 st->t_up = pe_local.timestamp; /* Record recent up event time */
1871 if ((cnt > 1) || /* Ignore if more fingers touch surface */
1872 (!st->t_st_x)) /* IGNORE if info was cleared, long press,move */
1875 if ((pe_local.timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1876 { /* Too long of a wait, reset all values */
1877 st->line_st.x = pe_local.x;
1878 st->line_st.y = pe_local.y;
1879 st->t_st_y = st->t_st_x = pe_local.timestamp;
1880 st->xdir = st->ydir = 0;
1883 st->info.x2 = pe_local.x;
1884 st->info.y2 = pe_local.y;
1885 st->line_end.x = pe_local.x;
1886 st->line_end.y = pe_local.y;
1887 st->t_end = pe_local.timestamp;
1889 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe_local.x, pe_local.y,
1890 st->t_st_x, st->t_st_y, pe_local.timestamp);
1892 if ((fabs(st->info.mx) > ELM_GESTURE_MINIMUM_MOMENTUM) ||
1893 (fabs(st->info.my) > ELM_GESTURE_MINIMUM_MOMENTUM))
1894 state_to_report = ELM_GESTURE_STATE_END;
1896 state_to_report = ELM_GESTURE_STATE_ABORT;
1898 ev_flag = _set_state(gesture, state_to_report, &st->info,
1900 consume_event(wd, event_info, event_type, ev_flag);
1909 compare_line_device(const void *data1, const void *data2)
1910 { /* Compare device component of line struct */
1911 const Line_Data *ln1 = data1;
1912 const int *device = data2;
1914 if (ln1->t_st) /* Compare only with lines that started */
1915 return (ln1->device - (*device));
1923 * This function construct line struct from input.
1924 * @param info pointer to store line momentum.
1925 * @param st line info to store input data.
1926 * @param pe The recent input event as stored in pe struct.
1928 * @ingroup Elm_Gesture_Layer
1931 _single_line_process(Elm_Gesture_Line_Info *info, Line_Data *st,
1932 Pointer_Event *pe, Evas_Callback_Type event_type)
1933 { /* Record events and set momentum for line pointed by st */
1939 case EVAS_CALLBACK_MOUSE_DOWN:
1940 case EVAS_CALLBACK_MOUSE_MOVE:
1941 case EVAS_CALLBACK_MULTI_DOWN:
1942 case EVAS_CALLBACK_MULTI_MOVE:
1944 { /* This happens only when line starts */
1945 st->line_st.x = pe->x;
1946 st->line_st.y = pe->y;
1947 st->t_st = pe->timestamp;
1948 st->device = pe->device;
1949 info->momentum.x1 = pe->x;
1950 info->momentum.y1 = pe->y;
1951 info->momentum.tx = pe->timestamp;
1952 info->momentum.ty = pe->timestamp;
1959 case EVAS_CALLBACK_MOUSE_UP:
1960 case EVAS_CALLBACK_MULTI_UP:
1961 /* IGNORE if line info was cleared, like long press, move */
1965 st->line_end.x = pe->x;
1966 st->line_end.y = pe->y;
1967 st->t_end = pe->timestamp;
1976 _line_data_reset(st);
1980 info->momentum.x2 = pe->x;
1981 info->momentum.y2 = pe->y;
1982 _set_momentum(&info->momentum, st->line_st.x, st->line_st.y, pe->x, pe->y,
1983 st->t_st, st->t_st, pe->timestamp);
1991 * This function test for (n) line gesture.
1992 * @param obj The gesture-layer object.
1993 * @param pe The recent input event as stored in pe struct.
1994 * @param event_info Original input event pointer.
1995 * @param event_type Type of original input event.
1996 * @param g_type what Gesture we are testing.
1998 * @ingroup Elm_Gesture_Layer
2001 _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2002 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2006 Widget_Data *wd = elm_widget_data_get(obj);
2008 Gesture_Info *gesture = wd->gesture[g_type];
2009 if (!gesture ) return;
2011 /* When continues enable = TRUE a gesture may START on MOVE event */
2012 /* We don't allow this to happen with the if-statement below. */
2013 /* When continues enable = FALSE a gesture may START on DOWN only */
2014 /* Therefor it would NOT start on MOVE event. */
2015 /* NOTE that touched list is updated AFTER this function returns */
2016 /* so (count == 0) when we get here on first touch on surface. */
2017 if ((wd->glayer_continues_enable) && (!eina_list_count(wd->touched)))
2018 return; /* Got move on mouse-over move */
2020 Line_Type *st = gesture->data;
2023 st = calloc(1, sizeof(Line_Type));
2027 Line_Data *line = NULL;
2028 Eina_List *list = st->list;
2029 unsigned cnt = eina_list_count(list);
2032 { /* list is not empty, locate this device on list */
2033 line = (Line_Data *) eina_list_search_unsorted(st->list,
2034 compare_line_device, &pe->device);
2038 { /* List is empty or device not found, new line-struct on START only */
2039 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2040 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
2041 ((wd->glayer_continues_enable) && /* START on MOVE also */
2042 ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
2043 (event_type == EVAS_CALLBACK_MULTI_MOVE))))
2044 { /* Allocate new item on START only */
2045 line = calloc(1, sizeof(Line_Data));
2046 _line_data_reset(line);
2047 list = eina_list_append(list, line);
2052 if (!line) /* This may happen on MOVE that comes before DOWN */
2053 return; /* No line-struct to work with, can't continue testing */
2055 if (_single_line_process(&st->info, line, pe, event_type)) /* update st with input */
2056 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
2058 /* Get direction and magnitude of the line */
2060 get_vector(line->line_st.x, line->line_st.y, pe->x, pe->y,
2061 &line->line_length, &angle);
2063 /* These are used later to compare lines length */
2064 Evas_Coord shortest_line_len = line->line_length;
2065 Evas_Coord longest_line_len = line->line_length;
2066 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2068 /* Now update line-state */
2070 { /* Analyze line only if line started */
2071 if (line->line_angle >= 0.0)
2072 { /* if line direction was set, we test if broke tolerance */
2073 double a = fabs(angle - line->line_angle);
2075 double d = (tan(DEG2RAD(a))) * line->line_length; /* Distance from line */
2076 #if defined(DEBUG_GESTURE_LAYER)
2077 printf("%s a=<%f> d=<%f>\n", __func__, a, d);
2079 if ((d > wd->line_distance_tolerance) || (a > wd->line_angular_tolerance))
2080 { /* Broke tolerance: abort line and start a new one */
2081 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2082 &st->info, EINA_FALSE);
2083 consume_event(wd, event_info, event_type, ev_flag);
2087 if (wd->glayer_continues_enable)
2088 { /* We may finish line if momentum is zero */
2089 /* This is for continues-gesture */
2090 if ((!st->info.momentum.mx) && (!st->info.momentum.my))
2091 { /* Finish line on zero momentum for continues gesture */
2092 line->line_end.x = pe->x;
2093 line->line_end.y = pe->y;
2094 line->t_end = pe->timestamp;
2099 { /* Record the line angle as it broke minimum length for line */
2100 if (line->line_length >= wd->line_min_length)
2101 st->info.angle = line->line_angle = angle;
2107 if (line->line_angle < 0.0)
2108 { /* it's not a line, too short more close to a tap */
2109 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2110 &st->info, EINA_FALSE);
2111 consume_event(wd, event_info, event_type, ev_flag);
2117 /* Count how many lines already started / ended */
2120 unsigned int tm_start = pe->timestamp;
2121 unsigned int tm_end = pe->timestamp;
2124 double base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
2125 Eina_Bool lines_parallel = EINA_TRUE;
2126 EINA_LIST_FOREACH(list, l, t_line)
2129 base_angle = t_line->line_angle;
2132 if (t_line->line_angle >= 0)
2133 { /* Compare angle only with lines with direction defined */
2134 if (fabs(base_angle - t_line->line_angle) >
2135 wd->line_angular_tolerance)
2136 lines_parallel = EINA_FALSE;
2140 if (t_line->line_length)
2141 { /* update only if this line is used */
2142 if (shortest_line_len > t_line->line_length)
2143 shortest_line_len = t_line->line_length;
2145 if (longest_line_len < t_line->line_length)
2146 longest_line_len = t_line->line_length;
2152 if (t_line->t_st < tm_start)
2153 tm_start = t_line->t_st;
2159 if (t_line->t_end < tm_end)
2160 tm_end = t_line->t_end;
2164 st->info.momentum.n = started;
2168 ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2169 (event_type == EVAS_CALLBACK_MULTI_DOWN)))
2170 { /* user lift one finger then starts again without line-end - ABORT */
2171 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2173 consume_event(wd, event_info, event_type, ev_flag);
2177 if (!lines_parallel)
2178 { /* Lines are NOT at same direction, abort this gesture */
2179 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2181 consume_event(wd, event_info, event_type, ev_flag);
2186 /* We report ABORT if lines length are NOT matching when fingers are up */
2187 if ((longest_line_len - shortest_line_len) > (elm_finger_size_get()*2))
2189 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2191 consume_event(wd, event_info, event_type, ev_flag);
2195 if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > wd->flick_time_limit_ms))
2196 { /* We consider FLICK as a fast line.ABORT if take too long to finish */
2197 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2199 consume_event(wd, event_info, event_type, ev_flag);
2205 case EVAS_CALLBACK_MOUSE_UP:
2206 case EVAS_CALLBACK_MULTI_UP:
2207 if ((started) && (started == ended))
2209 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2210 &st->info, EINA_FALSE);
2211 consume_event(wd, event_info, event_type, ev_flag);
2216 case EVAS_CALLBACK_MOUSE_DOWN:
2217 case EVAS_CALLBACK_MULTI_DOWN:
2218 case EVAS_CALLBACK_MOUSE_MOVE:
2219 case EVAS_CALLBACK_MULTI_MOVE:
2222 if (wd->glayer_continues_enable && (started == ended))
2223 { /* For continues gesture */
2224 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2225 &st->info, EINA_FALSE);
2226 consume_event(wd, event_info, event_type, ev_flag);
2229 { /* When continues, may START on MOVE event too */
2230 Elm_Gesture_State s = ELM_GESTURE_STATE_MOVE;
2232 /* This happens when: on n > 1 lines then one finger up */
2233 /* caused abort, then put finger down. */
2234 /* This will stop line from starting again. */
2235 /* Number of lines, MUST match touched-device in list */
2236 if ((!wd->glayer_continues_enable) &&
2237 (eina_list_count(st->list) < eina_list_count(wd->touched)))
2238 s = ELM_GESTURE_STATE_ABORT;
2240 if (gesture->state == ELM_GESTURE_STATE_UNDEFINED)
2241 s = ELM_GESTURE_STATE_START;
2243 ev_flag = _set_state(gesture, s, &st->info, EINA_TRUE);
2244 consume_event(wd, event_info, event_type, ev_flag);
2250 return; /* Unhandeld event type */
2257 * This function is used to check if rotation gesture started.
2258 * @param st Contains current rotation values from user input.
2259 * @return TRUE/FALSE if we need to set rotation START.
2261 * @ingroup Elm_Gesture_Layer
2264 rotation_broke_tolerance(Rotate_Type *st)
2266 if (st->info.base_angle < 0)
2267 return EINA_FALSE; /* Angle has to be computed first */
2269 if (st->rotate_angular_tolerance < 0)
2272 double low = st->info.base_angle - st->rotate_angular_tolerance;
2273 double high = st->info.base_angle + st->rotate_angular_tolerance;
2274 double t = st->info.angle;
2298 #if defined(DEBUG_GESTURE_LAYER)
2299 printf("%s angle=<%f> low=<%f> high=<%f>\n", __func__, t, low, high);
2301 if ((t < low) || (t > high))
2302 { /* This marks that roation action has started */
2303 st->rotate_angular_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
2304 st->info.base_angle = st->info.angle; /* Avoid jump in angle value */
2314 * This function is used for computing the gap between fingers.
2315 * It returns the length and center point between fingers.
2317 * @param x1 first finger x location.
2318 * @param y1 first finger y location.
2319 * @param x2 second finger x location.
2320 * @param y2 second finger y location.
2321 * @param x Gets center point x cord (output)
2322 * @param y Gets center point y cord (output)
2324 * @return length of the line between (x1,y1), (x2,y2) in pixels.
2326 * @ingroup Elm_Gesture_Layer
2329 get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
2330 Evas_Coord y2, Evas_Coord *x, Evas_Coord *y)
2332 double a, b, xx, yy, gap;
2335 gap = sqrt(xx*xx + yy*yy);
2337 /* START - Compute zoom center point */
2338 /* The triangle defined as follows:
2346 * http://en.wikipedia.org/wiki/Trigonometric_functions
2347 *************************************/
2348 if (((int) xx) && ((int) yy))
2350 double A = atan((yy / xx));
2351 #if defined(DEBUG_GESTURE_LAYER)
2352 printf("xx=<%f> yy=<%f> A=<%f>\n", xx, yy, A);
2354 a = (Evas_Coord) ((gap / 2) * sin(A));
2355 b = (Evas_Coord) ((gap / 2) * cos(A));
2356 *x = (Evas_Coord) ((x2 > x1) ? (x1 + b) : (x2 + b));
2357 *y = (Evas_Coord) ((y2 > y1) ? (y1 + a) : (y2 + a));
2362 { /* horiz line, take half width */
2363 #if defined(DEBUG_GESTURE_LAYER)
2364 printf("==== HORIZ ====\n");
2366 *x = (Evas_Coord) (xx / 2);
2367 *y = (Evas_Coord) (y1);
2371 { /* vert line, take half width */
2372 #if defined(DEBUG_GESTURE_LAYER)
2373 printf("==== VERT ====\n");
2375 *x = (Evas_Coord) (x1);
2376 *y = (Evas_Coord) (yy / 2);
2379 /* END - Compute zoom center point */
2381 return (Evas_Coord) gap;
2387 * This function is used for computing zoom value.
2389 * @param st Pointer to zoom data based on user input.
2390 * @param tm_end Recent input event timestamp.
2391 * @param zoom_val Current computed zoom value.
2393 * @return zoom momentum
2395 * @ingroup Elm_Gesture_Layer
2398 _zoom_momentum_get(Zoom_Type *st, unsigned int tm_end, double zoom_val)
2400 unsigned int tm_total;
2402 { /* Init, and we don't start computing momentum yet */
2403 st->m_st_tm = st->m_prev_tm = tm_end;
2404 st->m_base = zoom_val;
2408 if ((tm_end - ELM_GESTURE_MOMENTUM_DELAY) < st->m_st_tm)
2409 return 0.0; /* we don't start to compute momentum yet */
2412 { /* if direction was already defined, check if changed */
2413 if (((st->dir < 0) && (zoom_val > st->info.zoom)) ||
2414 ((st->dir > 0) && (zoom_val < st->info.zoom)))
2415 { /* Direction changed, reset momentum */
2417 st->dir = (-st->dir);
2422 st->dir = (zoom_val > st->info.zoom) ? 1 : -1; /* init */
2424 if ((tm_end - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->m_prev_tm)
2426 st->m_st_tm = 0; /* Rest momentum when waiting too long */
2430 st->m_prev_tm = tm_end;
2431 tm_total = tm_end - st->m_st_tm;
2434 return ((zoom_val - st->m_base) * 1000) / tm_total;
2442 * This function is used for computing zoom value.
2444 * @param st Pointer to zoom data based on user input.
2445 * @param x1 first finger x location.
2446 * @param y1 first finger y location.
2447 * @param x2 second finger x location.
2448 * @param y2 second finger y location.
2449 * @param factor zoom-factor, used to determine how fast zoom works.
2451 * @return zoom value, when 1.0 means no zoom, 0.5 half size...
2453 * @ingroup Elm_Gesture_Layer
2456 compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1,
2457 Evas_Coord x2, Evas_Coord y2, double zoom_finger_factor)
2460 unsigned int tm_end = (st->zoom_mv.timestamp > st->zoom_mv1.timestamp) ?
2461 st->zoom_mv.timestamp : st->zoom_mv1.timestamp;
2463 Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
2464 &st->info.x, &st->info.y);
2466 st->info.radius = diam / 2;
2470 st->zoom_base = diam;
2471 return st->info.zoom;
2474 if (st->zoom_distance_tolerance)
2475 { /* zoom tolerance <> ZERO, means zoom action NOT started yet */
2476 if (diam < (st->zoom_base - st->zoom_distance_tolerance))
2477 { /* avoid jump with zoom value when break tolerance */
2478 st->zoom_base -= st->zoom_distance_tolerance;
2479 st->zoom_distance_tolerance = 0;
2482 if (diam > (st->zoom_base + st->zoom_distance_tolerance))
2483 { /* avoid jump with zoom value when break tolerance */
2484 st->zoom_base += st->zoom_distance_tolerance;
2485 st->zoom_distance_tolerance = 0;
2491 /* We use factor only on the difference between gap-base */
2492 /* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
2493 rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
2494 (float) st->zoom_base) * zoom_finger_factor));
2496 /* Momentum: zoom per second: */
2497 st->info.momentum = _zoom_momentum_get(st, tm_end, rt);
2505 * This function handles zoom with mouse wheel.
2506 * thats a combination of wheel + CTRL key.
2507 * @param obj The gesture-layer object.
2508 * @param event_info Original input event pointer.
2509 * @param event_type Type of original input event.
2510 * @param g_type what Gesture we are testing.
2512 * @ingroup Elm_Gesture_Layer
2515 _zoom_with_wheel_test(Evas_Object *obj, void *event_info,
2516 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2518 Widget_Data *wd = elm_widget_data_get(obj);
2520 if (!wd->gesture[g_type]) return;
2522 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2523 Zoom_Type *st = gesture_zoom->data;
2524 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2526 { /* Allocated once on first time, used for zoom intermediate data */
2527 st = calloc(1, sizeof(Zoom_Type));
2528 gesture_zoom->data = st;
2529 _zoom_test_reset(gesture_zoom);
2534 case EVAS_CALLBACK_KEY_UP:
2536 Evas_Event_Key_Up *p = event_info;
2537 if ((!strcmp(p->keyname, "Control_L")) ||
2538 (!strcmp(p->keyname, "Control_R")))
2539 { /* Test if we ended a zoom gesture when releasing CTRL */
2540 if ((st->zoom_wheel) &&
2541 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2542 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2543 { /* User released CTRL after zooming */
2544 st->info.momentum = _zoom_momentum_get(st,
2545 p->timestamp, st->info.zoom);
2547 ev_flag = _set_state(gesture_zoom,
2548 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2549 consume_event(wd, event_info, event_type, ev_flag);
2557 case EVAS_CALLBACK_MOUSE_WHEEL:
2560 Elm_Gesture_State s;
2561 if (!evas_key_modifier_is_set(
2562 ((Evas_Event_Mouse_Wheel *) event_info)->modifiers,
2564 { /* if using wheel witout CTRL after starting zoom */
2565 if ((st->zoom_wheel) &&
2566 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2567 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2569 ev_flag = _set_state(gesture_zoom,
2570 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2571 consume_event(wd, event_info, event_type, ev_flag);
2576 return; /* Ignore mouse-wheel without control */
2579 /* Using mouse wheel with CTRL for zoom */
2580 if (st->zoom_wheel || (st->zoom_distance_tolerance == 0))
2581 { /* (zoom_wheel == NULL) and (zoom_distance_tolerance == 0)
2582 we continue a zoom gesture */
2584 s = ELM_GESTURE_STATE_MOVE;
2587 { /* On first wheel event, report START */
2588 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
2589 evas_object_evas_get(wd->target), "Control");
2591 s = ELM_GESTURE_STATE_START;
2592 if (!evas_object_key_grab(wd->target, "Control_L", mask, 0, EINA_FALSE))
2593 ERR("Failed to Grabbed CTRL_L");
2594 if (!evas_object_key_grab(wd->target, "Control_R", mask, 0, EINA_FALSE))
2595 ERR("Failed to Grabbed CTRL_R");
2598 st->zoom_distance_tolerance = 0; /* Cancel tolerance */
2599 st->zoom_wheel = (Evas_Event_Mouse_Wheel *) event_info;
2600 st->info.x = st->zoom_wheel->canvas.x;
2601 st->info.y = st->zoom_wheel->canvas.y;
2603 if (st->zoom_wheel->z < 0) /* zoom in */
2604 st->info.zoom += (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2606 if (st->zoom_wheel->z > 0) /* zoom out */
2607 st->info.zoom -= (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2609 if (st->info.zoom < 0.0)
2610 st->info.zoom = 0.0;
2612 st->info.momentum = _zoom_momentum_get(st,
2613 st->zoom_wheel->timestamp, st->info.zoom);
2615 ev_flag = _set_state(gesture_zoom, s, &st->info, force);
2616 consume_event(wd, event_info, event_type, ev_flag);
2628 * This function is used to test zoom gesture.
2629 * user may combine zoom, rotation together.
2630 * so its possible that both will be detected from input.
2631 * (both are two-finger movement-oriented gestures)
2633 * @param obj The gesture-layer object.
2634 * @param event_info Pointer to recent input event.
2635 * @param event_type Recent input event type.
2636 * @param g_type what Gesture we are testing.
2638 * @ingroup Elm_Gesture_Layer
2641 _zoom_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2642 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2646 Widget_Data *wd = elm_widget_data_get(obj);
2648 if (!wd->gesture[g_type]) return;
2650 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2651 Zoom_Type *st = gesture_zoom->data;
2654 { /* Allocated once on first time, used for zoom data */
2655 st = calloc(1, sizeof(Zoom_Type));
2656 gesture_zoom->data = st;
2657 _zoom_test_reset(gesture_zoom);
2661 /* Start - new zoom testing, letting all fingers start */
2662 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2665 case EVAS_CALLBACK_MOUSE_MOVE:
2666 case EVAS_CALLBACK_MULTI_MOVE:
2667 /* if non-continues mode and gesture NOT started, ignore MOVE */
2668 if ((!wd->glayer_continues_enable) &&
2669 (!st->zoom_st.timestamp))
2672 case EVAS_CALLBACK_MOUSE_DOWN:
2673 case EVAS_CALLBACK_MULTI_DOWN:
2674 { /* Here we take care of zoom-start and zoom move */
2678 if(eina_list_count(wd->touched) > 2)
2679 { /* Process zoom only when 2 fingers on surface */
2680 ev_flag = _set_state(gesture_zoom,
2681 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2682 consume_event(wd, event_info, event_type, ev_flag);
2687 if (!st->zoom_st.timestamp)
2688 { /* Now scan touched-devices list and find other finger */
2689 EINA_LIST_FOREACH(wd->touched, l, p)
2690 { /* Device of other finger <> pe device */
2691 if (p->device != pe->device)
2695 if (!p) /* Single finger on touch */
2698 /* Record down fingers */
2699 consume_event(wd, event_info, event_type, ev_flag);
2700 memcpy(&st->zoom_st, pe, sizeof(Pointer_Event));
2701 memcpy(&st->zoom_st1, p, sizeof(Pointer_Event));
2703 /* Set mv field as well to be ready for MOVE events */
2704 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2705 memcpy(&st->zoom_mv1, p, sizeof(Pointer_Event));
2707 /* Here we have zoom_st, zoom_st1 set, report START */
2708 /* Set zoom-base after BOTH down events recorded */
2709 /* Compute length of line between fingers zoom start */
2710 st->info.zoom = 1.0;
2711 st->zoom_base = get_finger_gap_length(st->zoom_st1.x,
2712 st->zoom_st1.y, st->zoom_st.x, st->zoom_st.y,
2713 &st->info.x, &st->info.y);
2715 st->info.radius = st->zoom_base / 2;
2717 if ((gesture_zoom->state != ELM_GESTURE_STATE_START) &&
2718 (gesture_zoom->state != ELM_GESTURE_STATE_MOVE))
2719 { /* zoom started with mouse-wheel, don't report twice */
2720 ev_flag = _set_state(gesture_zoom,
2721 ELM_GESTURE_STATE_START, &st->info, EINA_FALSE);
2722 consume_event(wd, event_info, event_type, ev_flag);
2725 return; /* Zoom started */
2726 } /* End of ZOOM_START handling */
2729 /* if we got here, we have (exacally) two fingers on surfce */
2730 /* we also after START, report MOVE */
2731 /* First detect which finger moved */
2732 if (pe->device == st->zoom_mv.device)
2733 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2734 else if (pe->device == st->zoom_mv1.device)
2735 memcpy(&st->zoom_mv1, pe, sizeof(Pointer_Event));
2737 /* Compute change in zoom as fingers move */
2738 st->info.zoom = compute_zoom(st,
2739 st->zoom_mv.x, st->zoom_mv.y,
2740 st->zoom_mv1.x, st->zoom_mv1.y,
2741 wd->zoom_finger_factor);
2743 if (!st->zoom_distance_tolerance)
2744 { /* Zoom broke tolerance, report move */
2745 double d = st->info.zoom - st->next_step;
2749 if (d >= wd->zoom_step)
2750 { /* Report move in steps */
2751 st->next_step = st->info.zoom;
2753 ev_flag = _set_state(gesture_zoom,
2754 ELM_GESTURE_STATE_MOVE,
2755 &st->info, EINA_TRUE);
2756 consume_event(wd, event_info, event_type, ev_flag);
2758 } /* End of ZOOM_MOVE handling */
2763 case EVAS_CALLBACK_MOUSE_UP:
2764 case EVAS_CALLBACK_MULTI_UP:
2765 /* Reset timestamp of finger-up.This is used later
2766 by _zoom_test_reset() to retain finger-down data */
2767 consume_event(wd, event_info, event_type, ev_flag);
2768 if (((st->zoom_wheel) || (st->zoom_base)) &&
2769 (st->zoom_distance_tolerance == 0))
2771 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
2772 &st->info, EINA_FALSE);
2773 consume_event(wd, event_info, event_type, ev_flag);
2778 /* if we got here not a ZOOM */
2779 if (gesture_zoom->state != ELM_GESTURE_STATE_UNDEFINED)
2780 { /* Must be != undefined, if gesture started */
2781 ev_flag = _set_state(gesture_zoom,
2782 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2783 consume_event(wd, event_info, event_type, ev_flag);
2786 _zoom_test_reset(gesture_zoom);
2796 _get_rotate_properties(Rotate_Type *st,
2797 Evas_Coord x1, Evas_Coord y1,
2798 Evas_Coord x2, Evas_Coord y2,
2800 { /* FIXME: Fix momentum computation, it's wrong */
2801 double prev_angle = *angle;
2802 st->info.radius = get_finger_gap_length(x1, y1, x2, y2,
2803 &st->info.x, &st->info.y) / 2;
2805 *angle = get_angle(x1, y1, x2, y2);
2807 if (angle == &st->info.angle)
2808 { /* Fingers are moving, compute momentum */
2809 unsigned int tm_start =
2810 (st->rotate_st.timestamp > st->rotate_st1.timestamp)
2811 ? st->rotate_st.timestamp : st->rotate_st1.timestamp;
2812 unsigned int tm_end =
2813 (st->rotate_mv.timestamp > st->rotate_mv1.timestamp)
2814 ? st->rotate_mv.timestamp : st->rotate_mv1.timestamp;
2816 unsigned int tm_total = tm_end - tm_start;
2818 { /* Momentum computed as:
2819 accumulated roation angle (deg) divided by time */
2821 if (((prev_angle < 90) && ((*angle) > 270)) ||
2822 ((prev_angle > 270) && ((*angle) < 90)))
2823 { /* We circle passing ZERO point */
2824 prev_angle = (*angle);
2826 else m = prev_angle - (*angle);
2828 st->accum_momentum += m;
2830 if ((tm_end - st->prev_momentum_tm) < 100)
2831 st->prev_momentum += m;
2834 if (fabs(st->prev_momentum) < 0.002)
2835 st->accum_momentum = 0.0; /* reset momentum */
2837 st->prev_momentum = 0.0; /* Start again */
2840 st->prev_momentum_tm = tm_end;
2841 st->info.momentum = (st->accum_momentum * 1000) / tm_total;
2845 st->info.momentum = 0;
2851 * This function is used to test rotation gesture.
2852 * user may combine zoom, rotation together.
2853 * so its possible that both will be detected from input.
2854 * (both are two-finger movement-oriented gestures)
2856 * @param obj The gesture-layer object.
2857 * @param event_info Pointer to recent input event.
2858 * @param event_type Recent input event type.
2859 * @param g_type what Gesture we are testing.
2861 * @ingroup Elm_Gesture_Layer
2864 _rotate_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2865 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2870 Widget_Data *wd = elm_widget_data_get(obj);
2872 if (!wd->gesture[g_type]) return;
2874 Gesture_Info *gesture = wd->gesture[g_type];
2880 { /* Allocated once on first time */
2881 st = calloc(1, sizeof(Rotate_Type));
2883 _rotate_test_reset(gesture);
2887 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2890 case EVAS_CALLBACK_MOUSE_MOVE:
2891 case EVAS_CALLBACK_MULTI_MOVE:
2892 /* if non-continues mode and gesture NOT started, ignore MOVE */
2893 if ((!wd->glayer_continues_enable) &&
2894 (!st->rotate_st.timestamp))
2897 case EVAS_CALLBACK_MOUSE_DOWN:
2898 case EVAS_CALLBACK_MULTI_DOWN:
2899 { /* Here we take care of rotate-start and rotate move */
2903 if(eina_list_count(wd->touched) > 2)
2904 { /* Process rotate only when 2 fingers on surface */
2905 ev_flag = _set_state(gesture,
2906 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2907 consume_event(wd, event_info, event_type, ev_flag);
2912 if (!st->rotate_st.timestamp)
2913 { /* Now scan touched-devices list and find other finger */
2914 EINA_LIST_FOREACH(wd->touched, l, p)
2915 { /* Device of other finger <> pe device */
2916 if (p->device != pe->device)
2921 return; /* Single finger on touch */
2923 /* Record down fingers */
2924 consume_event(wd, event_info, event_type, ev_flag);
2925 memcpy(&st->rotate_st, pe, sizeof(Pointer_Event));
2926 memcpy(&st->rotate_st1, p, sizeof(Pointer_Event));
2928 /* Set mv field as well to be ready for MOVE events */
2929 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2930 memcpy(&st->rotate_mv1, p, sizeof(Pointer_Event));
2932 /* Here we have rotate_st, rotate_st1 set, report START */
2933 /* Set rotate-base after BOTH down events recorded */
2934 /* Compute length of line between fingers rotate start */
2935 _get_rotate_properties(st,
2936 st->rotate_st.x, st->rotate_st.y,
2937 st->rotate_st1.x, st->rotate_st1.y,
2938 &st->info.base_angle);
2940 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
2941 &st->info, EINA_FALSE);
2942 consume_event(wd, event_info, event_type, ev_flag);
2944 return; /* Rotate started */
2945 } /* End of ROTATE_START handling */
2948 /* if we got here, we have (exacally) two fingers on surfce */
2949 /* we also after START, report MOVE */
2950 /* First detect which finger moved */
2951 if (pe->device == st->rotate_mv.device)
2952 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2953 else if (pe->device == st->rotate_mv1.device)
2954 memcpy(&st->rotate_mv1, pe, sizeof(Pointer_Event));
2956 /* Compute change in rotate as fingers move */
2957 _get_rotate_properties(st,
2958 st->rotate_mv.x, st->rotate_mv.y,
2959 st->rotate_mv1.x, st->rotate_mv1.y,
2962 if (rotation_broke_tolerance(st))
2963 { /* Rotation broke tolerance, report move */
2964 double d = st->info.angle - st->next_step;
2968 if (d >= wd->rotate_step)
2969 { /* Report move in steps */
2970 st->next_step = st->info.angle;
2972 ev_flag = _set_state(gesture,
2973 ELM_GESTURE_STATE_MOVE, &st->info, EINA_TRUE);
2974 consume_event(wd, event_info, event_type, ev_flag);
2976 } /* End of ROTATE_MOVE handling */
2981 case EVAS_CALLBACK_MOUSE_UP:
2982 case EVAS_CALLBACK_MULTI_UP:
2983 consume_event(wd, event_info, event_type, ev_flag);
2984 /* Reset timestamp of finger-up.This is used later
2985 by rotate_test_reset() to retain finger-down data */
2986 if (st->rotate_angular_tolerance < 0)
2988 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2989 &st->info, EINA_FALSE);
2990 consume_event(wd, event_info, event_type, ev_flag);
2995 if (gesture->state != ELM_GESTURE_STATE_UNDEFINED)
2996 { /* Must be != undefined, if gesture started */
2997 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2998 &st->info, EINA_FALSE);
2999 consume_event(wd, event_info, event_type, ev_flag);
3002 _rotate_test_reset(gesture);
3013 * This function is used to save input events in an abstract struct
3014 * to be used later by getsure-testing functions.
3016 * @param data The gesture-layer object.
3017 * @param event_info Pointer to recent input event.
3018 * @param event_type Recent input event type.
3019 * @param pe The abstract data-struct (output).
3021 * @ingroup Elm_Gesture_Layer
3024 _make_pointer_event(void *data, void *event_info,
3025 Evas_Callback_Type event_type, Pointer_Event *pe)
3027 Widget_Data *wd = elm_widget_data_get(data);
3028 if (!wd) return EINA_FALSE;
3030 memset(pe, '\0', sizeof(*pe));
3033 case EVAS_CALLBACK_MOUSE_DOWN:
3034 pe->x = ((Evas_Event_Mouse_Down *) event_info)->canvas.x;
3035 pe->y = ((Evas_Event_Mouse_Down *) event_info)->canvas.y;
3036 pe->timestamp = ((Evas_Event_Mouse_Down *) event_info)->timestamp;
3037 pe->device = ELM_MOUSE_DEVICE;
3040 case EVAS_CALLBACK_MOUSE_UP:
3041 pe->x = ((Evas_Event_Mouse_Up *) event_info)->canvas.x;
3042 pe->y = ((Evas_Event_Mouse_Up *) event_info)->canvas.y;
3043 pe->timestamp = ((Evas_Event_Mouse_Up *) event_info)->timestamp;
3044 pe->device = ELM_MOUSE_DEVICE;
3047 case EVAS_CALLBACK_MOUSE_MOVE:
3048 pe->x = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.x;
3049 pe->y = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.y;
3050 pe->timestamp = ((Evas_Event_Mouse_Move *) event_info)->timestamp;
3051 pe->device = ELM_MOUSE_DEVICE;
3054 case EVAS_CALLBACK_MULTI_DOWN:
3055 pe->x = ((Evas_Event_Multi_Down *) event_info)->canvas.x;
3056 pe->y = ((Evas_Event_Multi_Down *) event_info)->canvas.y;
3057 pe->timestamp = ((Evas_Event_Multi_Down *) event_info)->timestamp;
3058 pe->device = ((Evas_Event_Multi_Down *) event_info)->device;
3061 case EVAS_CALLBACK_MULTI_UP:
3062 pe->x = ((Evas_Event_Multi_Up *) event_info)->canvas.x;
3063 pe->y = ((Evas_Event_Multi_Up *) event_info)->canvas.y;
3064 pe->timestamp = ((Evas_Event_Multi_Up *) event_info)->timestamp;
3065 pe->device = ((Evas_Event_Multi_Up *) event_info)->device;
3068 case EVAS_CALLBACK_MULTI_MOVE:
3069 pe->x = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.x;
3070 pe->y = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.y;
3071 pe->timestamp = ((Evas_Event_Multi_Move *) event_info)->timestamp;
3072 pe->device = ((Evas_Event_Multi_Move *) event_info)->device;
3079 pe->event_type = event_type;
3086 * This function restartes line, flick, zoom and rotate gestures
3087 * when gesture-layer continues-gestures enabled.
3088 * Example of continues-gesture:
3089 * When doing a line, user stops moving finger but keeps fingers on touch.
3090 * This will cause line-end, then as user continues moving his finger
3091 * it re-starts line gesture.
3092 * When continue mode is disabled, user has to lift finger from touch
3093 * to end a gesture. Them touch-again to start a new one.
3095 * @param data The gesture-layer object.
3096 * @param wd gesture layer widget data.
3097 * @param states_reset flag that marks gestures were reset in history clear.
3099 * @ingroup Elm_Gesture_Layer
3101 void continues_gestures_restart(void *data, Eina_Bool states_reset)
3103 Widget_Data *wd = elm_widget_data_get(data);
3106 /* Run through events to restart gestures */
3108 Eina_Bool n_momentum, n_lines, n_flicks, zoom, rotate;
3109 /* We turn-on flag for finished, aborted, not-started gestures */
3110 g = wd->gesture[ELM_GESTURE_MOMENTUM];
3111 n_momentum = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3112 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3115 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
3116 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3120 g = wd->gesture[ELM_GESTURE_N_LINES];
3121 n_lines = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3122 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3125 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
3126 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3130 g = wd->gesture[ELM_GESTURE_N_FLICKS];
3131 n_flicks = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3132 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3135 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
3136 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3140 g = wd->gesture[ELM_GESTURE_ZOOM];
3141 zoom = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3142 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3145 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
3146 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3150 g = wd->gesture[ELM_GESTURE_ROTATE];
3151 rotate = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3152 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3155 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
3156 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3164 * This function the core-function where input handling is done.
3165 * Here we get user input and stream it to gesture testing.
3166 * We notify user about any gestures with new state:
3168 * START - gesture started.
3169 * MOVE - gesture is ongoing.
3170 * END - gesture was completed.
3171 * ABORT - gesture was aborted after START, MOVE (will NOT be completed)
3173 * We also check if a gesture was detected, then reset event history
3174 * If no gestures were found we reset gesture test flag
3175 * after streaming event-history to widget.
3176 * (stream to the widget all events not consumed as a gesture)
3178 * @param data The gesture-layer object.
3179 * @param event_info Pointer to recent input event.
3180 * @param event_type Recent input event type.
3182 * @ingroup Elm_Gesture_Layer
3185 _event_process(void *data, Evas_Object *obj __UNUSED__,
3186 void *event_info, Evas_Callback_Type event_type)
3189 Pointer_Event *pe = NULL;
3190 Widget_Data *wd = elm_widget_data_get(data);
3193 #if defined(DEBUG_GESTURE_LAYER)
3196 printf("Gesture | State | is tested\n");
3197 for(i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
3201 printf(" %d %d %d\n", i, g->state, g->test);
3205 /* Start testing candidate gesture from here */
3206 if (_make_pointer_event(data, event_info, event_type, &_pe))
3209 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
3210 _n_long_tap_test(data, pe, event_info, event_type,
3211 ELM_GESTURE_N_LONG_TAPS);
3213 /* This takes care of single, double and tripple tap */
3214 _tap_gestures_test(data, pe, event_info, event_type);
3216 if (IS_TESTED(ELM_GESTURE_MOMENTUM))
3217 _momentum_test(data, pe, event_info, event_type,
3218 ELM_GESTURE_MOMENTUM);
3220 if (IS_TESTED(ELM_GESTURE_N_LINES))
3221 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_LINES);
3223 if (IS_TESTED(ELM_GESTURE_N_FLICKS))
3224 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_FLICKS);
3226 if (_elm_config->glayer_zoom_finger_enable && IS_TESTED(ELM_GESTURE_ZOOM))
3227 _zoom_test(data, pe, event_info, event_type, ELM_GESTURE_ZOOM);
3229 if (IS_TESTED(ELM_GESTURE_ZOOM))
3230 _zoom_with_wheel_test(data, event_info, event_type, ELM_GESTURE_ZOOM);
3232 if (_elm_config->glayer_rotate_finger_enable && IS_TESTED(ELM_GESTURE_ROTATE))
3233 _rotate_test(data, pe, event_info, event_type, ELM_GESTURE_ROTATE);
3235 if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
3236 _event_history_add(data, event_info, event_type);
3237 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3238 (event_type == EVAS_CALLBACK_MULTI_UP))
3240 Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type);
3243 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD);
3244 _event_history_add(data, event_info, event_type);
3248 /* we maintain list of touched devices */
3249 /* We also use move to track current device x.y pos */
3250 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
3251 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
3252 (event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
3253 (event_type == EVAS_CALLBACK_MULTI_MOVE))
3255 wd->touched = _add_touched_device(wd->touched, pe);
3257 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3258 (event_type == EVAS_CALLBACK_MULTI_UP))
3260 wd->touched = _remove_touched_device(wd->touched, pe);
3263 /* Report current states and clear history if needed */
3264 Eina_Bool states_reset = _clear_if_finished(data);
3265 if (wd->glayer_continues_enable)
3266 continues_gestures_restart(data, states_reset);
3271 * For all _mouse_* / multi_* functions wethen send this event to
3272 * _event_process function.
3274 * @param data The gesture-layer object.
3275 * @param event_info Pointer to recent input event.
3277 * @ingroup Elm_Gesture_Layer
3280 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3283 Widget_Data *wd = elm_widget_data_get(data);
3285 if (((Evas_Event_Mouse_Down *) event_info)->button != 1)
3286 return; /* We only process left-click at the moment */
3288 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_DOWN);
3292 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3295 Widget_Data *wd = elm_widget_data_get(data);
3298 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_MOVE);
3302 _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3305 Widget_Data *wd = elm_widget_data_get(data);
3308 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_DOWN);
3312 _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3315 Widget_Data *wd = elm_widget_data_get(data);
3318 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_UP);
3322 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3325 Widget_Data *wd = elm_widget_data_get(data);
3328 if (((Evas_Event_Mouse_Up *) event_info)->button != 1)
3329 return; /* We only process left-click at the moment */
3331 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_UP);
3335 _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3338 Widget_Data *wd = elm_widget_data_get(data);
3341 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_WHEEL);
3345 _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3348 Widget_Data *wd = elm_widget_data_get(data);
3351 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_DOWN);
3355 _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3358 Widget_Data *wd = elm_widget_data_get(data);
3361 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_MOVE);
3365 _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3368 Widget_Data *wd = elm_widget_data_get(data);
3371 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_UP);
3375 elm_gesture_layer_hold_events_get(Evas_Object *obj)
3377 Widget_Data *wd = elm_widget_data_get(obj);
3378 if (!wd) return EINA_FALSE;
3380 return !wd->repeat_events;
3384 elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool r)
3386 Widget_Data *wd = elm_widget_data_get(obj);
3389 wd->repeat_events = !r;
3393 elm_gesture_layer_zoom_step_set(Evas_Object *obj, double s)
3395 Widget_Data *wd = elm_widget_data_get(obj);
3405 elm_gesture_layer_rotate_step_set(Evas_Object *obj, double s)
3407 Widget_Data *wd = elm_widget_data_get(obj);
3413 wd->rotate_step = s;
3417 elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *t)
3419 Widget_Data *wd = elm_widget_data_get(obj);
3420 if (!wd) return EINA_FALSE;
3425 /* if was attached before, unregister callbacks first */
3427 _unregister_callbacks(obj);
3431 _register_callbacks(obj);
3436 elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Types idx,
3437 Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data)
3439 Widget_Data *wd = elm_widget_data_get(obj);
3443 if (!wd->gesture[idx])
3444 wd->gesture[idx] = calloc(1, sizeof(Gesture_Info));
3445 if (!wd->gesture[idx]) return;
3447 p = wd->gesture[idx];
3450 p->fn[cb_type].cb = cb;
3451 p->fn[cb_type].user_data = data;
3452 p->state = ELM_GESTURE_STATE_UNDEFINED;
3457 _disable_hook(Evas_Object *obj)
3459 if (elm_widget_disabled_get(obj))
3460 _unregister_callbacks(obj);
3462 _register_callbacks(obj);
3466 elm_gesture_layer_add(Evas_Object *parent)
3472 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
3474 ELM_SET_WIDTYPE(widtype, "gesture_layer");
3475 elm_widget_type_set(obj, "gesture_layer");
3476 elm_widget_sub_object_add(parent, obj);
3477 elm_widget_data_set(obj, wd);
3478 elm_widget_del_hook_set(obj, _del_hook);
3479 elm_widget_disable_hook_set(obj, _disable_hook);
3482 wd->line_min_length =_elm_config->glayer_line_min_length * elm_finger_size_get();
3483 wd->zoom_distance_tolerance = _elm_config->glayer_zoom_distance_tolerance * elm_finger_size_get();
3484 wd->line_distance_tolerance = _elm_config->glayer_line_distance_tolerance * elm_finger_size_get();
3485 wd->zoom_finger_factor = _elm_config->glayer_zoom_finger_factor;
3486 wd->zoom_wheel_factor = _elm_config->glayer_zoom_wheel_factor; /* mouse wheel zoom steps */
3487 wd->rotate_angular_tolerance = _elm_config->glayer_rotate_angular_tolerance;
3488 wd->line_angular_tolerance = _elm_config->glayer_line_angular_tolerance;
3489 wd->flick_time_limit_ms = _elm_config->glayer_flick_time_limit_ms;
3490 wd->long_tap_start_timeout = _elm_config->glayer_long_tap_start_timeout;
3491 wd->repeat_events = EINA_TRUE;
3492 wd->glayer_continues_enable = _elm_config->glayer_continues_enable;
3494 #if defined(DEBUG_GESTURE_LAYER)
3495 printf("size of Gestures = <%d>\n", sizeof(wd->gesture));
3496 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);
3498 memset(wd->gesture, 0, sizeof(wd->gesture));