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
12 /* Some Trigo values */
13 #define RAD_90DEG M_PI_2
14 #define RAD_180DEG M_PI
15 #define RAD_270DEG (M_PI_2 * 3)
16 #define RAD_360DEG (M_PI * 2)
17 /* #define DEBUG_GESTURE_LAYER 1 */
20 _glayer_bufdup(void *buf, size_t size)
27 #define COPY_EVENT_INFO(EV) _glayer_bufdup(EV, sizeof(*EV))
30 #define SET_TEST_BIT(P) do { \
31 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; \
34 #define IS_TESTED(T) ((wd->gesture[T]) ? wd->gesture[T]->test : EINA_FALSE)
40 * Struct holds callback information.
42 * @ingroup Elm_Gesture_Layer
46 void *user_data; /**< Holds user data to CB (like sd) */
47 Elm_Gesture_Event_Cb cb;
54 * type for callback information
56 * @ingroup Elm_Gesture_Layer
58 typedef struct _Func_Data Func_Data;
63 * @struct _Gesture_Info
64 * Struct holds gesture info
66 * @ingroup Elm_Gesture_Layer
71 void *data; /**< Holds gesture intemidiate processing data */
72 Func_Data fn[ELM_GESTURE_STATE_ABORT + 1]; /**< Callback info for states */
73 Elm_Gesture_Types g_type; /**< gesture type */
74 Elm_Gesture_State state; /**< gesture state */
75 void *info; /**< Data for the state callback */
76 Eina_Bool test; /**< if true this gesture should be tested on input */
82 * @typedef Gesture_Info
83 * Type for _Gesture_Info
85 * @ingroup Elm_Gesture_Layer
87 typedef struct _Gesture_Info Gesture_Info;
92 * @struct _Event_History
93 * Struct holds event history.
94 * These events are repeated if no gesture found.
96 * @ingroup Elm_Gesture_Layer
102 Evas_Callback_Type event_type;
108 * @typedef Event_History
109 * Type for _Event_History
111 * @ingroup Elm_Gesture_Layer
113 typedef struct _Event_History Event_History;
118 * @struct _Pointer_Event
119 * Struct holds pointer-event info
120 * This is a generic pointer event structure
122 * @ingroup Elm_Gesture_Layer
124 struct _Pointer_Event
127 unsigned int timestamp;
129 Evas_Callback_Type event_type;
135 * @typedef Pointer_Event
136 * Type for generic pointer event structure
138 * @ingroup Elm_Gesture_Layer
140 typedef struct _Pointer_Event Pointer_Event;
142 /* All *Type structs hold result for the user in 'info' field
143 * The rest is gesture processing intermediate data.
144 * NOTE: info field must be FIRST in the struct.
145 * This is used when reporting ABORT in event_history_clear() */
148 Elm_Gesture_Taps_Info info;
151 unsigned int n_taps_needed;
155 typedef struct _Taps_Type Taps_Type;
157 struct _Long_Tap_Type
159 Elm_Gesture_Taps_Info info;
162 unsigned int max_touched;
163 Ecore_Timer *timeout; /* When this expires, long tap STARTed */
166 typedef struct _Long_Tap_Type Long_Tap_Type;
168 struct _Momentum_Type
169 { /* Fields used by _line_test() */
170 Elm_Gesture_Momentum_Info info;
171 Evas_Coord_Point line_st;
172 Evas_Coord_Point line_end;
173 unsigned int t_st_x; /* Time start on X */
174 unsigned int t_st_y; /* Time start on Y */
175 unsigned int t_end; /* Time end */
176 unsigned int t_up; /* Recent up event time */
179 typedef struct _Momentum_Type Momentum_Type;
183 Evas_Coord_Point line_st;
184 Evas_Coord_Point line_end;
185 Evas_Coord line_length;
186 unsigned int t_st; /* Time start */
187 unsigned int t_end; /* Time end */
189 double line_angle; /* Current angle of line */
191 typedef struct _Line_Data Line_Data;
194 { /* Fields used by _line_test() */
195 Elm_Gesture_Line_Info info;
196 Eina_List *list; /* List of Line_Data */
198 typedef struct _Line_Type Line_Type;
201 { /* Fields used by _zoom_test() */
202 Elm_Gesture_Zoom_Info info;
203 Pointer_Event zoom_st;
204 Pointer_Event zoom_mv;
205 Pointer_Event zoom_st1;
206 Pointer_Event zoom_mv1;
207 Evas_Event_Mouse_Wheel *zoom_wheel;
208 Evas_Coord zoom_base; /* Holds gap between fingers on zoom-start */
209 Evas_Coord zoom_distance_tolerance;
210 Elm_Gesture_Momentum_Info momentum1; /* For continues gesture */
211 Elm_Gesture_Momentum_Info momentum2; /* For continues gesture */
214 typedef struct _Zoom_Type Zoom_Type;
217 { /* Fields used by _rotation_test() */
218 Elm_Gesture_Rotate_Info info;
219 Pointer_Event rotate_st;
220 Pointer_Event rotate_mv;
221 Pointer_Event rotate_st1;
222 Pointer_Event rotate_mv1;
223 double rotate_angular_tolerance;
225 Elm_Gesture_Momentum_Info momentum1; /* For continues gesture */
226 Elm_Gesture_Momentum_Info momentum2; /* For continues gesture */
228 typedef struct _Rotate_Type Rotate_Type;
232 Evas_Object *target; /* Target Widget */
233 Event_History *event_history_list;
236 Evas_Coord zoom_distance_tolerance;
237 Evas_Coord line_distance_tolerance;
238 double line_angular_tolerance;
239 double zoom_wheel_factor; /* mouse wheel zoom steps */
240 double zoom_finger_factor; /* used for zoom factor */
241 double rotate_angular_tolerance;
242 unsigned int flick_time_limit_ms;
243 double long_tap_start_timeout;
244 Eina_Bool glayer_continues_enable;
249 Gesture_Info *gesture[ELM_GESTURE_LAST];
250 Ecore_Timer *dbl_timeout; /* When this expires, dbl click/taps ABORTed */
251 Eina_List *pending; /* List of devices need to refeed *UP event */
252 Eina_List *touched; /* Information of touched devices */
254 Eina_Bool repeat_events : 1;
256 typedef struct _Widget_Data Widget_Data;
258 static const char *widtype = NULL;
259 static void _del_hook(Evas_Object *obj);
261 static Eina_Bool _event_history_clear(Evas_Object *obj);
262 static void _reset_states(Widget_Data *wd);
263 static void _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
264 static void _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
265 static void _zoom_with_wheel_test(Evas_Object *obj, void *event_info, Evas_Callback_Type event_type, Elm_Gesture_Types g_type);
266 static void _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
267 static void _mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
268 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
269 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
271 static void _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
272 static void _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
273 static void _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
275 /* START - Functions to manage touched-device list */
278 * This function is used to find if device is touched
280 * @ingroup Elm_Gesture_Layer
283 compare_device(const void *data1, const void *data2)
284 { /* Compare the two device numbers */
285 return (((Pointer_Event *) data1)->device -((Pointer_Event *) data2)->device);
291 * Remove Pointer Event from touched device list
292 * @param list Pointer to touched device list.
293 * @param Pointer_Event Pointer to PE.
295 * @ingroup Elm_Gesture_Layer
298 _remove_touched_device(Eina_List *list, Pointer_Event *pe)
300 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
304 return eina_list_remove(list, p);
313 * Recoed Pointer Event in touched device list
314 * Note: This fuction allocates memory for PE event
315 * This memory is released in _remove_touched_device()
316 * @param list Pointer to touched device list.
317 * @param Pointer_Event Pointer to PE.
319 * @ingroup Elm_Gesture_Layer
322 _add_touched_device(Eina_List *list, Pointer_Event *pe)
324 Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
326 { /* We like to track device touch-position, overwrite info */
327 memcpy(p, pe, sizeof(Pointer_Event));
331 if ((pe->event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
332 (pe->event_type == EVAS_CALLBACK_MULTI_DOWN))
333 { /* Add touched device on DOWN event only */
334 p = malloc(sizeof(Pointer_Event));
335 /* Freed in _remove_touched_device() */
336 memcpy(p, pe, sizeof(Pointer_Event));
337 return eina_list_append(list, p);
342 /* END - Functions to manage touched-device list */
348 * @param event_info pointer to event.
350 * @ingroup Elm_Gesture_Layer
352 static Evas_Event_Flags
353 _get_event_flag(void *event_info, Evas_Callback_Type event_type)
357 case EVAS_CALLBACK_MOUSE_IN:
358 return ((Evas_Event_Mouse_In *) event_info)->event_flags;
359 case EVAS_CALLBACK_MOUSE_OUT:
360 return ((Evas_Event_Mouse_Out *) event_info)->event_flags;
361 case EVAS_CALLBACK_MOUSE_DOWN:
362 return ((Evas_Event_Mouse_Down *) event_info)->event_flags;
363 case EVAS_CALLBACK_MOUSE_MOVE:
364 return ((Evas_Event_Mouse_Move *) event_info)->event_flags;
365 case EVAS_CALLBACK_MOUSE_UP:
366 return ((Evas_Event_Mouse_Up *) event_info)->event_flags;
367 case EVAS_CALLBACK_MOUSE_WHEEL:
368 return ((Evas_Event_Mouse_Wheel *) event_info)->event_flags;
369 case EVAS_CALLBACK_MULTI_DOWN:
370 return ((Evas_Event_Multi_Down *) event_info)->event_flags;
371 case EVAS_CALLBACK_MULTI_MOVE:
372 return ((Evas_Event_Multi_Move *) event_info)->event_flags;
373 case EVAS_CALLBACK_MULTI_UP:
374 return ((Evas_Event_Multi_Up *) event_info)->event_flags;
375 case EVAS_CALLBACK_KEY_DOWN:
376 return ((Evas_Event_Key_Down *) event_info)->event_flags;
377 case EVAS_CALLBACK_KEY_UP:
378 return ((Evas_Event_Key_Up *) event_info)->event_flags;
380 return EVAS_EVENT_FLAG_NONE;
387 * Sets event flag to value returned from user callback
388 * @param wd Widget Data
389 * @param event_info pointer to event.
390 * @param event_type what type was ev (mouse down, etc...)
391 * @param ev_flags event flags
393 * @ingroup Elm_Gesture_Layer
396 consume_event(Widget_Data *wd, void *event_info,
397 Evas_Callback_Type event_type, Evas_Event_Flags ev_flags)
398 { /* Mark EVAS_EVENT_FLAG_ON_HOLD on events that are used by gesture layer */
399 /* ev_flags != EVAS_EVENT_FLAG_NONE means target used event and g-layer */
400 /* should not refeed this event. */
402 return; /* This happens when restarting gestures */
404 if ((ev_flags) || (!wd->repeat_events))
408 case EVAS_CALLBACK_MOUSE_DOWN:
409 ((Evas_Event_Mouse_Down *) event_info)->event_flags |= ev_flags;
411 case EVAS_CALLBACK_MOUSE_MOVE:
412 ((Evas_Event_Mouse_Move *) event_info)->event_flags |= ev_flags;
414 case EVAS_CALLBACK_MOUSE_UP:
415 ((Evas_Event_Mouse_Up *) event_info)->event_flags |= ev_flags;
417 case EVAS_CALLBACK_MOUSE_WHEEL:
418 ((Evas_Event_Mouse_Wheel *) event_info)->event_flags |= ev_flags;
420 case EVAS_CALLBACK_MULTI_DOWN:
421 ((Evas_Event_Multi_Down *) event_info)->event_flags |= ev_flags;
423 case EVAS_CALLBACK_MULTI_MOVE:
424 ((Evas_Event_Multi_Move *) event_info)->event_flags |= ev_flags;
426 case EVAS_CALLBACK_MULTI_UP:
427 ((Evas_Event_Multi_Up *) event_info)->event_flags |= ev_flags;
429 case EVAS_CALLBACK_KEY_DOWN:
430 ((Evas_Event_Key_Down *) event_info)->event_flags |= ev_flags;
432 case EVAS_CALLBACK_KEY_UP:
433 ((Evas_Event_Key_Up *) event_info)->event_flags |= ev_flags;
444 * Report current state of a gesture by calling user callback.
445 * @param gesture what gesture state we report.
446 * @param info inforamtion for user callback
448 * @ingroup Elm_Gesture_Layer
450 static Evas_Event_Flags
451 _report_state(Gesture_Info *gesture, void *info)
452 { /* We report current state (START, MOVE, END, ABORT), once */
453 #if defined(DEBUG_GESTURE_LAYER)
454 printf("%s reporting gesture=<%d> state=<%d>\n" , __func__, gesture->g_type,
457 if ((gesture->state != ELM_GESTURE_STATE_UNDEFINED) &&
458 (gesture->fn[gesture->state].cb))
459 { /* Fill state-info struct and send ptr to user callback */
460 return gesture->fn[gesture->state].cb(
461 gesture->fn[gesture->state].user_data, info);
464 return EVAS_EVENT_FLAG_NONE;
470 * Update state for a given gesture.
471 * We may update gesture state to:
472 * UNDEFINED - current input did not start gesure yet.
473 * START - gesture started according to input.
474 * MOVE - gusture in progress.
475 * END - gesture completed according to input.
476 * ABORT - input does not matches gesure.
477 * note that we may move from UNDEFINED to ABORT
478 * because we may detect that gesture will not START
479 * with a given input.
481 * @param g given gesture to change state.
482 * @param s gesure new state.
483 * @param info buffer to be sent to user callback on report_state.
484 * @param force makes report_state to report the new-state even
485 * if its same as current state. Works for MOVE - gesture in progress.
487 * @ingroup Elm_Gesture_Layer
489 static Evas_Event_Flags
490 _set_state(Gesture_Info *g, Elm_Gesture_State s,
491 void *info, Eina_Bool force)
493 Elm_Gesture_State old_state;
494 if ((g->state == s) && (!force))
495 return EVAS_EVENT_FLAG_NONE;
497 old_state = g->state;
500 g->info = info; /* Information for user callback */
501 if ((g->state == ELM_GESTURE_STATE_ABORT) ||
502 (g->state == ELM_GESTURE_STATE_END))
503 g->test = EINA_FALSE;
505 if ((g->state != ELM_GESTURE_STATE_UNDEFINED) &&
506 (!((old_state == ELM_GESTURE_STATE_UNDEFINED) &&
507 (s == ELM_GESTURE_STATE_ABORT))))
508 return _report_state(g, g->info);
510 return EVAS_EVENT_FLAG_NONE;
516 * This resets all gesture states and sets test-bit.
517 * this is used for restarting gestures to listen to input.
518 * happens after we complete a gesture or no gesture was detected.
519 * @param wd Widget data of the gesture-layer object.
521 * @ingroup Elm_Gesture_Layer
524 _reset_states(Widget_Data *wd)
528 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
533 _set_state(p, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
542 * if gesture was NOT detected AND we only have gestures in ABORT state
543 * we clear history immediately to be ready for input.
545 * @param obj The gesture-layer object.
546 * @return TRUE on event history_clear
548 * @ingroup Elm_Gesture_Layer
551 _clear_if_finished(Evas_Object *obj)
553 Widget_Data *wd = elm_widget_data_get(obj);
554 if (!wd) return EINA_FALSE;
557 /* Clear history if all we have aborted gestures */
558 Eina_Bool reset_s = EINA_TRUE, all_undefined = EINA_TRUE;
559 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
560 { /* If no gesture started and all we have aborted gestures, reset all */
561 Gesture_Info *p = wd->gesture[i];
562 if ((p) && (p->state != ELM_GESTURE_STATE_UNDEFINED))
564 if ((p->state == ELM_GESTURE_STATE_START) ||
565 (p->state == ELM_GESTURE_STATE_MOVE))
566 reset_s = EINA_FALSE;
568 all_undefined = EINA_FALSE;
572 if (reset_s && (!all_undefined))
573 return _event_history_clear(obj);
579 _inside(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
581 int w = elm_finger_size_get() >> 1; /* Finger size devided by 2 */
597 /* All *test_reset() funcs are called to clear
598 * gesture intermediate data.
599 * This happens when we need to reset our tests.
600 * for example when gesture is detected or all ABORTed. */
602 _tap_gestures_test_reset(Gesture_Info *gesture)
607 Widget_Data *wd = elm_widget_data_get(gesture->obj);
608 wd->dbl_timeout = NULL;
615 EINA_LIST_FREE(((Taps_Type *) gesture->data)->l, data)
616 EINA_LIST_FREE(data, pe)
619 memset(gesture->data, 0, sizeof(Taps_Type));
622 /* All *test_reset() funcs are called to clear
623 * gesture intermediate data.
624 * This happens when we need to reset our tests.
625 * for example when gesture is detected or all ABORTed. */
627 _n_long_tap_test_reset(Gesture_Info *gesture)
635 Long_Tap_Type *st = gesture->data;
638 EINA_LIST_FOREACH(st->touched, l, p)
641 eina_list_free(st->touched);
642 if (st->timeout) ecore_timer_del(st->timeout);
643 memset(gesture->data, 0, sizeof(Long_Tap_Type));
647 _momentum_test_reset(Gesture_Info *gesture)
655 memset(gesture->data, 0, sizeof(Momentum_Type));
659 _line_data_reset(Line_Data *st)
664 memset(st, 0, sizeof(Line_Data));
665 st->line_angle = ELM_GESTURE_NEGATIVE_ANGLE;
669 _line_test_reset(Gesture_Info *gesture)
677 Line_Type *st = gesture->data;
678 Eina_List *list = st->list;
681 EINA_LIST_FOREACH(list, l, t_line)
684 eina_list_free(list);
689 _zoom_test_reset(Gesture_Info *gesture)
697 Widget_Data *wd = elm_widget_data_get(gesture->obj);
698 Zoom_Type *st = gesture->data;
699 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
700 evas_object_evas_get(wd->target), "Control");
701 evas_object_key_ungrab(wd->target, "Control_L", mask, 0);
702 evas_object_key_ungrab(wd->target, "Control_R", mask, 0);
704 memset(st, 0, sizeof(Zoom_Type));
705 st->zoom_distance_tolerance = wd->zoom_distance_tolerance;
710 _rotate_test_reset(Gesture_Info *gesture)
718 Widget_Data *wd = elm_widget_data_get(gesture->obj);
719 Rotate_Type *st = gesture->data;
721 memset(st, 0, sizeof(Rotate_Type));
722 st->info.base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
723 st->rotate_angular_tolerance = wd->rotate_angular_tolerance;
730 * We register callbacks when gesture layer is attached to an object
731 * or when its enabled after disable.
733 * @param obj The gesture-layer object.
735 * @ingroup Elm_Gesture_Layer
738 _register_callbacks(Evas_Object *obj)
740 Widget_Data *wd = elm_widget_data_get(obj);
745 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
747 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
749 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_UP,
752 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
755 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_DOWN,
757 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_MOVE,
759 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_UP,
762 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_DOWN,
764 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_UP,
772 * We unregister callbacks when gesture layer is disabled.
774 * @param obj The gesture-layer object.
776 * @ingroup Elm_Gesture_Layer
779 _unregister_callbacks(Evas_Object *obj)
781 Widget_Data *wd = elm_widget_data_get(obj);
786 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
788 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
790 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_UP,
793 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
796 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_DOWN,
799 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_MOVE,
802 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_UP,
805 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_DOWN,
807 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_UP,
812 /* START - Event history list handling functions */
815 * This function is used to find if device number
816 * is found in a list of devices.
817 * The list contains devices for refeeding *UP event
819 * @ingroup Elm_Gesture_Layer
822 device_in_pending_list(const void *data1, const void *data2)
823 { /* Compare the two device numbers */
824 return (((intptr_t) data1) - ((intptr_t) data2));
830 * This functions adds device to refeed-pending device list
831 * @ingroup Elm_Gesture_Layer
834 _add_device_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
836 int device = ELM_MOUSE_DEVICE;
839 case EVAS_CALLBACK_MOUSE_DOWN:
841 case EVAS_CALLBACK_MULTI_DOWN:
842 device = ((Evas_Event_Multi_Down *) event)->device;
848 if (!eina_list_search_unsorted_list(list, device_in_pending_list,
851 return eina_list_append(list, (intptr_t*) device);
860 * This functions returns pending-device node
861 * @ingroup Elm_Gesture_Layer
864 _device_is_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
866 int device = ELM_MOUSE_DEVICE;
869 case EVAS_CALLBACK_MOUSE_UP:
871 case EVAS_CALLBACK_MULTI_UP:
872 device = ((Evas_Event_Multi_Up *) event)->device;
878 return eina_list_search_unsorted_list(list, device_in_pending_list,
879 (intptr_t *) device);
885 * This function reports ABORT to all none-detected gestures
886 * Then resets test bits for all desired gesures
887 * and clears input-events history.
888 * note: if no gesture was detected, events from history list
889 * are streamed to the widget because it's unused by layer.
890 * user may cancel refeed of events by setting repeat events.
892 * @param obj The gesture-layer object.
894 * @ingroup Elm_Gesture_Layer
897 _event_history_clear(Evas_Object *obj)
899 Widget_Data *wd = elm_widget_data_get(obj);
900 if (!wd) return EINA_FALSE;
904 Evas *e = evas_object_evas_get(obj);
905 Eina_Bool gesture_found = EINA_FALSE;
906 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
911 if (p->state == ELM_GESTURE_STATE_END)
912 gesture_found = EINA_TRUE;
914 { /* Report ABORT to all gestures that still not finished */
915 _set_state(p, ELM_GESTURE_STATE_ABORT, wd->gesture[i]->info,
921 _reset_states(wd); /* we are ready to start testing for gestures again */
923 /* Clear all gestures intermediate data */
924 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
925 { /* We do not clear a long-tap gesture if fingers still on surface */
926 /* and gesture timer still pending to test gesture state */
927 Long_Tap_Type *st = wd->gesture[ELM_GESTURE_N_LONG_TAPS]->data;
928 if ((st) && /* st not allocated if clear occurs before 1st input */
929 ((!eina_list_count(st->touched)) || (!st->timeout)))
930 _n_long_tap_test_reset(wd->gesture[ELM_GESTURE_N_LONG_TAPS]);
935 ecore_timer_del(wd->dbl_timeout);
936 wd->dbl_timeout = NULL;
939 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_TAPS]);
940 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
941 _tap_gestures_test_reset(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
942 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
943 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
944 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
945 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
946 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
948 /* Disable gesture layer so refeeded events won't be consumed by it */
949 _unregister_callbacks(obj);
950 while (wd->event_history_list)
953 t = wd->event_history_list;
954 Eina_List *pending = _device_is_pending(wd->pending,
955 wd->event_history_list->event,
956 wd->event_history_list->event_type);
958 /* Refeed events if no gesture matched input */
959 if (pending || ((!gesture_found) && (!wd->repeat_events)))
961 evas_event_refeed_event(e, wd->event_history_list->event,
962 wd->event_history_list->event_type);
966 wd->pending = eina_list_remove_list(wd->pending, pending);
970 wd->pending = _add_device_pending(wd->pending,
971 wd->event_history_list->event,
972 wd->event_history_list->event_type);
976 free(wd->event_history_list->event);
977 wd->event_history_list = (Event_History *) eina_inlist_remove(
978 EINA_INLIST_GET(wd->event_history_list),
979 EINA_INLIST_GET(wd->event_history_list));
982 _register_callbacks(obj);
989 * This function copies input events.
990 * We copy event info before adding it to history.
991 * The memory is freed when we clear history.
993 * @param event the event to copy
994 * @param event_type event type to copy
996 * @ingroup Elm_Gesture_Layer
999 _copy_event_info(void *event, Evas_Callback_Type event_type)
1003 case EVAS_CALLBACK_MOUSE_DOWN:
1004 return COPY_EVENT_INFO((Evas_Event_Mouse_Down *) event);
1006 case EVAS_CALLBACK_MOUSE_MOVE:
1007 return COPY_EVENT_INFO((Evas_Event_Mouse_Move *) event);
1009 case EVAS_CALLBACK_MOUSE_UP:
1010 return COPY_EVENT_INFO((Evas_Event_Mouse_Up *) event);
1012 case EVAS_CALLBACK_MOUSE_WHEEL:
1013 return COPY_EVENT_INFO((Evas_Event_Mouse_Wheel *) event);
1015 case EVAS_CALLBACK_MULTI_DOWN:
1016 return COPY_EVENT_INFO((Evas_Event_Multi_Down *) event);
1018 case EVAS_CALLBACK_MULTI_MOVE:
1019 return COPY_EVENT_INFO((Evas_Event_Multi_Move *) event);
1021 case EVAS_CALLBACK_MULTI_UP:
1022 return COPY_EVENT_INFO((Evas_Event_Multi_Up *) event);
1024 case EVAS_CALLBACK_KEY_DOWN:
1025 return COPY_EVENT_INFO((Evas_Event_Key_Down *) event);
1027 case EVAS_CALLBACK_KEY_UP:
1028 return COPY_EVENT_INFO((Evas_Event_Key_Up *) event);
1036 _event_history_add(Evas_Object *obj, void *event, Evas_Callback_Type event_type)
1038 Widget_Data *wd = elm_widget_data_get(obj);
1040 if (!wd) return EINA_FALSE;
1042 ev = malloc(sizeof(Event_History));
1043 ev->event = _copy_event_info(event, event_type); /* Freed on event_history_clear */
1044 ev->event_type = event_type;
1045 wd->event_history_list = (Event_History *) eina_inlist_append(
1046 EINA_INLIST_GET(wd->event_history_list), EINA_INLIST_GET(ev));
1050 /* END - Event history list handling functions */
1053 _del_hook(Evas_Object *obj)
1055 Widget_Data *wd = elm_widget_data_get(obj);
1058 _event_history_clear(obj);
1059 eina_list_free(wd->pending);
1061 Pointer_Event *data;
1062 EINA_LIST_FREE(wd->touched, data)
1065 if (!elm_widget_disabled_get(obj))
1066 _unregister_callbacks(obj);
1068 /* Free all gestures internal data structures */
1070 for (i = 0; i < ELM_GESTURE_LAST; i++)
1073 if (wd->gesture[i]->data)
1074 free(wd->gesture[i]->data);
1076 free(wd->gesture[i]);
1083 compare_match_fingers(const void *data1, const void *data2)
1084 { /* Compare coords of first item in list to cur coords */
1085 const Pointer_Event *pe1 = eina_list_data_get(data1);
1086 const Pointer_Event *pe2 = data2;
1088 if (_inside(pe1->x, pe1->y, pe2->x, pe2->y))
1090 else if (pe1->x < pe2->x)
1094 if (pe1->x == pe2->x)
1095 return pe1->y - pe2->y;
1102 compare_pe_device(const void *data1, const void *data2)
1103 { /* Compare device of first item in list to our pe device */
1104 const Pointer_Event *pe1 = eina_list_data_get(data1);
1105 const Pointer_Event *pe2 = data2;
1107 /* Only match if last was a down event */
1108 if ((pe1->event_type != EVAS_CALLBACK_MULTI_DOWN) &&
1109 (pe1->event_type != EVAS_CALLBACK_MOUSE_DOWN))
1113 if (pe1->device == pe2->device)
1115 else if (pe1->device < pe2->device)
1122 _record_pointer_event(Taps_Type *st, Eina_List *pe_list, Pointer_Event *pe,
1123 Widget_Data *wd, void *event_info, Evas_Callback_Type event_type)
1124 { /* Keep copy of pe and record it in list */
1125 Pointer_Event *p = malloc(sizeof(Pointer_Event));
1126 memcpy(p, pe, sizeof(Pointer_Event));
1127 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1133 /* This will also update middle-point to report to user later */
1134 st->info.x = st->sum_x / st->n_taps;
1135 st->info.y = st->sum_y / st->n_taps;
1136 st->info.timestamp = pe->timestamp;
1140 pe_list = eina_list_append(pe_list, p);
1141 st->l = eina_list_append(st->l, pe_list);
1144 pe_list = eina_list_append(pe_list, p);
1152 * This function sets state a tap-gesture to END or ABORT
1154 * @param data gesture info pointer
1156 * @ingroup Elm_Gesture_Layer
1159 _tap_gesture_finish(void *data)
1160 { /* This function will test each tap gesture when timer expires */
1161 Gesture_Info *gesture = data;
1162 Elm_Gesture_State s = ELM_GESTURE_STATE_END;
1163 /* Here we check if taps-gesture was completed successfuly */
1164 /* Count how many taps were recieved on each device then */
1165 /* determine if it matches n_taps_needed defined on START */
1166 Taps_Type *st = gesture->data;
1169 EINA_LIST_FOREACH(st->l, l, pe_list)
1171 if (eina_list_count(pe_list) != st->n_taps_needed)
1172 { /* No match taps number on device, ABORT */
1173 s = ELM_GESTURE_STATE_ABORT;
1178 st->info.n = eina_list_count(st->l);
1179 _set_state(gesture, s, gesture->info, EINA_FALSE);
1180 _tap_gestures_test_reset(gesture);
1186 * when this timer expires we finish tap gestures.
1188 * @param data The gesture-layer object.
1189 * @return cancles callback for this timer.
1191 * @ingroup Elm_Gesture_Layer
1194 _multi_tap_timeout(void *data)
1196 Widget_Data *wd = elm_widget_data_get(data);
1197 if (!wd) return EINA_FALSE;
1199 if (IS_TESTED(ELM_GESTURE_N_TAPS))
1200 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TAPS]);
1202 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
1203 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
1205 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
1206 _tap_gesture_finish(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
1208 _clear_if_finished(data);
1209 wd->dbl_timeout = NULL;
1210 return ECORE_CALLBACK_CANCEL;
1216 * when this timer expires we START long tap gesture
1218 * @param data The gesture-layer object.
1219 * @return cancles callback for this timer.
1221 * @ingroup Elm_Gesture_Layer
1224 _long_tap_timeout(void *data)
1226 Gesture_Info *gesture = data;
1227 Long_Tap_Type *st = gesture->data;
1230 _set_state(gesture, ELM_GESTURE_STATE_START,
1231 gesture->data, EINA_FALSE);
1233 return ECORE_CALLBACK_CANCEL;
1240 * This function checks if a tap gesture should start
1242 * @param wd Gesture Layer Widget Data.
1243 * @param pe The recent input event as stored in pe struct.
1244 * @param event_info Original input event pointer.
1245 * @param event_type Type of original input event.
1246 * @param gesture what gesture is tested
1247 * @param how many taps for this gesture (1, 2 or 3)
1249 * @return Flag to determine if we need to set a timer for finish
1251 * @ingroup Elm_Gesture_Layer
1254 _tap_gesture_start(Widget_Data *wd, Pointer_Event *pe,
1255 void *event_info, Evas_Callback_Type event_type,
1256 Gesture_Info *gesture, int taps)
1257 { /* Here we fill Tap struct */
1258 Taps_Type *st = gesture->data;
1260 { /* Allocated once on first time */
1261 st = calloc(1, sizeof(Taps_Type));
1263 _tap_gestures_test_reset(gesture);
1266 Eina_List *pe_list = NULL;
1267 Pointer_Event *pe_down = NULL;
1268 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1269 switch (pe->event_type)
1271 case EVAS_CALLBACK_MULTI_DOWN:
1272 case EVAS_CALLBACK_MOUSE_DOWN:
1273 /* Check if got tap on same cord was tapped before */
1274 pe_list = eina_list_search_unsorted(st->l, compare_match_fingers, pe);
1277 eina_list_search_unsorted(st->l, compare_pe_device, pe))
1278 { /* This device was touched in other cord before completion */
1279 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1280 &st->info, EINA_FALSE);
1281 consume_event(wd, event_info, event_type, ev_flag);
1286 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1287 if ((pe->device == 0) && (eina_list_count(pe_list) == 1))
1288 { /* This is the first mouse down we got */
1289 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1290 &st->info, EINA_FALSE);
1291 consume_event(wd, event_info, event_type, ev_flag);
1293 st->n_taps_needed = taps * 2; /* count DOWN and UP */
1300 case EVAS_CALLBACK_MULTI_UP:
1301 case EVAS_CALLBACK_MOUSE_UP:
1302 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1306 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1309 case EVAS_CALLBACK_MULTI_MOVE:
1310 case EVAS_CALLBACK_MOUSE_MOVE:
1311 /* Get first event in first list, this has to be a Mouse Down event */
1312 /* and verify that user didn't move out of this area before next tap */
1313 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1316 pe_down = eina_list_data_get(pe_list);
1317 if (!_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1319 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1320 &st->info, EINA_FALSE);
1321 consume_event(wd, event_info, event_type, ev_flag);
1337 * This function checks all click/tap and double/triple taps
1339 * @param obj The gesture-layer object.
1340 * @param pe The recent input event as stored in pe struct.
1341 * @param event_info Original input event pointer.
1342 * @param event_type Type of original input event.
1344 * @ingroup Elm_Gesture_Layer
1347 _tap_gestures_test(Evas_Object *obj, Pointer_Event *pe,
1348 void *event_info, Evas_Callback_Type event_type)
1349 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1350 Eina_Bool need_timer = EINA_FALSE;
1351 Widget_Data *wd = elm_widget_data_get(obj);
1354 if (!pe) /* this happens when unhandled event arrived */
1355 return; /* see _make_pointer_event function */
1357 if (IS_TESTED(ELM_GESTURE_N_TAPS))
1358 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1359 wd->gesture[ELM_GESTURE_N_TAPS], 1);
1361 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
1362 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1363 wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS], 2);
1365 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
1366 need_timer |= _tap_gesture_start(wd, pe, event_info, event_type,
1367 wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS], 3);
1369 if ((need_timer) && (!wd->dbl_timeout))
1370 { /* Set a timer to finish these gestures */
1371 wd->dbl_timeout = ecore_timer_add(0.4, _multi_tap_timeout,
1379 * This function computes center-point for long-tap gesture
1381 * @param st Long Tap gesture info pointer
1382 * @param pe The recent input event as stored in pe struct.
1384 * @ingroup Elm_Gesture_Layer
1387 _compute_taps_center(Long_Tap_Type *st,
1388 Evas_Coord *x_out, Evas_Coord *y_out, Pointer_Event *pe)
1390 if(!eina_list_count(st->touched))
1395 Evas_Coord x = 0, y = 0;
1396 EINA_LIST_FOREACH(st->touched, l, p)
1397 { /* Accumulate all then take avarage */
1398 if (p->device == pe->device)
1399 { /* This will take care of values coming from MOVE event */
1410 *x_out = x / eina_list_count(st->touched);
1411 *y_out = y / eina_list_count(st->touched);
1417 * This function checks N long-tap gesture.
1419 * @param obj The gesture-layer object.
1420 * @param pe The recent input event as stored in pe struct.
1421 * @param event_info Original input event pointer.
1422 * @param event_type Type of original input event.
1423 * @param g_type what Gesture we are testing.
1424 * @param taps How many click/taps we test for.
1426 * @ingroup Elm_Gesture_Layer
1429 _n_long_tap_test(Evas_Object *obj, Pointer_Event *pe,
1430 void *event_info, Evas_Callback_Type event_type,
1431 Elm_Gesture_Types g_type)
1432 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1433 Widget_Data *wd = elm_widget_data_get(obj);
1436 if (!pe) /* this happens when unhandled event arrived */
1437 return; /* see _make_pointer_event function */
1438 Gesture_Info *gesture = wd->gesture[g_type];
1439 if (!gesture) return;
1441 Long_Tap_Type *st = gesture->data;
1443 { /* Allocated once on first time */
1444 st = calloc(1, sizeof(Long_Tap_Type));
1446 _n_long_tap_test_reset(gesture);
1449 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1450 switch (pe->event_type)
1452 case EVAS_CALLBACK_MULTI_DOWN:
1453 case EVAS_CALLBACK_MOUSE_DOWN:
1454 st->touched = _add_touched_device(st->touched, pe);
1455 st->info.n = eina_list_count(st->touched);
1456 if (st->info.n > st->max_touched)
1457 st->max_touched = st->info.n;
1459 { /* User removed finger from touch, then put back - ABORT */
1460 if ((gesture->state == ELM_GESTURE_STATE_START) ||
1461 (gesture->state == ELM_GESTURE_STATE_MOVE))
1463 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1464 &st->info, EINA_FALSE);
1465 consume_event(wd, event_info, event_type, ev_flag);
1469 if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
1470 { /* This is the first mouse down we got */
1471 st->info.timestamp = pe->timestamp;
1473 /* To test long tap */
1474 /* When this timer expires, gesture STARTED */
1476 st->timeout = ecore_timer_add(wd->long_tap_start_timeout,
1477 _long_tap_timeout, gesture);
1480 consume_event(wd, event_info, event_type, ev_flag);
1481 _compute_taps_center(st, &st->info.x, &st->info.y, pe);
1482 st->center_x = st->info.x;
1483 st->center_y = st->info.y;
1486 case EVAS_CALLBACK_MULTI_UP:
1487 case EVAS_CALLBACK_MOUSE_UP:
1488 st->touched = _remove_touched_device(st->touched, pe);
1489 _compute_taps_center(st, &st->center_x, &st->center_y, pe);
1491 ((gesture->state == ELM_GESTURE_STATE_START) ||
1492 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1493 { /* Report END only for gesture that STARTed */
1494 if (eina_list_count(st->touched) == 0)
1495 { /* Report END only at last release event */
1496 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1497 &st->info, EINA_FALSE);
1498 consume_event(wd, event_info, event_type, ev_flag);
1502 { /* Stop test, user lifts finger before long-start */
1503 if (st->timeout) ecore_timer_del(st->timeout);
1505 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
1506 &st->info, EINA_FALSE);
1507 consume_event(wd, event_info, event_type, ev_flag);
1512 case EVAS_CALLBACK_MULTI_MOVE:
1513 case EVAS_CALLBACK_MOUSE_MOVE:
1515 ((gesture->state == ELM_GESTURE_STATE_START) ||
1516 (gesture->state == ELM_GESTURE_STATE_MOVE)))
1517 { /* Report MOVE only if STARTED */
1520 Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
1522 _compute_taps_center(st, &x, &y, pe);
1523 /* ABORT if user moved fingers out of tap area */
1524 #if defined(DEBUG_GESTURE_LAYER)
1525 printf("%s x,y=(%d,%d) st->info.x,st->info.y=(%d,%d)\n",__func__,x,y,st->info.x,st->info.y);
1527 if (!_inside(x, y, st->center_x, st->center_y))
1528 state_to_report = ELM_GESTURE_STATE_ABORT;
1530 /* Report MOVE if gesture started */
1531 ev_flag = _set_state(gesture, state_to_report,
1532 &st->info, EINA_TRUE);
1533 consume_event(wd, event_info, event_type, ev_flag);
1545 * This function computes momentum for MOMENTUM, LINE and FLICK gestures
1546 * This momentum value will be sent to widget when gesture is completed.
1548 * @param momentum pointer to buffer where we record momentum value.
1549 * @param x1 x coord where user started gesture.
1550 * @param y1 y coord where user started gesture.
1551 * @param x2 x coord where user completed gesture.
1552 * @param y2 y coord where user completed gesture.
1553 * @param t1x timestamp for X, when user started gesture.
1554 * @param t1y timestamp for Y, when user started gesture.
1555 * @param t2 timestamp when user completed gesture.
1557 * @ingroup Elm_Gesture_Layer
1560 _set_momentum(Elm_Gesture_Momentum_Info *momentum, Evas_Coord x1, Evas_Coord y1,
1561 Evas_Coord x2, Evas_Coord y2, unsigned int t1x, unsigned int t1y,
1564 Evas_Coord velx = 0, vely = 0, vel;
1565 Evas_Coord dx = x2 - x1;
1566 Evas_Coord dy = y2 - y1;
1570 velx = (dx * 1000) / dtx;
1573 vely = (dy * 1000) / dty;
1575 vel = sqrt((velx * velx) + (vely * vely));
1577 if ((_elm_config->thumbscroll_friction > 0.0) &&
1578 (vel > _elm_config->thumbscroll_momentum_threshold))
1579 { /* report momentum */
1580 momentum->mx = velx;
1581 momentum->my = vely;
1593 * This function is used for computing rotation angle (DEG).
1595 * @param x1 first finger x location.
1596 * @param y1 first finger y location.
1597 * @param x2 second finger x location.
1598 * @param y2 second finger y location.
1600 * @return angle of the line between (x1,y1), (x2,y2) in Radians.
1602 * @ingroup Elm_Gesture_Layer
1605 get_angle(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
1611 if (((int) xx) && ((int) yy))
1618 return RAD_360DEG - a;
1629 return RAD_180DEG + a;
1633 return RAD_180DEG - a;
1639 { /* Horizontal line */
1664 * This function is used for computing the magnitude and direction
1665 * of vector between two points.
1667 * @param x1 first finger x location.
1668 * @param y1 first finger y location.
1669 * @param x2 second finger x location.
1670 * @param y2 second finger y location.
1671 * @param l length computed (output)
1672 * @param a angle computed (output)
1674 * @ingroup Elm_Gesture_Layer
1677 get_vector(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2,
1678 Evas_Coord *l, double *a)
1683 *l = (Evas_Coord) sqrt(xx*xx + yy*yy);
1684 *a = get_angle(x1, y1, x2, y2);
1688 _get_direction(Evas_Coord x1, Evas_Coord x2)
1700 * This function tests momentum gesture.
1701 * @param obj The gesture-layer object.
1702 * @param pe The recent input event as stored in pe struct.
1703 * @param event_info recent input event.
1704 * @param event_type recent event type.
1705 * @param g_type what Gesture we are testing.
1707 * @ingroup Elm_Gesture_Layer
1710 _momentum_test(Evas_Object *obj, Pointer_Event *pe,
1711 void *event_info, Evas_Callback_Type event_type,
1712 Elm_Gesture_Types g_type)
1714 Widget_Data *wd = elm_widget_data_get(obj);
1716 Gesture_Info *gesture = wd->gesture[g_type];
1717 if (!gesture ) return;
1719 if ((wd->glayer_continues_enable) && (!eina_list_count(wd->touched)))
1720 return; /* Got move on mouse-over move */
1722 Momentum_Type *st = gesture->data;
1723 Elm_Gesture_State state_to_report = ELM_GESTURE_STATE_MOVE;
1725 { /* Allocated once on first time */
1726 st = calloc(1, sizeof(Momentum_Type));
1728 _momentum_test_reset(gesture);
1734 /* First make avarage of all touched devices to determine center point */
1737 Pointer_Event pe_local = *pe; /* Copy pe event info to local */
1738 unsigned int cnt = 1; /* We start counter counting current pe event */
1739 EINA_LIST_FOREACH(wd->touched, l, p)
1740 if (p->device != pe_local.device)
1748 /* Compute avarage to get center point */
1752 /* If user added finger - reset gesture */
1753 if ((st->info.n) && (st->info.n < cnt))
1754 state_to_report = ELM_GESTURE_STATE_ABORT;
1756 if (st->info.n < cnt)
1759 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1762 case EVAS_CALLBACK_MOUSE_DOWN:
1763 case EVAS_CALLBACK_MULTI_DOWN:
1764 case EVAS_CALLBACK_MOUSE_MOVE:
1765 case EVAS_CALLBACK_MULTI_MOVE:
1768 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1769 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
1770 (wd->glayer_continues_enable)) /* start also on MOVE */
1771 { /* We start on MOVE when cont-enabled only */
1772 st->line_st.x = st->line_end.x = pe_local.x;
1773 st->line_st.y = st->line_end.y = pe_local.y;
1774 st->t_st_x = st->t_st_y = st->t_end = pe_local.timestamp;
1775 st->xdir = st->ydir = 0;
1776 st->info.x2 = st->info.x1 = pe_local.x;
1777 st->info.y2 = st->info.y1 = pe_local.y;
1778 st->info.tx = st->info.ty = pe_local.timestamp;
1779 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1780 &st->info, EINA_FALSE);
1781 consume_event(wd, event_info, event_type, ev_flag);
1788 /* ABORT gesture if got DOWN or MOVE event after UP+timeout */
1790 ((st->t_up + ELM_GESTURE_MULTI_TIMEOUT) < pe_local.timestamp))
1791 state_to_report = ELM_GESTURE_STATE_ABORT;
1793 if ((pe_local.timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1794 { /* Too long of a wait, reset all values */
1795 st->line_st.x = pe_local.x;
1796 st->line_st.y = pe_local.y;
1797 st->t_st_y = st->t_st_x = pe_local.timestamp;
1798 st->info.tx = st->t_st_x;
1799 st->info.ty = st->t_st_y;
1800 st->xdir = st->ydir = 0;
1805 xdir = _get_direction(st->line_st.x, pe_local.x);
1806 ydir = _get_direction(st->line_st.y, pe_local.y);
1807 if (!xdir || (xdir == (-st->xdir)))
1809 st->line_st.x = st->line_end.x;
1810 st->info.tx = st->t_st_x = st->t_end;
1814 if (!ydir || (ydir == (-st->ydir)))
1816 st->line_st.y = st->line_end.y;
1817 st->info.ty = st->t_st_y = st->t_end;
1822 st->info.x2 = st->line_end.x = pe_local.x;
1823 st->info.y2 = st->line_end.y = pe_local.y;
1824 st->t_end = pe_local.timestamp;
1825 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe_local.x, pe_local.y,
1826 st->t_st_x, st->t_st_y, pe_local.timestamp);
1827 ev_flag = _set_state(gesture, state_to_report, &st->info,
1829 consume_event(wd, event_info, event_type, ev_flag);
1833 case EVAS_CALLBACK_MOUSE_UP:
1834 case EVAS_CALLBACK_MULTI_UP:
1835 st->t_up = pe_local.timestamp; /* Record recent up event time */
1836 if ((cnt > 1) || /* Ignore if more fingers touch surface */
1837 (!st->t_st_x)) /* IGNORE if info was cleared, long press,move */
1840 if ((pe_local.timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1841 { /* Too long of a wait, reset all values */
1842 st->line_st.x = pe_local.x;
1843 st->line_st.y = pe_local.y;
1844 st->t_st_y = st->t_st_x = pe_local.timestamp;
1845 st->xdir = st->ydir = 0;
1848 st->info.x2 = pe_local.x;
1849 st->info.y2 = pe_local.y;
1850 st->line_end.x = pe_local.x;
1851 st->line_end.y = pe_local.y;
1852 st->t_end = pe_local.timestamp;
1854 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe_local.x, pe_local.y,
1855 st->t_st_x, st->t_st_y, pe_local.timestamp);
1857 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END, &st->info,
1859 consume_event(wd, event_info, event_type, ev_flag);
1868 compare_line_device(const void *data1, const void *data2)
1869 { /* Compare device component of line struct */
1870 const Line_Data *ln1 = data1;
1871 const int *device = data2;
1873 if (ln1->t_st) /* Compare only with lines that started */
1874 return (ln1->device - (*device));
1882 * This function construct line struct from input.
1883 * @param info pointer to store line momentum.
1884 * @param st line info to store input data.
1885 * @param pe The recent input event as stored in pe struct.
1887 * @ingroup Elm_Gesture_Layer
1890 _single_line_process(Elm_Gesture_Line_Info *info, Line_Data *st,
1891 Pointer_Event *pe, Evas_Callback_Type event_type)
1892 { /* Record events and set momentum for line pointed by st */
1898 case EVAS_CALLBACK_MOUSE_DOWN:
1899 case EVAS_CALLBACK_MOUSE_MOVE:
1900 case EVAS_CALLBACK_MULTI_DOWN:
1901 case EVAS_CALLBACK_MULTI_MOVE:
1903 { /* This happens only when line starts */
1904 st->line_st.x = pe->x;
1905 st->line_st.y = pe->y;
1906 st->t_st = pe->timestamp;
1907 st->device = pe->device;
1908 info->momentum.x1 = pe->x;
1909 info->momentum.y1 = pe->y;
1910 info->momentum.tx = pe->timestamp;
1911 info->momentum.ty = pe->timestamp;
1918 case EVAS_CALLBACK_MOUSE_UP:
1919 case EVAS_CALLBACK_MULTI_UP:
1920 /* IGNORE if line info was cleared, like long press, move */
1924 st->line_end.x = pe->x;
1925 st->line_end.y = pe->y;
1926 st->t_end = pe->timestamp;
1935 _line_data_reset(st);
1939 info->momentum.x2 = pe->x;
1940 info->momentum.y2 = pe->y;
1941 _set_momentum(&info->momentum, st->line_st.x, st->line_st.y, pe->x, pe->y,
1942 st->t_st, st->t_st, pe->timestamp);
1950 * This function test for (n) line gesture.
1951 * @param obj The gesture-layer object.
1952 * @param pe The recent input event as stored in pe struct.
1953 * @param event_info Original input event pointer.
1954 * @param event_type Type of original input event.
1955 * @param g_type what Gesture we are testing.
1957 * @ingroup Elm_Gesture_Layer
1960 _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
1961 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
1965 Widget_Data *wd = elm_widget_data_get(obj);
1967 Gesture_Info *gesture = wd->gesture[g_type];
1968 if (!gesture ) return;
1970 if ((wd->glayer_continues_enable) && (!eina_list_count(wd->touched)))
1971 return; /* Got move on mouse-over move */
1973 Line_Type *st = gesture->data;
1976 st = calloc(1, sizeof(Line_Type));
1980 Line_Data *line = NULL;
1981 Eina_List *list = st->list;
1982 unsigned cnt = eina_list_count(list);
1985 { /* list is not empty, locate this device on list */
1986 line = (Line_Data *) eina_list_search_unsorted(st->list,
1987 compare_line_device, &pe->device);
1991 { /* List is empty or device not found, new line-struct on START only */
1992 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1993 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
1994 ((wd->glayer_continues_enable) && /* START on MOVE also */
1995 ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
1996 (event_type == EVAS_CALLBACK_MULTI_MOVE))))
1997 { /* Allocate new item on START only */
1998 line = calloc(1, sizeof(Line_Data));
1999 _line_data_reset(line);
2000 list = eina_list_append(list, line);
2005 if (!line) /* This may happen on MOVE that comes before DOWN */
2006 return; /* No line-struct to work with, can't continue testing */
2008 if (_single_line_process(&st->info, line, pe, event_type)) /* update st with input */
2009 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
2011 /* Get direction and magnitude of the line */
2013 get_vector(line->line_st.x, line->line_st.y, pe->x, pe->y,
2014 &line->line_length, &angle);
2016 /* These are used later to compare lines length */
2017 Evas_Coord shortest_line_len = line->line_length;
2018 Evas_Coord longest_line_len = line->line_length;
2019 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2021 /* Now update line-state */
2023 { /* Analyze line only if line started */
2024 if (line->line_angle >= 0.0)
2025 { /* if line direction was set, we test if broke tolerance */
2026 double a = fabs(angle - line->line_angle);
2028 double d = (tan(a)) * line->line_length; /* Distance from line */
2029 #if defined(DEBUG_GESTURE_LAYER)
2030 printf("%s a=<%f> d=<%f>\n", __func__, (a * 57.295779513), d);
2032 if ((d > wd->line_distance_tolerance) || (a > wd->line_angular_tolerance))
2033 { /* Broke tolerance: abort line and start a new one */
2034 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2035 &st->info, EINA_FALSE);
2036 consume_event(wd, event_info, event_type, ev_flag);
2040 if (wd->glayer_continues_enable)
2041 { /* We may finish line if momentum is zero */
2042 /* This is for continues-gesture */
2043 if ((!st->info.momentum.mx) && (!st->info.momentum.my))
2044 { /* Finish line on zero momentum for continues gesture */
2045 line->line_end.x = pe->x;
2046 line->line_end.y = pe->y;
2047 line->t_end = pe->timestamp;
2052 { /* Record the line angle as it broke minimum length for line */
2053 if (line->line_length >= wd->line_min_length)
2054 st->info.angle = line->line_angle = angle;
2060 if (line->line_angle < 0.0)
2061 { /* it's not a line, too short more close to a tap */
2062 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2063 &st->info, EINA_FALSE);
2064 consume_event(wd, event_info, event_type, ev_flag);
2070 /* Count how many lines already started / ended */
2073 unsigned int tm_start = pe->timestamp;
2074 unsigned int tm_end = pe->timestamp;
2077 double base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
2078 Eina_Bool lines_parallel = EINA_TRUE;
2079 EINA_LIST_FOREACH(list, l, t_line)
2082 base_angle = t_line->line_angle;
2085 if (t_line->line_angle >= 0)
2086 { /* Compare angle only with lines with direction defined */
2087 if (fabs(base_angle - t_line->line_angle) >
2088 wd->line_angular_tolerance)
2089 lines_parallel = EINA_FALSE;
2093 if (t_line->line_length)
2094 { /* update only if this line is used */
2095 if (shortest_line_len > t_line->line_length)
2096 shortest_line_len = t_line->line_length;
2098 if (longest_line_len < t_line->line_length)
2099 longest_line_len = t_line->line_length;
2105 if (t_line->t_st < tm_start)
2106 tm_start = t_line->t_st;
2112 if (t_line->t_end < tm_end)
2113 tm_end = t_line->t_end;
2117 st->info.momentum.n = started;
2121 ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2122 (event_type == EVAS_CALLBACK_MULTI_DOWN)))
2123 { /* user lift one finger then starts again without line-end - ABORT */
2124 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2126 consume_event(wd, event_info, event_type, ev_flag);
2130 if (!lines_parallel)
2131 { /* Lines are NOT at same direction, abort this gesture */
2132 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2134 consume_event(wd, event_info, event_type, ev_flag);
2139 /* We report ABORT if lines length are NOT matching when fingers are up */
2140 if ((longest_line_len - shortest_line_len) > (elm_finger_size_get()*2))
2142 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2144 consume_event(wd, event_info, event_type, ev_flag);
2148 if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > wd->flick_time_limit_ms))
2149 { /* We consider FLICK as a fast line.ABORT if take too long to finish */
2150 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
2152 consume_event(wd, event_info, event_type, ev_flag);
2158 case EVAS_CALLBACK_MOUSE_UP:
2159 case EVAS_CALLBACK_MULTI_UP:
2160 if ((started) && (started == ended))
2162 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2163 &st->info, EINA_FALSE);
2164 consume_event(wd, event_info, event_type, ev_flag);
2169 case EVAS_CALLBACK_MOUSE_DOWN:
2170 case EVAS_CALLBACK_MULTI_DOWN:
2171 case EVAS_CALLBACK_MOUSE_MOVE:
2172 case EVAS_CALLBACK_MULTI_MOVE:
2175 if (wd->glayer_continues_enable && (started == ended))
2176 { /* For continues gesture */
2177 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2178 &st->info, EINA_FALSE);
2179 consume_event(wd, event_info, event_type, ev_flag);
2182 { /* When continues, may START on MOVE event too */
2183 Elm_Gesture_State s = ELM_GESTURE_STATE_MOVE;
2185 /* This happens when: on n > 1 lines then one finger up */
2186 /* caused abort, then put finger down. */
2187 /* This will stop line from starting again. */
2188 /* Number of lines, MUST match touched-device in list */
2189 if ((!wd->glayer_continues_enable) &&
2190 (eina_list_count(st->list) < eina_list_count(wd->touched)))
2191 s = ELM_GESTURE_STATE_ABORT;
2193 if (gesture->state == ELM_GESTURE_STATE_UNDEFINED)
2194 s = ELM_GESTURE_STATE_START;
2196 ev_flag = _set_state(gesture, s, &st->info, EINA_TRUE);
2197 consume_event(wd, event_info, event_type, ev_flag);
2203 return; /* Unhandeld event type */
2210 * This function is used to check if rotation gesture started.
2211 * @param st Contains current rotation values from user input.
2212 * @return TRUE/FALSE if we need to set rotation START.
2214 * @ingroup Elm_Gesture_Layer
2217 rotation_broke_tolerance(Rotate_Type *st)
2219 if (st->info.base_angle < 0)
2220 return EINA_FALSE; /* Angle has to be computed first */
2222 if (st->rotate_angular_tolerance < 0)
2225 double low = st->info.base_angle - st->rotate_angular_tolerance;
2226 double high = st->info.base_angle + st->rotate_angular_tolerance;
2227 double t = st->info.angle;
2240 if (high > RAD_360DEG)
2251 #if defined(DEBUG_GESTURE_LAYER)
2252 printf("%s angle=<%f> low=<%f> high=<%f>\n", __func__, t, low, high);
2254 if ((t < low) || (t > high))
2255 { /* This marks that roation action has started */
2256 st->rotate_angular_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
2257 st->info.base_angle = st->info.angle; /* Avoid jump in angle value */
2267 * This function is used for computing the gap between fingers.
2268 * It returns the length and center point between fingers.
2270 * @param x1 first finger x location.
2271 * @param y1 first finger y location.
2272 * @param x2 second finger x location.
2273 * @param y2 second finger y location.
2274 * @param x Gets center point x cord (output)
2275 * @param y Gets center point y cord (output)
2277 * @return length of the line between (x1,y1), (x2,y2) in pixels.
2279 * @ingroup Elm_Gesture_Layer
2282 get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
2283 Evas_Coord y2, Evas_Coord *x, Evas_Coord *y)
2285 double a, b, xx, yy, gap;
2288 gap = sqrt(xx*xx + yy*yy);
2290 /* START - Compute zoom center point */
2291 /* The triangle defined as follows:
2299 * http://en.wikipedia.org/wiki/Trigonometric_functions
2300 *************************************/
2301 if (((int) xx) && ((int) yy))
2303 double A = atan((yy / xx));
2304 #if defined(DEBUG_GESTURE_LAYER)
2305 printf("xx=<%f> yy=<%f> A=<%f>\n", xx, yy, A);
2307 a = (Evas_Coord) ((gap / 2) * sin(A));
2308 b = (Evas_Coord) ((gap / 2) * cos(A));
2309 *x = (Evas_Coord) ((x2 > x1) ? (x1 + b) : (x2 + b));
2310 *y = (Evas_Coord) ((y2 > y1) ? (y1 + a) : (y2 + a));
2315 { /* horiz line, take half width */
2316 #if defined(DEBUG_GESTURE_LAYER)
2317 printf("==== HORIZ ====\n");
2319 *x = (Evas_Coord) (xx / 2);
2320 *y = (Evas_Coord) (y1);
2324 { /* vert line, take half width */
2325 #if defined(DEBUG_GESTURE_LAYER)
2326 printf("==== VERT ====\n");
2328 *x = (Evas_Coord) (x1);
2329 *y = (Evas_Coord) (yy / 2);
2332 /* END - Compute zoom center point */
2334 return (Evas_Coord) gap;
2340 * This function is used for computing zoom value.
2342 * @param st Pointer to zoom data based on user input.
2343 * @param x1 first finger x location.
2344 * @param y1 first finger y location.
2345 * @param x2 second finger x location.
2346 * @param y2 second finger y location.
2347 * @param factor zoom-factor, used to determine how fast zoom works.
2349 * @return zoom value, when 1.0 means no zoom, 0.5 half size...
2351 * @ingroup Elm_Gesture_Layer
2354 compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2355 Evas_Coord x2, Evas_Coord y2, unsigned int tm2, double zoom_finger_factor)
2358 Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
2359 &st->info.x, &st->info.y);
2361 st->info.radius = diam / 2;
2365 st->zoom_base = diam;
2366 return st->info.zoom;
2369 if (st->zoom_distance_tolerance)
2370 { /* zoom tolerance <> ZERO, means zoom action NOT started yet */
2371 if (diam < (st->zoom_base - st->zoom_distance_tolerance))
2372 { /* avoid jump with zoom value when break tolerance */
2373 st->zoom_base -= st->zoom_distance_tolerance;
2374 st->zoom_distance_tolerance = 0;
2377 if (diam > (st->zoom_base + st->zoom_distance_tolerance))
2378 { /* avoid jump with zoom value when break tolerance */
2379 st->zoom_base += st->zoom_distance_tolerance;
2380 st->zoom_distance_tolerance = 0;
2386 /* We use factor only on the difference between gap-base */
2387 /* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
2388 rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
2389 (float) st->zoom_base) * zoom_finger_factor));
2392 /* Momentum: zoom per second: (NOT YET SUPPORTED) */
2393 st->info.momentum = (((rt - 1.0) * 1000) / (tm2 - tm1));
2404 * This function handles zoom with mouse wheel.
2405 * thats a combination of wheel + CTRL key.
2406 * @param obj The gesture-layer object.
2407 * @param event_info Original input event pointer.
2408 * @param event_type Type of original input event.
2409 * @param g_type what Gesture we are testing.
2411 * @ingroup Elm_Gesture_Layer
2414 _zoom_with_wheel_test(Evas_Object *obj, void *event_info,
2415 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2417 Widget_Data *wd = elm_widget_data_get(obj);
2419 if (!wd->gesture[g_type]) return;
2421 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2422 Zoom_Type *st = gesture_zoom->data;
2423 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2425 { /* Allocated once on first time, used for zoom intermediate data */
2426 st = calloc(1, sizeof(Zoom_Type));
2427 gesture_zoom->data = st;
2428 _zoom_test_reset(gesture_zoom);
2433 case EVAS_CALLBACK_KEY_UP:
2435 Evas_Event_Key_Up *p = event_info;
2436 if ((!strcmp(p->keyname, "Control_L")) ||
2437 (!strcmp(p->keyname, "Control_R")))
2438 { /* Test if we ended a zoom gesture when releasing CTRL */
2439 if ((st->zoom_wheel) &&
2440 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2441 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2442 { /* User released CTRL after zooming */
2443 ev_flag = _set_state(gesture_zoom,
2444 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2445 consume_event(wd, event_info, event_type, ev_flag);
2453 case EVAS_CALLBACK_MOUSE_WHEEL:
2456 Elm_Gesture_State s;
2457 if (!evas_key_modifier_is_set(
2458 ((Evas_Event_Mouse_Wheel *) event_info)->modifiers,
2460 { /* if using wheel witout CTRL after starting zoom */
2461 if ((st->zoom_wheel) &&
2462 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2463 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2465 ev_flag = _set_state(gesture_zoom,
2466 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2467 consume_event(wd, event_info, event_type, ev_flag);
2472 return; /* Ignore mouse-wheel without control */
2475 /* Using mouse wheel with CTRL for zoom */
2476 if (st->zoom_wheel || (st->zoom_distance_tolerance == 0))
2477 { /* when (zoom_wheel == NULL) and (zoom_distance_tolerance == 0)
2478 we continue a zoom gesture */
2480 s = ELM_GESTURE_STATE_MOVE;
2483 { /* On first wheel event, report START */
2484 Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
2485 evas_object_evas_get(wd->target), "Control");
2487 s = ELM_GESTURE_STATE_START;
2488 if (!evas_object_key_grab(wd->target, "Control_L", mask, 0, EINA_FALSE))
2489 ERR("Failed to Grabbed CTRL_L");
2490 if (!evas_object_key_grab(wd->target, "Control_R", mask, 0, EINA_FALSE))
2491 ERR("Failed to Grabbed CTRL_R");
2494 st->zoom_distance_tolerance = 0; /* Cancel tolerance */
2495 st->zoom_wheel = (Evas_Event_Mouse_Wheel *) event_info;
2496 st->info.x = st->zoom_wheel->canvas.x;
2497 st->info.y = st->zoom_wheel->canvas.y;
2499 if (st->zoom_wheel->z < 0) /* zoom in */
2500 st->info.zoom += (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2502 if (st->zoom_wheel->z > 0) /* zoom out */
2503 st->info.zoom -= (wd->zoom_finger_factor * wd->zoom_wheel_factor);
2505 if (st->info.zoom < 0.0)
2506 st->info.zoom = 0.0;
2508 ev_flag = _set_state(gesture_zoom, s, &st->info, force);
2509 consume_event(wd, event_info, event_type, ev_flag);
2521 * This function is used to test zoom gesture.
2522 * user may combine zoom, rotation together.
2523 * so its possible that both will be detected from input.
2524 * (both are two-finger movement-oriented gestures)
2526 * @param obj The gesture-layer object.
2527 * @param event_info Pointer to recent input event.
2528 * @param event_type Recent input event type.
2529 * @param g_type what Gesture we are testing.
2531 * @ingroup Elm_Gesture_Layer
2534 _zoom_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2535 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2539 Widget_Data *wd = elm_widget_data_get(obj);
2541 if (!wd->gesture[g_type]) return;
2543 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2544 Zoom_Type *st = gesture_zoom->data;
2547 { /* Allocated once on first time, used for zoom data */
2548 st = calloc(1, sizeof(Zoom_Type));
2549 gesture_zoom->data = st;
2550 _zoom_test_reset(gesture_zoom);
2554 /* Start - new zoom testing, letting all fingers start */
2555 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2558 case EVAS_CALLBACK_MOUSE_MOVE:
2559 case EVAS_CALLBACK_MULTI_MOVE:
2560 /* if non-continues mode and gesture NOT started, ignore MOVE */
2561 if ((!wd->glayer_continues_enable) &&
2562 (!st->zoom_st.timestamp))
2565 case EVAS_CALLBACK_MOUSE_DOWN:
2566 case EVAS_CALLBACK_MULTI_DOWN:
2567 { /* Here we take care of zoom-start and zoom move */
2571 if(eina_list_count(wd->touched) > 2)
2572 { /* Process zoom only when 2 fingers on surface */
2573 ev_flag = _set_state(gesture_zoom,
2574 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2575 consume_event(wd, event_info, event_type, ev_flag);
2580 if (!st->zoom_st.timestamp)
2581 { /* Now scan touched-devices list and find other finger */
2582 EINA_LIST_FOREACH(wd->touched, l, p)
2583 { /* Device of other finger <> pe device */
2584 if (p->device != pe->device)
2588 if (!p) /* Single finger on touch */
2591 /* Record down fingers */
2592 consume_event(wd, event_info, event_type, ev_flag);
2593 memcpy(&st->zoom_st, pe, sizeof(Pointer_Event));
2594 memcpy(&st->zoom_st1, p, sizeof(Pointer_Event));
2596 /* Set mv field as well to be ready for MOVE events */
2597 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2598 memcpy(&st->zoom_mv1, p, sizeof(Pointer_Event));
2600 /* Here we have zoom_st, zoom_st1 set, report START */
2601 /* Set zoom-base after BOTH down events recorded */
2602 /* Compute length of line between fingers zoom start */
2603 st->info.zoom = 1.0;
2604 st->zoom_base = get_finger_gap_length(st->zoom_st1.x,
2605 st->zoom_st1.y, st->zoom_st.x, st->zoom_st.y,
2606 &st->info.x, &st->info.y);
2608 st->info.radius = st->zoom_base / 2;
2610 if ((gesture_zoom->state != ELM_GESTURE_STATE_START) &&
2611 (gesture_zoom->state != ELM_GESTURE_STATE_MOVE))
2612 { /* zoom started with mouse-wheel, don't report twice */
2613 ev_flag = _set_state(gesture_zoom,
2614 ELM_GESTURE_STATE_START, &st->info, EINA_FALSE);
2615 consume_event(wd, event_info, event_type, ev_flag);
2618 return; /* Zoom started */
2619 } /* End of ZOOM_START handling */
2622 /* if we got here, we have (exacally) two fingers on surfce */
2623 /* we also after START, report MOVE */
2624 /* First detect which finger moved */
2625 if (pe->device == st->zoom_mv.device)
2626 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2627 else if (pe->device == st->zoom_mv1.device)
2628 memcpy(&st->zoom_mv1, pe, sizeof(Pointer_Event));
2630 /* Compute change in zoom as fingers move */
2631 st->info.zoom = compute_zoom(st,
2632 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2633 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2634 wd->zoom_finger_factor);
2636 if (!st->zoom_distance_tolerance)
2637 { /* Zoom broke tolerance, report move */
2638 double d = st->info.zoom - st->next_step;
2642 if (d >= wd->zoom_step)
2643 { /* Report move in steps */
2644 st->next_step = st->info.zoom;
2646 ev_flag = _set_state(gesture_zoom,
2647 ELM_GESTURE_STATE_MOVE,
2648 &st->info, EINA_TRUE);
2649 consume_event(wd, event_info, event_type, ev_flag);
2651 } /* End of ZOOM_MOVE handling */
2656 case EVAS_CALLBACK_MOUSE_UP:
2657 case EVAS_CALLBACK_MULTI_UP:
2658 /* Reset timestamp of finger-up.This is used later
2659 by _zoom_test_reset() to retain finger-down data */
2660 consume_event(wd, event_info, event_type, ev_flag);
2661 if (((st->zoom_wheel) || (st->zoom_base)) &&
2662 (st->zoom_distance_tolerance == 0))
2664 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
2665 &st->info, EINA_FALSE);
2666 consume_event(wd, event_info, event_type, ev_flag);
2671 /* if we got here not a ZOOM */
2672 if (gesture_zoom->state != ELM_GESTURE_STATE_UNDEFINED)
2673 { /* Must be != undefined, if gesture started */
2674 ev_flag = _set_state(gesture_zoom,
2675 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2676 consume_event(wd, event_info, event_type, ev_flag);
2679 _zoom_test_reset(gesture_zoom);
2689 _get_rotate_properties(Rotate_Type *st,
2690 Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2691 Evas_Coord x2, Evas_Coord y2, unsigned int tm2,
2694 st->info.radius = get_finger_gap_length(x1, y1, x2, y2,
2695 &st->info.x, &st->info.y) / 2;
2697 *angle = get_angle(x1, y1, x2, y2);
2698 #if 0 /* (NOT YET SUPPORTED) */
2699 if (angle == &st->info.angle)
2700 { /* Compute momentum: TODO: bug when breaking 0, 360 values */
2701 st->info.momentum = (((*angle) - st->info.base_angle) /
2702 (fabs(tm2 - tm1))) * 1000;
2705 st->info.momentum = 0;
2715 * This function is used to test rotation gesture.
2716 * user may combine zoom, rotation together.
2717 * so its possible that both will be detected from input.
2718 * (both are two-finger movement-oriented gestures)
2720 * @param obj The gesture-layer object.
2721 * @param event_info Pointer to recent input event.
2722 * @param event_type Recent input event type.
2723 * @param g_type what Gesture we are testing.
2725 * @ingroup Elm_Gesture_Layer
2728 _rotate_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2729 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2734 Widget_Data *wd = elm_widget_data_get(obj);
2736 if (!wd->gesture[g_type]) return;
2738 Gesture_Info *gesture = wd->gesture[g_type];
2739 Rotate_Type *st = gesture->data;
2744 { /* Allocated once on first time */
2745 st = calloc(1, sizeof(Rotate_Type));
2747 _rotate_test_reset(gesture);
2751 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2754 case EVAS_CALLBACK_MOUSE_MOVE:
2755 case EVAS_CALLBACK_MULTI_MOVE:
2756 /* if non-continues mode and gesture NOT started, ignore MOVE */
2757 if ((!wd->glayer_continues_enable) &&
2758 (!st->rotate_st.timestamp))
2761 case EVAS_CALLBACK_MOUSE_DOWN:
2762 case EVAS_CALLBACK_MULTI_DOWN:
2763 { /* Here we take care of rotate-start and rotate move */
2767 if(eina_list_count(wd->touched) > 2)
2768 { /* Process rotate only when 2 fingers on surface */
2769 ev_flag = _set_state(gesture,
2770 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2771 consume_event(wd, event_info, event_type, ev_flag);
2776 if (!st->rotate_st.timestamp)
2777 { /* Now scan touched-devices list and find other finger */
2778 EINA_LIST_FOREACH(wd->touched, l, p)
2779 { /* Device of other finger <> pe device */
2780 if (p->device != pe->device)
2785 return; /* Single finger on touch */
2787 /* Record down fingers */
2788 consume_event(wd, event_info, event_type, ev_flag);
2789 memcpy(&st->rotate_st, pe, sizeof(Pointer_Event));
2790 memcpy(&st->rotate_st1, p, sizeof(Pointer_Event));
2792 /* Set mv field as well to be ready for MOVE events */
2793 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2794 memcpy(&st->rotate_mv1, p, sizeof(Pointer_Event));
2796 /* Here we have rotate_st, rotate_st1 set, report START */
2797 /* Set rotate-base after BOTH down events recorded */
2798 /* Compute length of line between fingers rotate start */
2799 _get_rotate_properties(st,
2800 st->rotate_st.x, st->rotate_st.y,
2801 st->rotate_st.timestamp,
2802 st->rotate_st1.x, st->rotate_st1.y,
2803 st->rotate_st1.timestamp, &st->info.base_angle);
2805 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
2806 &st->info, EINA_FALSE);
2807 consume_event(wd, event_info, event_type, ev_flag);
2809 return; /* Rotate started */
2810 } /* End of ROTATE_START handling */
2813 /* if we got here, we have (exacally) two fingers on surfce */
2814 /* we also after START, report MOVE */
2815 /* First detect which finger moved */
2816 if (pe->device == st->rotate_mv.device)
2817 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2818 else if (pe->device == st->rotate_mv1.device)
2819 memcpy(&st->rotate_mv1, pe, sizeof(Pointer_Event));
2821 /* Compute change in rotate as fingers move */
2822 _get_rotate_properties(st,
2823 st->rotate_mv.x, st->rotate_mv.y,
2824 st->rotate_mv.timestamp,
2825 st->rotate_mv1.x, st->rotate_mv1.y,
2826 st->rotate_mv1.timestamp, &st->info.angle);
2828 if (rotation_broke_tolerance(st))
2829 { /* Rotation broke tolerance, report move */
2830 double d = st->info.angle - st->next_step;
2834 if (d >= wd->rotate_step)
2835 { /* Report move in steps */
2836 st->next_step = st->info.angle;
2838 ev_flag = _set_state(gesture,
2839 ELM_GESTURE_STATE_MOVE, &st->info, EINA_TRUE);
2840 consume_event(wd, event_info, event_type, ev_flag);
2842 } /* End of ROTATE_MOVE handling */
2847 case EVAS_CALLBACK_MOUSE_UP:
2848 case EVAS_CALLBACK_MULTI_UP:
2849 consume_event(wd, event_info, event_type, ev_flag);
2850 /* Reset timestamp of finger-up.This is used later
2851 by rotate_test_reset() to retain finger-down data */
2852 if (st->rotate_angular_tolerance < 0)
2854 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2855 &st->info, EINA_FALSE);
2856 consume_event(wd, event_info, event_type, ev_flag);
2861 if (gesture->state != ELM_GESTURE_STATE_UNDEFINED)
2862 { /* Must be != undefined, if gesture started */
2863 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2864 &st->info, EINA_FALSE);
2865 consume_event(wd, event_info, event_type, ev_flag);
2868 _rotate_test_reset(gesture);
2879 * This function is used to save input events in an abstract struct
2880 * to be used later by getsure-testing functions.
2882 * @param data The gesture-layer object.
2883 * @param event_info Pointer to recent input event.
2884 * @param event_type Recent input event type.
2885 * @param pe The abstract data-struct (output).
2887 * @ingroup Elm_Gesture_Layer
2890 _make_pointer_event(void *data, void *event_info,
2891 Evas_Callback_Type event_type, Pointer_Event *pe)
2893 Widget_Data *wd = elm_widget_data_get(data);
2894 if (!wd) return EINA_FALSE;
2896 memset(pe, '\0', sizeof(*pe));
2899 case EVAS_CALLBACK_MOUSE_DOWN:
2900 pe->x = ((Evas_Event_Mouse_Down *) event_info)->canvas.x;
2901 pe->y = ((Evas_Event_Mouse_Down *) event_info)->canvas.y;
2902 pe->timestamp = ((Evas_Event_Mouse_Down *) event_info)->timestamp;
2903 pe->device = ELM_MOUSE_DEVICE;
2906 case EVAS_CALLBACK_MOUSE_UP:
2907 pe->x = ((Evas_Event_Mouse_Up *) event_info)->canvas.x;
2908 pe->y = ((Evas_Event_Mouse_Up *) event_info)->canvas.y;
2909 pe->timestamp = ((Evas_Event_Mouse_Up *) event_info)->timestamp;
2910 pe->device = ELM_MOUSE_DEVICE;
2913 case EVAS_CALLBACK_MOUSE_MOVE:
2914 pe->x = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.x;
2915 pe->y = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.y;
2916 pe->timestamp = ((Evas_Event_Mouse_Move *) event_info)->timestamp;
2917 pe->device = ELM_MOUSE_DEVICE;
2920 case EVAS_CALLBACK_MULTI_DOWN:
2921 pe->x = ((Evas_Event_Multi_Down *) event_info)->canvas.x;
2922 pe->y = ((Evas_Event_Multi_Down *) event_info)->canvas.y;
2923 pe->timestamp = ((Evas_Event_Multi_Down *) event_info)->timestamp;
2924 pe->device = ((Evas_Event_Multi_Down *) event_info)->device;
2927 case EVAS_CALLBACK_MULTI_UP:
2928 pe->x = ((Evas_Event_Multi_Up *) event_info)->canvas.x;
2929 pe->y = ((Evas_Event_Multi_Up *) event_info)->canvas.y;
2930 pe->timestamp = ((Evas_Event_Multi_Up *) event_info)->timestamp;
2931 pe->device = ((Evas_Event_Multi_Up *) event_info)->device;
2934 case EVAS_CALLBACK_MULTI_MOVE:
2935 pe->x = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.x;
2936 pe->y = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.y;
2937 pe->timestamp = ((Evas_Event_Multi_Move *) event_info)->timestamp;
2938 pe->device = ((Evas_Event_Multi_Move *) event_info)->device;
2945 pe->event_type = event_type;
2952 * This function restartes line, flick, zoom and rotate gestures
2953 * when gesture-layer continues-gestures enabled.
2954 * Example of continues-gesture:
2955 * When doing a line, user stops moving finger but keeps fingers on touch.
2956 * This will cause line-end, then as user continues moving his finger
2957 * it re-starts line gesture.
2958 * When continue mode is disabled, user has to lift finger from touch
2959 * to end a gesture. Them touch-again to start a new one.
2961 * @param data The gesture-layer object.
2962 * @param wd gesture layer widget data.
2963 * @param states_reset flag that marks gestures were reset in history clear.
2965 * @ingroup Elm_Gesture_Layer
2967 void continues_gestures_restart(void *data, Eina_Bool states_reset)
2969 Widget_Data *wd = elm_widget_data_get(data);
2972 /* Run through events to restart gestures */
2974 Eina_Bool n_momentum, n_lines, n_flicks, zoom, rotate;
2975 /* We turn-on flag for finished, aborted, not-started gestures */
2976 g = wd->gesture[ELM_GESTURE_MOMENTUM];
2977 n_momentum = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2978 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2981 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
2982 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2986 g = wd->gesture[ELM_GESTURE_N_LINES];
2987 n_lines = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2988 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
2991 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
2992 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
2996 g = wd->gesture[ELM_GESTURE_N_FLICKS];
2997 n_flicks = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
2998 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3001 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
3002 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3006 g = wd->gesture[ELM_GESTURE_ZOOM];
3007 zoom = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3008 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3011 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
3012 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3016 g = wd->gesture[ELM_GESTURE_ROTATE];
3017 rotate = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
3018 && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
3021 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
3022 _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
3030 * This function the core-function where input handling is done.
3031 * Here we get user input and stream it to gesture testing.
3032 * We notify user about any gestures with new state:
3034 * START - gesture started.
3035 * MOVE - gesture is ongoing.
3036 * END - gesture was completed.
3037 * ABORT - gesture was aborted after START, MOVE (will NOT be completed)
3039 * We also check if a gesture was detected, then reset event history
3040 * If no gestures were found we reset gesture test flag
3041 * after streaming event-history to widget.
3042 * (stream to the widget all events not consumed as a gesture)
3044 * @param data The gesture-layer object.
3045 * @param event_info Pointer to recent input event.
3046 * @param event_type Recent input event type.
3048 * @ingroup Elm_Gesture_Layer
3051 _event_process(void *data, Evas_Object *obj __UNUSED__,
3052 void *event_info, Evas_Callback_Type event_type)
3055 Pointer_Event *pe = NULL;
3056 Widget_Data *wd = elm_widget_data_get(data);
3059 #if defined(DEBUG_GESTURE_LAYER)
3062 printf("Gesture | State | is tested\n");
3063 for(i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
3067 printf(" %d %d %d\n", i, g->state, g->test);
3071 /* Start testing candidate gesture from here */
3072 if (_make_pointer_event(data, event_info, event_type, &_pe))
3075 if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
3076 _n_long_tap_test(data, pe, event_info, event_type,
3077 ELM_GESTURE_N_LONG_TAPS);
3079 /* This takes care of single, double and tripple tap */
3080 _tap_gestures_test(data, pe, event_info, event_type);
3082 if (IS_TESTED(ELM_GESTURE_MOMENTUM))
3083 _momentum_test(data, pe, event_info, event_type,
3084 ELM_GESTURE_MOMENTUM);
3086 if (IS_TESTED(ELM_GESTURE_N_LINES))
3087 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_LINES);
3089 if (IS_TESTED(ELM_GESTURE_N_FLICKS))
3090 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_FLICKS);
3092 if (IS_TESTED(ELM_GESTURE_ZOOM))
3093 _zoom_test(data, pe, event_info, event_type, ELM_GESTURE_ZOOM);
3095 if (IS_TESTED(ELM_GESTURE_ZOOM))
3096 _zoom_with_wheel_test(data, event_info, event_type, ELM_GESTURE_ZOOM);
3098 if (IS_TESTED(ELM_GESTURE_ROTATE))
3099 _rotate_test(data, pe, event_info, event_type, ELM_GESTURE_ROTATE);
3101 if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
3102 _event_history_add(data, event_info, event_type);
3103 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3104 (event_type == EVAS_CALLBACK_MULTI_UP))
3106 Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type);
3109 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD);
3110 _event_history_add(data, event_info, event_type);
3114 /* we maintain list of touched devices */
3115 /* We also use move to track current device x.y pos */
3116 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
3117 (event_type == EVAS_CALLBACK_MULTI_DOWN) ||
3118 (event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
3119 (event_type == EVAS_CALLBACK_MULTI_MOVE))
3121 wd->touched = _add_touched_device(wd->touched, pe);
3123 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
3124 (event_type == EVAS_CALLBACK_MULTI_UP))
3126 wd->touched = _remove_touched_device(wd->touched, pe);
3129 /* Report current states and clear history if needed */
3130 Eina_Bool states_reset = _clear_if_finished(data);
3131 if (wd->glayer_continues_enable)
3132 continues_gestures_restart(data, states_reset);
3137 * For all _mouse_* / multi_* functions wethen send this event to
3138 * _event_process function.
3140 * @param data The gesture-layer object.
3141 * @param event_info Pointer to recent input event.
3143 * @ingroup Elm_Gesture_Layer
3146 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3149 Widget_Data *wd = elm_widget_data_get(data);
3151 if (((Evas_Event_Mouse_Down *) event_info)->button != 1)
3152 return; /* We only process left-click at the moment */
3154 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_DOWN);
3158 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3161 Widget_Data *wd = elm_widget_data_get(data);
3164 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_MOVE);
3168 _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3171 Widget_Data *wd = elm_widget_data_get(data);
3174 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_DOWN);
3178 _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3181 Widget_Data *wd = elm_widget_data_get(data);
3184 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_UP);
3188 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3191 Widget_Data *wd = elm_widget_data_get(data);
3194 if (((Evas_Event_Mouse_Up *) event_info)->button != 1)
3195 return; /* We only process left-click at the moment */
3197 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_UP);
3201 _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3204 Widget_Data *wd = elm_widget_data_get(data);
3207 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_WHEEL);
3211 _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3214 Widget_Data *wd = elm_widget_data_get(data);
3217 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_DOWN);
3221 _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3224 Widget_Data *wd = elm_widget_data_get(data);
3227 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_MOVE);
3231 _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
3234 Widget_Data *wd = elm_widget_data_get(data);
3237 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_UP);
3241 elm_gesture_layer_hold_events_get(Evas_Object *obj)
3243 Widget_Data *wd = elm_widget_data_get(obj);
3244 if (!wd) return EINA_FALSE;
3246 return !wd->repeat_events;
3250 elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool r)
3252 Widget_Data *wd = elm_widget_data_get(obj);
3255 wd->repeat_events = !r;
3259 elm_gesture_layer_zoom_step_set(Evas_Object *obj, double s)
3261 Widget_Data *wd = elm_widget_data_get(obj);
3271 elm_gesture_layer_rotate_step_set(Evas_Object *obj, double s)
3273 Widget_Data *wd = elm_widget_data_get(obj);
3279 wd->rotate_step = s;
3283 elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *t)
3285 Widget_Data *wd = elm_widget_data_get(obj);
3286 if (!wd) return EINA_FALSE;
3291 /* if was attached before, unregister callbacks first */
3293 _unregister_callbacks(obj);
3297 _register_callbacks(obj);
3302 elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Types idx,
3303 Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data)
3305 Widget_Data *wd = elm_widget_data_get(obj);
3309 if (!wd->gesture[idx])
3310 wd->gesture[idx] = calloc(1, sizeof(Gesture_Info));
3311 if (!wd->gesture[idx]) return;
3313 p = wd->gesture[idx];
3316 p->fn[cb_type].cb = cb;
3317 p->fn[cb_type].user_data = data;
3318 p->state = ELM_GESTURE_STATE_UNDEFINED;
3323 _disable_hook(Evas_Object *obj)
3325 if (elm_widget_disabled_get(obj))
3326 _unregister_callbacks(obj);
3328 _register_callbacks(obj);
3332 elm_gesture_layer_add(Evas_Object *parent)
3338 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
3340 wd = ELM_NEW(Widget_Data);
3341 e = evas_object_evas_get(parent);
3342 if (!e) return NULL;
3343 obj = elm_widget_add(e);
3344 ELM_SET_WIDTYPE(widtype, "gesture_layer");
3345 elm_widget_type_set(obj, "gesture_layer");
3346 elm_widget_sub_object_add(parent, obj);
3347 elm_widget_data_set(obj, wd);
3348 elm_widget_del_hook_set(obj, _del_hook);
3349 elm_widget_disable_hook_set(obj, _disable_hook);
3352 wd->line_min_length =_elm_config->glayer_line_min_length * elm_finger_size_get();
3353 wd->zoom_distance_tolerance = _elm_config->glayer_zoom_distance_tolerance * elm_finger_size_get();
3354 wd->line_distance_tolerance = _elm_config->glayer_line_distance_tolerance * elm_finger_size_get();
3355 wd->zoom_finger_factor = _elm_config->glayer_zoom_finger_factor;
3356 wd->zoom_wheel_factor = _elm_config->glayer_zoom_wheel_factor; /* mouse wheel zoom steps */
3357 wd->rotate_angular_tolerance = _elm_config->glayer_rotate_angular_tolerance;
3358 wd->line_angular_tolerance = _elm_config->glayer_line_angular_tolerance;
3359 wd->flick_time_limit_ms = _elm_config->glayer_flick_time_limit_ms;
3360 wd->long_tap_start_timeout = _elm_config->glayer_long_tap_start_timeout;
3361 wd->repeat_events = EINA_TRUE;
3362 wd->glayer_continues_enable = _elm_config->glayer_continues_enable;
3364 #if defined(DEBUG_GESTURE_LAYER)
3365 printf("size of Gestures = <%d>\n", sizeof(wd->gesture));
3366 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);
3368 memset(wd->gesture, 0, sizeof(wd->gesture));