From: JengHyun Kang Date: Mon, 24 Jul 2017 05:47:34 +0000 (+0900) Subject: add a gesture activate/deactivate functions X-Git-Tag: submit/tizen/20170728.065325^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=02af0fb6aa1454e6798eadee54eae2327758fef8;p=platform%2Fcore%2Fuifw%2Fe-mod-tizen-gesture.git add a gesture activate/deactivate functions - Runtime selective gesture activation / deactivation Change-Id: I7fa86fd092b0e6a2c28b971054902fcb51d04b01 --- diff --git a/src/e_mod_gesture_events.c b/src/e_mod_gesture_events.c index 08c312a..4698392 100644 --- a/src/e_mod_gesture_events.c +++ b/src/e_mod_gesture_events.c @@ -346,6 +346,8 @@ _e_gesture_process_edge_swipe_down(Ecore_Event_Mouse_Button *ev) int i; unsigned int idx = ev->multi.device+1; + if (!edge_swipes->activation.active) return; + if (gesture->gesture_events.recognized_gesture) _e_gesture_edge_swipe_cancel(); @@ -405,6 +407,8 @@ _e_gesture_process_edge_swipe_move(Ecore_Event_Mouse_Move *ev) Coords diff; unsigned int idx = ev->multi.device+1; + if (!edge_swipes->activation.active) return; + if (!(edge_swipes->enabled_finger & (1 << idx))) return; @@ -474,6 +478,9 @@ _e_gesture_process_edge_swipe_move(Ecore_Event_Mouse_Move *ev) static void _e_gesture_process_edge_swipe_up(Ecore_Event_Mouse_Button *ev) { + E_Gesture_Event_Edge_Swipe *edge_swipes = &gesture->gesture_events.edge_swipes; + + if (!edge_swipes->activation.active) return; if (gesture->gesture_events.event_keep) _e_gesture_event_flush(); _e_gesture_edge_swipe_cancel(); @@ -657,6 +664,8 @@ _e_gesture_process_pan_down(Ecore_Event_Mouse_Button *ev) { E_Gesture_Event_Pan *pans = &gesture->gesture_events.pans; + if (!pans->activation.active) return; + if (gesture->gesture_events.recognized_gesture && !((gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PAN) || (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PINCH))) @@ -677,6 +686,8 @@ _e_gesture_process_pan_move(Ecore_Event_Mouse_Move *ev) Coords cur_point = {0,}; int idx, diff_x, diff_y, mode; + if (!pans->activation.active) return; + if (gesture->gesture_events.recognized_gesture && !((gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PAN) || (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PINCH))) @@ -720,6 +731,9 @@ _e_gesture_process_pan_move(Ecore_Event_Mouse_Move *ev) static void _e_gesture_process_pan_up(Ecore_Event_Mouse_Button *ev) { + E_Gesture_Event_Pan *pans = &gesture->gesture_events.pans; + + if (!pans->activation.active) return; _e_gesture_pan_cancel(); } @@ -792,6 +806,8 @@ _e_gesture_process_pinch_down(Ecore_Event_Mouse_Button *ev) { E_Gesture_Event_Pinch *pinch = &gesture->gesture_events.pinchs; + if (!pinch->activation.active) return; + if (gesture->gesture_events.recognized_gesture && !((gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PAN) || (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PINCH))) @@ -812,6 +828,8 @@ _e_gesture_process_pinch_move(Ecore_Event_Mouse_Move *ev) int idx, mode, cx = 0, cy = 0; double current_distance = 0.0, diff = 0.0, angle = 0.0; + if (!pinch->activation.active) return; + if (gesture->gesture_events.recognized_gesture && !((gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PAN) || (gesture->gesture_events.recognized_gesture & E_GESTURE_TYPE_PINCH))) @@ -856,6 +874,9 @@ _e_gesture_process_pinch_move(Ecore_Event_Mouse_Move *ev) static void _e_gesture_process_pinch_up(Ecore_Event_Mouse_Button *ev) { + E_Gesture_Event_Pinch *pinch = &gesture->gesture_events.pinchs; + + if (!pinch->activation.active) return; _e_gesture_pinch_cancel(); } @@ -1052,6 +1073,8 @@ _e_gesture_process_tap_down(Ecore_Event_Mouse_Button *ev) { E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps; + if (!taps->activation.active) return; + if (gesture->gesture_events.recognized_gesture) _e_gesture_tap_cancel(); @@ -1109,6 +1132,8 @@ _e_gesture_process_tap_move(Ecore_Event_Mouse_Move *ev) Rect current_rect = {0, }; int xx1, yy1, xx2, yy2; + if (!taps->activation.active) return; + if (gesture->gesture_events.recognized_gesture) _e_gesture_tap_cancel(); @@ -1134,6 +1159,8 @@ _e_gesture_process_tap_up(Ecore_Event_Mouse_Button *ev) { E_Gesture_Event_Tap *taps = &gesture->gesture_events.taps; + if (!taps->activation.active) return; + if (gesture->gesture_events.recognized_gesture) _e_gesture_tap_cancel(); @@ -1441,7 +1468,8 @@ _e_gesture_process_palm(int val) if (val <= 0) return; if (!gesture->grabbed_gesture) return; - if (!(gesture->gesture_filter & E_GESTURE_TYPE_PALM_COVER)) + if (!(gesture->gesture_filter & E_GESTURE_TYPE_PALM_COVER) && + gesture->gesture_events.palm_covers.activation.active) { _e_gesture_process_palm_cover(val); } @@ -1463,6 +1491,38 @@ _e_gesture_process_axis_update(void *event) return E_GESTURE_EVENT_STATE_PROPAGATE; } +void +e_gesture_event_deactivate_check(void) +{ + if (gesture->gesture_events.num_pressed <= 0) return; + if (gesture->gesture_filter == E_GESTURE_TYPE_ALL) return; + + if (!(gesture->gesture_filter & E_GESTURE_TYPE_EDGE_SWIPE) && + gesture->gesture_events.edge_swipes.activation.active) + { + _e_gesture_edge_swipe_cancel(); + } + + if (!(gesture->gesture_filter & E_GESTURE_TYPE_TAP) && + gesture->gesture_events.taps.activation.active) + { + _e_gesture_tap_cancel(); + } + + if (!(gesture->gesture_filter & E_GESTURE_TYPE_PAN) && + gesture->gesture_events.pans.activation.active) + { + _e_gesture_pan_cancel(); + } + + if (!(gesture->gesture_filter & E_GESTURE_TYPE_PINCH) && + gesture->gesture_events.pinchs.activation.active) + { + _e_gesture_pinch_cancel(); + } + +} + /* Function for checking the existing grab for a key and sending key event(s) */ Eina_Bool e_gesture_process_events(void *event, int type) diff --git a/src/e_mod_main.c b/src/e_mod_main.c index 5871936..cdbc9bd 100644 --- a/src/e_mod_main.c +++ b/src/e_mod_main.c @@ -613,6 +613,220 @@ _e_gesture_deselect_palm_cover(struct wl_client *client, struct wl_resource *res return ret; } +static Eina_Bool +_e_gesture_deactivate_find_surface(Eina_List *list, struct wl_resource *surface) +{ + Eina_List *l; + E_Gesture_Activate_Surface_Info *idata; + + EINA_LIST_FOREACH(list, l, idata) + { + if (surface == idata->surface) + { + return EINA_TRUE; + } + } + return EINA_FALSE; +} + +static char * +_e_gesture_util_type_to_string(unsigned int type) +{ + switch (type) + { + case E_GESTURE_TYPE_EDGE_SWIPE: + return "edge_swipe"; + case E_GESTURE_TYPE_TAP: + return "tap"; + case E_GESTURE_TYPE_PALM_COVER: + return "palm_cover"; + case E_GESTURE_TYPE_PAN: + return "pan"; + case E_GESTURE_TYPE_PINCH: + return "pinch"; + default: + return "unknown"; + } +} + +static void +_e_gesture_deactivate_list_unset(struct wl_client *client, struct wl_resource *surface, E_Gesture_Activate_Info *info, unsigned int type) +{ + Eina_List *l, *l_next; + struct wl_resource *surface_data; + + if (surface) + { + EINA_LIST_FOREACH_SAFE(info->surfaces, l, l_next, surface_data) + { + if (surface_data == surface) + { + info->surfaces = eina_list_remove_list(info->surfaces, l); + break; + } + } + } + else if (info->client && (info->client == client)) + { + info->client = NULL; + info->active = EINA_TRUE; + } + else + { + GTWRN("Failed to unset %s deactivate. surface: %p, client: %p (already deactivated client: %p)\n", _e_gesture_util_type_to_string(type), surface, client, info->client); + } +} + +static void +_e_gesture_deactivate_cb_client_listener(struct wl_listener *l, void *data) +{ + struct wl_client *client = data; + + _e_gesture_deactivate_list_unset(client, NULL, &gesture->gesture_events.edge_swipes.activation, E_GESTURE_TYPE_EDGE_SWIPE); + _e_gesture_deactivate_list_unset(client, NULL, &gesture->gesture_events.taps.activation, E_GESTURE_TYPE_TAP); + _e_gesture_deactivate_list_unset(client, NULL, &gesture->gesture_events.palm_covers.activation, E_GESTURE_TYPE_PALM_COVER); + _e_gesture_deactivate_list_unset(client, NULL, &gesture->gesture_events.pans.activation, E_GESTURE_TYPE_PAN); + _e_gesture_deactivate_list_unset(client, NULL, &gesture->gesture_events.pinchs.activation, E_GESTURE_TYPE_PINCH); + + wl_list_remove(&l->link); + E_FREE(l); +} + +static void +_e_gesture_deactivate_cb_surface_listener(struct wl_listener *l, void *data) +{ + struct wl_resource *surface = data; + + _e_gesture_deactivate_list_unset(NULL, surface, &gesture->gesture_events.edge_swipes.activation, E_GESTURE_TYPE_EDGE_SWIPE); + _e_gesture_deactivate_list_unset(NULL, surface, &gesture->gesture_events.taps.activation, E_GESTURE_TYPE_TAP); + _e_gesture_deactivate_list_unset(NULL, surface, &gesture->gesture_events.palm_covers.activation, E_GESTURE_TYPE_PALM_COVER); + _e_gesture_deactivate_list_unset(NULL, surface, &gesture->gesture_events.pans.activation, E_GESTURE_TYPE_PAN); + _e_gesture_deactivate_list_unset(NULL, surface, &gesture->gesture_events.pinchs.activation, E_GESTURE_TYPE_PINCH); + + wl_list_remove(&l->link); + E_FREE(l); +} + +static int +_e_gesture_deactivate_listener_add(struct wl_client *client, struct wl_resource * surface) +{ + struct wl_listener *destroy_listener = NULL; + + EINA_SAFETY_ON_FALSE_RETURN_VAL(client || surface, TIZEN_GESTURE_ERROR_INVALID_DATA); + + destroy_listener = E_NEW(struct wl_listener, 1); + if (!destroy_listener) + { + GTERR("Failed to allocate memory for deactivate destroy listener !\n"); + return TIZEN_GESTURE_ERROR_NO_SYSTEM_RESOURCES; + } + + if (surface) + { + destroy_listener->notify = _e_gesture_deactivate_cb_surface_listener; + wl_resource_add_destroy_listener(surface, destroy_listener); + } + else + { + destroy_listener->notify = _e_gesture_deactivate_cb_client_listener; + wl_client_add_destroy_listener(client, destroy_listener); + } + + return TIZEN_GESTURE_ERROR_NONE; +} + +static int +_e_gesture_deactivate_list_set(struct wl_client *client, struct wl_resource *surface, E_Gesture_Activate_Info *info, unsigned int type) +{ + int ret = TIZEN_GESTURE_ERROR_NONE; + + if (surface) + { + if (!_e_gesture_deactivate_find_surface(info->surfaces, surface)) + { + info->surfaces = eina_list_append(info->surfaces, surface); + _e_gesture_deactivate_listener_add(client, surface); + } + } + else if (!info->client) + { + info->client = client; + info->active = EINA_FALSE; + _e_gesture_deactivate_listener_add(client, surface); + } + else + { + GTWRN("Failed to deactivate %s !(request surface: %p, client: %p), already deactivated client: %p\n", + _e_gesture_util_type_to_string(type), surface, client, info->client); + ret = TIZEN_GESTURE_ERROR_GRABBED_ALREADY; + } + + return ret; +} + +static int +_e_gesture_deactivate_set(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *surface, + uint32_t type) +{ + int ret = TIZEN_GESTURE_ERROR_NONE; + + if (type & E_GESTURE_TYPE_EDGE_SWIPE) + { + ret = _e_gesture_deactivate_list_set(client, surface, &gesture->gesture_events.edge_swipes.activation, E_GESTURE_TYPE_EDGE_SWIPE); + } + if (type & E_GESTURE_TYPE_TAP) + { + ret = _e_gesture_deactivate_list_set(client, surface, &gesture->gesture_events.taps.activation, E_GESTURE_TYPE_TAP); + } + if (type & E_GESTURE_TYPE_PALM_COVER) + { + ret = _e_gesture_deactivate_list_set(client, surface, &gesture->gesture_events.palm_covers.activation, E_GESTURE_TYPE_PALM_COVER); + } + if (type & E_GESTURE_TYPE_PAN) + { + ret = _e_gesture_deactivate_list_set(client, surface, &gesture->gesture_events.pans.activation, E_GESTURE_TYPE_PAN); + } + if (type & E_GESTURE_TYPE_PINCH) + { + ret = _e_gesture_deactivate_list_set(client, surface, &gesture->gesture_events.pinchs.activation, E_GESTURE_TYPE_PINCH); + } + + return ret; +} + +static int +_e_gesture_deactivate_unset(struct wl_client *client, + struct wl_resource *resource, + struct wl_resource *surface, + uint32_t type) +{ + int ret = TIZEN_GESTURE_ERROR_NONE; + + if (type & E_GESTURE_TYPE_EDGE_SWIPE) + { + _e_gesture_deactivate_list_unset(client, surface, &gesture->gesture_events.edge_swipes.activation, E_GESTURE_TYPE_EDGE_SWIPE); + } + if (type & E_GESTURE_TYPE_TAP) + { + _e_gesture_deactivate_list_unset(client, surface, &gesture->gesture_events.taps.activation, E_GESTURE_TYPE_TAP); + } + if (type & E_GESTURE_TYPE_PALM_COVER) + { + _e_gesture_deactivate_list_unset(client, surface, &gesture->gesture_events.palm_covers.activation, E_GESTURE_TYPE_PALM_COVER); + } + if (type & E_GESTURE_TYPE_PAN) + { + _e_gesture_deactivate_list_unset(client, surface, &gesture->gesture_events.pans.activation, E_GESTURE_TYPE_PAN); + } + if (type & E_GESTURE_TYPE_PINCH) + { + _e_gesture_deactivate_list_unset(client, surface, &gesture->gesture_events.pinchs.activation, E_GESTURE_TYPE_PINCH); + } + + return ret; +} static void _e_gesture_cb_grab_edge_swipe(struct wl_client *client, @@ -971,7 +1185,10 @@ _e_gesture_cb_activate_set(struct wl_client *client, { int ret = TIZEN_GESTURE_ERROR_NONE; - ret = TIZEN_GESTURE_ERROR_NOT_SUPPORTED; + if (!active) + ret = _e_gesture_deactivate_set(client, resource, surface, type); + else + ret = _e_gesture_deactivate_unset(client, resource, surface, type); tizen_gesture_send_activate_notify(resource, surface, type, active, ret); } @@ -1051,6 +1268,50 @@ _e_gesture_event_filter(void *data, void *loop_data EINA_UNUSED, int type, void return e_gesture_process_events(event, type); } +static void +_e_gesture_deactivate_surface_list_check(struct wl_resource *surface, E_Gesture_Activate_Info *info) +{ + Eina_Bool res; + + res = _e_gesture_deactivate_find_surface(info->surfaces, surface); + + if (res) info->active = EINA_FALSE; + else info->active = EINA_TRUE; +} + +static void +_e_gesture_deactivate_surface_check(E_Client *ec) +{ + struct wl_resource *surface; + + EINA_SAFETY_ON_NULL_RETURN(ec); + EINA_SAFETY_ON_NULL_RETURN(ec->comp_data); + + surface = ec->comp_data->wl_surface; + if (!surface) return; + + if (!gesture->gesture_events.edge_swipes.activation.client) + { + _e_gesture_deactivate_surface_list_check(surface, &gesture->gesture_events.edge_swipes.activation); + } + if (!gesture->gesture_events.taps.activation.client) + { + _e_gesture_deactivate_surface_list_check(surface, &gesture->gesture_events.taps.activation); + } + if (!gesture->gesture_events.palm_covers.activation.client) + { + _e_gesture_deactivate_surface_list_check(surface, &gesture->gesture_events.palm_covers.activation); + } + if (!gesture->gesture_events.pans.activation.client) + { + _e_gesture_deactivate_surface_list_check(surface, &gesture->gesture_events.pans.activation); + } + if (!gesture->gesture_events.pinchs.activation.client) + { + _e_gesture_deactivate_surface_list_check(surface, &gesture->gesture_events.pinchs.activation); + } +} + static void _e_gesture_window_gesture_disabled_change(E_Client *ec) { @@ -1083,6 +1344,8 @@ _e_gesture_cb_client_focus_in(void *data, int type, void *event) EINA_SAFETY_ON_NULL_RETURN_VAL(ec->comp_data, ECORE_CALLBACK_PASS_ON); _e_gesture_window_gesture_disabled_change(ec); + _e_gesture_deactivate_surface_check(ec); + e_gesture_event_deactivate_check(); return ECORE_CALLBACK_PASS_ON; } diff --git a/src/e_mod_main.h b/src/e_mod_main.h index 263ab7c..fd12119 100644 --- a/src/e_mod_main.h +++ b/src/e_mod_main.h @@ -15,12 +15,13 @@ #define E_GESTURE_TYPE_EDGE_DRAG TIZEN_GESTURE_TYPE_EDGE_DRAG #define E_GESTURE_TYPE_TAP TIZEN_GESTURE_TYPE_TAP #define E_GESTURE_TYPE_PALM_COVER TIZEN_GESTURE_TYPE_PALM_COVER -#define E_GESTURE_TYPE_PAN (TIZEN_GESTURE_TYPE_PALM_COVER << 1) -#define E_GESTURE_TYPE_PINCH (TIZEN_GESTURE_TYPE_PALM_COVER << 2) +#define E_GESTURE_TYPE_PAN TIZEN_GESTURE_TYPE_PAN +#define E_GESTURE_TYPE_PINCH TIZEN_GESTURE_TYPE_PINCH +#define E_GESTURE_TYPE_PALM_SWIPE TIZEN_GESTURE_TYPE_PALM_SWIPE #define E_GESTURE_FINGER_MAX 3 -#define E_GESTURE_TYPE_MAX (E_GESTURE_TYPE_PINCH + 1) -#define E_GESTURE_TYPE_ALL (E_GESTURE_TYPE_EDGE_SWIPE | E_GESTURE_TYPE_EDGE_DRAG | E_GESTURE_TYPE_TAP | E_GESTURE_TYPE_PAN | E_GESTURE_TYPE_PINCH | E_GESTURE_TYPE_PALM_COVER) +#define E_GESTURE_TYPE_MAX (E_GESTURE_TYPE_PALM_SWIPE + 1) +#define E_GESTURE_TYPE_ALL (E_GESTURE_TYPE_EDGE_SWIPE | E_GESTURE_TYPE_EDGE_DRAG | E_GESTURE_TYPE_TAP | E_GESTURE_TYPE_PAN | E_GESTURE_TYPE_PINCH | E_GESTURE_TYPE_PALM_COVER | E_GESTURE_TYPE_PALM_SWIPE) #define E_GESTURE_KEYBOARD_NAME "Gesture Keyboard" #define E_GESTURE_AUX_HINT_GESTURE_DISABLE "wm.policy.win.gesture.disable" @@ -78,6 +79,8 @@ typedef struct _E_Gesture_Finger E_Gesture_Finger; typedef struct _E_Gesture_Event_Info E_Gesture_Event_Info; typedef struct _E_Gesture_Event_Client E_Gesture_Event_Client; typedef struct _E_Gesture_Select_Surface E_Gesture_Select_Surface; +typedef struct _E_Gesture_Activate_Surface_Info E_Gesture_Activate_Surface_Info; +typedef struct _E_Gesture_Activate_Info E_Gesture_Activate_Info; typedef enum _E_Gesture_Edge E_Gesture_Edge; typedef enum _E_Gesture_Event_State E_Gesture_Event_State; @@ -147,6 +150,19 @@ struct _E_Gesture_Event_Info void *event; }; +struct _E_Gesture_Activate_Surface_Info +{ + Eina_Bool active; + struct wl_resource *surface; +}; + +struct _E_Gesture_Activate_Info +{ + Eina_Bool active; + struct wl_client *client; + Eina_List *surfaces; +}; + struct _E_Gesture_Conf_Edd { char *key_device_name; @@ -217,6 +233,7 @@ struct _E_Gesture_Event_Edge_Swipe_Finger struct _E_Gesture_Event_Edge_Swipe { + E_Gesture_Activate_Info activation; E_Gesture_Event_Edge_Swipe_Finger fingers[E_GESTURE_FINGER_MAX + 2]; unsigned int edge; @@ -246,6 +263,7 @@ struct _E_Gesture_Event_Tap_Finger struct _E_Gesture_Event_Tap { + E_Gesture_Activate_Info activation; E_Gesture_Event_Tap_Finger fingers[E_GESTURE_FINGER_MAX + 2]; E_Gesture_Tap_State state; unsigned int enabled_finger; @@ -264,6 +282,7 @@ struct _E_Gesture_Event_Tap struct _E_Gesture_Event_Pan { + E_Gesture_Activate_Info activation; E_Gesture_Event_Client fingers[E_GESTURE_FINGER_MAX + 2]; E_Gesture_PanPinch_State state; Coords start_point; @@ -277,6 +296,7 @@ struct _E_Gesture_Event_Pan struct _E_Gesture_Event_Pinch { + E_Gesture_Activate_Info activation; E_Gesture_Event_Client fingers[E_GESTURE_FINGER_MAX + 2]; E_Gesture_PanPinch_State state; double distance; @@ -288,6 +308,7 @@ struct _E_Gesture_Event_Pinch struct _E_Gesture_Event_Palm_Cover { + E_Gesture_Activate_Info activation; E_Gesture_Event_Client client_info; Eina_List *select_surface_list; unsigned int start_time; @@ -359,6 +380,7 @@ E_API void *e_modapi_init(E_Module *m); E_API int e_modapi_shutdown(E_Module *m); E_API int e_modapi_save(E_Module *m); +void e_gesture_event_deactivate_check(void); Eina_Bool e_gesture_process_events(void *event, int type); int e_gesture_type_convert(uint32_t type);