1 #include <Elementary.h>
3 /** @defgroup Elm_Gesture_Layer Gesture Layer */
6 #define ELM_MOUSE_DEVICE 0
7 #define ELM_GESTURE_ZOOM_FACTOR 1.0
8 #define ELM_GESTURE_ZOOM_WHEEL_FACTOR 0.05
9 #define ELM_GESTURE_ROTATION_TOLERANCE 0.034906585 /* Represents 2 DEG */
10 /* ELM_GESTURE_NEGATIVE_ANGLE - magic number says we didn't compute this yet */
11 #define ELM_GESTURE_NEGATIVE_ANGLE (-1.0) /* Magic number */
12 #define ELM_GESTURE_MOMENTUM_TIMEOUT 50
13 #define ELM_GESTURE_LINE_ANGLE_TOLERANCE 0.34906585 /* Represents 20 DEG */
14 #define FLICK_MAX_MS 60
15 #define DBL_CLICK_TIME 400
17 /* Some Trigo values */
18 #define RAD_90DEG M_PI_2
19 #define RAD_180DEG M_PI
20 #define RAD_270DEG (M_PI_2 * 3)
21 #define RAD_360DEG (M_PI * 2)
24 _glayer_bufdup(void *buf, size_t size)
31 #define COPY_EVENT_INFO(EV) _glayer_bufdup(EV, sizeof(*EV))
34 #define SET_TEST_BIT(P) do { \
35 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; \
38 #define IS_TESTED(T) ((wd->gesture[T]) ? wd->gesture[T]->test : EINA_FALSE)
44 * Struct holds callback information.
46 * @ingroup Elm_Gesture_Layer
50 void *user_data; /**< Holds user data to CB (like sd) */
51 Elm_Gesture_Event_Cb cb;
58 * type for callback information
60 * @ingroup Elm_Gesture_Layer
62 typedef struct _Func_Data Func_Data;
67 * @struct _Gesture_Info
68 * Struct holds gesture info
70 * @ingroup Elm_Gesture_Layer
75 void *data; /**< Holds gesture intemidiate processing data */
76 Func_Data fn[ELM_GESTURE_STATE_ABORT + 1]; /**< Callback info for states */
77 Elm_Gesture_Types g_type; /**< gesture type */
78 Elm_Gesture_State state; /**< gesture state */
79 void *info; /**< Data for the state callback */
80 Eina_Bool test; /**< if true this gesture should be tested on input */
86 * @typedef Gesture_Info
87 * Type for _Gesture_Info
89 * @ingroup Elm_Gesture_Layer
91 typedef struct _Gesture_Info Gesture_Info;
96 * @struct _Event_History
97 * Struct holds event history.
98 * These events are repeated if no gesture found.
100 * @ingroup Elm_Gesture_Layer
102 struct _Event_History
106 Evas_Callback_Type event_type;
112 * @typedef Event_History
113 * Type for _Event_History
115 * @ingroup Elm_Gesture_Layer
117 typedef struct _Event_History Event_History;
122 * @struct _Pointer_Event
123 * Struct holds pointer-event info
124 * This is a generic pointer event structure
126 * @ingroup Elm_Gesture_Layer
128 struct _Pointer_Event
131 unsigned int timestamp;
133 Evas_Callback_Type event_type;
139 * @typedef Pointer_Event
140 * Type for generic pointer event structure
142 * @ingroup Elm_Gesture_Layer
144 typedef struct _Pointer_Event Pointer_Event;
146 /* All *Type structs hold result for the user in 'info' field
147 * The rest is gesture processing intermediate data.
148 * NOTE: info field must be FIRST in the struct.
149 * This is used when reporting ABORT in event_history_clear() */
152 Elm_Gesture_Taps_Info info;
153 unsigned int count_ups;
159 typedef struct _Taps_Type Taps_Type;
161 struct _Momentum_Type
162 { /* Fields used by _line_test() */
163 Elm_Gesture_Momentum_Info info;
164 Evas_Coord_Point line_st;
165 Evas_Coord_Point line_end;
166 unsigned int t_st_x; /* Time start on X */
167 unsigned int t_st_y; /* Time start on Y */
168 unsigned int t_end; /* Time end */
171 typedef struct _Momentum_Type Momentum_Type;
175 Evas_Coord_Point line_st;
176 Evas_Coord_Point line_end;
177 Evas_Coord line_length;
178 unsigned int t_st; /* Time start */
179 unsigned int t_end; /* Time end */
181 double line_angle; /* Current angle of line */
183 typedef struct _Line_Data Line_Data;
186 { /* Fields used by _line_test() */
187 Elm_Gesture_Line_Info info;
188 Eina_List *list; /* List of Line_Data */
190 typedef struct _Line_Type Line_Type;
193 { /* Fields used by _zoom_test() */
194 Elm_Gesture_Zoom_Info info;
195 Pointer_Event zoom_st;
196 Pointer_Event zoom_mv;
197 Pointer_Event zoom_st1;
198 Pointer_Event zoom_mv1;
199 Evas_Event_Mouse_Wheel *zoom_wheel;
200 Evas_Coord zoom_base; /* Holds gap between fingers on zoom-start */
201 Evas_Coord zoom_tolerance;
204 typedef struct _Zoom_Type Zoom_Type;
207 { /* Fields used by _rotation_test() */
208 Elm_Gesture_Rotate_Info info;
209 Pointer_Event rotate_st;
210 Pointer_Event rotate_mv;
211 Pointer_Event rotate_st1;
212 Pointer_Event rotate_mv1;
213 double rotate_tolerance;
216 typedef struct _Rotate_Type Rotate_Type;
220 Evas_Object *target; /* Target Widget */
221 Event_History *event_history_list;
224 Evas_Coord zoom_tolerance;
225 Evas_Coord line_tolerance;
226 float zoom_wheel_factor; /* mouse wheel zoom steps */
227 float factor; /* used for zoom factor */
228 double rotate_tolerance;
233 Gesture_Info *gesture[ELM_GESTURE_LAST];
234 Ecore_Timer *dbl_timeout; /* When this expires, dbl click/taps ABORTed */
235 Eina_List *pending; /* List of devices need to refeed *UP event */
236 Eina_List *touched; /* Information of touched devices */
238 Eina_Bool repeat_events : 1;
240 typedef struct _Widget_Data Widget_Data;
242 static const char *widtype = NULL;
243 static void _del_hook(Evas_Object *obj);
245 static void _event_history_clear(Evas_Object *obj);
246 static void _reset_states(Widget_Data *wd);
247 static void _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
248 static void _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
249 static void _zoom_with_wheel_test(Evas_Object *obj, void *event_info, Evas_Callback_Type event_type, Elm_Gesture_Types g_type);
250 static void _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
251 static void _mouse_down(void *data, Evas *e, Evas_Object *obj, void *event_info);
252 static void _mouse_move(void *data, Evas *e, Evas_Object *obj, void *event_info);
253 static void _mouse_up(void *data, Evas *e, Evas_Object *obj, void *event_info);
255 static void _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
256 static void _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
257 static void _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
259 /* START - Functions to manage touched-device list */
262 * This function is used to find if device is touched
264 * @ingroup Elm_Gesture_Layer
267 device_is_touched(const void *data1, const void *data2)
268 { /* Compare the two device numbers */
269 return (((Pointer_Event *) data1)->device -((Pointer_Event *) data2)->device);
275 * Recoed Pointer Event in touched device list
276 * Note: This fuction allocates memory for PE event
277 * This memory is released in _remove_touched_device()
278 * @param list Pointer to touched device list.
279 * @param Pointer_Event Pointer to PE.
281 * @ingroup Elm_Gesture_Layer
284 _add_touched_device(Eina_List *list, Pointer_Event *pe)
286 if (eina_list_search_unsorted_list(list, device_is_touched, pe))
289 Pointer_Event *p = malloc(sizeof(Pointer_Event ));
290 memcpy(p, pe, sizeof(Pointer_Event)); /* Freed in _remove_touched_device() */
291 return eina_list_append(list, p);
297 * Remove Pointer Event from touched device list
298 * @param list Pointer to touched device list.
299 * @param Pointer_Event Pointer to PE.
301 * @ingroup Elm_Gesture_Layer
304 _remove_touched_device(Eina_List *list, Pointer_Event *pe)
306 Pointer_Event *p = eina_list_search_unsorted(list, device_is_touched, pe);
310 return eina_list_remove(list, p);
315 /* END - Functions to manage touched-device list */
321 * @param event_info pointer to event.
323 * @ingroup Elm_Gesture_Layer
325 static Evas_Event_Flags
326 _get_event_flag(void *event_info, Evas_Callback_Type event_type)
330 case EVAS_CALLBACK_MOUSE_IN:
331 return ((Evas_Event_Mouse_In *) event_info)->event_flags;
332 case EVAS_CALLBACK_MOUSE_OUT:
333 return ((Evas_Event_Mouse_Out *) event_info)->event_flags;
334 case EVAS_CALLBACK_MOUSE_DOWN:
335 return ((Evas_Event_Mouse_Down *) event_info)->event_flags;
336 case EVAS_CALLBACK_MOUSE_MOVE:
337 return ((Evas_Event_Mouse_Move *) event_info)->event_flags;
338 case EVAS_CALLBACK_MOUSE_UP:
339 return ((Evas_Event_Mouse_Up *) event_info)->event_flags;
340 case EVAS_CALLBACK_MOUSE_WHEEL:
341 return ((Evas_Event_Mouse_Wheel *) event_info)->event_flags;
342 case EVAS_CALLBACK_MULTI_DOWN:
343 return ((Evas_Event_Multi_Down *) event_info)->event_flags;
344 case EVAS_CALLBACK_MULTI_MOVE:
345 return ((Evas_Event_Multi_Move *) event_info)->event_flags;
346 case EVAS_CALLBACK_MULTI_UP:
347 return ((Evas_Event_Multi_Up *) event_info)->event_flags;
348 case EVAS_CALLBACK_KEY_DOWN:
349 return ((Evas_Event_Key_Down *) event_info)->event_flags;
350 case EVAS_CALLBACK_KEY_UP:
351 return ((Evas_Event_Key_Up *) event_info)->event_flags;
353 return EVAS_EVENT_FLAG_NONE;
360 * Sets event flag to value returned from user callback
361 * @param wd Widget Data
362 * @param event_info pointer to event.
363 * @param event_type what type was ev (mouse down, etc...)
364 * @param ev_flags event flags
366 * @ingroup Elm_Gesture_Layer
369 consume_event(Widget_Data *wd, void *event_info,
370 Evas_Callback_Type event_type, Evas_Event_Flags ev_flags)
371 { /* Mark EVAS_EVENT_FLAG_ON_HOLD on events that are used by gesture layer */
372 /* ev_flags != EVAS_EVENT_FLAG_NONE means target used event and g-layer */
373 /* should not refeed this event. */
374 if ((ev_flags) || (!wd->repeat_events))
378 case EVAS_CALLBACK_MOUSE_DOWN:
379 ((Evas_Event_Mouse_Down *) event_info)->event_flags |= ev_flags;
381 case EVAS_CALLBACK_MOUSE_MOVE:
382 ((Evas_Event_Mouse_Move *) event_info)->event_flags |= ev_flags;
384 case EVAS_CALLBACK_MOUSE_UP:
385 ((Evas_Event_Mouse_Up *) event_info)->event_flags |= ev_flags;
387 case EVAS_CALLBACK_MOUSE_WHEEL:
388 ((Evas_Event_Mouse_Wheel *) event_info)->event_flags |= ev_flags;
390 case EVAS_CALLBACK_MULTI_DOWN:
391 ((Evas_Event_Multi_Down *) event_info)->event_flags |= ev_flags;
393 case EVAS_CALLBACK_MULTI_MOVE:
394 ((Evas_Event_Multi_Move *) event_info)->event_flags |= ev_flags;
396 case EVAS_CALLBACK_MULTI_UP:
397 ((Evas_Event_Multi_Up *) event_info)->event_flags |= ev_flags;
399 case EVAS_CALLBACK_KEY_DOWN:
400 ((Evas_Event_Key_Down *) event_info)->event_flags |= ev_flags;
402 case EVAS_CALLBACK_KEY_UP:
403 ((Evas_Event_Key_Up *) event_info)->event_flags |= ev_flags;
414 * Report current state of a gesture by calling user callback.
415 * @param gesture what gesture state we report.
416 * @param info inforamtion for user callback
418 * @ingroup Elm_Gesture_Layer
420 static Evas_Event_Flags
421 _report_state(Gesture_Info *gesture, void *info)
422 { /* We report current state (START, MOVE, END, ABORT), once */
423 #if defined(DEBUG_GESTURE_LAYER)
424 printf("%s reporting gesture=<%d> state=<%d>\n" , __func__, g_type,
427 if ((gesture->state != ELM_GESTURE_STATE_UNDEFINED) &&
428 (gesture->fn[gesture->state].cb))
429 { /* Fill state-info struct and send ptr to user callback */
430 return gesture->fn[gesture->state].cb(
431 gesture->fn[gesture->state].user_data, info);
434 return EVAS_EVENT_FLAG_NONE;
440 * Update state for a given gesture.
441 * We may update gesture state to:
442 * UNDEFINED - current input did not start gesure yet.
443 * START - gesture started according to input.
444 * MOVE - gusture in progress.
445 * END - gesture completed according to input.
446 * ABORT - input does not matches gesure.
447 * note that we may move from UNDEFINED to ABORT
448 * because we may detect that gesture will not START
449 * with a given input.
451 * @param g given gesture to change state.
452 * @param s gesure new state.
453 * @param info buffer to be sent to user callback on report_state.
454 * @param force makes report_state to report the new-state even
455 * if its same as current state. Works for MOVE - gesture in progress.
457 * @ingroup Elm_Gesture_Layer
459 static Evas_Event_Flags
460 _set_state(Gesture_Info *g, Elm_Gesture_State s,
461 void *info, Eina_Bool force)
463 Elm_Gesture_State old_state;
464 if ((g->state == s) && (!force))
465 return EVAS_EVENT_FLAG_NONE;
467 old_state = g->state;
470 g->info = info; /* Information for user callback */
471 if ((g->state == ELM_GESTURE_STATE_ABORT) ||
472 (g->state == ELM_GESTURE_STATE_END))
473 g->test = EINA_FALSE;
475 if ((g->state != ELM_GESTURE_STATE_UNDEFINED) &&
476 (!((old_state == ELM_GESTURE_STATE_UNDEFINED) &&
477 (s == ELM_GESTURE_STATE_ABORT))))
478 return _report_state(g, g->info);
480 return EVAS_EVENT_FLAG_NONE;
486 * This resets all gesture states and sets test-bit.
487 * this is used for restarting gestures to listen to input.
488 * happens after we complete a gesture or no gesture was detected.
489 * @param wd Widget data of the gesture-layer object.
491 * @ingroup Elm_Gesture_Layer
494 _reset_states(Widget_Data *wd)
498 for (i = ELM_GESTURE_FIRST; i < ELM_GESTURE_LAST; i++)
503 _set_state(p, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
512 * if gesture was NOT detected AND we only have gestures in ABORT state
513 * we clear history immediately to be ready for input.
515 * @param obj The gesture-layer object.
517 * @ingroup Elm_Gesture_Layer
520 _clear_if_finished(Evas_Object *obj)
522 Widget_Data *wd = elm_widget_data_get(obj);
526 /* Clear history if all we have aborted gestures */
527 Eina_Bool reset_s = EINA_TRUE, all_undefined = EINA_TRUE;
528 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
529 { /* If no gesture started and all we have aborted gestures, reset all */
530 Gesture_Info *p = wd->gesture[i];
531 if ((p) && (p->state != ELM_GESTURE_STATE_UNDEFINED))
533 if ((p->state == ELM_GESTURE_STATE_START) ||
534 (p->state == ELM_GESTURE_STATE_MOVE))
535 reset_s = EINA_FALSE;
537 all_undefined = EINA_FALSE;
541 // if ((!wd->touched) || (reset_s && !all_undefined))
542 /* (!wd->touched && reset_s) - don't stop zoom with mouse-wheel */
543 if (reset_s && (!eina_list_count(wd->touched) || !all_undefined))
544 _event_history_clear(obj);
548 _inside(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
550 int w = elm_finger_size_get() >> 1; /* Finger size devided by 2 */
566 /* All *test_reset() funcs are called to clear
567 * gesture intermediate data.
568 * This happens when we need to reset our tests.
569 * for example when gesture is detected or all ABORTed. */
571 _dbl_click_test_reset(Gesture_Info *gesture)
576 Widget_Data *wd = elm_widget_data_get(gesture->obj);
577 if (wd->dbl_timeout) ecore_timer_del(wd->dbl_timeout);
578 wd->dbl_timeout = NULL;
585 EINA_LIST_FREE(((Taps_Type *) gesture->data)->l, data)
586 EINA_LIST_FREE(data, pe)
589 memset(gesture->data, 0, sizeof(Taps_Type));
593 _momentum_test_reset(Gesture_Info *gesture)
601 memset(gesture->data, 0, sizeof(Momentum_Type));
605 _line_data_reset(Line_Data *st)
610 memset(st, 0, sizeof(Line_Data));
611 st->line_angle = ELM_GESTURE_NEGATIVE_ANGLE;
615 _line_test_reset(Gesture_Info *gesture)
623 Line_Type *st = gesture->data;
624 Eina_List *list = st->list;
627 EINA_LIST_FOREACH(list, l, t_line)
630 eina_list_free(list);
635 _zoom_test_reset(Gesture_Info *gesture)
643 Widget_Data *wd = elm_widget_data_get(gesture->obj);
644 Zoom_Type *st = gesture->data;
645 Pointer_Event pe, pe1;
647 pe.timestamp = pe1.timestamp = 0;
649 if (eina_list_search_unsorted_list(wd->touched, device_is_touched,
651 memcpy(&pe, &st->zoom_st, sizeof(Pointer_Event));
653 if (eina_list_search_unsorted_list(wd->touched, device_is_touched,
655 memcpy(&pe1, &st->zoom_st1, sizeof(Pointer_Event));
657 memset(st, 0, sizeof(Zoom_Type));
659 /* If user released one finger only, restore down-info */
660 if (pe.timestamp && (!pe1.timestamp))
661 memcpy(&st->zoom_st, &pe, sizeof(Pointer_Event));
663 if (pe1.timestamp && (!pe.timestamp))
664 memcpy(&st->zoom_st1, &pe1, sizeof(Pointer_Event));
666 st->zoom_tolerance = wd->zoom_tolerance;
671 _rotate_test_reset(Gesture_Info *gesture)
679 Widget_Data *wd = elm_widget_data_get(gesture->obj);
680 Rotate_Type *st = gesture->data;
681 Pointer_Event pe, pe1;
683 pe.timestamp = pe1.timestamp = 0;
685 if (eina_list_search_unsorted_list(wd->touched, device_is_touched,
687 memcpy(&pe, &st->rotate_st, sizeof(Pointer_Event));
689 if (eina_list_search_unsorted_list(wd->touched, device_is_touched,
691 memcpy(&pe1, &st->rotate_st1, sizeof(Pointer_Event));
693 memset(st, 0, sizeof(Rotate_Type));
695 /* If user released one finger only, restore down-info */
696 if (pe.timestamp && (!pe1.timestamp))
697 memcpy(&st->rotate_st, &pe, sizeof(Pointer_Event));
699 if (pe1.timestamp && (!pe.timestamp))
700 memcpy(&st->rotate_st1, &pe1, sizeof(Pointer_Event));
703 st->info.base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
704 st->rotate_tolerance = wd->rotate_tolerance;
711 * We register callbacks when gesture layer is attached to an object
712 * or when its enabled after disable.
714 * @param obj The gesture-layer object.
716 * @ingroup Elm_Gesture_Layer
719 _register_callbacks(Evas_Object *obj)
721 Widget_Data *wd = elm_widget_data_get(obj);
726 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
728 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
730 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_UP,
733 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
736 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_DOWN,
738 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_MOVE,
740 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_MULTI_UP,
743 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_DOWN,
745 evas_object_event_callback_add(wd->target, EVAS_CALLBACK_KEY_UP,
753 * We unregister callbacks when gesture layer is disabled.
755 * @param obj The gesture-layer object.
757 * @ingroup Elm_Gesture_Layer
760 _unregister_callbacks(Evas_Object *obj)
762 Widget_Data *wd = elm_widget_data_get(obj);
767 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_DOWN,
769 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_MOVE,
771 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_UP,
774 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MOUSE_WHEEL,
777 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_DOWN,
780 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_MOVE,
783 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_MULTI_UP,
786 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_DOWN,
788 evas_object_event_callback_del(wd->target, EVAS_CALLBACK_KEY_UP,
793 /* START - Event history list handling functions */
796 * This function is used to find if device number
797 * is found in a list of devices.
798 * The list contains devices for refeeding *UP event
800 * @ingroup Elm_Gesture_Layer
803 device_in_pending_list(const void *data1, const void *data2)
804 { /* Compare the two device numbers */
805 return (((int) data1) - ((int) data2));
811 * This functions adds device to refeed-pending device list
812 * @ingroup Elm_Gesture_Layer
815 _add_device_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
817 int device = ELM_MOUSE_DEVICE;
820 case EVAS_CALLBACK_MOUSE_DOWN:
822 case EVAS_CALLBACK_MULTI_DOWN:
823 device = ((Evas_Event_Multi_Down *) event)->device;
829 if (!eina_list_search_unsorted_list(list, device_in_pending_list,
832 return eina_list_append(list, (void *) device);
841 * This functions returns pending-device node
842 * @ingroup Elm_Gesture_Layer
845 _device_is_pending(Eina_List *list, void *event, Evas_Callback_Type event_type)
847 int device = ELM_MOUSE_DEVICE;
850 case EVAS_CALLBACK_MOUSE_UP:
852 case EVAS_CALLBACK_MULTI_UP:
853 device = ((Evas_Event_Multi_Up *) event)->device;
859 return eina_list_search_unsorted_list(list, device_in_pending_list,
866 * This function reports ABORT to all none-detected gestures
867 * Then resets test bits for all desired gesures
868 * and clears input-events history.
869 * note: if no gesture was detected, events from history list
870 * are streamed to the widget because it's unused by layer.
871 * user may cancel refeed of events by setting repeat events.
873 * @param obj The gesture-layer object.
875 * @ingroup Elm_Gesture_Layer
878 _event_history_clear(Evas_Object *obj)
880 Widget_Data *wd = elm_widget_data_get(obj);
885 Evas *e = evas_object_evas_get(obj);
886 Eina_Bool gesture_found = EINA_FALSE;
887 for (i = ELM_GESTURE_FIRST ; i < ELM_GESTURE_LAST; i++)
892 if (p->state == ELM_GESTURE_STATE_END)
893 gesture_found = EINA_TRUE;
895 { /* Report ABORT to all gestures that still not finished */
896 _set_state(p, ELM_GESTURE_STATE_ABORT, wd->gesture[i]->info,
902 _reset_states(wd); /* we are ready to start testing for gestures again */
904 /* Clear all gestures intermediate date */
905 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_TAPS]);
906 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
907 _dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
908 _momentum_test_reset(wd->gesture[ELM_GESTURE_MOMENTUM]);
909 _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
910 _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
911 _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
912 _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
914 /* Disable gesture layer so refeeded events won't be consumed by it */
915 _unregister_callbacks(obj);
916 while (wd->event_history_list)
919 t = wd->event_history_list;
920 Eina_List *pending = _device_is_pending(wd->pending,
921 wd->event_history_list->event,
922 wd->event_history_list->event_type);
924 /* Refeed events if no gesture matched input */
925 if (pending || ((!gesture_found) && (!wd->repeat_events)))
927 evas_event_refeed_event(e, wd->event_history_list->event,
928 wd->event_history_list->event_type);
932 wd->pending = eina_list_remove_list(wd->pending, pending);
933 int device = ELM_MOUSE_DEVICE;
934 if (wd->event_history_list->event_type == EVAS_CALLBACK_MULTI_UP)
935 device = ((Evas_Event_Multi_Up *)
936 (wd->event_history_list->event))->device;
939 wd->pending = _add_device_pending(wd->pending,
940 wd->event_history_list->event,
941 wd->event_history_list->event_type);
944 free(wd->event_history_list->event);
945 wd->event_history_list = (Event_History *) eina_inlist_remove(
946 EINA_INLIST_GET(wd->event_history_list),
947 EINA_INLIST_GET(wd->event_history_list));
950 _register_callbacks(obj);
956 * This function copies input events.
957 * We copy event info before adding it to history.
958 * The memory is freed when we clear history.
960 * @param event the event to copy
961 * @param event_type event type to copy
963 * @ingroup Elm_Gesture_Layer
966 _copy_event_info(void *event, Evas_Callback_Type event_type)
970 case EVAS_CALLBACK_MOUSE_DOWN:
971 return COPY_EVENT_INFO((Evas_Event_Mouse_Down *) event);
973 case EVAS_CALLBACK_MOUSE_MOVE:
974 return COPY_EVENT_INFO((Evas_Event_Mouse_Move *) event);
976 case EVAS_CALLBACK_MOUSE_UP:
977 return COPY_EVENT_INFO((Evas_Event_Mouse_Up *) event);
979 case EVAS_CALLBACK_MOUSE_WHEEL:
980 return COPY_EVENT_INFO((Evas_Event_Mouse_Wheel *) event);
982 case EVAS_CALLBACK_MULTI_DOWN:
983 return COPY_EVENT_INFO((Evas_Event_Multi_Down *) event);
985 case EVAS_CALLBACK_MULTI_MOVE:
986 return COPY_EVENT_INFO((Evas_Event_Multi_Move *) event);
988 case EVAS_CALLBACK_MULTI_UP:
989 return COPY_EVENT_INFO((Evas_Event_Multi_Up *) event);
991 case EVAS_CALLBACK_KEY_DOWN:
992 return COPY_EVENT_INFO((Evas_Event_Key_Down *) event);
994 case EVAS_CALLBACK_KEY_UP:
995 return COPY_EVENT_INFO((Evas_Event_Key_Up *) event);
1003 _event_history_add(Evas_Object *obj, void *event, Evas_Callback_Type event_type)
1005 Widget_Data *wd = elm_widget_data_get(obj);
1007 if (!wd) return EINA_FALSE;
1009 ev = malloc(sizeof(Event_History));
1010 ev->event = _copy_event_info(event, event_type); /* Freed on event_history_clear */
1011 ev->event_type = event_type;
1012 wd->event_history_list = (Event_History *) eina_inlist_append(
1013 EINA_INLIST_GET(wd->event_history_list), EINA_INLIST_GET(ev));
1017 /* END - Event history list handling functions */
1020 _del_hook(Evas_Object *obj)
1022 Widget_Data *wd = elm_widget_data_get(obj);
1025 _event_history_clear(obj);
1026 eina_list_free(wd->pending);
1028 Pointer_Event *data;
1029 EINA_LIST_FREE(wd->touched, data)
1032 if (!elm_widget_disabled_get(obj))
1033 _unregister_callbacks(obj);
1035 /* Free all gestures internal data structures */
1037 for (i = 0; i < ELM_GESTURE_LAST; i++)
1040 if (wd->gesture[i]->data)
1041 free(wd->gesture[i]->data);
1043 free(wd->gesture[i]);
1050 compare_match_fingers(const void *data1, const void *data2)
1051 { /* Compare coords of first item in list to cur coords */
1052 const Pointer_Event *pe1 = eina_list_data_get(data1);
1053 const Pointer_Event *pe2 = data2;
1055 if (_inside(pe1->x, pe1->y, pe2->x, pe2->y))
1057 else if (pe1->x < pe2->x)
1061 if (pe1->x == pe2->x)
1062 return pe1->y - pe2->y;
1069 compare_pe_device(const void *data1, const void *data2)
1070 { /* Compare coords of first item in list to cur coords */
1071 const Pointer_Event *pe1 = eina_list_data_get(eina_list_last(data1));
1072 const Pointer_Event *pe2 = data2;
1074 /* Only match if last was a down event */
1075 if ((pe1->event_type != EVAS_CALLBACK_MULTI_DOWN) &&
1076 (pe1->event_type != EVAS_CALLBACK_MOUSE_DOWN))
1080 if (pe1->device == pe2->device)
1082 else if (pe1->device < pe2->device)
1089 _record_pointer_event(Taps_Type *st, Eina_List *pe_list, Pointer_Event *pe,
1090 Widget_Data *wd, void *event_info, Evas_Callback_Type event_type)
1091 { /* Keep copy of pe and record it in list */
1092 Pointer_Event *p = malloc(sizeof(Pointer_Event));
1093 memcpy(p, pe, sizeof(Pointer_Event));
1094 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1100 /* This will also update middle-point to report to user later */
1101 st->info.x = st->sum_x / st->n_taps;
1102 st->info.y = st->sum_y / st->n_taps;
1103 st->info.timestamp = pe->timestamp;
1107 pe_list = eina_list_append(pe_list, p);
1108 st->l = eina_list_append(st->l, pe_list);
1111 pe_list = eina_list_append(pe_list, p);
1119 * when this timer expires we ABORT double click gesture.
1121 * @param data The gesture-layer object.
1122 * @return cancles callback for this timer.
1124 * @ingroup Elm_Gesture_Layer
1127 _dbl_click_timeout(void *data)
1129 Gesture_Info *gesture = data;
1130 Widget_Data *wd = elm_widget_data_get(gesture->obj);
1132 wd->dbl_timeout = NULL;
1133 _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1134 gesture->info, EINA_FALSE);
1136 _dbl_click_test_reset(gesture);
1137 _clear_if_finished(gesture->obj);
1138 return ECORE_CALLBACK_CANCEL;
1144 * This function checks all click/tap and double/triple taps
1146 * @param obj The gesture-layer object.
1147 * @param pe The recent input event as stored in pe struct.
1148 * @param event_info Original input event pointer.
1149 * @param event_type Type of original input event.
1150 * @param g_type what Gesture we are testing.
1151 * @param taps How many click/taps we test for.
1153 * @ingroup Elm_Gesture_Layer
1156 _dbl_click_test(Evas_Object *obj, Pointer_Event *pe,
1157 void *event_info, Evas_Callback_Type event_type,
1158 Elm_Gesture_Types g_type, int taps)
1159 { /* Here we fill Recent_Taps struct and fire-up click/tap timers */
1160 Widget_Data *wd = elm_widget_data_get(obj);
1163 if (!pe) /* this happens when unhandled event arrived */
1164 return; /* see _make_pointer_event function */
1166 Gesture_Info *gesture = wd->gesture[g_type];
1167 if (!gesture ) return;
1169 if ((gesture->state == ELM_GESTURE_STATE_UNDEFINED) &&
1170 eina_list_count(wd->touched))
1171 return; /* user left a finger on device, do NOT start */
1173 Taps_Type *st = gesture->data;
1175 { /* Allocated once on first time */
1176 st = calloc(1, sizeof(Taps_Type));
1178 _dbl_click_test_reset(gesture);
1181 Eina_List *pe_list = NULL;
1182 Pointer_Event *pe_down = NULL;
1183 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1184 switch (pe->event_type)
1186 case EVAS_CALLBACK_MULTI_DOWN:
1187 case EVAS_CALLBACK_MOUSE_DOWN:
1188 pe_list = eina_list_search_unsorted(st->l, compare_match_fingers, pe);
1189 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1190 if ((pe->device == 0) && (eina_list_count(pe_list) == 1))
1191 { /* This is the first mouse down we got */
1192 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1193 &st->info, EINA_FALSE);
1194 consume_event(wd, event_info, event_type, ev_flag);
1196 /* To test dbl_click/dbl_tap */
1197 /* When this timer expires, gesture ABORTed if not completed */
1198 if (!wd->dbl_timeout && (taps > 1))
1199 wd->dbl_timeout = ecore_timer_add(0.4, _dbl_click_timeout,
1206 case EVAS_CALLBACK_MULTI_UP:
1207 case EVAS_CALLBACK_MOUSE_UP:
1208 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1210 return; /* Got only first mouse_down and mouse_up */
1212 pe_list = _record_pointer_event(st, pe_list, pe, wd, event_info, event_type);
1214 if (eina_list_count(pe_list) <= (unsigned int) ((taps - 1) * 2))
1215 return; /* Got only first mouse_down and mouse_up */
1217 /* Get first event in first list, this has to be Mouse Down event */
1218 pe_down = eina_list_data_get(pe_list);
1220 if (_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1226 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1227 &st->info, EINA_FALSE);
1228 consume_event(wd, event_info, event_type, ev_flag);
1232 if (st->count_ups == eina_list_count(st->l))
1234 /* Abort if we found a single click */
1235 if ((taps == 1) && (st->count_ups == 1))
1237 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1238 &st->info, EINA_FALSE);
1239 consume_event(wd, event_info, event_type, ev_flag);
1242 st->info.n = st->count_ups;
1243 ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
1244 &st->info, EINA_FALSE);
1245 consume_event(wd, event_info, event_type, ev_flag);
1252 case EVAS_CALLBACK_MULTI_MOVE:
1253 case EVAS_CALLBACK_MOUSE_MOVE:
1254 /* Get first event in first list, this has to be a Mouse Down event */
1255 /* and verify that user didn't move out of this area before next tap */
1256 pe_list = eina_list_search_unsorted(st->l, compare_pe_device, pe);
1259 pe_down = eina_list_data_get(pe_list);
1260 if (!_inside(pe_down->x, pe_down->y, pe->x, pe->y))
1262 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1263 &st->info, EINA_FALSE);
1264 consume_event(wd, event_info, event_type, ev_flag);
1277 * This function computes momentum for MOMENTUM, LINE and FLICK gestures
1278 * This momentum value will be sent to widget when gesture is completed.
1280 * @param momentum pointer to buffer where we record momentum value.
1281 * @param x1 x coord where user started gesture.
1282 * @param y1 y coord where user started gesture.
1283 * @param x2 x coord where user completed gesture.
1284 * @param y2 y coord where user completed gesture.
1285 * @param t1x timestamp for X, when user started gesture.
1286 * @param t1y timestamp for Y, when user started gesture.
1287 * @param t2 timestamp when user completed gesture.
1289 * @ingroup Elm_Gesture_Layer
1292 _set_momentum(Elm_Gesture_Momentum_Info *momentum, Evas_Coord x1, Evas_Coord y1,
1293 Evas_Coord x2, Evas_Coord y2, unsigned int t1x, unsigned int t1y,
1296 Evas_Coord velx = 0, vely = 0, vel;
1297 Evas_Coord dx = x2 - x1;
1298 Evas_Coord dy = y2 - y1;
1302 velx = (dx * 1000) / dtx;
1305 vely = (dy * 1000) / dty;
1307 vel = sqrt((velx * velx) + (vely * vely));
1309 if ((_elm_config->thumbscroll_friction > 0.0) &&
1310 (vel > _elm_config->thumbscroll_momentum_threshold))
1311 { /* report momentum */
1312 momentum->mx = velx;
1313 momentum->my = vely;
1325 * This function is used for computing rotation angle (DEG).
1327 * @param x1 first finger x location.
1328 * @param y1 first finger y location.
1329 * @param x2 second finger x location.
1330 * @param y2 second finger y location.
1332 * @return angle of the line between (x1,y1), (x2,y2) in Radians.
1334 * @ingroup Elm_Gesture_Layer
1337 get_angle(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2)
1343 if (((int) xx) && ((int) yy))
1350 return RAD_360DEG - a;
1361 return RAD_180DEG + a;
1365 return RAD_180DEG - a;
1371 { /* Horizontal line */
1396 * This function is used for computing the magnitude and direction
1397 * of vector between two points.
1399 * @param x1 first finger x location.
1400 * @param y1 first finger y location.
1401 * @param x2 second finger x location.
1402 * @param y2 second finger y location.
1403 * @param l length computed (output)
1404 * @param a angle computed (output)
1406 * @ingroup Elm_Gesture_Layer
1409 get_vector(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2, Evas_Coord y2,
1410 Evas_Coord *l, double *a)
1415 *l = (Evas_Coord) sqrt(xx*xx + yy*yy);
1416 *a = get_angle(x1, y1, x2, y2);
1420 _get_direction(Evas_Coord x1, Evas_Coord x2)
1433 * This function tests momentum gesture.
1434 * @param obj The gesture-layer object.
1435 * @param pe The recent input event as stored in pe struct.
1436 * @param event_info recent input event.
1437 * @param event_type recent event type.
1438 * @param g_type what Gesture we are testing.
1440 * @ingroup Elm_Gesture_Layer
1443 _momentum_test(Evas_Object *obj, Pointer_Event *pe,
1444 void *event_info, Evas_Callback_Type event_type,
1445 Elm_Gesture_Types g_type)
1447 Widget_Data *wd = elm_widget_data_get(obj);
1449 Gesture_Info *gesture = wd->gesture[g_type];
1450 if (!gesture ) return;
1452 if ((gesture->state == ELM_GESTURE_STATE_UNDEFINED) &&
1453 eina_list_count(wd->touched))
1454 return; /* user left a finger on device, do NOT start */
1456 Momentum_Type *st = gesture->data;
1458 { /* Allocated once on first time */
1459 st = calloc(1, sizeof(Momentum_Type));
1461 _momentum_test_reset(gesture);
1467 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1468 switch (pe->event_type)
1470 case EVAS_CALLBACK_MOUSE_DOWN:
1471 st->line_st.x = st->line_end.x = pe->x;
1472 st->line_st.y = st->line_end.y = pe->y;
1473 st->t_st_x = st->t_st_y = st->t_end = pe->timestamp;
1474 st->xdir = st->ydir = 0;
1475 st->info.x2 = st->info.x1 = pe->x;
1476 st->info.y2 = st->info.y1 = pe->y;
1477 st->info.tx = st->info.ty = pe->timestamp;
1478 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1479 &st->info, EINA_FALSE);
1480 consume_event(wd, event_info, event_type, ev_flag);
1483 case EVAS_CALLBACK_MOUSE_UP:
1484 /* IGNORE if line info was cleared, like long press, move */
1488 if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1490 /* Too long of a wait, reset all values */
1491 st->line_st.x = pe->x;
1492 st->line_st.y = pe->y;
1493 st->t_st_y = st->t_st_x = pe->timestamp;
1494 st->xdir = st->ydir = 0;
1497 st->info.x2 = pe->x;
1498 st->info.y2 = pe->y;
1499 st->line_end.x = pe->x;
1500 st->line_end.y = pe->y;
1501 st->t_end = pe->timestamp;
1503 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
1504 st->t_st_x, st->t_st_y, pe->timestamp);
1506 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END, &st->info,
1508 consume_event(wd, event_info, event_type, ev_flag);
1512 case EVAS_CALLBACK_MOUSE_MOVE:
1513 /* IGNORE if line info was cleared, like long press, move */
1517 if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
1519 /* Too long of a wait, reset all values */
1520 st->line_st.x = pe->x;
1521 st->line_st.y = pe->y;
1522 st->t_st_y = st->t_st_x = pe->timestamp;
1523 st->info.tx = st->t_st_x;
1524 st->info.ty = st->t_st_y;
1525 st->xdir = st->ydir = 0;
1530 xdir = _get_direction(st->line_end.x, pe->x);
1531 ydir = _get_direction(st->line_end.y, pe->y);
1532 if (!xdir || (xdir == (-st->xdir)))
1534 st->line_st.x = st->line_end.x;
1535 st->info.tx = st->t_st_x = st->t_end;
1539 if (!ydir || (ydir == (-st->ydir)))
1541 st->line_st.y = st->line_end.y;
1542 st->info.ty = st->t_st_y = st->t_end;
1547 st->info.x2 = st->line_end.x = pe->x;
1548 st->info.y2 = st->line_end.y = pe->y;
1549 st->t_end = pe->timestamp;
1550 _set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
1551 st->t_st_x, st->t_st_y, pe->timestamp);
1552 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE, &st->info,
1554 consume_event(wd, event_info, event_type, ev_flag);
1557 case EVAS_CALLBACK_MULTI_UP:
1558 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
1560 consume_event(wd, event_info, event_type, ev_flag);
1569 compare_line_device(const void *data1, const void *data2)
1570 { /* Compare device component of line struct */
1571 const Line_Data *ln1 = data1;
1572 const int *device = data2;
1574 if (ln1->t_st) /* Compare only with lines that started */
1575 return (ln1->device - (*device));
1583 * This function construct line struct from input.
1584 * @param info pointer to store line momentum.
1585 * @param st line info to store input data.
1586 * @param pe The recent input event as stored in pe struct.
1588 * @ingroup Elm_Gesture_Layer
1591 _single_line_process(Elm_Gesture_Line_Info *info, Line_Data *st,
1593 { /* Record events and set momentum for line pointed by st */
1597 switch (pe->event_type)
1599 case EVAS_CALLBACK_MOUSE_DOWN:
1600 case EVAS_CALLBACK_MULTI_DOWN:
1601 st->line_st.x = pe->x;
1602 st->line_st.y = pe->y;
1603 st->t_st = pe->timestamp;
1604 st->device = pe->device;
1605 info->momentum.x1 = pe->x;
1606 info->momentum.y1 = pe->y;
1607 info->momentum.tx = pe->timestamp;
1608 info->momentum.ty = pe->timestamp;
1613 case EVAS_CALLBACK_MOUSE_UP:
1614 case EVAS_CALLBACK_MULTI_UP:
1615 /* IGNORE if line info was cleared, like long press, move */
1619 st->line_end.x = pe->x;
1620 st->line_end.y = pe->y;
1621 st->t_end = pe->timestamp;
1624 case EVAS_CALLBACK_MOUSE_MOVE:
1625 case EVAS_CALLBACK_MULTI_MOVE:
1626 /* IGNORE if line info was cleared, like long press, move */
1637 _line_data_reset(st);
1641 info->momentum.x2 = pe->x;
1642 info->momentum.y2 = pe->y;
1643 _set_momentum(&info->momentum, st->line_st.x, st->line_st.y, pe->x, pe->y,
1644 st->t_st, st->t_st, pe->timestamp);
1652 * This function test for (n) line gesture.
1653 * @param obj The gesture-layer object.
1654 * @param pe The recent input event as stored in pe struct.
1655 * @param event_info Original input event pointer.
1656 * @param event_type Type of original input event.
1657 * @param g_type what Gesture we are testing.
1659 * @ingroup Elm_Gesture_Layer
1662 _n_line_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
1663 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
1667 Widget_Data *wd = elm_widget_data_get(obj);
1669 Gesture_Info *gesture = wd->gesture[g_type];
1670 if (!gesture ) return;
1672 if ((gesture->state == ELM_GESTURE_STATE_UNDEFINED) &&
1673 eina_list_count(wd->touched))
1674 return; /* user left a finger on device, do NOT start */
1676 Line_Type *st = gesture->data;
1679 st = calloc(1, sizeof(Line_Type));
1683 Line_Data *line = NULL;
1684 Eina_List *list = st->list;
1685 unsigned int i, cnt = eina_list_count(list);
1688 { /* list is not empty, locate this device on list */
1689 line = (Line_Data *) eina_list_search_unsorted(st->list,
1690 compare_line_device, &pe->device);
1693 { /* Try to locate an empty-node */
1694 for (i = 0; i < cnt; i++)
1696 line = eina_list_nth(list, i);
1698 break; /* Found a free node */
1706 { /* List is empty or device not found, new line-struct on START only */
1707 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1708 (event_type == EVAS_CALLBACK_MULTI_DOWN))
1709 { /* Allocate new item on START */
1710 line = calloc(1, sizeof(Line_Data));
1711 _line_data_reset(line);
1712 list = eina_list_append(list, line);
1717 if (!line) /* This may happen on MOVE that comes before DOWN */
1718 return; /* No line-struct to work with, can't continue testing */
1721 if (_single_line_process(&st->info, line, pe)) /* update st with input */
1722 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
1724 /* Get direction and magnitude of the line */
1726 get_vector(line->line_st.x, line->line_st.y, pe->x, pe->y,
1727 &line->line_length, &angle);
1729 /* These are used later to compare lines length */
1730 Evas_Coord shortest_line_len = line->line_length;
1731 Evas_Coord longest_line_len = line->line_length;
1732 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
1734 /* Now update line-state */
1736 { /* Analyze line only if line started */
1737 if (line->line_angle >= 0.0)
1738 { /* if line direction was set, we test if broke tolerance */
1739 double a = fabs(angle - line->line_angle);
1741 double d = (tan(a)) * line->line_length; /* Distance from line */
1742 #if defined(DEBUG_GESTURE_LAYER)
1743 printf("%s a=<%f> d=<%f>\n", __func__, (a * 57.295779513), d);
1745 if ((d > wd->line_tolerance) || (a > ELM_GESTURE_LINE_ANGLE_TOLERANCE))
1746 // if (a > ELM_GESTURE_LINE_ANGLE_TOLERANCE)
1747 { /* Broke tolerance: abort line and start a new one */
1748 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1749 &st->info, EINA_FALSE);
1750 consume_event(wd, event_info, event_type, ev_flag);
1755 { /* Record the line angle as it broke minimum length for line */
1756 if (line->line_length >= wd->line_min_length)
1757 st->info.angle = line->line_angle = angle;
1762 if (line->line_angle < 0.0)
1763 { /* it's not a line, too short more close to a tap */
1764 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
1765 &st->info, EINA_FALSE);
1766 consume_event(wd, event_info, event_type, ev_flag);
1772 /* Count how many lines already started / ended */
1775 unsigned int tm_start = pe->timestamp;
1776 unsigned int tm_end = pe->timestamp;
1779 double base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
1780 Eina_Bool lines_parallel = EINA_TRUE;
1781 EINA_LIST_FOREACH(list, l, t_line)
1784 base_angle = t_line->line_angle;
1787 if (t_line->line_angle >= 0)
1788 { /* Compare angle only with lines with direction defined */
1789 if (fabs(base_angle - t_line->line_angle) >
1790 ELM_GESTURE_LINE_ANGLE_TOLERANCE)
1791 lines_parallel = EINA_FALSE;
1795 if (t_line->line_length)
1796 { /* update only if this line is used */
1797 if (shortest_line_len > t_line->line_length)
1798 shortest_line_len = t_line->line_length;
1800 if (longest_line_len < t_line->line_length)
1801 longest_line_len = t_line->line_length;
1807 if (t_line->t_st < tm_start)
1808 tm_start = t_line->t_st;
1814 if (t_line->t_end < tm_end)
1815 tm_end = t_line->t_end;
1819 st->info.n = started;
1823 ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
1824 (event_type == EVAS_CALLBACK_MULTI_DOWN)))
1825 { /* user lift one finger then starts again without line-end - ABORT */
1826 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
1828 consume_event(wd, event_info, event_type, ev_flag);
1832 if (!lines_parallel)
1833 { /* Lines are NOT at same direction, abort this gesture */
1834 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
1836 consume_event(wd, event_info, event_type, ev_flag);
1841 /* We report ABORT if lines length are NOT matching when fingers are up */
1842 if ((longest_line_len - shortest_line_len) > (elm_finger_size_get()*2))
1844 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
1846 consume_event(wd, event_info, event_type, ev_flag);
1850 if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > FLICK_MAX_MS))
1851 { /* We consider FLICK as a fast line.ABORT if take too long to finish */
1852 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
1854 consume_event(wd, event_info, event_type, ev_flag);
1860 case EVAS_CALLBACK_MOUSE_UP:
1861 case EVAS_CALLBACK_MULTI_UP:
1862 if ((started) && (started == ended))
1864 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
1865 &st->info, EINA_FALSE);
1866 consume_event(wd, event_info, event_type, ev_flag);
1871 case EVAS_CALLBACK_MOUSE_DOWN:
1872 case EVAS_CALLBACK_MULTI_DOWN:
1875 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
1876 &st->info, EINA_TRUE);
1877 consume_event(wd, event_info, event_type, ev_flag);
1882 case EVAS_CALLBACK_MOUSE_MOVE:
1883 case EVAS_CALLBACK_MULTI_MOVE:
1886 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
1887 &st->info, EINA_TRUE);
1888 consume_event(wd, event_info, event_type, ev_flag);
1894 return; /* Unhandeld event type */
1901 * This function is used to check if rotation gesture started.
1902 * @param st Contains current rotation values from user input.
1903 * @return TRUE/FALSE if we need to set rotation START.
1905 * @ingroup Elm_Gesture_Layer
1908 rotation_broke_tolerance(Rotate_Type *st)
1910 if (st->info.base_angle < 0)
1911 return EINA_FALSE; /* Angle has to be computed first */
1913 if (st->rotate_tolerance < 0)
1916 double low = st->info.base_angle - st->rotate_tolerance;
1917 double high = st->info.base_angle + st->rotate_tolerance;
1918 double t = st->info.angle;
1931 if (high > RAD_360DEG)
1942 #if defined(DEBUG_GESTURE_LAYER)
1943 printf("%s angle=<%d> low=<%d> high=<%d>\n", __func__, t, low, high);
1945 if ((t < low) || (t > high))
1946 { /* This marks that roation action has started */
1947 st->rotate_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
1948 st->info.base_angle = st->info.angle; /* Avoid jump in angle value */
1958 * This function is used for computing the gap between fingers.
1959 * It returns the length and center point between fingers.
1961 * @param x1 first finger x location.
1962 * @param y1 first finger y location.
1963 * @param x2 second finger x location.
1964 * @param y2 second finger y location.
1965 * @param x Gets center point x cord (output)
1966 * @param y Gets center point y cord (output)
1968 * @return length of the line between (x1,y1), (x2,y2) in pixels.
1970 * @ingroup Elm_Gesture_Layer
1973 get_finger_gap_length(Evas_Coord x1, Evas_Coord y1, Evas_Coord x2,
1974 Evas_Coord y2, Evas_Coord *x, Evas_Coord *y)
1976 double a, b, xx, yy, gap;
1979 gap = sqrt(xx*xx + yy*yy);
1981 /* START - Compute zoom center point */
1982 /* The triangle defined as follows:
1990 * http://en.wikipedia.org/wiki/Trigonometric_functions
1991 *************************************/
1992 if (((int) xx) && ((int) yy))
1994 double A = atan((yy / xx));
1995 #if defined(DEBUG_GESTURE_LAYER)
1996 printf("xx=<%f> yy=<%f> A=<%f>\n", xx, yy, A);
1998 a = (Evas_Coord) ((gap / 2) * sin(A));
1999 b = (Evas_Coord) ((gap / 2) * cos(A));
2000 *x = (Evas_Coord) ((x2 > x1) ? (x1 + b) : (x2 + b));
2001 *y = (Evas_Coord) ((y2 > y1) ? (y1 + a) : (y2 + a));
2006 { /* horiz line, take half width */
2007 #if defined(DEBUG_GESTURE_LAYER)
2008 printf("==== HORIZ ====\n");
2010 *x = (Evas_Coord) (xx / 2);
2011 *y = (Evas_Coord) (y1);
2015 { /* vert line, take half width */
2016 #if defined(DEBUG_GESTURE_LAYER)
2017 printf("==== VERT ====\n");
2019 *x = (Evas_Coord) (x1);
2020 *y = (Evas_Coord) (yy / 2);
2023 /* END - Compute zoom center point */
2025 return (Evas_Coord) gap;
2031 * This function is used for computing zoom value.
2033 * @param st Pointer to zoom data based on user input.
2034 * @param x1 first finger x location.
2035 * @param y1 first finger y location.
2036 * @param x2 second finger x location.
2037 * @param y2 second finger y location.
2038 * @param factor zoom-factor, used to determine how fast zoom works.
2040 * @return zoom value, when 1.0 means no zoom, 0.5 half size...
2042 * @ingroup Elm_Gesture_Layer
2044 /* FIXME change float to double */
2046 compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2047 Evas_Coord x2, Evas_Coord y2, unsigned int tm2, float factor)
2050 Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
2051 &st->info.x, &st->info.y);
2053 st->info.radius = diam / 2;
2057 st->zoom_base = diam;
2058 return st->info.zoom;
2061 if (st->zoom_tolerance)
2062 { /* zoom tolerance <> ZERO, means zoom action NOT started yet */
2063 if (diam < (st->zoom_base - st->zoom_tolerance))
2064 { /* avoid jump with zoom value when break tolerance */
2065 st->zoom_base -= st->zoom_tolerance;
2066 st->zoom_tolerance = 0;
2069 if (diam > (st->zoom_base + st->zoom_tolerance))
2070 { /* avoid jump with zoom value when break tolerance */
2071 st->zoom_base += st->zoom_tolerance;
2072 st->zoom_tolerance = 0;
2078 /* We use factor only on the difference between gap-base */
2079 /* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
2080 rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
2081 (float) st->zoom_base) * factor));
2084 /* Momentum: zoom per second: (NOT YET SUPPORTED) */
2085 st->info.momentum = (((rt - 1.0) * 1000) / (tm2 - tm1));
2096 * This function handles zoom with mouse wheel.
2097 * thats a combination of wheel + CTRL key.
2098 * @param obj The gesture-layer object.
2099 * @param event_info Original input event pointer.
2100 * @param event_type Type of original input event.
2101 * @param g_type what Gesture we are testing.
2103 * @ingroup Elm_Gesture_Layer
2106 _zoom_with_wheel_test(Evas_Object *obj, void *event_info,
2107 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2109 Widget_Data *wd = elm_widget_data_get(obj);
2111 if (!wd->gesture[g_type]) return;
2113 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2114 Zoom_Type *st = gesture_zoom->data;
2115 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2117 { /* Allocated once on first time, used for zoom intermediate data */
2118 st = calloc(1, sizeof(Zoom_Type));
2119 gesture_zoom->data = st;
2120 _zoom_test_reset(gesture_zoom);
2125 case EVAS_CALLBACK_KEY_UP:
2127 Evas_Event_Key_Up *p = event_info;
2128 if ((!strcmp(p->keyname, "Control_L")) ||
2129 (!strcmp(p->keyname, "Control_R")))
2130 { /* Test if we ended a zoom gesture when releasing CTRL */
2131 if ((st->zoom_wheel) &&
2132 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2133 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2134 { /* User released CTRL after zooming */
2135 ev_flag = _set_state(gesture_zoom,
2136 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2137 consume_event(wd, event_info, event_type, ev_flag);
2145 case EVAS_CALLBACK_MOUSE_WHEEL:
2148 Elm_Gesture_State s;
2149 if (!evas_key_modifier_is_set(
2150 ((Evas_Event_Mouse_Wheel *) event_info)->modifiers,
2152 { /* if using wheel witout CTRL after starting zoom */
2153 if ((st->zoom_wheel) &&
2154 ((gesture_zoom->state == ELM_GESTURE_STATE_START) ||
2155 (gesture_zoom->state == ELM_GESTURE_STATE_MOVE)))
2157 ev_flag = _set_state(gesture_zoom,
2158 ELM_GESTURE_STATE_END, &st->info, EINA_FALSE);
2159 consume_event(wd, event_info, event_type, ev_flag);
2164 return; /* Ignore mouse-wheel without control */
2167 /* Using mouse wheel with CTRL for zoom */
2168 if (st->zoom_wheel || (st->zoom_tolerance == 0))
2169 { /* when (zoom_wheel == NULL) and (zoom_tolerance == 0)
2170 we continue a zoom gesture */
2172 s = ELM_GESTURE_STATE_MOVE;
2175 { /* On first wheel event, report START */
2177 s = ELM_GESTURE_STATE_START;
2180 st->zoom_tolerance = 0; /* Cancel tolerance */
2181 st->zoom_wheel = (Evas_Event_Mouse_Wheel *) event_info;
2182 st->info.x = st->zoom_wheel->canvas.x;
2183 st->info.y = st->zoom_wheel->canvas.y;
2185 if (st->zoom_wheel->z > 0) /* zoom in */
2186 st->info.zoom += (wd->factor * wd->zoom_wheel_factor);
2188 if (st->zoom_wheel->z < 0) /* zoom out */
2189 st->info.zoom -= (wd->factor * wd->zoom_wheel_factor);
2191 if (st->info.zoom < 0.0)
2192 st->info.zoom = 0.0;
2194 ev_flag = _set_state(gesture_zoom, s, &st->info, force);
2195 consume_event(wd, event_info, event_type, ev_flag);
2207 * This function is used to test zoom gesture.
2208 * user may combine zoom, rotation together.
2209 * so its possible that both will be detected from input.
2210 * (both are two-finger movement-oriented gestures)
2212 * @param obj The gesture-layer object.
2213 * @param event_info Pointer to recent input event.
2214 * @param event_type Recent input event type.
2215 * @param g_type what Gesture we are testing.
2217 * @ingroup Elm_Gesture_Layer
2220 _zoom_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2221 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2225 Widget_Data *wd = elm_widget_data_get(obj);
2227 if (!wd->gesture[g_type]) return;
2229 Gesture_Info *gesture_zoom = wd->gesture[g_type];
2230 Zoom_Type *st = gesture_zoom->data;
2233 { /* Allocated once on first time, used for zoom data */
2234 st = calloc(1, sizeof(Zoom_Type));
2235 gesture_zoom->data = st;
2236 _zoom_test_reset(gesture_zoom);
2239 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2242 case EVAS_CALLBACK_MOUSE_DOWN:
2243 consume_event(wd, event_info, event_type, ev_flag);
2244 memcpy(&st->zoom_st, pe, sizeof(Pointer_Event));
2248 case EVAS_CALLBACK_MOUSE_MOVE:
2249 consume_event(wd, event_info, event_type, ev_flag);
2250 if (!st->zoom_st.timestamp)
2251 return; /* we got move event before down event.Ignore it */
2253 consume_event(wd, event_info, event_type, ev_flag);
2254 memcpy(&st->zoom_mv, pe, sizeof(Pointer_Event));
2256 /* We match this point to previous multi-move or multi-down event */
2257 if (st->zoom_mv1.timestamp)
2259 st->info.zoom = compute_zoom(st,
2260 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2261 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2266 if (st->zoom_st1.timestamp)
2268 st->info.zoom = compute_zoom(st,
2269 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2270 st->zoom_st1.x, st->zoom_st1.y, st->zoom_st1.timestamp,
2277 case EVAS_CALLBACK_MULTI_MOVE:
2278 if (!st->zoom_st1.timestamp)
2279 return; /* We get move event before down event.Ignore it */
2281 consume_event(wd, event_info, event_type, ev_flag);
2282 if (st->zoom_mv1.timestamp)
2284 if (st->zoom_mv1.device !=
2285 ((Evas_Event_Multi_Move *) event_info)->device)
2286 { /* A third finger on screen, abort zoom */
2287 ev_flag = _set_state(gesture_zoom,
2288 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2289 consume_event(wd, event_info, event_type, ev_flag);
2295 memcpy(&st->zoom_mv1, pe, sizeof(Pointer_Event));
2297 /* Match this point to previous mouse-move or mouse-down event */
2298 if (st->zoom_mv.timestamp)
2300 st->info.zoom = compute_zoom(st,
2301 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2302 st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
2307 if (st->zoom_st.timestamp)
2309 st->info.zoom = compute_zoom(st,
2310 st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
2311 st->zoom_st.x, st->zoom_st.y, st->zoom_st.timestamp,
2318 case EVAS_CALLBACK_MULTI_DOWN:
2319 consume_event(wd, event_info, event_type, ev_flag);
2320 memcpy(&st->zoom_st1, pe, sizeof(Pointer_Event));
2323 case EVAS_CALLBACK_MOUSE_UP:
2324 case EVAS_CALLBACK_MULTI_UP:
2325 /* Reset timestamp of finger-up.This is used later
2326 by _zoom_test_reset() to retain finger-down data */
2327 consume_event(wd, event_info, event_type, ev_flag);
2328 if (((st->zoom_wheel) || (st->zoom_base)) &&
2329 (st->zoom_tolerance == 0))
2331 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
2332 &st->info, EINA_FALSE);
2333 consume_event(wd, event_info, event_type, ev_flag);
2338 /* if we got here not a ZOOM */
2339 if (gesture_zoom->state != ELM_GESTURE_STATE_UNDEFINED)
2340 { /* Must be != undefined, if gesture started */
2341 ev_flag = _set_state(gesture_zoom,
2342 ELM_GESTURE_STATE_ABORT, &st->info, EINA_FALSE);
2343 consume_event(wd, event_info, event_type, ev_flag);
2346 _zoom_test_reset(gesture_zoom);
2355 if (!st->zoom_tolerance)
2356 if ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
2357 (event_type == EVAS_CALLBACK_MULTI_MOVE))
2359 { /* Zoom broke tolerance, report move */
2360 double d = st->info.zoom - st->next_step;
2364 if (d >= wd->zoom_step)
2365 { /* Report move in steps */
2366 st->next_step = st->info.zoom;
2368 ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_MOVE,
2369 &st->info, EINA_TRUE);
2370 consume_event(wd, event_info, event_type, ev_flag);
2377 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2378 (event_type == EVAS_CALLBACK_MULTI_DOWN))
2379 { /* report zoom start finger location is zoom-center temporarly */
2380 /* Zoom may have started with mouse-wheel, don't report START */
2381 if ((st->zoom_st.timestamp) && (st->zoom_st1.timestamp))
2382 { /* Set zoom-base after BOTH down events were recorded */
2383 /* Compute length of line between fingers on zoom start */
2384 st->info.zoom = 1.0;
2385 st->zoom_base = get_finger_gap_length(st->zoom_st1.x,
2386 st->zoom_st1.y, st->zoom_st.x, st->zoom_st.y,
2387 &st->info.x, &st->info.y);
2389 st->info.radius = st->zoom_base / 2;
2391 if ((gesture_zoom->state != ELM_GESTURE_STATE_START) &&
2392 (gesture_zoom->state != ELM_GESTURE_STATE_MOVE))
2393 { /* Report START only when two fingers touching */
2394 ev_flag = _set_state(gesture_zoom,
2395 ELM_GESTURE_STATE_START, &st->info, EINA_FALSE);
2396 consume_event(wd, event_info, event_type, ev_flag);
2405 _get_rotate_properties(Rotate_Type *st,
2406 Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
2407 Evas_Coord x2, Evas_Coord y2, unsigned int tm2,
2410 st->info.radius = get_finger_gap_length(x1, y1, x2, y2,
2411 &st->info.x, &st->info.y) / 2;
2413 *angle = get_angle(x1, y1, x2, y2);
2414 #if 0 /* (NOT YET SUPPORTED) */
2415 if (angle == &st->info.angle)
2416 { /* Compute momentum: TODO: bug when breaking 0, 360 values */
2417 st->info.momentum = (((*angle) - st->info.base_angle) /
2418 (fabs(tm2 - tm1))) * 1000;
2421 st->info.momentum = 0;
2431 * This function is used to test rotation gesture.
2432 * user may combine zoom, rotation together.
2433 * so its possible that both will be detected from input.
2434 * (both are two-finger movement-oriented gestures)
2436 * @param obj The gesture-layer object.
2437 * @param event_info Pointer to recent input event.
2438 * @param event_type Recent input event type.
2439 * @param g_type what Gesture we are testing.
2441 * @ingroup Elm_Gesture_Layer
2444 _rotate_test(Evas_Object *obj, Pointer_Event *pe, void *event_info,
2445 Evas_Callback_Type event_type, Elm_Gesture_Types g_type)
2450 Widget_Data *wd = elm_widget_data_get(obj);
2452 if (!wd->gesture[g_type]) return;
2454 Gesture_Info *gesture = wd->gesture[g_type];
2455 Rotate_Type *st = gesture->data;
2460 { /* Allocated once on first time */
2461 st = calloc(1, sizeof(Rotate_Type));
2463 _rotate_test_reset(gesture);
2467 Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
2471 case EVAS_CALLBACK_MOUSE_DOWN:
2472 consume_event(wd, event_info, event_type, ev_flag);
2473 memcpy(&st->rotate_st, pe, sizeof(Pointer_Event));
2477 case EVAS_CALLBACK_MOUSE_MOVE:
2478 if (!st->rotate_st.timestamp)
2479 break; /* We got move event before down event.Ignore it */
2481 consume_event(wd, event_info, event_type, ev_flag);
2482 memcpy(&st->rotate_mv, pe, sizeof(Pointer_Event));
2484 /* Match this point to previous multi-move or multi-down event */
2485 if (st->rotate_mv1.timestamp)
2486 { /* Compute rotation angle and report to user */
2487 _get_rotate_properties(st,
2488 st->rotate_mv.x, st->rotate_mv.y, st->rotate_mv.timestamp,
2489 st->rotate_mv1.x, st->rotate_mv1.y, st->rotate_mv1.timestamp,
2494 if (st->rotate_st1.timestamp)
2495 { /* Compute rotation angle and report to user */
2496 _get_rotate_properties(st,
2497 st->rotate_mv.x, st->rotate_mv.y, st->rotate_mv.timestamp,
2498 st->rotate_st1.x, st->rotate_st1.y, st->rotate_st1.timestamp,
2505 case EVAS_CALLBACK_MULTI_MOVE:
2506 if (!st->rotate_st1.timestamp)
2507 break; /* We got move event before down event.Ignore it */
2509 consume_event(wd, event_info, event_type, ev_flag);
2510 if (st->rotate_mv1.timestamp)
2512 if (st->rotate_mv1.device !=
2513 ((Evas_Event_Multi_Move *) event_info)->device)
2514 { /* A third finger on screen, abort rotate */
2515 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2516 &st->info, EINA_FALSE);
2517 consume_event(wd, event_info, event_type, ev_flag);
2523 memcpy(&st->rotate_mv1, pe, sizeof(Pointer_Event));
2525 /* Match this point to previous mouse-move or mouse-down event */
2526 if (st->rotate_mv.timestamp)
2527 { /* Compute rotation angle and report to user */
2528 _get_rotate_properties(st,
2529 st->rotate_mv.x, st->rotate_mv.y, st->rotate_mv.timestamp,
2530 st->rotate_mv1.x, st->rotate_mv1.y, st->rotate_mv1.timestamp,
2535 if (st->rotate_st.timestamp)
2536 { /* Compute rotation angle and report to user */
2537 _get_rotate_properties(st,
2538 st->rotate_st.x, st->rotate_st.y, st->rotate_st.timestamp,
2539 st->rotate_mv1.x, st->rotate_mv1.y, st->rotate_mv1.timestamp,
2546 case EVAS_CALLBACK_MULTI_DOWN:
2547 consume_event(wd, event_info, event_type, ev_flag);
2548 memcpy(&st->rotate_st1, pe, sizeof(Pointer_Event));
2549 _get_rotate_properties(st,
2550 st->rotate_st.x, st->rotate_st.y, st->rotate_st.timestamp,
2551 st->rotate_st1.x, st->rotate_st1.y, st->rotate_st1.timestamp,
2555 case EVAS_CALLBACK_MOUSE_UP:
2556 case EVAS_CALLBACK_MULTI_UP:
2557 consume_event(wd, event_info, event_type, ev_flag);
2558 /* Reset timestamp of finger-up.This is used later
2559 by rotate_test_reset() to retain finger-down data */
2560 if (st->rotate_tolerance < 0)
2562 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
2563 &st->info, EINA_FALSE);
2564 consume_event(wd, event_info, event_type, ev_flag);
2569 if (gesture->state != ELM_GESTURE_STATE_UNDEFINED)
2570 { /* Must be != undefined, if gesture started */
2571 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
2572 &st->info, EINA_FALSE);
2573 consume_event(wd, event_info, event_type, ev_flag);
2576 _rotate_test_reset(gesture);
2583 if ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
2584 (event_type == EVAS_CALLBACK_MULTI_MOVE))
2585 { /* Report MOVE or ABORT for *MOVE event */
2586 if (rotation_broke_tolerance(st))
2587 { /* Rotation broke tolerance, report move */
2588 double d = st->info.angle - st->next_step;
2592 if (d >= wd->rotate_step)
2593 { /* Report move in steps */
2594 st->next_step = st->info.angle;
2596 ev_flag = _set_state(gesture,
2597 ELM_GESTURE_STATE_MOVE, &st->info, EINA_TRUE);
2598 consume_event(wd, event_info, event_type, ev_flag);
2605 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2606 (event_type == EVAS_CALLBACK_MULTI_DOWN))
2608 if ((st->rotate_st.timestamp) && (st->rotate_st1.timestamp))
2609 { /* two-fingers on touch screen - report rotate start */
2610 /* Set base angle, then report start. */
2611 _get_rotate_properties(st,
2612 st->rotate_st.x, st->rotate_st.y, st->rotate_st.timestamp,
2613 st->rotate_st1.x, st->rotate_st1.y, st->rotate_st1.timestamp,
2614 &st->info.base_angle);
2616 ev_flag = _set_state(gesture, ELM_GESTURE_STATE_START,
2617 &st->info, EINA_FALSE);
2618 consume_event(wd, event_info, event_type, ev_flag);
2628 * This function is used to save input events in an abstract struct
2629 * to be used later by getsure-testing functions.
2631 * @param data The gesture-layer object.
2632 * @param event_info Pointer to recent input event.
2633 * @param event_type Recent input event type.
2634 * @param pe The abstract data-struct (output).
2636 * @ingroup Elm_Gesture_Layer
2639 _make_pointer_event(void *data, void *event_info,
2640 Evas_Callback_Type event_type, Pointer_Event *pe)
2642 Widget_Data *wd = elm_widget_data_get(data);
2643 if (!wd) return EINA_FALSE;
2647 case EVAS_CALLBACK_MOUSE_DOWN:
2648 pe->x = ((Evas_Event_Mouse_Down *) event_info)->canvas.x;
2649 pe->y = ((Evas_Event_Mouse_Down *) event_info)->canvas.y;
2650 pe->timestamp = ((Evas_Event_Mouse_Down *) event_info)->timestamp;
2651 pe->device = ELM_MOUSE_DEVICE;
2654 case EVAS_CALLBACK_MOUSE_UP:
2655 pe->x = ((Evas_Event_Mouse_Up *) event_info)->canvas.x;
2656 pe->y = ((Evas_Event_Mouse_Up *) event_info)->canvas.y;
2657 pe->timestamp = ((Evas_Event_Mouse_Up *) event_info)->timestamp;
2658 pe->device = ELM_MOUSE_DEVICE;
2661 case EVAS_CALLBACK_MOUSE_MOVE:
2662 pe->x = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.x;
2663 pe->y = ((Evas_Event_Mouse_Move *) event_info)->cur.canvas.y;
2664 pe->timestamp = ((Evas_Event_Mouse_Move *) event_info)->timestamp;
2665 pe->device = ELM_MOUSE_DEVICE;
2668 case EVAS_CALLBACK_MULTI_DOWN:
2669 pe->x = ((Evas_Event_Multi_Down *) event_info)->canvas.x;
2670 pe->y = ((Evas_Event_Multi_Down *) event_info)->canvas.y;
2671 pe->timestamp = ((Evas_Event_Multi_Down *) event_info)->timestamp;
2672 pe->device = ((Evas_Event_Multi_Down *) event_info)->device;
2675 case EVAS_CALLBACK_MULTI_UP:
2676 pe->x = ((Evas_Event_Multi_Up *) event_info)->canvas.x;
2677 pe->y = ((Evas_Event_Multi_Up *) event_info)->canvas.y;
2678 pe->timestamp = ((Evas_Event_Multi_Up *) event_info)->timestamp;
2679 pe->device = ((Evas_Event_Multi_Up *) event_info)->device;
2682 case EVAS_CALLBACK_MULTI_MOVE:
2683 pe->x = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.x;
2684 pe->y = ((Evas_Event_Multi_Move *) event_info)->cur.canvas.y;
2685 pe->timestamp = ((Evas_Event_Multi_Move *) event_info)->timestamp;
2686 pe->device = ((Evas_Event_Multi_Move *) event_info)->device;
2693 pe->event_type = event_type;
2700 * This function the core-function where input handling is done.
2701 * Here we get user input and stream it to gesture testing.
2702 * We notify user about any gestures with new state:
2704 * START - gesture started.
2705 * MOVE - gesture is ongoing.
2706 * END - gesture was completed.
2707 * ABORT - gesture was aborted after START, MOVE (will NOT be completed)
2709 * We also check if a gesture was detected, then reset event history
2710 * If no gestures were found we reset gesture test flag
2711 * after streaming event-history to widget.
2712 * (stream to the widget all events not consumed as a gesture)
2714 * @param data The gesture-layer object.
2715 * @param event_info Pointer to recent input event.
2716 * @param event_type Recent input event type.
2718 * @ingroup Elm_Gesture_Layer
2721 _event_process(void *data, Evas_Object *obj __UNUSED__,
2722 void *event_info, Evas_Callback_Type event_type)
2725 Pointer_Event *pe = NULL;
2726 Widget_Data *wd = elm_widget_data_get(data);
2729 /* Start testing candidate gesture from here */
2730 if (_make_pointer_event(data, event_info, event_type, &_pe))
2733 if (IS_TESTED(ELM_GESTURE_N_TAPS))
2734 _dbl_click_test(data, pe, event_info, event_type,
2735 ELM_GESTURE_N_TAPS, 1);
2737 if (IS_TESTED(ELM_GESTURE_N_DOUBLE_TAPS))
2738 _dbl_click_test(data, pe, event_info, event_type,
2739 ELM_GESTURE_N_DOUBLE_TAPS, 2);
2741 if (IS_TESTED(ELM_GESTURE_N_TRIPLE_TAPS))
2742 _dbl_click_test(data, pe, event_info, event_type,
2743 ELM_GESTURE_N_TRIPLE_TAPS, 3);
2745 if (IS_TESTED(ELM_GESTURE_MOMENTUM))
2746 _momentum_test(data, pe, event_info, event_type,
2747 ELM_GESTURE_MOMENTUM);
2749 if (IS_TESTED(ELM_GESTURE_N_LINES))
2750 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_LINES);
2752 if (IS_TESTED(ELM_GESTURE_N_FLICKS))
2753 _n_line_test(data, pe, event_info, event_type, ELM_GESTURE_N_FLICKS);
2755 if (IS_TESTED(ELM_GESTURE_ZOOM))
2756 _zoom_test(data, pe, event_info, event_type, ELM_GESTURE_ZOOM);
2758 if (IS_TESTED(ELM_GESTURE_ZOOM))
2759 _zoom_with_wheel_test(data, event_info, event_type, ELM_GESTURE_ZOOM);
2761 if (IS_TESTED(ELM_GESTURE_ROTATE))
2762 _rotate_test(data, pe, event_info, event_type, ELM_GESTURE_ROTATE);
2764 if (_get_event_flag(event_info, event_type) & EVAS_EVENT_FLAG_ON_HOLD)
2765 _event_history_add(data, event_info, event_type);
2766 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
2767 (event_type == EVAS_CALLBACK_MULTI_UP))
2769 Eina_List *pending = _device_is_pending(wd->pending, event_info, event_type);
2772 consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_ON_HOLD);
2773 _event_history_add(data, event_info, event_type);
2777 /* we maintain list of touched devices*/
2778 if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
2779 (event_type == EVAS_CALLBACK_MULTI_DOWN))
2781 wd->touched = _add_touched_device(wd->touched, pe);
2783 else if ((event_type == EVAS_CALLBACK_MOUSE_UP) ||
2784 (event_type == EVAS_CALLBACK_MULTI_UP))
2786 wd->touched = _remove_touched_device(wd->touched, pe);
2789 /* Report current states and clear history if needed */
2790 _clear_if_finished(data);
2795 * For all _mouse_* / multi_* functions wethen send this event to
2796 * _event_process function.
2798 * @param data The gesture-layer object.
2799 * @param event_info Pointer to recent input event.
2801 * @ingroup Elm_Gesture_Layer
2804 _mouse_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2807 Widget_Data *wd = elm_widget_data_get(data);
2809 if (((Evas_Event_Mouse_Down *) event_info)->button != 1)
2810 return; /* We only process left-click at the moment */
2812 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_DOWN);
2816 _mouse_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2819 Widget_Data *wd = elm_widget_data_get(data);
2822 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_MOVE);
2826 _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2829 Widget_Data *wd = elm_widget_data_get(data);
2832 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_DOWN);
2836 _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2839 Widget_Data *wd = elm_widget_data_get(data);
2842 _event_process(data, obj, event_info, EVAS_CALLBACK_KEY_UP);
2846 _mouse_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2849 Widget_Data *wd = elm_widget_data_get(data);
2852 if (((Evas_Event_Mouse_Up *) event_info)->button != 1)
2853 return; /* We only process left-click at the moment */
2855 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_UP);
2859 _mouse_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2862 Widget_Data *wd = elm_widget_data_get(data);
2865 _event_process(data, obj, event_info, EVAS_CALLBACK_MOUSE_WHEEL);
2869 _multi_down(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2872 Widget_Data *wd = elm_widget_data_get(data);
2875 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_DOWN);
2879 _multi_move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2882 Widget_Data *wd = elm_widget_data_get(data);
2885 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_MOVE);
2889 _multi_up(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
2892 Widget_Data *wd = elm_widget_data_get(data);
2895 _event_process(data, obj, event_info, EVAS_CALLBACK_MULTI_UP);
2899 elm_gesture_layer_hold_events_get(Evas_Object *obj)
2901 Widget_Data *wd = elm_widget_data_get(obj);
2902 if (!wd) return EINA_FALSE;
2904 return !wd->repeat_events;
2908 elm_gesture_layer_hold_events_set(Evas_Object *obj, Eina_Bool r)
2910 Widget_Data *wd = elm_widget_data_get(obj);
2913 wd->repeat_events = !r;
2917 elm_gesture_layer_zoom_step_set(Evas_Object *obj, double s)
2919 Widget_Data *wd = elm_widget_data_get(obj);
2929 elm_gesture_layer_rotate_step_set(Evas_Object *obj, double s)
2931 Widget_Data *wd = elm_widget_data_get(obj);
2937 wd->rotate_step = s;
2941 elm_gesture_layer_attach(Evas_Object *obj, Evas_Object *t)
2943 Widget_Data *wd = elm_widget_data_get(obj);
2944 if (!wd) return EINA_FALSE;
2949 /* if was attached before, unregister callbacks first */
2951 _unregister_callbacks(obj);
2955 _register_callbacks(obj);
2960 elm_gesture_layer_cb_set(Evas_Object *obj, Elm_Gesture_Types idx,
2961 Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data)
2963 Widget_Data *wd = elm_widget_data_get(obj);
2966 if (!wd->gesture[idx])
2967 wd->gesture[idx] = calloc(1, sizeof(Gesture_Info));
2969 Gesture_Info *p = wd->gesture[idx];
2972 p->fn[cb_type].cb = cb;
2973 p->fn[cb_type].user_data = data;
2974 p->state = ELM_GESTURE_STATE_UNDEFINED;
2979 _disable_hook(Evas_Object *obj)
2981 if (elm_widget_disabled_get(obj))
2982 _unregister_callbacks(obj);
2984 _register_callbacks(obj);
2988 elm_gesture_layer_add(Evas_Object *parent)
2994 EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
2996 wd = ELM_NEW(Widget_Data);
2997 e = evas_object_evas_get(parent);
2998 if (!e) return NULL;
2999 obj = elm_widget_add(e);
3000 ELM_SET_WIDTYPE(widtype, "gesture_layer");
3001 elm_widget_type_set(obj, "gesture_layer");
3002 elm_widget_sub_object_add(parent, obj);
3003 elm_widget_data_set(obj, wd);
3004 elm_widget_del_hook_set(obj, _del_hook);
3005 elm_widget_disable_hook_set(obj, _disable_hook);
3008 wd->line_min_length = wd->zoom_tolerance = elm_finger_size_get();
3009 wd->line_tolerance = elm_finger_size_get() * 3;
3010 wd->factor = ELM_GESTURE_ZOOM_FACTOR;
3011 wd->zoom_wheel_factor = ELM_GESTURE_ZOOM_WHEEL_FACTOR ; /* mouse wheel zoom steps */
3012 wd->rotate_tolerance = ELM_GESTURE_ROTATION_TOLERANCE;
3013 wd->repeat_events = EINA_TRUE;
3015 #if defined(DEBUG_GESTURE_LAYER)
3016 printf("size of Gestures = <%d>\n", sizeof(wd->gesture));
3018 memset(wd->gesture, 0, sizeof(wd->gesture));