X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fefl_util.c;h=72295c3f571f37baae6a6e49889b4c7740208235;hb=469eb4e11dc3f685e39de14b68a6f83197ecde53;hp=2436df118e2f289ffe52ae6110478792cfd5dfec;hpb=004932fbccb35064201d48148216bb3faf2137b7;p=platform%2Fcore%2Fapi%2Fefl-util.git diff --git a/src/efl_util.c b/src/efl_util.c index 2436df1..72295c3 100644 --- a/src/efl_util.c +++ b/src/efl_util.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2011-2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -30,18 +30,68 @@ #include #include #include +#include -#include +#include #include #include #include #include +#include + #include #ifdef LOG_TAG #undef LOG_TAG #endif +/* Determine Tizen profile at runtime */ +#include +typedef enum { + TIZEN_PROFILE_UNKNOWN = 0, + TIZEN_PROFILE_MOBILE = 0x1, + TIZEN_PROFILE_WEARABLE = 0x2, + TIZEN_PROFILE_TV = 0x4, + TIZEN_PROFILE_IVI = 0x8, + TIZEN_PROFILE_COMMON = 0x10, +} tizen_profile_t; +static tizen_profile_t profile = TIZEN_PROFILE_UNKNOWN; +static tizen_profile_t _get_tizen_profile() +{ + char *profileName; + system_info_get_platform_string("http://tizen.org/feature/profile", &profileName); + switch (*profileName) { + case 'm': + case 'M': + profile = TIZEN_PROFILE_MOBILE; + break; + case 'w': + case 'W': + profile = TIZEN_PROFILE_WEARABLE; + break; + case 't': + case 'T': + profile = TIZEN_PROFILE_TV; + break; + case 'i': + case 'I': + profile = TIZEN_PROFILE_IVI; + break; + default: // common or unknown ==> ALL ARE COMMON. + profile = TIZEN_PROFILE_COMMON; + } + free(profileName); + + return profile; +} +static inline tizen_profile_t get_tizen_profile() +{ + if (__builtin_expect(profile != TIZEN_PROFILE_UNKNOWN, 1)) + return profile; + return _get_tizen_profile(); +} + + #define LOG_TAG "TIZEN_N_EFL_UTIL" @@ -89,17 +139,61 @@ typedef struct _Efl_Util_Wl_Output_Info int offset_x, offset_y, width, height; } Efl_Util_Wl_Output_Info; +typedef struct _Efl_Util_Gesture_Common_Grab_Data +{ + int type; +} Efl_Util_Gesture_Common_Grab_Data; + +typedef struct _Efl_Util_Gesture_Edge_Swipe_Grab_Data +{ + Efl_Util_Gesture_Common_Grab_Data base; + + unsigned int fingers; + efl_util_gesture_edge_e edge; + efl_util_gesture_edge_size_e edge_size; + unsigned int start_point; + unsigned int end_point; +} Efl_Util_Gesture_Edge_Swipe_Grab_Data; + +typedef struct _Efl_Util_Gesture_Edge_Drag_Grab_Data +{ + Efl_Util_Gesture_Common_Grab_Data base; + + unsigned int fingers; + efl_util_gesture_edge_e edge; + efl_util_gesture_edge_size_e edge_size; + unsigned int start_point; + unsigned int end_point; +} Efl_Util_Gesture_Edge_Drag_Grab_Data; + +typedef struct _Efl_Util_Gesture_Tap_Grab_Data +{ + Efl_Util_Gesture_Common_Grab_Data base; + + unsigned int fingers; + unsigned int repeats; +} Efl_Util_Gesture_Tap_Grab_Data; + +typedef struct _Efl_Util_Gesture_Palm_Cover_Grab_Data +{ + Efl_Util_Gesture_Common_Grab_Data base; +} Efl_Util_Gesture_Palm_Cover_Grab_Data; + typedef struct _Efl_Util_Data { /* wayland related stuffs */ struct { Eina_Bool init; + Ecore_Wl2_Display *wl2_display; struct wl_display *dpy; struct wl_event_queue *queue; + int dpy_fd; + Ecore_Fd_Handler *fd_hdl; struct { + unsigned int id; struct tizen_policy *proto; Eina_Hash *hash_noti_lv; Eina_Hash *hash_scr_mode; @@ -120,9 +214,16 @@ typedef struct _Efl_Util_Data } devmgr; struct { + unsigned int id; struct tizen_display_policy *proto; Eina_Hash *hash_brightness; } display_policy; + struct + { + struct tizen_gesture *proto; + int request_notified; + int event_init; + } gesture; } wl; struct @@ -136,10 +237,13 @@ static Efl_Util_Data _eflutil = { { EINA_FALSE, - NULL, NULL, - { NULL, NULL, NULL }, /* tizen_policy protocol */ + NULL, NULL, NULL, + -1, NULL, + { 0, NULL, NULL, NULL }, /* tizen_policy protocol */ { NULL, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */ - { NULL, -1 } /* tizen_input_device_manager protocol */ + { NULL, -1 }, /* tizen_input_device_manager protocol */ + { 0, NULL, NULL }, /* display_policy protocol */ + { NULL, -1, EINA_FALSE } /* tizen_gesture protocol */ }, { { NULL, 0 }, /* handler for notification level */ @@ -166,6 +270,7 @@ static void _cb_wl_tz_policy_iconify_state_changed(void *data static void _cb_wl_tz_policy_supported_aux_hints(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, struct wl_array *hints, uint32_t num_hints); static void _cb_wl_tz_policy_allowed_aux_hint(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, int id); static void _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options); +static void _cb_wl_conformant_region(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t serial); static void _cb_wl_tz_display_policy_brightness_done(void *data, struct tizen_display_policy *tizen_display_policy, struct wl_surface *surface_resource, int32_t brightness, uint32_t state); @@ -174,6 +279,17 @@ static void _cb_device_remove(void *data EINA_UNUSED, struct static void _cb_error(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t errorcode); static void _cb_block_expired(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED); +static void _cb_gesture_edge_swipe_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t edge EINA_UNUSED, uint32_t edge_size EINA_UNUSED, uint32_t start_point EINA_UNUSED, uint32_t end_point EINA_UNUSED, uint32_t error); +static void _cb_gesture_edge_swipe(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, int sx, int sy, uint32_t edge); +static void _cb_gesture_edge_drag_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t edge EINA_UNUSED, uint32_t edge_size EINA_UNUSED, uint32_t start_point EINA_UNUSED, uint32_t end_point EINA_UNUSED, uint32_t error); +static void _cb_gesture_edge_drag(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, int cx, int cy, uint32_t edge); +static void _cb_gesture_tap_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t repeats EINA_UNUSED, uint32_t error); +static void _cb_gesture_tap(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, uint32_t repeats); +static void _cb_gesture_palm_cover_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface EINA_UNUSED, uint32_t error); +static void _cb_gesture_palm_cover(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface EINA_UNUSED, uint32_t mode, uint32_t duration, int cx, int cy, uint32_t size, wl_fixed_t pressure); +static void _cb_gesture_activate_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface EINA_UNUSED, uint32_t type EINA_UNUSED, uint32_t active EINA_UNUSED, uint32_t error); + + static const struct wl_registry_listener _wl_reg_listener = { _cb_wl_reg_global, @@ -197,6 +313,7 @@ struct tizen_policy_listener _wl_tz_policy_listener = _cb_wl_tz_policy_supported_aux_hints, _cb_wl_tz_policy_allowed_aux_hint, _cb_wl_tz_policy_aux_message, + _cb_wl_conformant_region, }; struct tizen_input_device_manager_listener _wl_tz_devmgr_listener = @@ -212,6 +329,19 @@ struct tizen_display_policy_listener _wl_tz_display_policy_listener = _cb_wl_tz_display_policy_brightness_done, }; +struct tizen_gesture_listener _wl_tz_gesture_listener = +{ + _cb_gesture_edge_swipe_notify, + _cb_gesture_edge_swipe, + _cb_gesture_edge_drag_notify, + _cb_gesture_edge_drag, + _cb_gesture_tap_notify, + _cb_gesture_tap, + _cb_gesture_palm_cover_notify, + _cb_gesture_palm_cover, + _cb_gesture_activate_notify +}; + static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, @@ -285,35 +415,47 @@ _cb_info_find_by_win(Evas_Object *win, static Eina_Bool _wl_init(void) { + struct wl_display *display_wrapper = NULL; struct wl_registry *reg = NULL; if (_eflutil.wl.init) return EINA_TRUE; - ecore_wl_init(NULL); + ecore_wl2_init(); - _eflutil.wl.dpy = ecore_wl_display_get(); + _eflutil.wl.wl2_display = ecore_wl2_display_connect(NULL); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.wl2_display, fail); + _eflutil.wl.dpy = ecore_wl2_display_get(_eflutil.wl.wl2_display); EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail); + display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail); + _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy); EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail); - reg = wl_display_get_registry(_eflutil.wl.dpy); + wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue); + + reg = wl_display_get_registry(display_wrapper); + wl_proxy_wrapper_destroy(display_wrapper); + display_wrapper = NULL; EINA_SAFETY_ON_NULL_GOTO(reg, fail); - wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.queue); wl_registry_add_listener(reg, &_wl_reg_listener, NULL); _eflutil.wl.init = EINA_TRUE; return EINA_TRUE; fail: + if (display_wrapper) + wl_proxy_wrapper_destroy(display_wrapper); + if (_eflutil.wl.queue) { wl_event_queue_destroy(_eflutil.wl.queue); _eflutil.wl.queue = NULL; } - ecore_wl_shutdown(); + ecore_wl2_shutdown(); return EINA_FALSE; } @@ -393,7 +535,7 @@ static const struct tizen_screenshooter_listener tz_screenshooter_listener = static void _cb_wl_reg_global(void *data, struct wl_registry *reg, - unsigned int name, + unsigned int id, const char *interface, unsigned int version) { @@ -401,9 +543,9 @@ _cb_wl_reg_global(void *data, { struct tizen_policy *proto; proto = wl_registry_bind(reg, - name, + id, &tizen_policy_interface, - 1); + 7); if (!proto) return; tizen_policy_add_listener(proto, @@ -413,6 +555,7 @@ _cb_wl_reg_global(void *data, _eflutil.wl.policy.hash_noti_lv = eina_hash_pointer_new(free); _eflutil.wl.policy.hash_scr_mode = eina_hash_pointer_new(free); _eflutil.wl.policy.proto = proto; + _eflutil.wl.policy.id = id; } else if (strcmp(interface, "wl_output") == 0) { @@ -421,17 +564,17 @@ _cb_wl_reg_global(void *data, _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output); - output->output = wl_registry_bind(reg, name, &wl_output_interface, version); + output->output = wl_registry_bind(reg, id, &wl_output_interface, version); wl_output_add_listener(output->output, &output_listener, output); } else if (strcmp(interface, "tizen_input_device_manager") == 0) { - _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version); + _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, id, &tizen_input_device_manager_interface, version); tizen_input_device_manager_add_listener(_eflutil.wl.devmgr.devicemgr, &_wl_tz_devmgr_listener, NULL); } else if (!strcmp(interface, "tizen_display_policy")) { - _eflutil.wl.display_policy.proto = wl_registry_bind(reg, name, &tizen_display_policy_interface, version); + _eflutil.wl.display_policy.proto = wl_registry_bind(reg, id, &tizen_display_policy_interface, version); if (!_eflutil.wl.display_policy.proto) return; tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto, @@ -439,21 +582,36 @@ _cb_wl_reg_global(void *data, NULL); _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free); + _eflutil.wl.display_policy.id = id; + } + else if (strcmp(interface, "tizen_gesture") == 0) + { + _eflutil.wl.gesture.proto = wl_registry_bind(reg, id, &tizen_gesture_interface, version); + tizen_gesture_add_listener(_eflutil.wl.gesture.proto, &_wl_tz_gesture_listener, NULL); } - } /* LCOV_EXCL_START */ static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, - unsigned int name) + unsigned int id) { - _eflutil.wl.policy.proto = NULL; - eina_hash_free(_eflutil.wl.policy.hash_noti_lv); - eina_hash_free(_eflutil.wl.policy.hash_scr_mode); - - _eflutil.wl.display_policy.proto = NULL; - eina_hash_free(_eflutil.wl.display_policy.hash_brightness); + /* unset each global id number to 0 since global id is started + * from number 1 on server side display structure + */ + if (id == _eflutil.wl.policy.id) + { + _eflutil.wl.policy.id = 0; + _eflutil.wl.policy.proto = NULL; + eina_hash_free(_eflutil.wl.policy.hash_noti_lv); + eina_hash_free(_eflutil.wl.policy.hash_scr_mode); + } + else if (id == _eflutil.wl.display_policy.id) + { + _eflutil.wl.display_policy.id = 0; + _eflutil.wl.display_policy.proto = NULL; + eina_hash_free(_eflutil.wl.display_policy.hash_brightness); + } } /* LCOV_EXCL_STOP */ @@ -492,14 +650,14 @@ _cb_info_find_by_wlsurf(void *wlsurf, { Eina_List *l, *ll; Efl_Util_Callback_Info *info; - Ecore_Wl_Window *wlwin2 = NULL; + Ecore_Wl2_Window *wlwin2 = NULL; void *wlsurf2 = NULL; l = _cb_info_list_get(idx); EINA_LIST_FOREACH(l, ll, info) { - wlwin2 = elm_win_wl_window_get(info->win); - wlsurf2 = ecore_wl_window_surface_get(wlwin2); + wlwin2 = (Ecore_Wl2_Window *)elm_win_wl_window_get(info->win); + wlsurf2 = ecore_wl2_window_surface_get(wlwin2); if (wlsurf== wlsurf2) return info; } @@ -602,6 +760,9 @@ static void _cb_wl_tz_policy_allowed_aux_hint(void *data, str static void _cb_wl_tz_policy_aux_message(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface_resource, const char *key, const char *val, struct wl_array *options) { } +static void _cb_wl_conformant_region(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h, uint32_t serial) +{ +} /* LCOV_EXCL_STOP */ static void @@ -662,29 +823,29 @@ efl_util_set_notification_window_level(Evas_Object *window, } Elm_Win_Type type; - Ecore_Wl_Window *wlwin; + Ecore_Wl2_Window *wlwin; struct wl_surface *surface; Efl_Util_Wl_Surface_Lv_Info *lv_info; - Ecore_Wl_Window_Type wl_type; + Ecore_Wl2_Window_Type wl_type; res = _wl_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - wlwin = elm_win_wl_window_get(window); + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE); type = elm_win_type_get(window); if (type != ELM_WIN_NOTIFICATION) { - wl_type = ecore_wl_window_type_get(wlwin); - EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION), + wl_type = ecore_wl2_window_type_get(wlwin); + EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL2_WINDOW_TYPE_NOTIFICATION), EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE); } while (!_eflutil.wl.policy.proto) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - surface = ecore_wl_window_surface_get(wlwin); + surface = ecore_wl2_window_surface_get(wlwin); EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE); @@ -721,7 +882,7 @@ efl_util_set_notification_window_level(Evas_Object *window, int count = 0; while (lv_info->wait_for_done && (count < 3)) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); count++; } @@ -752,29 +913,29 @@ efl_util_get_notification_window_level(Evas_Object *window, EINA_SAFETY_ON_NULL_RETURN_VAL(level, EFL_UTIL_ERROR_INVALID_PARAMETER); Elm_Win_Type type; - Ecore_Wl_Window *wlwin; + Ecore_Wl2_Window *wlwin; struct wl_surface *surface; Efl_Util_Wl_Surface_Lv_Info *lv_info; - Ecore_Wl_Window_Type wl_type; + Ecore_Wl2_Window_Type wl_type; res = _wl_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - wlwin = elm_win_wl_window_get(window); + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE); type = elm_win_type_get(window); if (type != ELM_WIN_NOTIFICATION) { - wl_type = ecore_wl_window_type_get(wlwin); - EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL_WINDOW_TYPE_NOTIFICATION), + wl_type = ecore_wl2_window_type_get(wlwin); + EINA_SAFETY_ON_FALSE_RETURN_VAL((wl_type == ECORE_WL2_WINDOW_TYPE_NOTIFICATION), EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE); } while (!_eflutil.wl.policy.proto) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - surface = ecore_wl_window_surface_get(wlwin); + surface = ecore_wl2_window_surface_get(wlwin); EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE); @@ -786,7 +947,7 @@ efl_util_get_notification_window_level(Evas_Object *window, int count = 0; while ((lv_info->wait_for_done) && (count < 3)) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); count++; } @@ -867,7 +1028,7 @@ efl_util_set_window_opaque_state(Evas_Object *window, EINA_SAFETY_ON_FALSE_RETURN_VAL(((opaque >= 0) && (opaque <= 1)), EFL_UTIL_ERROR_INVALID_PARAMETER); - Ecore_Wl_Window *wlwin; + Ecore_Wl2_Window *wlwin; struct wl_surface *surface; if (!_eflutil.wl.policy.proto) @@ -883,11 +1044,11 @@ efl_util_set_window_opaque_state(Evas_Object *window, EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); } - wlwin = elm_win_wl_window_get(window); + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (!wlwin) return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; - surface = ecore_wl_window_surface_get(wlwin); + surface = ecore_wl2_window_surface_get(wlwin); if (!surface) return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; @@ -905,7 +1066,7 @@ efl_util_set_window_screen_mode(Evas_Object *window, (mode <= EFL_UTIL_SCREEN_MODE_ALWAYS_ON)), EFL_UTIL_ERROR_INVALID_PARAMETER); - Ecore_Wl_Window *wlwin; + Ecore_Wl2_Window *wlwin; struct wl_surface *surface; Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info; Eina_Bool res; @@ -913,13 +1074,13 @@ efl_util_set_window_screen_mode(Evas_Object *window, res = _wl_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - wlwin = elm_win_wl_window_get(window); + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (wlwin) { while (!_eflutil.wl.policy.proto) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - surface = ecore_wl_window_surface_get(wlwin); + surface = ecore_wl2_window_surface_get(wlwin); EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER); @@ -952,7 +1113,7 @@ efl_util_set_window_screen_mode(Evas_Object *window, int count = 0; while (scr_mode_info->wait_for_done && (count < 3)) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); count++; } @@ -983,7 +1144,7 @@ efl_util_get_window_screen_mode(Evas_Object *window, EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); EINA_SAFETY_ON_NULL_RETURN_VAL(mode, EFL_UTIL_ERROR_INVALID_PARAMETER); - Ecore_Wl_Window *wlwin; + Ecore_Wl2_Window *wlwin; struct wl_surface *surface; Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info; Eina_Bool res; @@ -991,13 +1152,13 @@ efl_util_get_window_screen_mode(Evas_Object *window, res = _wl_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - wlwin = elm_win_wl_window_get(window); + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (wlwin) { while (!_eflutil.wl.policy.proto) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - surface = ecore_wl_window_surface_get(wlwin); + surface = ecore_wl2_window_surface_get(wlwin); EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER); @@ -1008,7 +1169,7 @@ efl_util_get_window_screen_mode(Evas_Object *window, { while (scr_mode_info->wait_for_done) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); } } @@ -1032,12 +1193,15 @@ efl_util_get_window_screen_mode(Evas_Object *window, return EFL_UTIL_ERROR_INVALID_PARAMETER; } -#ifndef TIZEN_WEARABLE API int efl_util_set_window_screen_mode_error_cb(Evas_Object *window, efl_util_window_screen_mode_error_cb callback, void *user_data) { + /* Wearable device cannot use this. */ + if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE) + return EFL_UTIL_ERROR_NO_SUCH_DEVICE; + dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: efl_util_set_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead."); @@ -1058,6 +1222,10 @@ efl_util_set_window_screen_mode_error_cb(Evas_Object *window, API int efl_util_unset_window_screen_mode_error_cb(Evas_Object *window) { + /* Wearable device cannot use this. */ + if (get_tizen_profile() == TIZEN_PROFILE_WEARABLE) + return EFL_UTIL_ERROR_NO_SUCH_DEVICE; + dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: efl_util_unset_window_screen_mode_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_window_screen_mode() instead."); @@ -1070,12 +1238,11 @@ efl_util_unset_window_screen_mode_error_cb(Evas_Object *window) return EFL_UTIL_ERROR_NONE; } -#endif API int efl_util_set_window_brightness(Evas_Object *window, int brightness) { - Ecore_Wl_Window *wlwin; + Ecore_Wl2_Window *wlwin; struct wl_surface *surface; Efl_Util_Wl_Surface_Brightness_Info *brightness_info; Eina_Bool res; @@ -1086,13 +1253,13 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) res = _wl_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - wlwin = elm_win_wl_window_get(window); + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (wlwin) { while (!_eflutil.wl.display_policy.proto) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - surface = ecore_wl_window_surface_get(wlwin); + surface = ecore_wl2_window_surface_get(wlwin); EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER); @@ -1125,7 +1292,7 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) int count = 0; while (brightness_info->wait_for_done && (count < 3)) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); count++; } @@ -1151,7 +1318,7 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) API int efl_util_get_window_brightness(Evas_Object *window, int *brightness) { - Ecore_Wl_Window *wlwin; + Ecore_Wl2_Window *wlwin; struct wl_surface *surface; Efl_Util_Wl_Surface_Brightness_Info *brightness_info; Eina_Bool res; @@ -1162,13 +1329,13 @@ efl_util_get_window_brightness(Evas_Object *window, int *brightness) res = _wl_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - wlwin = elm_win_wl_window_get(window); + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER; while (!_eflutil.wl.display_policy.proto) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - surface = ecore_wl_window_surface_get(wlwin); + surface = ecore_wl2_window_surface_get(wlwin); EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER); @@ -1179,7 +1346,7 @@ efl_util_get_window_brightness(Evas_Object *window, int *brightness) { while (brightness_info->wait_for_done) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); } } @@ -1195,6 +1362,7 @@ efl_util_get_window_brightness(Evas_Object *window, int *brightness) struct _efl_util_inputgen_h { unsigned int init_type; + char name[32]; }; static void @@ -1261,6 +1429,72 @@ efl_util_input_initialize_generator(unsigned int dev_type) { int ret = EFL_UTIL_ERROR_NONE; efl_util_inputgen_h inputgen_h = NULL; + unsigned int clas = 0x0; + + if (!dev_type || + dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN + | EFL_UTIL_INPUT_DEVTYPE_KEYBOARD + | EFL_UTIL_INPUT_DEVTYPE_POINTER)) + { + set_last_result(EFL_UTIL_ERROR_NO_SUCH_DEVICE); + goto out; + } + + inputgen_h = (efl_util_inputgen_h)calloc(1, sizeof(struct _efl_util_inputgen_h)); + if (!inputgen_h) + { + set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); + goto out; + } + + inputgen_h->init_type |= dev_type; + + ret = _wl_init(); + if (ret == (int)EINA_FALSE) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + goto out; + } + + if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN; + if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD; + if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE; + + while (!_eflutil.wl.devmgr.devicemgr) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr, clas); + + while (_eflutil.wl.devmgr.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); + _eflutil.wl.devmgr.request_notified = -1; + + set_last_result(ret); + if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) + goto out; + + return inputgen_h; + +out: + if (inputgen_h) + { + free(inputgen_h); + inputgen_h = NULL; + } + return NULL; +} + +API efl_util_inputgen_h +efl_util_input_initialize_generator_with_name(unsigned int dev_type, const char *name) +{ + int ret = EFL_UTIL_ERROR_NONE; + efl_util_inputgen_h inputgen_h = NULL; + unsigned int clas = 0x0; if (!dev_type || dev_type & ~(EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN @@ -1279,6 +1513,7 @@ efl_util_input_initialize_generator(unsigned int dev_type) } inputgen_h->init_type |= dev_type; + strncpy(inputgen_h->name, name, 31); ret = _wl_init(); if (ret == (int)EINA_FALSE) @@ -1287,10 +1522,17 @@ efl_util_input_initialize_generator(unsigned int dev_type) goto out; } + if (dev_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN; + if (dev_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD; + if (dev_type & EFL_UTIL_INPUT_DEVTYPE_POINTER) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE; + while (!_eflutil.wl.devmgr.devicemgr) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - tizen_input_device_manager_init_generator(_eflutil.wl.devmgr.devicemgr); + tizen_input_device_manager_init_generator_with_name(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name); while (_eflutil.wl.devmgr.request_notified == -1) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); @@ -1313,18 +1555,27 @@ out: return NULL; } + API int efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h) { int ret = EFL_UTIL_ERROR_NONE; + unsigned int clas = 0x0; EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN; + if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD; + if (inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER) + clas |= TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE; + free(inputgen_h); inputgen_h = NULL; EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); - tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr); + tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr, clas); while (_eflutil.wl.devmgr.request_notified == -1) wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); @@ -1447,10 +1698,63 @@ struct _efl_util_screenshot_h /* tbm bufmgr */ tbm_bufmgr bufmgr; + + Eina_Bool auto_rotation; }; /* scrrenshot handle */ static efl_util_screenshot_h g_screenshot; +static Eina_Bool shot_mutex_init; +static pthread_mutex_t shot_lock; + +static Eina_Bool +_screenshot_mutex_init(void) +{ + if (shot_mutex_init) + return EINA_TRUE; + + if (pthread_mutex_init(&shot_lock, NULL)) + { + fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/ + return EINA_FALSE; /*LCOV_EXCL_LINE*/ + } + + shot_mutex_init = EINA_TRUE; + + return EINA_TRUE; +} + +static Eina_Bool +_screenshot_mutex_destory(void) +{ + if (!shot_mutex_init) + return EINA_TRUE; + + if (pthread_mutex_destroy(&shot_lock)) + { + fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/ + return EINA_FALSE; /*LCOV_EXCL_LINE*/ + } + + shot_mutex_init = EINA_FALSE; + + return EINA_TRUE; +} + +void +_screenshot_mutex_lock(void) +{ + if (!_screenshot_mutex_init()) + return; + + pthread_mutex_lock(&shot_lock); +} + +void +_screenshot_mutex_unlock(void) +{ + pthread_mutex_unlock(&shot_lock); +} API efl_util_screenshot_h efl_util_screenshot_initialize(int width, int height) @@ -1463,27 +1767,32 @@ efl_util_screenshot_initialize(int width, int height) EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param); EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param); + _screenshot_mutex_lock(); + if (!_eflutil.wl.shot.screenshooter) { ret = _wl_init(); if (ret == (int)EINA_FALSE) { set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + _screenshot_mutex_unlock(); return NULL; } wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy); - EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init); + EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_memory); _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_init); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_memory); + + wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue); reg = wl_display_get_registry(display_wrapper); + wl_proxy_wrapper_destroy(display_wrapper); + display_wrapper = NULL; EINA_SAFETY_ON_NULL_GOTO(reg, fail_init); - wl_proxy_set_queue((struct wl_proxy*)reg, _eflutil.wl.shot.queue); - wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL); ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); @@ -1509,6 +1818,8 @@ efl_util_screenshot_initialize(int width, int height) g_screenshot->height = height; } + _screenshot_mutex_unlock(); + return g_screenshot; } @@ -1517,6 +1828,7 @@ efl_util_screenshot_initialize(int width, int height) screenshot->width = width; screenshot->height = height; + screenshot->auto_rotation = EINA_TRUE; screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client); EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init); @@ -1526,6 +1838,8 @@ efl_util_screenshot_initialize(int width, int height) screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done); + _screenshot_mutex_unlock(); + return g_screenshot; fail_param: @@ -1537,21 +1851,26 @@ fail_memory: wl_proxy_wrapper_destroy(display_wrapper); set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); return NULL; -/* LCOV_EXCL_STOP */ fail_init: if (screenshot) efl_util_screenshot_deinitialize(screenshot); - if (display_wrapper) - wl_proxy_wrapper_destroy(display_wrapper); + _screenshot_mutex_unlock(); set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL); return NULL; +/* LCOV_EXCL_STOP */ } API int efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot) { + _screenshot_mutex_lock(); + if (!screenshot) - return EFL_UTIL_ERROR_INVALID_PARAMETER; + { + _screenshot_mutex_unlock(); + _screenshot_mutex_destory(); + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } free(screenshot); g_screenshot = NULL; @@ -1573,6 +1892,9 @@ efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot) _eflutil.wl.shot.tz_screenshooter = NULL; } + _screenshot_mutex_unlock(); + _screenshot_mutex_destory(); + return EFL_UTIL_ERROR_NONE; } @@ -1585,9 +1907,12 @@ efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot) Efl_Util_Wl_Output_Info *output; int ret = 0; + _screenshot_mutex_lock(); + if (!screenshot || (screenshot != g_screenshot)) { set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + _screenshot_mutex_unlock(); return NULL; } @@ -1629,6 +1954,10 @@ efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot) /* reset shot_done for next screenshot */ screenshot->shot_done = EINA_FALSE; + set_last_result(EFL_UTIL_ERROR_NONE); + + _screenshot_mutex_unlock(); + return t_surface; fail: @@ -1639,5 +1968,979 @@ fail: set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL); + _screenshot_mutex_unlock(); + return NULL; } + +/* LCOV_EXCL_START */ +API int +efl_util_screenshot_set_auto_rotation(efl_util_screenshot_h screenshot, int set) +{ + if (!screenshot || (screenshot != g_screenshot)) + return EFL_UTIL_ERROR_INVALID_PARAMETER; + + if (!(set == 0 || set == 1)) + return EFL_UTIL_ERROR_INVALID_PARAMETER; + + if (set) + g_screenshot->auto_rotation = EINA_TRUE; + else + g_screenshot->auto_rotation = EINA_FALSE; + + tizen_screenshooter_set_oneshot_auto_rotation(_eflutil.wl.shot.tz_screenshooter, g_screenshot->auto_rotation); + + return EFL_UTIL_ERROR_NONE; +} + +API int +efl_util_screenshot_get_auto_rotation(efl_util_screenshot_h screenshot, int *set) +{ + if (!screenshot || (screenshot != g_screenshot) || !set) + return EFL_UTIL_ERROR_INVALID_PARAMETER; + + *set = g_screenshot->auto_rotation; + + return EFL_UTIL_ERROR_NONE; +} +/* LCOV_EXCL_STOP */ + +struct _efl_util_gesture_h +{ + Eina_Bool init; +}; + +API int EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = 0; +API int EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0; +API int EFL_UTIL_EVENT_GESTURE_TAP = 0; +API int EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0; + +/* LCOV_EXCL_START */ +static void +_cb_gesture_edge_swipe_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t edge EINA_UNUSED, uint32_t edge_size EINA_UNUSED, uint32_t start_point EINA_UNUSED, uint32_t end_point EINA_UNUSED, uint32_t error) +{ + _eflutil.wl.gesture.request_notified = error; +} + +static void +_cb_gesture_edge_swipe(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, int sx, int sy, uint32_t edge) +{ + efl_util_event_gesture_edge_swipe_s *ev = NULL; + + ev = (efl_util_event_gesture_edge_swipe_s *)calloc(1, sizeof(*ev)); + if (!ev) return; + + ev->mode = mode; + + ev->fingers = fingers; + ev->sx = sx; + ev->sy = sy; + ev->edge = edge; + + ecore_event_add(EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE, ev, NULL, NULL); +} + +static void +_cb_gesture_edge_drag_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t edge EINA_UNUSED, uint32_t edge_size EINA_UNUSED, uint32_t start_point EINA_UNUSED, uint32_t end_point EINA_UNUSED, uint32_t error) +{ + _eflutil.wl.gesture.request_notified = error; +} + +static void +_cb_gesture_edge_drag(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, int cx, int cy, uint32_t edge) +{ + efl_util_event_gesture_edge_drag_s *ev = NULL; + + ev = (efl_util_event_gesture_edge_drag_s *)calloc(1, sizeof(*ev)); + if (!ev) return; + + ev->mode = mode; + + ev->fingers = fingers; + ev->cx = cx; + ev->cy = cy; + ev->edge = edge; + + ecore_event_add(EFL_UTIL_EVENT_GESTURE_EDGE_DRAG, ev, NULL, NULL); +} + +static void +_cb_gesture_tap_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t fingers EINA_UNUSED, uint32_t repeat EINA_UNUSED, uint32_t error) +{ + _eflutil.wl.gesture.request_notified = error; +} + +static void +_cb_gesture_tap(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, uint32_t mode, uint32_t fingers, uint32_t repeats) +{ + efl_util_event_gesture_tap_s *ev = NULL; + + ev = (efl_util_event_gesture_tap_s *)calloc(1, sizeof(*ev)); + if (!ev) return; + + ev->mode = mode; + + ev->fingers = fingers; + ev->repeats = repeats; + + ecore_event_add(EFL_UTIL_EVENT_GESTURE_TAP, ev, NULL, NULL); +} +/* LCOV_EXCL_STOP */ + +static void +_cb_gesture_palm_cover_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface EINA_UNUSED, uint32_t error) +{ + _eflutil.wl.gesture.request_notified = error; +} + +/* LCOV_EXCL_START */ +static void +_cb_gesture_palm_cover(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface, uint32_t mode, uint32_t duration, int cx, int cy, uint32_t size, wl_fixed_t pressure) +{ + efl_util_event_gesture_palm_cover_s *ev = NULL; + + ev = (efl_util_event_gesture_palm_cover_s *)calloc(1, sizeof(*ev)); + if (!ev) return; + + ev->mode = mode; + + ev->duration = duration; + ev->cx = cx; + ev->cy = cy; + ev->size = size; + ev->pressure = wl_fixed_to_int(pressure); + + ecore_event_add(EFL_UTIL_EVENT_GESTURE_PALM_COVER, ev, NULL, NULL); +} +/* LCOV_EXCL_STOP */ + +static void +_cb_gesture_activate_notify(void *data EINA_UNUSED, struct tizen_gesture *tizen_gesture EINA_UNUSED, struct wl_surface *surface EINA_UNUSED, uint32_t type EINA_UNUSED, uint32_t active EINA_UNUSED, uint32_t error) +{ + _eflutil.wl.gesture.request_notified = error; +} + +static efl_util_error_e +_efl_util_gesture_convert_error(int ret) +{ + switch (ret) + { + case TIZEN_GESTURE_ERROR_NONE: + return EFL_UTIL_ERROR_NONE; + case TIZEN_GESTURE_ERROR_INVALID_DATA: + return EFL_UTIL_ERROR_INVALID_PARAMETER; + case TIZEN_GESTURE_ERROR_NO_PERMISSION: + return EFL_UTIL_ERROR_PERMISSION_DENIED; + case TIZEN_GESTURE_ERROR_NO_SYSTEM_RESOURCES: + return EFL_UTIL_ERROR_OUT_OF_MEMORY; + case TIZEN_GESTURE_ERROR_GRABBED_ALREADY: + return EFL_UTIL_ERROR_NO_RESOURCE_AVAILABLE; + case TIZEN_GESTURE_ERROR_NOT_SUPPORTED: + return EFL_UTIL_ERROR_NOT_SUPPORTED; + default : + return EFL_UTIL_ERROR_NONE; + } +} + +/* LCOV_EXCL_START */ +static int +_efl_util_gesture_grab_edge_swipe(efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = NULL; + unsigned int fingers = 0; + unsigned int edge = 0; + unsigned int edge_size = 0; + unsigned int start_point = 0; + unsigned int end_point = 0; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_SWIPE, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + edge_swipe_data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)data; + + fingers = edge_swipe_data->fingers; + edge = edge_swipe_data->edge; + edge_size = edge_swipe_data->edge_size; + start_point = edge_swipe_data->start_point; + end_point = edge_swipe_data->end_point; + + tizen_gesture_grab_edge_swipe(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +static int +_efl_util_gesture_ungrab_edge_swipe(efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = NULL; + unsigned int fingers = 0; + unsigned int edge = 0; + unsigned int edge_size = 0; + unsigned int start_point = 0; + unsigned int end_point = 0; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_SWIPE, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + edge_swipe_data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)data; + + fingers = edge_swipe_data->fingers; + edge = edge_swipe_data->edge; + edge_size = edge_swipe_data->edge_size; + start_point = edge_swipe_data->start_point; + end_point = edge_swipe_data->end_point; + + tizen_gesture_ungrab_edge_swipe(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +static int +_efl_util_gesture_grab_edge_drag(efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = NULL; + unsigned int fingers = 0; + unsigned int edge = 0; + unsigned int edge_size = 0; + unsigned int start_point = 0; + unsigned int end_point = 0; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_DRAG, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + edge_drag_data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)data; + + fingers = edge_drag_data->fingers; + edge = edge_drag_data->edge; + edge_size = edge_drag_data->edge_size; + start_point = edge_drag_data->start_point; + end_point = edge_drag_data->end_point; + + tizen_gesture_grab_edge_drag(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +static int +_efl_util_gesture_ungrab_edge_drag(efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = NULL; + unsigned int fingers = 0; + unsigned int edge = 0; + unsigned int edge_size = 0; + unsigned int start_point = 0; + unsigned int end_point = 0; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_EDGE_DRAG, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + edge_drag_data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)data; + + fingers = edge_drag_data->fingers; + edge = edge_drag_data->edge; + edge_size = edge_drag_data->edge_size; + start_point = edge_drag_data->start_point; + end_point = edge_drag_data->end_point; + + tizen_gesture_ungrab_edge_drag(_eflutil.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + + +static int +_efl_util_gesture_grab_tap(efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + Efl_Util_Gesture_Tap_Grab_Data *tap_data = NULL; + unsigned int fingers = 0; + unsigned int repeats = 0; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_TAP, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + tap_data = (Efl_Util_Gesture_Tap_Grab_Data *)data; + + fingers = tap_data->fingers; + repeats = tap_data->repeats; + + tizen_gesture_grab_tap(_eflutil.wl.gesture.proto, fingers, repeats); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +static int +_efl_util_gesture_ungrab_tap(efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + Efl_Util_Gesture_Tap_Grab_Data *tap_data = NULL; + unsigned int fingers = 0; + unsigned int repeats = 0; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_TAP, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + tap_data = (Efl_Util_Gesture_Tap_Grab_Data *)data; + + fingers = tap_data->fingers; + repeats = tap_data->repeats; + + tizen_gesture_ungrab_tap(_eflutil.wl.gesture.proto, fingers, repeats); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +static int +_efl_util_gesture_grab_palm_cover(efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_PALM_COVER, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + tizen_gesture_grab_palm_cover(_eflutil.wl.gesture.proto); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +static int +_efl_util_gesture_ungrab_palm_cover(efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.gesture.proto, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(base_data->type == TIZEN_GESTURE_TYPE_PALM_COVER, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + tizen_gesture_ungrab_palm_cover(_eflutil.wl.gesture.proto); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +static Eina_Bool +_efl_util_fd_cb(void *data, Ecore_Fd_Handler *hdl) +{ + if (_eflutil.wl.dpy && _eflutil.wl.queue) + { + wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + return ECORE_CALLBACK_RENEW; + } + else + { + return ECORE_CALLBACK_CANCEL; + } +} +/* LCOV_EXCL_STOP */ + +API efl_util_gesture_h +efl_util_gesture_initialize(void) +{ + efl_util_gesture_h gesture_h = NULL; + int dpy_fd = -1; + + gesture_h = (efl_util_gesture_h)calloc(1, sizeof(struct _efl_util_gesture_h)); + if (!gesture_h) + { + set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */ + goto out; /* LCOV_EXCL_LINE */ + } + + if (_wl_init() == (int)EINA_FALSE) + { + set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */ + goto out; /* LCOV_EXCL_LINE */ + } + + while (!_eflutil.wl.gesture.proto) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); /* LCOV_EXCL_LINE */ + + if (_eflutil.wl.gesture.event_init <= 0) + { + if (ecore_event_init() <= 0) + { + set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */ + goto out; /* LCOV_EXCL_LINE */ + } + EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = ecore_event_type_new(); + EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = ecore_event_type_new(); + EFL_UTIL_EVENT_GESTURE_TAP = ecore_event_type_new(); + EFL_UTIL_EVENT_GESTURE_PALM_COVER = ecore_event_type_new(); + + dpy_fd = wl_display_get_fd(_eflutil.wl.dpy); + _eflutil.wl.dpy_fd = fcntl(dpy_fd, F_DUPFD_CLOEXEC, 0); + if (_eflutil.wl.dpy_fd >= 0) + _eflutil.wl.fd_hdl = ecore_main_fd_handler_add(_eflutil.wl.dpy_fd, + ECORE_FD_READ | ECORE_FD_WRITE | ECORE_FD_ERROR, + _efl_util_fd_cb, NULL, + NULL, NULL); + } + _eflutil.wl.gesture.event_init++; + gesture_h->init = EINA_TRUE; + + set_last_result(EFL_UTIL_ERROR_NONE); + return gesture_h; + +out: +/* LCOV_EXCL_START */ + if (gesture_h) + { + free(gesture_h); + gesture_h = NULL; + } + return gesture_h; +/* LCOV_EXCL_STOP */ +} + +API int +efl_util_gesture_deinitialize(efl_util_gesture_h gesture_h) +{ + EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER); + + free(gesture_h); + gesture_h = NULL; + + _eflutil.wl.gesture.event_init--; + + if (_eflutil.wl.gesture.event_init <= 0) + { + _eflutil.wl.gesture.event_init = 0; + ecore_event_shutdown(); + EFL_UTIL_EVENT_GESTURE_EDGE_SWIPE = 0; + EFL_UTIL_EVENT_GESTURE_EDGE_DRAG = 0; + EFL_UTIL_EVENT_GESTURE_TAP = 0; + EFL_UTIL_EVENT_GESTURE_PALM_COVER = 0; + if (_eflutil.wl.dpy_fd >= 0) + { + ecore_main_fd_handler_del(_eflutil.wl.fd_hdl); + _eflutil.wl.fd_hdl = NULL; + close(_eflutil.wl.dpy_fd); + _eflutil.wl.dpy_fd = -1; + } + } + + return EFL_UTIL_ERROR_NONE; +} + +API efl_util_gesture_data +efl_util_gesture_edge_swipe_new(efl_util_gesture_h gesture_h, unsigned int fingers, efl_util_gesture_edge_e edge) +{ + Efl_Util_Gesture_Edge_Swipe_Grab_Data *data; + + if (!gesture_h || gesture_h->init == EINA_FALSE) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (edge <= EFL_UTIL_GESTURE_EDGE_NONE || edge > EFL_UTIL_GESTURE_EDGE_LEFT) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + return NULL; + } + + data = (Efl_Util_Gesture_Edge_Swipe_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Edge_Swipe_Grab_Data)); + if (!data) + { + set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */ + return NULL; /* LCOV_EXCL_LINE */ + } + + data->base.type = TIZEN_GESTURE_TYPE_EDGE_SWIPE; + data->fingers = fingers; + data->edge = edge; + data->edge_size = EFL_UTIL_GESTURE_EDGE_SIZE_FULL; + + set_last_result(EFL_UTIL_ERROR_NONE); + + return (void *)data; +} + +API int +efl_util_gesture_edge_swipe_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data) +{ + if (!gesture_h || gesture_h->init == EINA_FALSE) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + if (!data) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + free(data); + data = NULL; + + return EFL_UTIL_ERROR_NONE; +} + +API int +efl_util_gesture_edge_swipe_size_set(efl_util_gesture_data data, efl_util_gesture_edge_size_e edge_size, unsigned int start_point, unsigned int end_point) +{ + Efl_Util_Gesture_Edge_Swipe_Grab_Data *edge_swipe_data = data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(edge_swipe_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_swipe_data->base.type == TIZEN_GESTURE_TYPE_EDGE_SWIPE, + EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_size == EFL_UTIL_GESTURE_EDGE_SIZE_PARTIAL, + EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(end_point > start_point, EFL_UTIL_ERROR_INVALID_PARAMETER); + + edge_swipe_data->edge_size = edge_size; + edge_swipe_data->start_point = start_point; + edge_swipe_data->end_point = end_point; + + return EFL_UTIL_ERROR_NONE; +} + +API efl_util_gesture_data +efl_util_gesture_edge_drag_new(efl_util_gesture_h gesture_h, unsigned int fingers, efl_util_gesture_edge_e edge) +{ + Efl_Util_Gesture_Edge_Drag_Grab_Data *data; + + if (!gesture_h || gesture_h->init == EINA_FALSE) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (edge <= EFL_UTIL_GESTURE_EDGE_NONE || edge > EFL_UTIL_GESTURE_EDGE_LEFT) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + return NULL; + } + + data = (Efl_Util_Gesture_Edge_Drag_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Edge_Drag_Grab_Data)); + if (!data) + { + set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */ + return NULL; /* LCOV_EXCL_LINE */ + } + + data->base.type = TIZEN_GESTURE_TYPE_EDGE_DRAG; + data->fingers = fingers; + data->edge = edge; + data->edge_size = EFL_UTIL_GESTURE_EDGE_SIZE_FULL; + + set_last_result(EFL_UTIL_ERROR_NONE); + + return (void *)data; +} + +API int +efl_util_gesture_edge_drag_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data) +{ + if (!gesture_h || gesture_h->init == EINA_FALSE) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + if (!data) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + free(data); + data = NULL; + + return EFL_UTIL_ERROR_NONE; +} + +API int +efl_util_gesture_edge_drag_size_set(efl_util_gesture_data data, efl_util_gesture_edge_size_e edge_size, unsigned int start_point, unsigned int end_point) +{ + Efl_Util_Gesture_Edge_Drag_Grab_Data *edge_drag_data = data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(edge_drag_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_drag_data->base.type == TIZEN_GESTURE_TYPE_EDGE_DRAG, + EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(edge_size == EFL_UTIL_GESTURE_EDGE_SIZE_PARTIAL, + EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(end_point > start_point, EFL_UTIL_ERROR_INVALID_PARAMETER); + + edge_drag_data->edge_size = edge_size; + edge_drag_data->start_point = start_point; + edge_drag_data->end_point = end_point; + + return EFL_UTIL_ERROR_NONE; +} + +API efl_util_gesture_data +efl_util_gesture_tap_new(efl_util_gesture_h gesture_h, unsigned int fingers, unsigned int repeats) +{ + Efl_Util_Gesture_Tap_Grab_Data *data; + + if (!gesture_h || gesture_h->init == EINA_FALSE) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + return NULL; + } + + if (fingers <= 1 || repeats <= 1) + { + set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); + return NULL; + } + + data = (Efl_Util_Gesture_Tap_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Tap_Grab_Data)); + if (!data) + { + set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */ + return NULL; /* LCOV_EXCL_LINE */ + } + + data->base.type = TIZEN_GESTURE_TYPE_TAP; + data->fingers = fingers; + data->repeats = repeats; + + set_last_result(EFL_UTIL_ERROR_NONE); + + return (void *)data; +} + +API int +efl_util_gesture_tap_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data) +{ + if (!gesture_h || gesture_h->init == EINA_FALSE) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + if (!data) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + free(data); + data = NULL; + + return EFL_UTIL_ERROR_NONE; +} + +API efl_util_gesture_data +efl_util_gesture_palm_cover_new(efl_util_gesture_h gesture_h) +{ + Efl_Util_Gesture_Palm_Cover_Grab_Data *data; + + if (!gesture_h || gesture_h->init == EINA_FALSE) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + return NULL; + } + + data = (Efl_Util_Gesture_Palm_Cover_Grab_Data *)calloc(1, sizeof(Efl_Util_Gesture_Palm_Cover_Grab_Data)); + if (!data) + { + set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); /* LCOV_EXCL_LINE */ + return NULL; /* LCOV_EXCL_LINE */ + } + + data->base.type = TIZEN_GESTURE_TYPE_PALM_COVER; + + set_last_result(EFL_UTIL_ERROR_NONE); + + return (void *)data; +} + +API int +efl_util_gesture_palm_cover_free(efl_util_gesture_h gesture_h, efl_util_gesture_data data) +{ + if (!gesture_h || gesture_h->init == EINA_FALSE) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + if (!data) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + free(data); + data = NULL; + + return EFL_UTIL_ERROR_NONE; +} + +/* LCOV_EXCL_START */ +API int +efl_util_gesture_grab(efl_util_gesture_h gesture_h, efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + + switch (base_data->type) + { + case TIZEN_GESTURE_TYPE_EDGE_SWIPE: + ret = _efl_util_gesture_grab_edge_swipe(data); + break; + case TIZEN_GESTURE_TYPE_EDGE_DRAG: + ret = _efl_util_gesture_grab_edge_drag(data); + break; + case TIZEN_GESTURE_TYPE_TAP: + ret = _efl_util_gesture_grab_tap(data); + break; + case TIZEN_GESTURE_TYPE_PALM_COVER: + ret = _efl_util_gesture_grab_palm_cover(data); + break; + default: + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + return ret; +} + +API int +efl_util_gesture_ungrab(efl_util_gesture_h gesture_h, efl_util_gesture_data data) +{ + int ret = EFL_UTIL_ERROR_NONE; + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + + switch (base_data->type) + { + case TIZEN_GESTURE_TYPE_EDGE_SWIPE: + ret = _efl_util_gesture_ungrab_edge_swipe(data); + break; + case TIZEN_GESTURE_TYPE_EDGE_DRAG: + ret = _efl_util_gesture_ungrab_edge_drag(data); + break; + case TIZEN_GESTURE_TYPE_TAP: + ret = _efl_util_gesture_ungrab_tap(data); + break; + case TIZEN_GESTURE_TYPE_PALM_COVER: + ret = _efl_util_gesture_ungrab_palm_cover(data); + break; + default: + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + return ret; +} +/* LCOV_EXCL_STOP */ + +API int +efl_util_gesture_select(efl_util_gesture_h gesture_h, Evas_Object *window, efl_util_gesture_data data) +{ + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + Ecore_Wl2_Window *wlwin; + struct wl_surface *surface; + int ret; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + + if (base_data->type != TIZEN_GESTURE_TYPE_PALM_COVER) + return EFL_UTIL_ERROR_NOT_SUPPORTED; + + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); + if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER; + + surface = ecore_wl2_window_surface_get(wlwin); + EINA_SAFETY_ON_NULL_RETURN_VAL(surface, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + tizen_gesture_select_palm_cover(_eflutil.wl.gesture.proto, surface); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +API int +efl_util_gesture_deselect(efl_util_gesture_h gesture_h, Evas_Object *window, efl_util_gesture_data data) +{ + Efl_Util_Gesture_Common_Grab_Data *base_data = NULL; + Ecore_Wl2_Window *wlwin; + struct wl_surface *surface; + int ret; + + base_data = (Efl_Util_Gesture_Common_Grab_Data *)data; + + EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(base_data, EFL_UTIL_ERROR_INVALID_PARAMETER); + + if (base_data->type != TIZEN_GESTURE_TYPE_PALM_COVER) + return EFL_UTIL_ERROR_NOT_SUPPORTED; + + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); + if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER; + + surface = ecore_wl2_window_surface_get(wlwin); + EINA_SAFETY_ON_NULL_RETURN_VAL(surface, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + tizen_gesture_deselect_palm_cover(_eflutil.wl.gesture.proto, surface); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} + +/* LCOV_EXCL_START */ +API int +efl_util_gesture_activate_set(efl_util_gesture_h gesture_h, unsigned int type, Eina_Bool active) +{ + int ret; + + EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_TRUE_RETURN_VAL(type == EFL_UTIL_GESTURE_TYPE_NONE, EFL_UTIL_ERROR_INVALID_PARAMETER); + + tizen_gesture_activate_set(_eflutil.wl.gesture.proto, NULL, type, active); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +} +/* LCOV_EXCL_STOP */ + +API int +efl_util_gesture_activate_set_on_window(efl_util_gesture_h gesture_h, Evas_Object *window, unsigned int type, Eina_Bool active) +{ + Ecore_Wl2_Window *wlwin; + struct wl_surface *surface; + int ret; + + EINA_SAFETY_ON_NULL_RETURN_VAL(gesture_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(gesture_h->init, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_TRUE_RETURN_VAL(type == EFL_UTIL_GESTURE_TYPE_NONE, EFL_UTIL_ERROR_INVALID_PARAMETER); + + wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); + if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER; + + surface = ecore_wl2_window_surface_get(wlwin); + EINA_SAFETY_ON_NULL_RETURN_VAL(surface, + EFL_UTIL_ERROR_INVALID_PARAMETER); + + tizen_gesture_activate_set(_eflutil.wl.gesture.proto, surface, type, active); + + while (_eflutil.wl.gesture.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + ret = _efl_util_gesture_convert_error(_eflutil.wl.gesture.request_notified); + _eflutil.wl.gesture.request_notified = -1; + + return ret; +}