2 #include "e_mod_main.h"
5 #ifdef _E_GESTURE_DEBUG_
7 _e_gesture_event_type_print(int type)
9 if (type == ECORE_EVENT_KEY_DOWN) return "KeyDown";
10 else if (type == ECORE_EVENT_KEY_UP) return "KeyUp";
11 else if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN) return "MouseDown";
12 else if (type == ECORE_EVENT_MOUSE_BUTTON_UP) return "MouseUp";
13 else if (type == ECORE_EVENT_MOUSE_MOVE) return "MouseMove";
14 else return "Unknown";
18 _e_gesture_event_print(void)
21 E_Gesture_Event_Info *data;
24 EINA_LIST_FOREACH(gesture->event_queue, l, data)
26 GTERR("[%d]%s event is queue\n", ++c, _e_gesture_event_type_print(data->type));
29 #endif //_E_GESTURE_DEBUG_
31 static void _e_gesture_send_edge_drag(int fingers, int x, int y, int edge, int mode);
34 _e_gesture_event_queue(int type, void *event)
36 E_Gesture_Event_Info *e_info = NULL;
37 e_info = E_NEW(E_Gesture_Event_Info, 1);
38 EINA_SAFETY_ON_NULL_RETURN(e_info);
40 if (type == ECORE_EVENT_KEY_DOWN ||
41 type == ECORE_EVENT_KEY_UP)
43 e_info->event = E_NEW(Ecore_Event_Key, 1);
45 memcpy(e_info->event, event, sizeof(Ecore_Event_Key));
47 else if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN ||
48 type == ECORE_EVENT_MOUSE_BUTTON_UP)
50 e_info->event = E_NEW(Ecore_Event_Mouse_Button, 1);
52 memcpy(e_info->event, event, sizeof(Ecore_Event_Mouse_Button));
54 else if (type == ECORE_EVENT_MOUSE_MOVE)
56 e_info->event = E_NEW(Ecore_Event_Mouse_Move, 1);
58 memcpy(e_info->event, event, sizeof(Ecore_Event_Mouse_Move));
62 gesture->event_queue = eina_list_append(gesture->event_queue, e_info);
66 if (e_info->event) E_FREE(e_info->event);
71 _e_gesture_event_flush(void)
73 Eina_List *l, *l_next;
74 E_Gesture_Event_Info *data;
76 if (gesture->event_state == E_GESTURE_EVENT_STATE_IGNORE ||
77 gesture->gesture_events.recognized_gesture) return;
78 if (gesture->gesture_filter != E_GESTURE_TYPE_ALL) return;
80 gesture->event_state = E_GESTURE_EVENT_STATE_PROPAGATE;
82 EINA_LIST_FOREACH_SAFE(gesture->event_queue, l, l_next, data)
84 if (data->type == ECORE_EVENT_MOUSE_BUTTON_DOWN)
86 ecore_event_evas_mouse_button_down(NULL, ECORE_EVENT_MOUSE_BUTTON_DOWN, data->event);
88 else if (data->type == ECORE_EVENT_MOUSE_BUTTON_UP)
90 ecore_event_evas_mouse_button_up(NULL, ECORE_EVENT_MOUSE_BUTTON_UP, data->event);
92 else if (data->type == ECORE_EVENT_MOUSE_MOVE)
94 ecore_event_evas_mouse_move(NULL, ECORE_EVENT_MOUSE_MOVE, data->event);
96 else if (data->type == ECORE_EVENT_KEY_DOWN)
98 ecore_event_evas_key_down(NULL, ECORE_EVENT_KEY_DOWN, data->event);
100 else if (data->type == ECORE_EVENT_KEY_UP)
102 ecore_event_evas_key_up(NULL, ECORE_EVENT_KEY_UP, data->event);
106 gesture->event_queue = eina_list_remove_list(gesture->event_queue, l);
111 _e_gesture_event_drop(void)
113 Eina_List *l, *l_next;
114 E_Gesture_Event_Info *data;
116 gesture->event_state = E_GESTURE_EVENT_STATE_IGNORE;
118 EINA_LIST_FOREACH_SAFE(gesture->event_queue, l, l_next, data)
122 gesture->event_queue = eina_list_remove_list(gesture->event_queue, l);
127 _e_gesture_util_center_axis_get(int num_finger, int *x, int *y)
130 int calc_x = 0, calc_y = 0;
139 for (i = 1; i <= num_finger; i++)
141 calc_x += gesture->gesture_events.base_point[i].axis.x;
142 calc_y += gesture->gesture_events.base_point[i].axis.y;
145 calc_x = (int)(calc_x / num_finger);
146 calc_y = (int)(calc_y / num_finger);
153 _e_gesture_util_distance_get(int x1, int y1, int x2, int y2)
157 distance = sqrt(((x2 - x1) * (x2 - x1)) + ((y2 - y1) * (y2 - y1)));
163 _e_gesture_util_distances_get(int num_finger)
165 int i, cx = 0, cy = 0;
166 double distance = 0.0;
168 _e_gesture_util_center_axis_get(num_finger, &cx, &cy);
170 for (i = 1; i <= num_finger; i++)
172 distance += _e_gesture_util_distance_get(cx, cy,
173 gesture->gesture_events.base_point[i].axis.x,
174 gesture->gesture_events.base_point[i].axis.y);
181 _e_gesture_util_angle_get(int x1, int y1, int x2, int y2)
183 double angle, xx, yy;
188 angle = atan2(yy, xx);
189 if ((x1 > x2) && (y1 > y2)) angle = angle + M_PI_2;
190 else if ((x2 > x1) && (y2 > y1)) angle = angle + M_PI_2;
192 angle = RAD2DEG(angle);
197 _e_gesture_util_rect_get(int finger, int *x1, int *y1, int *x2, int *y2)
201 *x1 = *x2 = gesture->gesture_events.base_point[1].axis.x;
202 *y1 = *y2 = gesture->gesture_events.base_point[1].axis.y;
204 for (i = 2; i < finger + 1; i++)
206 if (gesture->gesture_events.base_point[i].axis.x < *x1)
207 *x1 = gesture->gesture_events.base_point[i].axis.x;
208 else if (gesture->gesture_events.base_point[i].axis.x > *x2)
209 *x2 = gesture->gesture_events.base_point[i].axis.x;
211 if (gesture->gesture_events.base_point[i].axis.y < *y1)
212 *y1 = gesture->gesture_events.base_point[i].axis.y;
213 else if (gesture->gesture_events.base_point[i].axis.y > *y2)
214 *y2 = gesture->gesture_events.base_point[i].axis.y;
218 static struct wl_resource *
219 _e_gesture_util_eclient_surface_get(E_Client *ec)
221 if (!ec) return NULL;
222 if (e_object_is_del(E_OBJECT(ec))) return NULL;
223 if (!ec->comp_data) return NULL;
225 return ec->comp_data->surface;
229 _e_gesture_edge_swipe_cancel(void)
231 E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes;
233 if (edge_swipes->start_timer)
235 ecore_timer_del(edge_swipes->start_timer);
236 edge_swipes->start_timer = NULL;
238 if (edge_swipes->done_timer)
240 ecore_timer_del(edge_swipes->done_timer);
241 edge_swipes->done_timer = NULL;
244 edge_swipes->base.enabled_finger = 0x0;
245 edge_swipes->base.edge = E_GESTURE_EDGE_NONE;
247 gesture->gesture_filter |= E_GESTURE_TYPE_EDGE_SWIPE;
251 _e_gesture_keyevent_free(void *data EINA_UNUSED, void *ev)
253 Ecore_Event_Key *e = ev;
255 eina_stringshare_del(e->keyname);
256 eina_stringshare_del(e->key);
257 eina_stringshare_del(e->compose);
262 /* Optional: This function is currently used to generate back key.
263 * But how about change this function to generate every key?
264 * _e_gesture_send_key(char *keyname, Eina_Bool pressed)
267 _e_gesture_send_back_key(Eina_Bool pressed)
270 E_Gesture_Conf_Edd *conf = gesture->config->conf;
272 EINA_SAFETY_ON_NULL_RETURN(e_comp_wl->xkb.keymap);
274 ev = E_NEW(Ecore_Event_Key, 1);
275 EINA_SAFETY_ON_NULL_RETURN(ev);
277 ev->key = (char *)eina_stringshare_add("XF86Back");
278 ev->keyname = (char *)eina_stringshare_add(ev->key);
279 ev->compose = (char *)eina_stringshare_add(ev->key);
280 ev->timestamp = (int)(ecore_time_get()*1000);
282 ev->keycode = conf->edge_swipe.back_key;
283 ev->dev = gesture->device.kbd_device;
284 ev->window = e_comp->ee_win;
287 ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, _e_gesture_keyevent_free, NULL);
289 ecore_event_add(ECORE_EVENT_KEY_UP, ev, _e_gesture_keyevent_free, NULL);
293 _e_gesture_send_edge_swipe(int fingers, int x, int y, int edge)
295 Ecore_Event_Mouse_Button *ev_cancel;
296 E_Gesture_Conf_Edd *conf = gesture->config->conf;
298 E_Gesture_Event_Edge_Finger_Edge *edata;
299 E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes;
301 E_Event_Gesture_Edge_Swipe *ev_swipe;
303 if (gesture->gesture_events.event_keep)
305 _e_gesture_event_drop();
309 ev_cancel = E_NEW(Ecore_Event_Mouse_Button, 1);
310 EINA_SAFETY_ON_NULL_RETURN(ev_cancel);
312 ev_cancel->timestamp = (int)(ecore_time_get()*1000);
313 ev_cancel->same_screen = 1;
315 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev_cancel, NULL, NULL);
318 if (conf->edge_swipe.default_enable_back &&
319 edge == E_GESTURE_EDGE_TOP)
321 _e_gesture_send_back_key(EINA_TRUE);
322 _e_gesture_send_back_key(EINA_FALSE);
326 if (edge == E_GESTURE_EDGE_TOP ||
327 edge == E_GESTURE_EDGE_BOTTOM)
331 else if (edge == E_GESTURE_EDGE_RIGHT ||
332 edge == E_GESTURE_EDGE_LEFT)
337 EINA_LIST_FOREACH(edge_swipes->base.fingers[fingers].edge[edge], l, edata)
339 if (bp >= edata->sp && bp <= edata->ep)
341 GTINF("Send edge_swipe gesture (fingers: %d, edge: %d) to client: %p\n", fingers, edge, edata->client);
342 if (edata->client == E_GESTURE_SERVER_CLIENT)
344 ev_swipe = E_NEW(E_Event_Gesture_Edge_Swipe, 1);
345 EINA_SAFETY_ON_NULL_RETURN(ev_swipe);
347 ev_swipe->mode = E_GESTURE_MODE_DONE;
348 ev_swipe->edge = edge;
349 ev_swipe->fingers = fingers;
352 ecore_event_add(E_EVENT_GESTURE_EDGE_SWIPE, ev_swipe, NULL, NULL);
355 tizen_gesture_send_edge_swipe(edata->res, E_GESTURE_MODE_DONE, fingers, x, y, edge);
361 _e_gesture_edge_swipe_cancel();
362 gesture->gesture_events.recognized_gesture |= E_GESTURE_TYPE_EDGE_SWIPE;
365 static E_Gesture_Event_State
366 _e_gesture_process_device_add(void *event)
368 return e_gesture_device_add(event);
371 static E_Gesture_Event_State
372 _e_gesture_process_device_del(void *event)
374 return e_gesture_device_del(event);
378 _e_gesture_event_edge_check(E_Gesture_Event_Edge_Finger *fingers, int type, unsigned int edge)
380 E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes;
381 E_Gesture_Conf_Edd *conf = gesture->config->conf;
383 E_Gesture_Event_Edge_Finger_Edge *edata;
386 if (type == E_GESTURE_TYPE_EDGE_SWIPE)
388 if ((conf->edge_swipe.default_enable_back) &&
389 (edge == E_GESTURE_EDGE_TOP ||
390 ((edge_swipes->combined_keycode == conf->edge_swipe.compose_key) &&
391 (edge_swipes->base.edge == E_GESTURE_EDGE_LEFT))))
397 coords.x = fingers->start.x;
398 coords.y = fingers->start.y;
400 EINA_LIST_FOREACH(fingers->edge[edge], l, edata)
402 if (edge == E_GESTURE_EDGE_TOP ||
403 edge == E_GESTURE_EDGE_BOTTOM)
405 if ((coords.x >= edata->sp) &&
406 (coords.x <= edata->ep))
411 else if ((edge == E_GESTURE_EDGE_LEFT) ||
412 (edge == E_GESTURE_EDGE_RIGHT))
414 if (coords.y >= edata->sp &&
415 coords.y <= edata->ep)
426 _e_gesture_timer_edge_swipe_start(void *data)
428 E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes;
429 int idx = gesture->gesture_events.num_pressed;
432 GTDBG("Edge_Swipe start timer is expired. Currently alived edge_swipe fingers: 0x%x\n", edge_swipes->base.enabled_finger);
434 for (i = E_GESTURE_FINGER_MAX; i > idx; i--)
436 edge_swipes->base.enabled_finger &= ~(1 << i);
438 if ((edge_swipes->base.enabled_finger == 0x0) ||
439 (_e_gesture_event_edge_check(&edge_swipes->base.fingers[idx], E_GESTURE_TYPE_EDGE_SWIPE, edge_swipes->base.edge) == EINA_FALSE))
441 _e_gesture_edge_swipe_cancel();
442 if (gesture->gesture_events.event_keep)
443 _e_gesture_event_flush();
445 return ECORE_CALLBACK_CANCEL;
449 _e_gesture_timer_edge_swipe_done(void *data)
451 E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes;
453 GTDBG("Edge_Swipe done timer is expired. Currently alived edge_swipe fingers: 0x%x\n", edge_swipes->base.enabled_finger);
455 _e_gesture_edge_swipe_cancel();
456 if (gesture->gesture_events.event_keep)
457 _e_gesture_event_flush();
459 return ECORE_CALLBACK_CANCEL;
463 _e_gesture_process_edge_swipe_down(Ecore_Event_Mouse_Button *ev)
465 E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes;
466 E_Gesture_Conf_Edd *conf = gesture->config->conf;
468 unsigned int idx = ev->multi.device+1;
470 if (!edge_swipes->base.activation.active) return;
472 if (gesture->gesture_events.recognized_gesture)
473 _e_gesture_edge_swipe_cancel();
475 if (gesture->gesture_events.num_pressed == 1)
477 for (i = 1; i < E_GESTURE_FINGER_MAX+1; i++)
479 if (edge_swipes->base.fingers[i].enabled)
481 edge_swipes->base.enabled_finger |= (1 << i);
485 if (ev->y < conf->edge_swipe.area_offset)
486 edge_swipes->base.edge = E_GESTURE_EDGE_TOP;
487 else if (ev->y > e_comp->h - conf->edge_swipe.area_offset)
488 edge_swipes->base.edge = E_GESTURE_EDGE_BOTTOM;
489 else if (ev->x < conf->edge_swipe.area_offset)
490 edge_swipes->base.edge = E_GESTURE_EDGE_LEFT;
491 else if (ev->x > e_comp->w - conf->edge_swipe.area_offset)
492 edge_swipes->base.edge = E_GESTURE_EDGE_RIGHT;
494 if (!((1 << (edge_swipes->base.edge)) & edge_swipes->base.enabled_edge))
495 edge_swipes->base.edge = E_GESTURE_EDGE_NONE;
497 if (edge_swipes->base.edge != E_GESTURE_EDGE_NONE)
499 edge_swipes->base.fingers[idx].start.x = ev->x;
500 edge_swipes->base.fingers[idx].start.y = ev->y;
501 edge_swipes->start_timer = ecore_timer_add(conf->edge_swipe.time_begin, _e_gesture_timer_edge_swipe_start, NULL);
502 edge_swipes->done_timer = ecore_timer_add(conf->edge_swipe.time_done, _e_gesture_timer_edge_swipe_done, NULL);
506 _e_gesture_edge_swipe_cancel();
507 if (gesture->gesture_events.event_keep)
508 _e_gesture_event_flush();
513 edge_swipes->base.enabled_finger &= ~(1 << (gesture->gesture_events.num_pressed - 1));
514 if (edge_swipes->start_timer == NULL)
516 _e_gesture_edge_swipe_cancel();
517 if (gesture->gesture_events.event_keep)
518 _e_gesture_event_flush();
524 _e_gesture_process_edge_swipe_move(Ecore_Event_Mouse_Move *ev)
526 E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes;
527 E_Gesture_Conf_Edd *conf = gesture->config->conf;
529 unsigned int idx = ev->multi.device+1;
531 if (!edge_swipes->base.activation.active) return;
533 if (!(edge_swipes->base.enabled_finger & (1 << idx)))
536 diff.x = ABS(edge_swipes->base.fingers[idx].start.x - ev->x);
537 diff.y = ABS(edge_swipes->base.fingers[idx].start.y - ev->y);
539 switch(edge_swipes->base.edge)
541 case E_GESTURE_EDGE_TOP:
542 if (diff.x > conf->edge_swipe.min_length)
544 _e_gesture_edge_swipe_cancel();
545 if (gesture->gesture_events.event_keep)
546 _e_gesture_event_flush();
549 if (diff.y > conf->edge_swipe.max_length)
551 _e_gesture_send_edge_swipe(idx, edge_swipes->base.fingers[idx].start.x, edge_swipes->base.fingers[idx].start.y, E_GESTURE_EDGE_TOP);
554 case E_GESTURE_EDGE_LEFT:
555 if (diff.y > conf->edge_swipe.min_length)
557 _e_gesture_edge_swipe_cancel();
558 if (gesture->gesture_events.event_keep)
559 _e_gesture_event_flush();
562 if (diff.x > conf->edge_swipe.max_length)
564 _e_gesture_send_edge_swipe(idx, edge_swipes->base.fingers[idx].start.x, edge_swipes->base.fingers[idx].start.y, E_GESTURE_EDGE_LEFT);
567 case E_GESTURE_EDGE_BOTTOM:
568 if (diff.x > conf->edge_swipe.min_length)
570 _e_gesture_edge_swipe_cancel();
571 if (gesture->gesture_events.event_keep)
572 _e_gesture_event_flush();
575 if (diff.y > conf->edge_swipe.max_length)
577 _e_gesture_send_edge_swipe(idx, edge_swipes->base.fingers[idx].start.x, edge_swipes->base.fingers[idx].start.y, E_GESTURE_EDGE_BOTTOM);
580 case E_GESTURE_EDGE_RIGHT:
581 if (diff.y > conf->edge_swipe.min_length)
583 _e_gesture_edge_swipe_cancel();
584 if (gesture->gesture_events.event_keep)
585 _e_gesture_event_flush();
588 if (diff.x > conf->edge_swipe.max_length)
590 _e_gesture_send_edge_swipe(idx, edge_swipes->base.fingers[idx].start.x, edge_swipes->base.fingers[idx].start.y, E_GESTURE_EDGE_RIGHT);
594 GTWRN("Invalid edge(%d)\n", edge_swipes->base.edge);
600 _e_gesture_process_edge_swipe_up(Ecore_Event_Mouse_Button *ev)
602 E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes;
604 if (!edge_swipes->base.activation.active) return;
605 _e_gesture_edge_swipe_cancel();
606 if (gesture->gesture_events.event_keep)
607 _e_gesture_event_flush();
611 _e_gesture_edge_drag_cancel(void)
613 E_Gesture_Event_Edge_Drag *edge_drags = &gesture->gesture_events.edge_drags;
614 Coords current_point = {0, };
616 if (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_EDGE_DRAG)
618 _e_gesture_util_center_axis_get(edge_drags->idx, ¤t_point.x, ¤t_point.y);
619 _e_gesture_send_edge_drag(edge_drags->idx, current_point.x, current_point.y, edge_drags->base.edge, E_GESTURE_MODE_END);
622 if (edge_drags->start_timer)
624 ecore_timer_del(edge_drags->start_timer);
625 edge_drags->start_timer = NULL;
628 edge_drags->base.enabled_finger = 0x0;
629 edge_drags->base.edge = E_GESTURE_EDGE_NONE;
630 edge_drags->start_point.x = edge_drags->center_point.x = 0;
631 edge_drags->start_point.y = edge_drags->center_point.y = 0;
634 gesture->gesture_filter |= E_GESTURE_TYPE_EDGE_DRAG;
635 gesture->gesture_events.recognized_gesture &= ~E_GESTURE_TYPE_EDGE_DRAG;
639 _e_gesture_send_edge_drag(int fingers, int x, int y, int edge, int mode)
641 Ecore_Event_Mouse_Button *ev_cancel;
643 E_Gesture_Event_Edge_Finger_Edge *edata;
644 E_Gesture_Event_Edge_Drag *edge_drags = &gesture->gesture_events.edge_drags;
646 E_Event_Gesture_Edge_Drag *ev_drag;
648 if (gesture->gesture_events.event_keep)
650 _e_gesture_event_drop();
654 ev_cancel = E_NEW(Ecore_Event_Mouse_Button, 1);
655 EINA_SAFETY_ON_NULL_RETURN(ev_cancel);
657 ev_cancel->timestamp = (int)(ecore_time_get()*1000);
658 ev_cancel->same_screen = 1;
660 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev_cancel, NULL, NULL);
663 if (edge == E_GESTURE_EDGE_TOP ||
664 edge == E_GESTURE_EDGE_BOTTOM)
666 bp = edge_drags->start_point.x;
668 else if (edge == E_GESTURE_EDGE_RIGHT ||
669 edge == E_GESTURE_EDGE_LEFT)
671 bp = edge_drags->start_point.y;
674 EINA_LIST_FOREACH(edge_drags->base.fingers[fingers].edge[edge], l, edata)
676 if (bp >= edata->sp && bp <= edata->ep)
678 GTINF("Send edge drag gesture (fingers: %d, edge: %d) to client: %p\n", fingers, edge, edata->client);
679 if (edata->client == E_GESTURE_SERVER_CLIENT)
681 ev_drag = E_NEW(E_Event_Gesture_Edge_Drag, 1);
682 EINA_SAFETY_ON_NULL_RETURN(ev_drag);
684 ev_drag->mode = E_GESTURE_MODE_DONE;
685 ev_drag->edge = edge;
686 ev_drag->fingers = fingers;
689 ecore_event_add(E_EVENT_GESTURE_EDGE_DRAG, ev_drag, NULL, NULL);
692 tizen_gesture_send_edge_drag(edata->res, mode, fingers, x, y, edge);
697 gesture->gesture_events.recognized_gesture |= E_GESTURE_TYPE_EDGE_DRAG;
701 _e_gesture_timer_edge_drag_start(void *data)
703 E_Gesture_Event_Edge_Drag *edge_drags = &gesture->gesture_events.edge_drags;
704 int idx = gesture->gesture_events.num_pressed;
706 Coords start_point = {0, };
708 for (i = E_GESTURE_FINGER_MAX; i > idx; i--)
710 edge_drags->base.enabled_finger &= ~(1 << i);
713 if ((edge_drags->base.enabled_finger == 0x0) ||
714 (_e_gesture_event_edge_check(&edge_drags->base.fingers[idx], E_GESTURE_TYPE_EDGE_DRAG, edge_drags->base.edge) == EINA_FALSE))
716 _e_gesture_edge_drag_cancel();
717 if (gesture->gesture_events.event_keep)
718 _e_gesture_event_flush();
722 _e_gesture_util_center_axis_get(idx, &start_point.x, &start_point.y);
723 edge_drags->start_point.x = edge_drags->center_point.x = start_point.x;
724 edge_drags->start_point.y = edge_drags->center_point.y = start_point.y;
725 edge_drags->idx = idx;
726 _e_gesture_send_edge_drag(edge_drags->idx, edge_drags->center_point.x, edge_drags->center_point.y, edge_drags->base.edge, E_GESTURE_MODE_BEGIN);
729 ecore_timer_del(edge_drags->start_timer);
730 edge_drags->start_timer = NULL;
731 return ECORE_CALLBACK_CANCEL;
735 _e_gesture_process_edge_drag_down(Ecore_Event_Mouse_Button *ev)
737 E_Gesture_Event_Edge_Drag *edge_drags = &gesture->gesture_events.edge_drags;
738 E_Gesture_Conf_Edd *conf = gesture->config->conf;
740 unsigned int idx = ev->multi.device+1;
742 if (!edge_drags->base.activation.active) return;
744 if (gesture->gesture_events.recognized_gesture)
745 _e_gesture_edge_drag_cancel();
747 if (gesture->gesture_events.num_pressed == 1)
749 for (i = 1; i < E_GESTURE_FINGER_MAX+1; i++)
751 if (edge_drags->base.fingers[i].enabled)
753 edge_drags->base.enabled_finger |= (1 << i);
757 if (ev->y < conf->edge_drag.area_offset)
758 edge_drags->base.edge = E_GESTURE_EDGE_TOP;
759 else if (ev->y > e_comp->h - conf->edge_drag.area_offset)
760 edge_drags->base.edge = E_GESTURE_EDGE_BOTTOM;
761 else if (ev->x < conf->edge_drag.area_offset)
762 edge_drags->base.edge = E_GESTURE_EDGE_LEFT;
763 else if (ev->x > e_comp->w - conf->edge_drag.area_offset)
764 edge_drags->base.edge = E_GESTURE_EDGE_RIGHT;
766 if (!((1 << (edge_drags->base.edge)) & edge_drags->base.enabled_edge))
767 edge_drags->base.edge = E_GESTURE_EDGE_NONE;
769 if (edge_drags->base.edge != E_GESTURE_EDGE_NONE)
771 edge_drags->base.fingers[idx].start.x = ev->x;
772 edge_drags->base.fingers[idx].start.y = ev->y;
773 edge_drags->start_timer = ecore_timer_add(conf->edge_drag.time_begin, _e_gesture_timer_edge_drag_start, NULL);
777 _e_gesture_edge_drag_cancel();
778 if (gesture->gesture_events.event_keep)
779 _e_gesture_event_flush();
784 edge_drags->base.enabled_finger &= ~(1 << (gesture->gesture_events.num_pressed - 1));
785 if (edge_drags->start_timer == NULL)
787 _e_gesture_edge_drag_cancel();
788 if (gesture->gesture_events.event_keep)
789 _e_gesture_event_flush();
795 _e_gesture_process_edge_drag_move(Ecore_Event_Mouse_Move *ev)
797 E_Gesture_Event_Edge_Drag *edge_drags = &gesture->gesture_events.edge_drags;
798 E_Gesture_Conf_Edd *conf = gesture->config->conf;
800 Coords current_point = {0, };
801 unsigned int idx = ev->multi.device+1;
803 if (!edge_drags->base.activation.active) return;
805 if (!(edge_drags->base.enabled_finger & (1 << idx)))
808 if (edge_drags->start_timer) return;
810 _e_gesture_util_center_axis_get(gesture->gesture_events.num_pressed, ¤t_point.x, ¤t_point.y);
811 distance = _e_gesture_util_distance_get(edge_drags->center_point.x, edge_drags->center_point.y, current_point.x, current_point.y);
812 if (distance < (double)conf->edge_drag.diff_length)
817 edge_drags->center_point.x = current_point.x;
818 edge_drags->center_point.y = current_point.y;
820 _e_gesture_send_edge_drag(edge_drags->idx,
821 edge_drags->center_point.x, edge_drags->center_point.y,
822 edge_drags->base.edge, E_GESTURE_MODE_UPDATE);
826 _e_gesture_process_edge_drag_up(Ecore_Event_Mouse_Button *ev)
828 E_Gesture_Event_Edge_Drag *edge_drags = &gesture->gesture_events.edge_drags;
830 if (!edge_drags->base.activation.active) return;
831 _e_gesture_edge_drag_cancel();
832 if (gesture->gesture_events.event_keep)
833 _e_gesture_event_flush();
838 _e_gesture_pan_send(int mode, int fingers, int cx, int cy, struct wl_resource *res, struct wl_client *client)
840 Ecore_Event_Mouse_Button *ev_cancel;
841 E_Event_Gesture_Pan *ev_pan;
843 if (mode == E_GESTURE_MODE_BEGIN)
845 ev_cancel = E_NEW(Ecore_Event_Mouse_Button, 1);
846 EINA_SAFETY_ON_NULL_RETURN(ev_cancel);
848 ev_cancel->timestamp = (int)(ecore_time_get()*1000);
849 ev_cancel->same_screen = 1;
851 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev_cancel, NULL, NULL);
854 GTINF("Send pan gesture %d fingers. (%d, %d) to client: %p, mode: %d\n", fingers, cx, cy, client, mode);
855 if (client == E_GESTURE_SERVER_CLIENT)
857 ev_pan = E_NEW(E_Event_Gesture_Pan, 1);
858 EINA_SAFETY_ON_NULL_RETURN(ev_pan);
861 ev_pan->fingers = fingers;
865 ecore_event_add(E_EVENT_GESTURE_PAN, ev_pan, NULL, NULL);
868 gesture->gesture_events.recognized_gesture |= E_GESTURE_TYPE_PAN;
872 _e_gesture_pan_cancel(void)
874 E_Gesture_Event_Pan *pans = &gesture->gesture_events.pans;
876 if (pans->start_timer)
878 ecore_timer_del(pans->start_timer);
879 pans->start_timer = NULL;
881 if (pans->move_timer)
883 ecore_timer_del(pans->move_timer);
884 pans->move_timer = NULL;
887 if (pans->state == E_GESTURE_PANPINCH_STATE_MOVING)
888 _e_gesture_pan_send(E_GESTURE_MODE_END, pans->num_pan_fingers, 0, 0,
889 pans->fingers[pans->num_pan_fingers].res,
890 pans->fingers[pans->num_pan_fingers].client);
892 gesture->gesture_filter |= E_GESTURE_TYPE_PAN;
893 pans->state = E_GESTURE_PANPINCH_STATE_DONE;
897 _e_gesture_timer_pan_start(void *data)
899 E_Gesture_Event_Pan *pans = &gesture->gesture_events.pans;
900 int num_pressed = gesture->gesture_events.num_pressed;
903 if (pans->fingers[num_pressed].client)
905 for (i = 1; i <= num_pressed; i++)
907 pans->start_point.x += gesture->gesture_events.base_point[i].axis.x;
908 pans->start_point.y += gesture->gesture_events.base_point[i].axis.y;
910 pans->center_point.x = pans->start_point.x = (int)(pans->start_point.x / num_pressed);
911 pans->center_point.y = pans->start_point.y = (int)(pans->start_point.y / num_pressed);
912 pans->state = E_GESTURE_PANPINCH_STATE_START;
916 _e_gesture_pan_cancel();
918 return ECORE_CALLBACK_CANCEL;
922 _e_gesture_process_pan_down(Ecore_Event_Mouse_Button *ev)
924 E_Gesture_Event_Pan *pans = &gesture->gesture_events.pans;
926 if (!pans->activation.active) return;
928 if (gesture->gesture_events.recognized_gesture &&
929 !((gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PAN) ||
930 (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PINCH)))
931 _e_gesture_pan_cancel();
933 if (gesture->gesture_events.num_pressed == 1)
935 pans->state = E_GESTURE_PANPINCH_STATE_READY;
936 if (pans->start_timer) ecore_timer_del(pans->start_timer);
937 pans->start_timer = ecore_timer_add(E_GESTURE_PAN_START_TIME, _e_gesture_timer_pan_start, NULL);
942 _e_gesture_process_pan_move(Ecore_Event_Mouse_Move *ev)
944 E_Gesture_Event_Pan *pans = &gesture->gesture_events.pans;
945 Coords cur_point = {0,};
946 int idx, diff_x, diff_y, mode;
948 if (!pans->activation.active) return;
950 if (gesture->gesture_events.recognized_gesture &&
951 !((gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PAN) ||
952 (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PINCH)))
953 _e_gesture_pan_cancel();
955 idx = gesture->gesture_events.num_pressed;
956 if (idx <= 0) return;
957 if (pans->state == E_GESTURE_PANPINCH_STATE_READY) return;
959 _e_gesture_util_center_axis_get(gesture->gesture_events.num_pressed, &cur_point.x, &cur_point.y);
961 diff_x = cur_point.x - pans->center_point.x;
962 diff_y = cur_point.y - pans->center_point.y;
964 if ((ABS(diff_x) > E_GESTURE_PAN_MOVING_RANGE) || (ABS(diff_y) > E_GESTURE_PAN_MOVING_RANGE))
968 case E_GESTURE_PANPINCH_STATE_START:
969 mode = E_GESTURE_MODE_BEGIN;
970 pans->state = E_GESTURE_PANPINCH_STATE_MOVING;
971 pans->num_pan_fingers = idx;
973 case E_GESTURE_PANPINCH_STATE_MOVING:
974 mode = E_GESTURE_MODE_UPDATE;
980 if (ABS(diff_x) > E_GESTURE_PAN_MOVING_RANGE) pans->center_point.x = cur_point.x;
981 if (ABS(diff_y) > E_GESTURE_PAN_MOVING_RANGE) pans->center_point.y = cur_point.y;
983 _e_gesture_pan_send(mode, idx, cur_point.x, cur_point.y, pans->fingers[idx].res, pans->fingers[idx].client);
985 if (mode == E_GESTURE_MODE_BEGIN)
986 mode = E_GESTURE_MODE_UPDATE;
991 _e_gesture_process_pan_up(Ecore_Event_Mouse_Button *ev)
993 E_Gesture_Event_Pan *pans = &gesture->gesture_events.pans;
995 if (!pans->activation.active) return;
996 _e_gesture_pan_cancel();
1000 _e_gesture_pinch_send(int mode, int fingers, double distance, double angle, int cx, int cy, struct wl_resource *res, struct wl_client *client)
1002 Ecore_Event_Mouse_Button *ev_cancel;
1003 E_Event_Gesture_Pinch *ev_pinch;
1005 if (mode == E_GESTURE_MODE_BEGIN)
1007 ev_cancel = E_NEW(Ecore_Event_Mouse_Button, 1);
1008 EINA_SAFETY_ON_NULL_RETURN(ev_cancel);
1010 ev_cancel->timestamp = (int)(ecore_time_get()*1000);
1011 ev_cancel->same_screen = 1;
1013 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev_cancel, NULL, NULL);
1016 GTINF("Send pinch gesture (fingers: %d, distance: %lf, angle: %lf, cx: %d, cy: %d) to client: %p, mode: %d\n", fingers, distance, angle, cx, cy, client, mode);
1017 if (client == E_GESTURE_SERVER_CLIENT)
1019 ev_pinch = E_NEW(E_Event_Gesture_Pinch, 1);
1020 EINA_SAFETY_ON_NULL_RETURN(ev_pinch);
1022 ev_pinch->mode = mode;
1023 ev_pinch->fingers = fingers;
1024 ev_pinch->distance = distance;
1025 ev_pinch->angle = angle;
1029 ecore_event_add(E_EVENT_GESTURE_PINCH, ev_pinch, NULL, NULL);
1032 gesture->gesture_events.recognized_gesture |= E_GESTURE_TYPE_PINCH;
1036 _e_gesture_pinch_cancel(void)
1038 E_Gesture_Event_Pinch *pinchs = &gesture->gesture_events.pinchs;
1040 if (pinchs->start_timer)
1042 ecore_timer_del(pinchs->start_timer);
1043 pinchs->start_timer = NULL;
1045 if (pinchs->move_timer)
1047 ecore_timer_del(pinchs->move_timer);
1048 pinchs->move_timer = NULL;
1051 if (pinchs->state == E_GESTURE_PANPINCH_STATE_MOVING)
1052 _e_gesture_pinch_send(E_GESTURE_MODE_END, pinchs->num_pinch_fingers, 0.0, 0.0, 0, 0,
1053 pinchs->fingers[pinchs->num_pinch_fingers].res,
1054 pinchs->fingers[pinchs->num_pinch_fingers].client);
1056 gesture->gesture_filter |= E_GESTURE_TYPE_PINCH;
1057 pinchs->state = E_GESTURE_PANPINCH_STATE_DONE;
1061 _e_gesture_timer_pinch_start(void *data)
1063 E_Gesture_Event_Pinch *pinch = &gesture->gesture_events.pinchs;
1064 int num_pressed = gesture->gesture_events.num_pressed;
1066 if (pinch->fingers[num_pressed].client)
1068 pinch->distance = _e_gesture_util_distances_get(num_pressed);
1069 pinch->state = E_GESTURE_PANPINCH_STATE_START;
1073 _e_gesture_pinch_cancel();
1075 return ECORE_CALLBACK_CANCEL;
1079 _e_gesture_process_pinch_down(Ecore_Event_Mouse_Button *ev)
1081 E_Gesture_Event_Pinch *pinch = &gesture->gesture_events.pinchs;
1083 if (!pinch->activation.active) return;
1085 if (gesture->gesture_events.recognized_gesture &&
1086 !((gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PAN) ||
1087 (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PINCH)))
1088 _e_gesture_pinch_cancel();
1090 if (gesture->gesture_events.num_pressed == 1)
1092 pinch->state = E_GESTURE_PANPINCH_STATE_READY;
1093 if (pinch->start_timer) ecore_timer_del(pinch->start_timer);
1094 pinch->start_timer = ecore_timer_add(E_GESTURE_PAN_START_TIME, _e_gesture_timer_pinch_start, NULL);
1099 _e_gesture_process_pinch_move(Ecore_Event_Mouse_Move *ev)
1101 E_Gesture_Event_Pinch *pinch = &gesture->gesture_events.pinchs;
1102 int idx, mode, cx = 0, cy = 0;
1103 double current_distance = 0.0, diff = 0.0, angle = 0.0;
1105 if (!pinch->activation.active) return;
1107 if (gesture->gesture_events.recognized_gesture &&
1108 !((gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PAN) ||
1109 (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PINCH)))
1110 _e_gesture_pan_cancel();
1112 idx = gesture->gesture_events.num_pressed;
1113 if (idx <= 0) return;
1114 if (pinch->state == E_GESTURE_PANPINCH_STATE_READY) return;
1116 current_distance = _e_gesture_util_distances_get(idx);
1117 diff = current_distance - pinch->distance;
1119 if (ABS(diff) > E_GESTURE_PINCH_MOVING_DISTANCE_RANGE)
1121 pinch->distance = current_distance;
1122 switch (pinch->state)
1124 case E_GESTURE_PANPINCH_STATE_START:
1125 mode = E_GESTURE_MODE_BEGIN;
1126 pinch->state = E_GESTURE_PANPINCH_STATE_MOVING;
1127 pinch->num_pinch_fingers = idx;
1129 case E_GESTURE_PANPINCH_STATE_MOVING:
1130 mode = E_GESTURE_MODE_UPDATE;
1136 if (idx == 2) angle = _e_gesture_util_angle_get(gesture->gesture_events.base_point[1].axis.x,
1137 gesture->gesture_events.base_point[1].axis.y,
1138 gesture->gesture_events.base_point[2].axis.x,
1139 gesture->gesture_events.base_point[2].axis.y);
1142 _e_gesture_util_center_axis_get(idx, &cx, &cy);
1144 _e_gesture_pinch_send(mode, idx, pinch->distance, angle, cx, cy, pinch->fingers[idx].res, pinch->fingers[idx].client);
1149 _e_gesture_process_pinch_up(Ecore_Event_Mouse_Button *ev)
1151 E_Gesture_Event_Pinch *pinch = &gesture->gesture_events.pinchs;
1153 if (!pinch->activation.active) return;
1154 _e_gesture_pinch_cancel();
1159 e_gesture_util_tap_max_fingers_get(void)
1161 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1163 unsigned int max = 0;
1165 for (i = 0; i < E_GESTURE_FINGER_MAX +1; i++)
1167 if (taps->fingers[i].enabled) max = i;
1174 e_gesture_util_tap_max_repeats_get(unsigned int fingers)
1176 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1177 E_Gesture_Conf_Edd *conf = gesture->config->conf;
1179 unsigned int max = 0;
1181 for (i = 0; i < conf->tap.repeats_max + 1; i++)
1183 if (taps->fingers[fingers].repeats[i].client) max = i;
1190 _e_gesture_tap_cancel(void)
1192 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1194 if (taps->start_timer)
1196 ecore_timer_del(taps->start_timer);
1197 taps->start_timer = NULL;
1199 if (taps->done_timer)
1201 ecore_timer_del(taps->done_timer);
1202 taps->done_timer = NULL;
1204 if (taps->interval_timer)
1206 ecore_timer_del(taps->interval_timer);
1207 taps->interval_timer = NULL;
1211 taps->enabled_finger = 0;
1212 taps->current_finger = 0;
1213 taps->state = E_GESTURE_TAP_STATE_READY;
1214 taps->base_rect.x1 = 0;
1215 taps->base_rect.y1 = 0;
1216 taps->base_rect.x2 = 0;
1217 taps->base_rect.y2 = 0;
1218 gesture->gesture_filter |= E_GESTURE_TYPE_TAP;
1219 _e_gesture_event_flush();
1220 gesture->gesture_events.recognized_gesture &= ~E_GESTURE_TYPE_TAP;
1224 _e_gesture_send_tap(int fingers, int repeats, struct wl_client *client, struct wl_resource *res)
1226 E_Event_Gesture_Tap *ev_tap;
1228 GTINF("Send Tap gesture. %d fingers %d repeats to client (%p)\n", fingers, repeats, client);
1229 if (client == E_GESTURE_SERVER_CLIENT)
1231 ev_tap = E_NEW(E_Event_Gesture_Tap, 1);
1232 EINA_SAFETY_ON_NULL_RETURN(ev_tap);
1234 ev_tap->mode = E_GESTURE_MODE_DONE;
1235 ev_tap->fingers = fingers;
1236 ev_tap->repeats = repeats;
1238 ecore_event_add(E_EVENT_GESTURE_TAP, ev_tap, NULL, NULL);
1241 tizen_gesture_send_tap(res, E_GESTURE_MODE_DONE, fingers, repeats);
1242 _e_gesture_event_drop();
1243 gesture->gesture_events.recognized_gesture |= E_GESTURE_TYPE_TAP;
1245 _e_gesture_tap_cancel();
1249 _e_gesture_timer_tap_start(void *data)
1251 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1253 if (taps->fingers[taps->enabled_finger].enabled)
1255 taps->state = E_GESTURE_TAP_STATE_PROCESS;
1259 _e_gesture_tap_cancel();
1262 taps->start_timer = NULL;
1263 return ECORE_CALLBACK_CANCEL;
1267 _e_gesture_timer_tap_done(void *data)
1269 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1271 if (gesture->gesture_events.num_pressed)
1273 _e_gesture_tap_cancel();
1276 taps->done_timer = NULL;
1277 return ECORE_CALLBACK_CANCEL;
1281 _e_gesture_timer_tap_interval(void *data)
1283 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1285 if (taps->fingers[taps->enabled_finger].repeats[taps->repeats].client)
1287 _e_gesture_send_tap(taps->enabled_finger, taps->repeats,
1288 taps->fingers[taps->enabled_finger].repeats[taps->repeats].client,
1289 taps->fingers[taps->enabled_finger].repeats[taps->repeats].res);
1290 gesture->event_state = E_GESTURE_EVENT_STATE_KEEP;
1291 gesture->gesture_events.recognized_gesture &= ~E_GESTURE_TYPE_TAP;
1292 gesture->gesture_filter = E_GESTURE_TYPE_ALL & ~gesture->grabbed_gesture;
1296 /* All fingers are released. */
1297 gesture->gesture_filter = E_GESTURE_TYPE_ALL;
1298 _e_gesture_tap_cancel();
1300 gesture->event_state = E_GESTURE_EVENT_STATE_KEEP;
1301 gesture->gesture_filter = E_GESTURE_TYPE_ALL & ~gesture->grabbed_gesture;
1304 taps->interval_timer = NULL;
1305 return ECORE_CALLBACK_CANCEL;
1309 _e_gesture_tap_start(void)
1311 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1312 E_Gesture_Conf_Edd *conf = gesture->config->conf;
1314 taps->state = E_GESTURE_TAP_STATE_START;
1315 if (!taps->start_timer)
1317 taps->start_timer = ecore_timer_add(conf->tap.time_start, _e_gesture_timer_tap_start, NULL);
1319 if (!taps->done_timer)
1321 taps->done_timer = ecore_timer_add(conf->tap.time_done, _e_gesture_timer_tap_done, NULL);
1326 _e_gesture_tap_done(void)
1328 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1329 E_Gesture_Conf_Edd *conf = gesture->config->conf;
1331 if (taps->repeats >= conf->tap.repeats_max)
1332 _e_gesture_tap_cancel();
1334 if (!taps->fingers[taps->enabled_finger].enabled)
1335 _e_gesture_tap_cancel();
1337 if (!(gesture->gesture_filter & E_GESTURE_TYPE_TAP) &&
1338 gesture->gesture_events.num_pressed == 0)
1340 taps->state = E_GESTURE_TAP_STATE_WAIT;
1342 if (taps->done_timer)
1344 ecore_timer_del(taps->done_timer);
1345 taps->done_timer = NULL;
1347 taps->current_finger = 0;
1348 if (taps->repeats == taps->fingers[taps->enabled_finger].max_repeats)
1350 ecore_timer_del(taps->interval_timer);
1351 _e_gesture_timer_tap_interval(NULL);
1355 if (!taps->interval_timer)
1357 taps->interval_timer = ecore_timer_add(conf->tap.time_interval, _e_gesture_timer_tap_interval, NULL);
1364 _e_gesture_process_tap_down(Ecore_Event_Mouse_Button *ev)
1366 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1368 if (!taps->activation.active) return;
1370 if (gesture->gesture_events.recognized_gesture)
1371 _e_gesture_tap_cancel();
1373 if (taps->enabled_finger < gesture->gesture_events.num_pressed)
1374 taps->enabled_finger = gesture->gesture_events.num_pressed;
1376 taps->current_finger++;
1378 if (taps->enabled_finger > taps->max_fingers)
1379 _e_gesture_tap_cancel();
1381 if (taps->state == E_GESTURE_TAP_STATE_READY ||
1382 taps->state == E_GESTURE_TAP_STATE_START ||
1383 taps->state == E_GESTURE_TAP_STATE_PROCESS)
1385 _e_gesture_util_rect_get(taps->enabled_finger, &taps->base_rect.x1, &taps->base_rect.y1, &taps->base_rect.x2, &taps->base_rect.y2);
1388 switch (taps->state)
1390 case E_GESTURE_TAP_STATE_NONE:
1393 case E_GESTURE_TAP_STATE_READY:
1394 _e_gesture_tap_start();
1397 case E_GESTURE_TAP_STATE_START:
1400 case E_GESTURE_TAP_STATE_PROCESS:
1401 _e_gesture_tap_cancel();
1404 case E_GESTURE_TAP_STATE_WAIT:
1405 if (taps->interval_timer)
1407 ecore_timer_del(taps->interval_timer);
1408 taps->interval_timer = NULL;
1410 _e_gesture_tap_start();
1413 case E_GESTURE_TAP_STATE_DONE:
1422 _e_gesture_process_tap_move(Ecore_Event_Mouse_Move *ev)
1424 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1425 E_Gesture_Conf_Edd *conf = gesture->config->conf;
1426 Rect current_rect = {0, };
1427 int xx1, yy1, xx2, yy2;
1429 if (!taps->activation.active) return;
1431 if (gesture->gesture_events.recognized_gesture)
1432 _e_gesture_tap_cancel();
1434 _e_gesture_util_rect_get(taps->enabled_finger, ¤t_rect.x1, ¤t_rect.y1, ¤t_rect.x2, ¤t_rect.y2);
1436 xx1 = taps->base_rect.x1 - current_rect.x1;
1437 yy1 = taps->base_rect.y1 - current_rect.y1;
1438 xx2 = taps->base_rect.x2 - current_rect.x2;
1439 yy2 = taps->base_rect.y2 - current_rect.y2;
1441 if (ABS(xx1) > conf->tap.moving_range ||
1442 ABS(yy1) > conf->tap.moving_range ||
1443 ABS(xx2) > conf->tap.moving_range ||
1444 ABS(yy2) > conf->tap.moving_range)
1446 GTDBG("%d finger moving too large diff: (%d, %d)(%d, %d)\n", ev->multi.device, xx1, yy1, xx2, yy2);
1447 _e_gesture_tap_cancel();
1452 _e_gesture_process_tap_up(Ecore_Event_Mouse_Button *ev)
1454 E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps;
1456 if (!taps->activation.active) return;
1458 if (gesture->gesture_events.recognized_gesture)
1459 _e_gesture_tap_cancel();
1461 if (taps->enabled_finger != taps->current_finger)
1462 _e_gesture_tap_cancel();
1464 switch (taps->state)
1466 case E_GESTURE_TAP_STATE_NONE:
1469 case E_GESTURE_TAP_STATE_READY:
1470 _e_gesture_tap_cancel();
1473 case E_GESTURE_TAP_STATE_START:
1474 taps->state = E_GESTURE_TAP_STATE_PROCESS;
1475 if (taps->start_timer)
1477 ecore_timer_del(taps->start_timer);
1478 taps->start_timer = NULL;
1480 _e_gesture_tap_done();
1483 case E_GESTURE_TAP_STATE_PROCESS:
1484 _e_gesture_tap_done();
1487 case E_GESTURE_TAP_STATE_WAIT:
1488 if (taps->interval_timer)
1490 ecore_timer_del(taps->interval_timer);
1491 taps->interval_timer = NULL;
1493 _e_gesture_tap_start();
1496 case E_GESTURE_TAP_STATE_DONE:
1504 static E_Gesture_Event_State
1505 _e_gesture_process_mouse_button_down(void *event)
1507 Ecore_Event_Mouse_Button *ev = event;
1509 if (!gesture->grabbed_gesture)
1511 return E_GESTURE_EVENT_STATE_PROPAGATE;
1513 if (e_gesture_is_touch_device(ev->dev) == EINA_FALSE)
1515 return E_GESTURE_EVENT_STATE_PROPAGATE;
1517 if (ev->multi.device > E_GESTURE_FINGER_MAX)
1519 return E_GESTURE_EVENT_STATE_PROPAGATE;
1522 gesture->gesture_events.base_point[ev->multi.device + 1].pressed = EINA_TRUE;
1523 gesture->gesture_events.base_point[ev->multi.device + 1].axis.x = ev->x;
1524 gesture->gesture_events.base_point[ev->multi.device + 1].axis.y = ev->y;
1526 if (gesture->gesture_events.recognized_gesture)
1528 return E_GESTURE_EVENT_STATE_IGNORE;
1531 if (gesture->gesture_events.num_pressed == 1)
1533 if (gesture->gesture_filter == E_GESTURE_TYPE_ALL)
1535 gesture->event_state = E_GESTURE_EVENT_STATE_PROPAGATE;
1539 if (!(gesture->gesture_filter & E_GESTURE_TYPE_EDGE_SWIPE))
1541 _e_gesture_process_edge_swipe_down(ev);
1543 if (!(gesture->gesture_filter & E_GESTURE_TYPE_EDGE_DRAG))
1545 _e_gesture_process_edge_drag_down(ev);
1547 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PAN))
1549 _e_gesture_process_pan_down(ev);
1551 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PINCH))
1553 _e_gesture_process_pinch_down(ev);
1555 if (!(gesture->gesture_filter & E_GESTURE_TYPE_TAP))
1557 _e_gesture_process_tap_down(ev);
1560 return gesture->event_state;
1563 static E_Gesture_Event_State
1564 _e_gesture_process_mouse_button_up(void *event)
1566 Ecore_Event_Mouse_Button *ev = event;
1568 if (!gesture->grabbed_gesture)
1570 return E_GESTURE_EVENT_STATE_PROPAGATE;
1572 if (e_gesture_is_touch_device(ev->dev) == EINA_FALSE)
1574 return E_GESTURE_EVENT_STATE_PROPAGATE;
1576 if (ev->multi.device > E_GESTURE_FINGER_MAX)
1578 return E_GESTURE_EVENT_STATE_PROPAGATE;
1581 gesture->gesture_events.base_point[ev->multi.device + 1].pressed = EINA_FALSE;
1582 gesture->gesture_events.base_point[ev->multi.device + 1].axis.x = 0;
1583 gesture->gesture_events.base_point[ev->multi.device + 1].axis.y = 0;
1585 if (!(gesture->gesture_filter & E_GESTURE_TYPE_EDGE_SWIPE))
1587 _e_gesture_process_edge_swipe_up(ev);
1589 if (!(gesture->gesture_filter & E_GESTURE_TYPE_EDGE_DRAG))
1591 _e_gesture_process_edge_drag_up(ev);
1593 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PAN))
1595 _e_gesture_process_pan_up(ev);
1597 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PINCH))
1599 _e_gesture_process_pinch_up(ev);
1601 if (!(gesture->gesture_filter & E_GESTURE_TYPE_TAP))
1603 _e_gesture_process_tap_up(ev);
1606 if (gesture->gesture_events.recognized_gesture)
1608 if (gesture->gesture_events.num_pressed == 0)
1610 gesture->gesture_events.recognized_gesture = 0x0;
1612 return E_GESTURE_EVENT_STATE_IGNORE;
1615 return gesture->event_state;
1619 static E_Gesture_Event_State
1620 _e_gesture_process_mouse_move(void *event)
1622 Ecore_Event_Mouse_Move *ev = event;
1624 if (e_gesture_is_touch_device(ev->dev) == EINA_FALSE)
1626 return E_GESTURE_EVENT_STATE_PROPAGATE;
1628 if (ev->multi.device > E_GESTURE_FINGER_MAX)
1630 return E_GESTURE_EVENT_STATE_PROPAGATE;
1632 if (gesture->gesture_events.num_pressed == 0)
1634 return gesture->event_state;
1636 if (!gesture->grabbed_gesture)
1638 return E_GESTURE_EVENT_STATE_PROPAGATE;
1641 if (gesture->gesture_events.base_point[ev->multi.device + 1].pressed != EINA_TRUE)
1643 return gesture->event_state;
1645 gesture->gesture_events.base_point[ev->multi.device + 1].axis.x = ev->x;
1646 gesture->gesture_events.base_point[ev->multi.device + 1].axis.y = ev->y;
1648 if (!(gesture->gesture_filter & E_GESTURE_TYPE_EDGE_SWIPE))
1650 _e_gesture_process_edge_swipe_move(ev);
1652 if (!(gesture->gesture_filter & E_GESTURE_TYPE_EDGE_DRAG))
1654 _e_gesture_process_edge_drag_move(ev);
1656 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PAN))
1658 _e_gesture_process_pan_move(ev);
1660 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PINCH))
1662 _e_gesture_process_pinch_move(ev);
1664 if (!(gesture->gesture_filter & E_GESTURE_TYPE_TAP))
1666 _e_gesture_process_tap_move(ev);
1669 return gesture->event_state;
1672 static E_Gesture_Event_State
1673 _e_gesture_process_key_down(void *event)
1675 Ecore_Event_Key *ev = event;
1676 E_Gesture_Conf_Edd *conf = gesture->config->conf;
1678 if (ev->keycode == conf->edge_swipe.compose_key)
1680 gesture->gesture_events.edge_swipes.combined_keycode = conf->edge_swipe.compose_key;
1683 return E_GESTURE_EVENT_STATE_PROPAGATE;
1686 static E_Gesture_Event_State
1687 _e_gesture_process_key_up(void *event)
1689 Ecore_Event_Key *ev = event;
1690 E_Gesture_Conf_Edd *conf = gesture->config->conf;
1692 if (ev->keycode == conf->edge_swipe.compose_key)
1694 gesture->gesture_events.edge_swipes.combined_keycode = 0;
1697 return E_GESTURE_EVENT_STATE_PROPAGATE;
1701 _e_gesture_send_palm_cover(void)
1703 Ecore_Event_Mouse_Button *ev_cancel;
1704 E_Gesture_Event_Palm_Cover *palm_covers = &gesture->gesture_events.palm_covers;
1705 int duration = 0, time;
1707 unsigned int size = 0;
1708 wl_fixed_t pressure;
1709 struct wl_resource *surface = NULL, *res = NULL, *focus_surface = NULL;
1711 E_Gesture_Select_Surface *sdata;
1712 E_Event_Gesture_Palm_Cover *ev_palm_cover;
1714 time = (int)(ecore_time_get()*1000);
1716 if (gesture->event_state == E_GESTURE_EVENT_STATE_KEEP)
1718 _e_gesture_event_drop();
1720 else if (gesture->event_state == E_GESTURE_EVENT_STATE_PROPAGATE)
1722 ev_cancel = E_NEW(Ecore_Event_Mouse_Button, 1);
1723 EINA_SAFETY_ON_NULL_RETURN(ev_cancel);
1725 ev_cancel->timestamp = time;
1726 ev_cancel->same_screen = 1;
1728 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev_cancel, NULL, NULL);
1731 _e_gesture_util_center_axis_get(gesture->gesture_events.num_pressed, &cx, &cy);
1733 GTINF("Send palm_cover gesture to client: %p\n", palm_covers->client_info.client);
1735 if (palm_covers->client_info.client == E_GESTURE_SERVER_CLIENT)
1737 ev_palm_cover = E_NEW(E_Event_Gesture_Palm_Cover, 1);
1738 EINA_SAFETY_ON_NULL_RETURN(ev_palm_cover);
1740 ev_palm_cover->mode = E_GESTURE_MODE_BEGIN;
1741 ev_palm_cover->duration = duration;
1742 ev_palm_cover->cx = cx;
1743 ev_palm_cover->cy = cy;
1744 ev_palm_cover->size = size;
1745 ev_palm_cover->pressure = 0.0;
1746 ecore_event_add(E_EVENT_GESTURE_PALM_COVER, ev_palm_cover, NULL, NULL);
1748 ev_palm_cover = E_NEW(E_Event_Gesture_Palm_Cover, 1);
1749 EINA_SAFETY_ON_NULL_RETURN(ev_palm_cover);
1751 ev_palm_cover->mode = E_GESTURE_MODE_END;
1752 ev_palm_cover->duration = duration;
1753 ev_palm_cover->cx = cx;
1754 ev_palm_cover->cy = cy;
1755 ev_palm_cover->size = size;
1756 ev_palm_cover->pressure = 0.0;
1757 ecore_event_add(E_EVENT_GESTURE_PALM_COVER, ev_palm_cover, NULL, NULL);
1761 pressure = wl_fixed_from_double(0.0);
1763 focus_surface = _e_gesture_util_eclient_surface_get(e_client_focused_get());
1766 EINA_LIST_FOREACH(palm_covers->select_surface_list, l, sdata)
1768 if (focus_surface == sdata->surface)
1770 surface = sdata->surface;
1777 if (!surface || !res)
1779 res = palm_covers->client_info.res;
1783 tizen_gesture_send_palm_cover(palm_covers->client_info.res, surface, E_GESTURE_MODE_BEGIN, duration, size, pressure, cx, cy);
1784 tizen_gesture_send_palm_cover(palm_covers->client_info.res, surface, E_GESTURE_MODE_END, duration, size, pressure, cx, cy);
1787 gesture->event_state = E_GESTURE_EVENT_STATE_IGNORE;
1788 gesture->gesture_events.recognized_gesture |= E_GESTURE_TYPE_PALM_COVER;
1792 _e_gesture_process_palm_cover(int val)
1794 if (gesture->gesture_events.recognized_gesture)
1799 _e_gesture_send_palm_cover();
1803 _e_gesture_process_palm(int val)
1805 if (val <= 0) return;
1806 if (!gesture->grabbed_gesture) return;
1808 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PALM_COVER) &&
1809 gesture->gesture_events.palm_covers.activation.active)
1811 _e_gesture_process_palm_cover(val);
1815 static E_Gesture_Event_State
1816 _e_gesture_process_axis_update(void *event)
1818 Ecore_Event_Axis_Update *ev = event;
1821 for (i = 0; i < ev->naxis; i++)
1823 if (ev->axis[i].label == ECORE_AXIS_LABEL_TOUCH_PALM)
1825 _e_gesture_process_palm((int)ev->axis[i].value);
1828 return E_GESTURE_EVENT_STATE_PROPAGATE;
1832 e_gesture_event_deactivate_check(void)
1834 if (gesture->gesture_events.num_pressed <= 0) return;
1835 if (gesture->gesture_filter == E_GESTURE_TYPE_ALL) return;
1837 if (!(gesture->gesture_filter & E_GESTURE_TYPE_EDGE_SWIPE) &&
1838 gesture->gesture_events.edge_swipes.base.activation.active)
1840 _e_gesture_edge_swipe_cancel();
1843 if (!(gesture->gesture_filter & E_GESTURE_TYPE_TAP) &&
1844 gesture->gesture_events.taps.activation.active)
1846 _e_gesture_tap_cancel();
1849 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PAN) &&
1850 gesture->gesture_events.pans.activation.active)
1852 _e_gesture_pan_cancel();
1855 if (!(gesture->gesture_filter & E_GESTURE_TYPE_PINCH) &&
1856 gesture->gesture_events.pinchs.activation.active)
1858 _e_gesture_pinch_cancel();
1863 /* Function for checking the existing grab for a key and sending key event(s) */
1865 e_gesture_process_events(void *event, int type)
1867 E_Gesture_Event_State res = E_GESTURE_EVENT_STATE_PROPAGATE;
1868 Eina_Bool ret = EINA_TRUE;
1870 if (type == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1871 res = _e_gesture_process_mouse_button_down(event);
1872 else if (type == ECORE_EVENT_MOUSE_BUTTON_UP)
1873 res = _e_gesture_process_mouse_button_up(event);
1874 else if (type == ECORE_EVENT_MOUSE_MOVE)
1875 res = _e_gesture_process_mouse_move(event);
1876 else if (type == ECORE_EVENT_KEY_DOWN)
1877 res = _e_gesture_process_key_down(event);
1878 else if (type == ECORE_EVENT_KEY_UP)
1879 res = _e_gesture_process_key_up(event);
1880 else if (type == ECORE_EVENT_DEVICE_ADD)
1881 res = _e_gesture_process_device_add(event);
1882 else if (type == ECORE_EVENT_DEVICE_DEL)
1883 res = _e_gesture_process_device_del(event);
1884 else if (type == ECORE_EVENT_AXIS_UPDATE)
1885 res = _e_gesture_process_axis_update(event);
1890 case E_GESTURE_EVENT_STATE_PROPAGATE:
1893 case E_GESTURE_EVENT_STATE_KEEP:
1894 _e_gesture_event_queue(type, event);
1897 case E_GESTURE_EVENT_STATE_IGNORE:
1904 if (gesture->gesture_events.num_pressed == 0&&
1905 type == ECORE_EVENT_MOUSE_BUTTON_UP)
1907 if (gesture->grabbed_gesture & E_GESTURE_TYPE_TAP ||
1908 ((gesture->grabbed_gesture & E_GESTURE_TYPE_EDGE_SWIPE) &&
1909 gesture->gesture_events.event_keep))
1910 gesture->event_state = E_GESTURE_EVENT_STATE_KEEP;
1911 gesture->gesture_filter = E_GESTURE_TYPE_ALL & ~gesture->grabbed_gesture;