X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fefl_util.c;h=0f7794d1e37aa5ffbac94a4ba77ad303314d0ca0;hb=10a3cb4c1743f190bf772a76ed03c239ad01d285;hp=fd15f7e3607fd8684c3a1f93ab7c633c06b7fe7e;hpb=1d4effc0d6da7c8ea2634993521ad24c93c15cb3;p=platform%2Fcore%2Fapi%2Fefl-util.git diff --git a/src/efl_util.c b/src/efl_util.c index fd15f7e..0f7794d 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. @@ -14,6 +14,8 @@ * limitations under the License. */ +#define _GNU_SOURCE + #define LOG_TAG "TIZEN_N_EFL_UTIL" #include @@ -30,12 +32,14 @@ #include #include #include +#include -#include +#include #include #include #include -#include + +#include #include #ifdef LOG_TAG @@ -43,21 +47,9 @@ #endif #define LOG_TAG "TIZEN_N_EFL_UTIL" +#define EFL_UTIL_INPUT_GENERATOR_TOUCH_MAX_FINGER 10 - -/* callback handler index */ -#define CBH_NOTI_LEV 0 -#define CBH_SCR_MODE 1 -#define CBH_MAX 2 - -typedef void (*Efl_Util_Cb)(Evas_Object *, int, void *); - -typedef struct _Efl_Util_Callback_Info -{ - Evas_Object *win; - Efl_Util_Cb cb; - void *data; -} Efl_Util_Callback_Info; +#define NUM_EVENT_WAIT_DONE_COUNT 10 typedef struct _Efl_Util_Wl_Surface_Lv_Info { @@ -89,69 +81,149 @@ 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 _E_Devicemgr_Inputgen_Touch_Axis +{ + double radius_x; + double radius_y; + double pressure; + double angle; + double palm; +} E_Devicemgr_Inputgen_Touch_Axis; + 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; struct { + unsigned int id; struct tizen_policy *proto; Eina_Hash *hash_noti_lv; Eina_Hash *hash_scr_mode; } policy; struct { - struct screenshooter *screenshooter; + struct wl_event_queue *queue; + struct tizen_screenshooter *tz_screenshooter; struct wayland_tbm_client *tbm_client; Eina_List *output_list; + uint32_t noti; } shot; struct { struct tizen_input_device_manager *devicemgr; int request_notified; + Eina_List *devices; + Eina_List *wait_devices; + struct wl_event_source *wait_timer; + int max_touch_count; + int request_touch_count; } devmgr; struct { + unsigned int id; struct tizen_display_policy *proto; Eina_Hash *hash_brightness; } display_policy; } wl; +} Efl_Util_Data; +typedef struct _Efl_Util_Data_Default_Queue +{ + /* wayland related stuffs */ struct { - Eina_List *info_list; /* list of callback info */ - unsigned int atom; /* x11 atom */ - } cb_handler[CBH_MAX]; -} Efl_Util_Data; + Eina_Bool init; + Ecore_Wl2_Display *wl2_display; + struct wl_display *dpy; + + struct + { + unsigned int id; + struct tizen_gesture *proto; + int request_notified; + int event_init; + } gesture; + } wl; +} Efl_Util_Data_Default_Queue; + static Efl_Util_Data _eflutil = { { EINA_FALSE, - NULL, NULL, - { NULL, NULL, NULL }, /* tizen_policy protocol */ - { NULL, NULL, NULL }, /* screenshooter protocol */ - { NULL, -1 } /* tizen_input_device_manager protocol */ + NULL, NULL, NULL, + { 0, NULL, NULL, NULL }, /* tizen_policy protocol */ + { NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */ + { NULL, -1, NULL, NULL, NULL, 0, 0 }, /* tizen_input_device_manager protocol */ + { 0, NULL, NULL } /* display_policy protocol */ }, +}; + +static Efl_Util_Data_Default_Queue _eflutil_defaultqueue = +{ { - { NULL, 0 }, /* handler for notification level */ - { NULL, 0 } /* handler for screen mode */ + EINA_FALSE, + NULL, NULL, + { 0, NULL, -1, 0 } /* gesture protocol */ }, }; -static Eina_Bool _cb_info_add(Evas_Object *win, Efl_Util_Cb cb, void *data, int idx); -static Eina_Bool _cb_info_del_by_win(Evas_Object *win, int idx); -static Eina_List *_cb_info_list_get(int idx); -static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx); + static Eina_Bool _wl_init(void); +static Eina_Bool _wl_init_default_queue(void); static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version); static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name); -static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx); +static void _cb_wl_default_queue_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version); +static void _cb_wl_default_queue_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name); +static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version); +static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name); static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant); static void _cb_wl_tz_policy_conformant_area(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); static void _cb_wl_tz_policy_notification_done(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, int32_t level, uint32_t state); @@ -161,6 +233,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); @@ -168,6 +241,18 @@ static void _cb_device_add(void *data EINA_UNUSED, struct tiz static void _cb_device_remove(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, struct tizen_input_device *device EINA_UNUSED, struct wl_seat *seat EINA_UNUSED); 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_max_touch_count(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, int32_t max_count EINA_UNUSED, struct wl_seat *seat 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 = { @@ -175,6 +260,12 @@ static const struct wl_registry_listener _wl_reg_listener = _cb_wl_reg_global_remove }; +static const struct wl_registry_listener _wl_reg_screenshooter_listener = +{ + _cb_wl_reg_screenshooter_global, + _cb_wl_reg_screenshooter_global_remove +}; + struct tizen_policy_listener _wl_tz_policy_listener = { _cb_wl_tz_policy_conformant, @@ -186,6 +277,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 = @@ -193,7 +285,8 @@ struct tizen_input_device_manager_listener _wl_tz_devmgr_listener = _cb_device_add, _cb_device_remove, _cb_error, - _cb_block_expired + _cb_block_expired, + _cb_max_touch_count }; struct tizen_display_policy_listener _wl_tz_display_policy_listener = @@ -201,108 +294,103 @@ struct tizen_display_policy_listener _wl_tz_display_policy_listener = _cb_wl_tz_display_policy_brightness_done, }; -static Eina_Bool -_cb_info_add(Evas_Object *win, - Efl_Util_Cb cb, - void *data, - int idx) +static const struct wl_registry_listener _wl_default_queue_reg_listener = { - Efl_Util_Callback_Info *info; + _cb_wl_default_queue_reg_global, + _cb_wl_default_queue_reg_global_remove +}; - info = _cb_info_find_by_win(win, idx); - if (info) - { - _eflutil.cb_handler[idx].info_list - = eina_list_remove(_eflutil.cb_handler[idx].info_list, - info); - free(info); - } +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 +}; - info = (Efl_Util_Callback_Info *)calloc(1, sizeof(Efl_Util_Callback_Info)); - if (!info) return EINA_FALSE; +static Eina_Bool +_wl_init(void) +{ + struct wl_display *display_wrapper = NULL; + struct wl_registry *reg = NULL; - info->win = win; - info->cb = cb; - info->data = data; + if (_eflutil.wl.init) return EINA_TRUE; - _eflutil.cb_handler[idx].info_list - = eina_list_append(_eflutil.cb_handler[idx].info_list, - info); + ecore_wl2_init(); - return EINA_TRUE; -} + _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); -static Eina_Bool -_cb_info_del_by_win(Evas_Object *win, - int idx) -{ - Efl_Util_Callback_Info *info; + display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail); - info = _cb_info_find_by_win(win, idx); - if (!info) return EINA_FALSE; + _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail); - _eflutil.cb_handler[idx].info_list - = eina_list_remove(_eflutil.cb_handler[idx].info_list, - info); - free(info); + wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue); - return EINA_TRUE; -} + reg = wl_display_get_registry(display_wrapper); + wl_proxy_wrapper_destroy(display_wrapper); + display_wrapper = NULL; + EINA_SAFETY_ON_NULL_GOTO(reg, fail); -static Eina_List * -_cb_info_list_get(int idx) -{ - return _eflutil.cb_handler[idx].info_list; -} + wl_registry_add_listener(reg, &_wl_reg_listener, NULL); -static Efl_Util_Callback_Info * -_cb_info_find_by_win(Evas_Object *win, - int idx) -{ - Eina_List *l, *ll; - Efl_Util_Callback_Info *info; + _eflutil.wl.init = EINA_TRUE; - l = _cb_info_list_get(idx); - EINA_LIST_FOREACH(l, ll, info) + return EINA_TRUE; +fail: + if (display_wrapper) + wl_proxy_wrapper_destroy(display_wrapper); + + if (_eflutil.wl.queue) { - if (info->win == win) return info; + wl_event_queue_destroy(_eflutil.wl.queue); + _eflutil.wl.queue = NULL; } - return NULL; + ecore_wl2_shutdown(); + return EINA_FALSE; } static Eina_Bool -_wl_init(void) +_wl_init_default_queue(void) { + struct wl_display *display_wrapper = NULL; struct wl_registry *reg = NULL; - if (_eflutil.wl.init) return EINA_TRUE; + if (_eflutil_defaultqueue.wl.init) return EINA_TRUE; - ecore_wl_init(NULL); + if (ecore_wl2_init() <= 0) return EINA_FALSE; - _eflutil.wl.dpy = ecore_wl_display_get(); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail); + _eflutil_defaultqueue.wl.wl2_display = ecore_wl2_connected_display_get(NULL); + EINA_SAFETY_ON_NULL_GOTO(_eflutil_defaultqueue.wl.wl2_display, fail); + _eflutil_defaultqueue.wl.dpy = ecore_wl2_display_get(_eflutil_defaultqueue.wl.wl2_display); + EINA_SAFETY_ON_NULL_GOTO(_eflutil_defaultqueue.wl.dpy, fail); - _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail); + display_wrapper = wl_proxy_create_wrapper(_eflutil_defaultqueue.wl.dpy); + EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail); - reg = wl_display_get_registry(_eflutil.wl.dpy); + 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); + wl_registry_add_listener(reg, &_wl_default_queue_reg_listener, NULL); - _eflutil.wl.init = EINA_TRUE; + _eflutil_defaultqueue.wl.init = EINA_TRUE; return EINA_TRUE; fail: - if (_eflutil.wl.queue) - { - wl_event_queue_destroy(_eflutil.wl.queue); - _eflutil.wl.queue = NULL; - } - ecore_wl_shutdown(); + ecore_wl2_shutdown(); return EINA_FALSE; } @@ -350,22 +438,35 @@ static const struct wl_output_listener output_listener = }; static void -_cb_wl_screenshot_done(void *data, struct screenshooter *screenshooter) +_cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format) +{ +} + +static void +_cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti) +{ + _eflutil.wl.shot.noti = noti; +} + +static void +_cb_tz_screenshot_done(void *data, struct tizen_screenshooter *tz_screenshooter) { Eina_Bool *shot_done = (Eina_Bool*)data; if (shot_done) *shot_done = EINA_TRUE; } -static const struct screenshooter_listener screenshooter_listener = +static const struct tizen_screenshooter_listener tz_screenshooter_listener = { - _cb_wl_screenshot_done + _cb_tz_screenshot_format, + _cb_tz_screenshot_noti, + _cb_tz_screenshot_done, }; static void _cb_wl_reg_global(void *data, struct wl_registry *reg, - unsigned int name, + unsigned int id, const char *interface, unsigned int version) { @@ -373,9 +474,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, @@ -385,6 +486,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) { @@ -393,22 +495,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, "screenshooter") == 0) - { - _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version); - screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL); - } 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, @@ -416,41 +513,85 @@ _cb_wl_reg_global(void *data, NULL); _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free); + _eflutil.wl.display_policy.id = id; } - } /* 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 */ -static Efl_Util_Callback_Info * -_cb_info_find_by_wlsurf(void *wlsurf, - int idx) +static void +_cb_wl_default_queue_reg_global(void *data, + struct wl_registry *reg, + unsigned int id, + const char *interface, + unsigned int version) { - Eina_List *l, *ll; - Efl_Util_Callback_Info *info; - Ecore_Wl_Window *wlwin2 = NULL; - void *wlsurf2 = NULL; + if (strcmp(interface, "tizen_gesture") == 0) + { + _eflutil_defaultqueue.wl.gesture.id = id; + _eflutil_defaultqueue.wl.gesture.proto = wl_registry_bind(reg, id, &tizen_gesture_interface, version); + tizen_gesture_add_listener(_eflutil_defaultqueue.wl.gesture.proto, &_wl_tz_gesture_listener, NULL); + } +} +/* LCOV_EXCL_START */ +static void +_cb_wl_default_queue_reg_global_remove(void *data, + struct wl_registry *reg, + unsigned int id) +{ + if (id == _eflutil_defaultqueue.wl.gesture.id) + { + _eflutil_defaultqueue.wl.gesture.id = 0; + _eflutil_defaultqueue.wl.gesture.proto = NULL; + } +} +/* LCOV_EXCL_STOP */ + - l = _cb_info_list_get(idx); - EINA_LIST_FOREACH(l, ll, info) +static void +_cb_wl_reg_screenshooter_global(void *data, + struct wl_registry *reg, + unsigned int name, + const char *interface, + unsigned int version) +{ + if (strcmp(interface, "tizen_screenshooter") == 0) { - wlwin2 = elm_win_wl_window_get(info->win); - wlsurf2 = ecore_wl_window_surface_get(wlwin2); - if (wlsurf== wlsurf2) return info; + _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version); + tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL); + + wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); } +} - return NULL; +/* LCOV_EXCL_START */ +static void +_cb_wl_reg_screenshooter_global_remove(void *data, + struct wl_registry *reg, + unsigned int name) +{ } static void @@ -475,7 +616,6 @@ _cb_wl_tz_policy_notification_done(void *data, uint32_t state) { Efl_Util_Wl_Surface_Lv_Info *lv_info; - Efl_Util_Callback_Info *cb_info; lv_info = eina_hash_find(_eflutil.wl.policy.hash_noti_lv, &surface); if (lv_info) @@ -484,16 +624,6 @@ _cb_wl_tz_policy_notification_done(void *data, lv_info->wait_for_done = EINA_FALSE; lv_info->state = state; } - - if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return; - - cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_NOTI_LEV); - if (!cb_info) return; - if (!cb_info->cb) return; - - cb_info->cb(cb_info->win, - EFL_UTIL_ERROR_PERMISSION_DENIED, - cb_info->data); } /* LCOV_EXCL_START */ @@ -510,9 +640,7 @@ _cb_wl_tz_policy_scr_mode_done(void *data, uint32_t mode, uint32_t state) { - Efl_Util_Wl_Surface_Scr_Mode_Info *scr_mode_info; - Efl_Util_Callback_Info *cb_info; scr_mode_info = eina_hash_find(_eflutil.wl.policy.hash_scr_mode, &surface); if (scr_mode_info) @@ -521,16 +649,6 @@ _cb_wl_tz_policy_scr_mode_done(void *data, scr_mode_info->wait_for_done = EINA_FALSE; scr_mode_info->state = state; } - - if (state != TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED) return; - - cb_info = _cb_info_find_by_wlsurf((void *)surface, CBH_SCR_MODE); - if (!cb_info) return; - if (!cb_info->cb) return; - - cb_info->cb(cb_info->win, - EFL_UTIL_ERROR_PERMISSION_DENIED, - cb_info->data); } /* LCOV_EXCL_START */ @@ -549,6 +667,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 @@ -592,46 +713,30 @@ efl_util_set_notification_window_level(Evas_Object *window, (level <= EFL_UTIL_NOTIFICATION_LEVEL_TOP), EFL_UTIL_ERROR_INVALID_PARAMETER); - if (level == EFL_UTIL_NOTIFICATION_LEVEL_1) - { - dlog_print(DLOG_WARN, LOG_TAG, - "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_1 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT instead."); - } - else if (level == EFL_UTIL_NOTIFICATION_LEVEL_2) - { - dlog_print(DLOG_WARN, LOG_TAG, - "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_2 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM instead."); - } - else if (level == EFL_UTIL_NOTIFICATION_LEVEL_3) - { - dlog_print(DLOG_WARN, LOG_TAG, - "DEPRECATION WARNING: EFL_UTIL_NOTIFICATION_LEVEL_3 is deprecated and will be removed from next release. Use EFL_UTIL_NOTIFICATION_LEVEL_TOP instead."); - } - 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); @@ -666,9 +771,9 @@ efl_util_set_notification_window_level(Evas_Object *window, if (lv_info->wait_for_done) { int count = 0; - while (lv_info->wait_for_done && (count < 3)) + while (lv_info->wait_for_done && (count < NUM_EVENT_WAIT_DONE_COUNT)) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); count++; } @@ -699,29 +804,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); @@ -731,9 +836,9 @@ efl_util_get_notification_window_level(Evas_Object *window, if (lv_info->wait_for_done) { int count = 0; - while ((lv_info->wait_for_done) && (count < 3)) + while ((lv_info->wait_for_done) && (count < NUM_EVENT_WAIT_DONE_COUNT)) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); count++; } @@ -747,9 +852,6 @@ efl_util_get_notification_window_level(Evas_Object *window, switch (lv_info->level) { - case TIZEN_POLICY_LEVEL_1: *level = EFL_UTIL_NOTIFICATION_LEVEL_1; break; - case TIZEN_POLICY_LEVEL_2: *level = EFL_UTIL_NOTIFICATION_LEVEL_2; break; - case TIZEN_POLICY_LEVEL_3: *level = EFL_UTIL_NOTIFICATION_LEVEL_3; break; case TIZEN_POLICY_LEVEL_NONE: *level = EFL_UTIL_NOTIFICATION_LEVEL_NONE; break; case TIZEN_POLICY_LEVEL_DEFAULT: *level = EFL_UTIL_NOTIFICATION_LEVEL_DEFAULT; break; case TIZEN_POLICY_LEVEL_MEDIUM: *level = EFL_UTIL_NOTIFICATION_LEVEL_MEDIUM; break; @@ -767,44 +869,6 @@ efl_util_get_notification_window_level(Evas_Object *window, } API int -efl_util_set_notification_window_level_error_cb(Evas_Object *window, - efl_util_notification_window_level_error_cb callback, - void *user_data) -{ - dlog_print(DLOG_WARN, LOG_TAG, - "DEPRECATION WARNING: efl_util_set_notification_window_level_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_notification_window_level() instead."); - - Eina_Bool ret = EINA_FALSE; - - EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER); - - ret = _cb_info_add(window, - (Efl_Util_Cb)callback, - user_data, - CBH_NOTI_LEV); - if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY; - - return EFL_UTIL_ERROR_NONE; -} - -API int -efl_util_unset_notification_window_level_error_cb(Evas_Object *window) -{ - dlog_print(DLOG_WARN, LOG_TAG, - "DEPRECATION WARNING: efl_util_unset_notification_window_level_error_cb() is deprecated and will be removed from next release. Use the return value of efl_util_set_notification_window_level() instead."); - - Eina_Bool ret = EINA_FALSE; - - EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); - - ret = _cb_info_del_by_win(window, CBH_NOTI_LEV); - if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER; - - return EFL_UTIL_ERROR_NONE; -} - -API int efl_util_set_window_opaque_state(Evas_Object *window, int opaque) { @@ -814,7 +878,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) @@ -830,11 +894,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; @@ -852,7 +916,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; @@ -860,13 +924,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); @@ -897,9 +961,9 @@ efl_util_set_window_screen_mode(Evas_Object *window, if (scr_mode_info->wait_for_done) { int count = 0; - while (scr_mode_info->wait_for_done && (count < 3)) + while (scr_mode_info->wait_for_done && (count < NUM_EVENT_WAIT_DONE_COUNT)) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); count++; } @@ -930,7 +994,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; @@ -938,13 +1002,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); @@ -955,7 +1019,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); } } @@ -979,50 +1043,10 @@ 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) -{ - 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."); - - Eina_Bool ret = EINA_FALSE; - - EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(callback, EFL_UTIL_ERROR_INVALID_PARAMETER); - - ret = _cb_info_add(window, - (Efl_Util_Cb)callback, - user_data, - CBH_SCR_MODE); - if (!ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY; - - return EFL_UTIL_ERROR_NONE; -} - -API int -efl_util_unset_window_screen_mode_error_cb(Evas_Object *window) -{ - 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."); - - Eina_Bool ret = EINA_FALSE; - - EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); - - ret = _cb_info_del_by_win(window, CBH_SCR_MODE); - if (!ret) return EFL_UTIL_ERROR_INVALID_PARAMETER; - - 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; @@ -1033,13 +1057,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); @@ -1070,9 +1094,9 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) if (brightness_info->wait_for_done) { int count = 0; - while (brightness_info->wait_for_done && (count < 3)) + while (brightness_info->wait_for_done && (count < NUM_EVENT_WAIT_DONE_COUNT)) { - ecore_wl_flush(); + ecore_wl2_display_flush(_eflutil.wl.wl2_display); wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); count++; } @@ -1098,7 +1122,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; @@ -1109,13 +1133,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); @@ -1126,7 +1150,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); } } @@ -1142,31 +1166,33 @@ efl_util_get_window_brightness(Evas_Object *window, int *brightness) struct _efl_util_inputgen_h { unsigned int init_type; + char name[32]; + E_Devicemgr_Inputgen_Touch_Axis *axis_info; }; +/* LCOV_EXCL_STOP */ + static void _cb_device_add(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, - struct tizen_input_device *device EINA_UNUSED, + struct tizen_input_device *device, struct wl_seat *seat EINA_UNUSED) { ; } -/* LCOV_EXCL_START */ static void _cb_device_remove(void *data EINA_UNUSED, struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, uint32_t serial EINA_UNUSED, const char *identifier EINA_UNUSED, - struct tizen_input_device *device EINA_UNUSED, + struct tizen_input_device *device, struct wl_seat *seat EINA_UNUSED) { ; } -/* LCOV_EXCL_STOP */ static void _cb_error(void *data EINA_UNUSED, @@ -1185,6 +1211,16 @@ _cb_block_expired(void *data EINA_UNUSED, } /* LCOV_EXCL_STOP */ +static void +_cb_max_touch_count(void *data EINA_UNUSED, + struct tizen_input_device_manager *tizen_input_device_manager EINA_UNUSED, + uint32_t serial EINA_UNUSED, + int32_t max_count, + struct wl_seat *seat EINA_UNUSED) +{ + _eflutil.wl.devmgr.max_touch_count = max_count; +} + static efl_util_error_e _efl_util_input_convert_input_generator_error(int ret) { @@ -1198,19 +1234,23 @@ _efl_util_input_convert_input_generator_error(int ret) return EFL_UTIL_ERROR_OUT_OF_MEMORY; case TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER: return EFL_UTIL_ERROR_INVALID_PARAMETER; + case TIZEN_INPUT_DEVICE_MANAGER_ERROR_NOT_ALLOWED: + return EFL_UTIL_ERROR_NO_RESOURCE_AVAILABLE; default : return EFL_UTIL_ERROR_NONE; } } -API efl_util_inputgen_h -efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type) +static efl_util_inputgen_h +_efl_util_input_create_inputgen(unsigned int dev_type, const char *name, int *ret, int with_name) { - int ret = EFL_UTIL_ERROR_NONE; efl_util_inputgen_h inputgen_h = NULL; + unsigned int clas = 0x0; - if ((dev_type <= EFL_UTIL_INPUT_DEVTYPE_NONE) || - (dev_type >= EFL_UTIL_INPUT_DEVTYPE_MAX)) + 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; @@ -1224,27 +1264,45 @@ efl_util_input_initialize_generator(efl_util_input_device_type_e dev_type) } inputgen_h->init_type |= dev_type; + if (with_name) + { + if (name) strncpy(inputgen_h->name, name, 31); + else strncpy(inputgen_h->name, "Input Generator", 31); + } - ret = _wl_init(); - if (ret == (int)EINA_FALSE) + *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); + if (with_name == 2) + tizen_input_device_manager_init_generator_with_sync(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name); + else if (with_name == 1) + tizen_input_device_manager_init_generator_with_name(_eflutil.wl.devmgr.devicemgr, clas, inputgen_h->name); + else + 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); + *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) + set_last_result(*ret); + if (*ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE) goto out; return inputgen_h; @@ -1258,39 +1316,122 @@ out: return NULL; } -API int -efl_util_input_deinitialize_generator(efl_util_inputgen_h inputgen_h) +API efl_util_inputgen_h +efl_util_input_initialize_generator(unsigned int dev_type) { int ret = EFL_UTIL_ERROR_NONE; - EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + efl_util_inputgen_h inputgen_h = NULL; - free(inputgen_h); - inputgen_h = NULL; + inputgen_h = _efl_util_input_create_inputgen(dev_type, NULL, &ret, 0); + if (!inputgen_h) + return NULL; - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); + return inputgen_h; +} - tizen_input_device_manager_deinit_generator(_eflutil.wl.devmgr.devicemgr); +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; - while (_eflutil.wl.devmgr.request_notified == -1) - wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + inputgen_h = _efl_util_input_create_inputgen(dev_type, name, &ret, 1); + if (!inputgen_h) + return NULL; - ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); - _eflutil.wl.devmgr.request_notified = -1; + return inputgen_h; +} - return ret; +API efl_util_inputgen_h +efl_util_input_initialize_generator_with_sync(unsigned int dev_type, const char *name) +{ + int ret = EFL_UTIL_ERROR_NONE; + efl_util_inputgen_h inputgen_h = NULL; + + inputgen_h = _efl_util_input_create_inputgen(dev_type, name, &ret, 2); + if (!inputgen_h) + return NULL; + + return inputgen_h; } API int -efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed) +efl_util_input_set_touch_count(int max_count) { int ret = EFL_UTIL_ERROR_NONE; - EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE); + ret = _wl_init(); + if (ret == (int)EINA_FALSE) + { + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); + while (!_eflutil.wl.devmgr.devicemgr) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + if (_eflutil.wl.devmgr.max_touch_count >= max_count) + return EFL_UTIL_ERROR_NONE; + + tizen_input_device_manager_set_touch_count(_eflutil.wl.devmgr.devicemgr, max_count); + + 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; + + if (ret == EFL_UTIL_ERROR_NONE) + { + _eflutil.wl.devmgr.request_touch_count = max_count; + } + + return ret; +} + +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; + + if (inputgen_h->axis_info) + free(inputgen_h->axis_info); + + 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, 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; + + return ret; +} + +API int +efl_util_input_generate_key(efl_util_inputgen_h inputgen_h, const char *key_name, int pressed) +{ + int ret = EFL_UTIL_ERROR_NONE; + + EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(pressed == 0 || pressed == 1, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_KEYBOARD, EFL_UTIL_ERROR_NO_SUCH_DEVICE); + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); tizen_input_device_manager_generate_key(_eflutil.wl.devmgr.devicemgr, key_name, pressed); @@ -1315,6 +1456,9 @@ efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx, EINA_SAFETY_ON_FALSE_RETURN_VAL((x > 0 && y > 0), EFL_UTIL_ERROR_INVALID_PARAMETER); EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE); + if (idx >= _eflutil.wl.devmgr.max_touch_count) + return EFL_UTIL_ERROR_INVALID_PARAMETER; + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); switch(touch_type) @@ -1343,159 +1487,1745 @@ efl_util_input_generate_touch(efl_util_inputgen_h inputgen_h, int idx, return ret; } -struct _efl_util_screenshot_h +static int +_efl_util_input_generate_touch_axis_send(unsigned int type, double value) { - int width; - int height; + int ret; - Eina_Bool shot_done; + tizen_input_device_manager_generate_axis(_eflutil.wl.devmgr.devicemgr, type, wl_fixed_from_double(value)); - /* tbm bufmgr */ - tbm_bufmgr bufmgr; -}; + while (_eflutil.wl.devmgr.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); -/* scrrenshot handle */ -static efl_util_screenshot_h g_screenshot; + ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); + _eflutil.wl.devmgr.request_notified = -1; -API efl_util_screenshot_h -efl_util_screenshot_initialize(int width, int height) -{ - efl_util_screenshot_h screenshot = NULL; + return ret; +} - if (!_eflutil.wl.shot.screenshooter) +static void +_efl_util_input_generate_touch_axis_cleanup(efl_util_inputgen_h inputgen_h, int idx) +{ + int i; + if (idx >= 0) { - int ret = 0; - _wl_init(); - while (!_eflutil.wl.shot.screenshooter && ret != -1) - ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init); - - _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init); + inputgen_h->axis_info[idx].radius_x = 1.0; + inputgen_h->axis_info[idx].radius_y = 1.0; + inputgen_h->axis_info[idx].pressure = 1.0; + inputgen_h->axis_info[idx].angle = 0.0; + inputgen_h->axis_info[idx].palm = 0.0; } - - EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param); - EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param); - - if (g_screenshot) + else { - if (g_screenshot->width != width || g_screenshot->height != height) + for (i = 0; i < EFL_UTIL_INPUT_GENERATOR_TOUCH_MAX_FINGER; i++) { - g_screenshot->width = width; - g_screenshot->height = height; + inputgen_h->axis_info[i].radius_x = 1.0; + inputgen_h->axis_info[i].radius_y = 1.0; + inputgen_h->axis_info[i].pressure = 1.0; + inputgen_h->axis_info[i].angle = 0.0; + inputgen_h->axis_info[i].palm = 0.0; } + } +} - return g_screenshot; +static int +_efl_util_input_generate_touch_axis_process(efl_util_inputgen_h inputgen_h, int idx, double radius_x, + double radius_y, double pressure, double angle, double palm) +{ + int ret = EFL_UTIL_ERROR_NONE; + + if (!inputgen_h->axis_info) + { + inputgen_h->axis_info = calloc(EFL_UTIL_INPUT_GENERATOR_TOUCH_MAX_FINGER, + sizeof(E_Devicemgr_Inputgen_Touch_Axis)); + _efl_util_input_generate_touch_axis_cleanup(inputgen_h, -1); } - screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h)); - EINA_SAFETY_ON_NULL_GOTO(screenshot, fail_memory); + if (inputgen_h->axis_info[idx].radius_x != radius_x) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_RADIUS_X, radius_x); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].radius_x = radius_x; + } + if (inputgen_h->axis_info[idx].radius_y != radius_y) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_RADIUS_Y, radius_y); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].radius_y = radius_y; + } + if (inputgen_h->axis_info[idx].pressure != pressure) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_PRESSURE, pressure); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].pressure = pressure; + } + if (inputgen_h->axis_info[idx].angle != angle) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_ANGLE, angle); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].angle = angle; + } + if (inputgen_h->axis_info[idx].palm != palm) + { + ret = _efl_util_input_generate_touch_axis_send(TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_PALM, palm); + if (ret != EFL_UTIL_ERROR_NONE) return ret; + inputgen_h->axis_info[idx].palm = palm; + } - screenshot->width = width; - screenshot->height = height; + return ret; +} - screenshot->bufmgr = wayland_tbm_client_get_bufmgr(_eflutil.wl.shot.tbm_client); - EINA_SAFETY_ON_NULL_GOTO(screenshot->bufmgr, fail_init); +API int +efl_util_input_generate_touch_axis(efl_util_inputgen_h inputgen_h, int idx, + efl_util_input_touch_type_e touch_type, int x, int y, + double radius_x, double radius_y, + double pressure, double angle, double palm) +{ + int ret, version; + enum tizen_input_device_manager_pointer_event_type type; - g_screenshot = screenshot; - set_last_result(EFL_UTIL_ERROR_NONE); + EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(idx >= 0, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_TOUCHSCREEN, EFL_UTIL_ERROR_NO_SUCH_DEVICE); + EINA_SAFETY_ON_FALSE_RETURN_VAL((radius_x >= 0.0 && radius_y >= 0.0), EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL((pressure >= 0.0 && palm >= 0.0), EFL_UTIL_ERROR_INVALID_PARAMETER); - screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, &screenshot->shot_done); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); + version = tizen_input_device_manager_get_version(_eflutil.wl.devmgr.devicemgr); + EINA_SAFETY_ON_FALSE_RETURN_VAL((version >= 3), EFL_UTIL_ERROR_NOT_SUPPORTED); - return g_screenshot; + switch(touch_type) + { + case EFL_UTIL_INPUT_TOUCH_BEGIN: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN; + break; + case EFL_UTIL_INPUT_TOUCH_UPDATE: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE; + break; + case EFL_UTIL_INPUT_TOUCH_END: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END; + break; + default: + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } -fail_param: - set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); - return NULL; -fail_memory: -/* LCOV_EXCL_START */ - set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); - return NULL; -/* LCOV_EXCL_STOP */ -fail_init: - if (screenshot) - efl_util_screenshot_deinitialize(screenshot); - set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL); - return NULL; -} + if (touch_type != EFL_UTIL_INPUT_TOUCH_END) + _efl_util_input_generate_touch_axis_process(inputgen_h, idx, radius_x, radius_y, pressure, angle, palm); + else + _efl_util_input_generate_touch_axis_cleanup(inputgen_h, idx); -API int -efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot) -{ - if (!screenshot) - return EFL_UTIL_ERROR_INVALID_PARAMETER; + tizen_input_device_manager_generate_touch(_eflutil.wl.devmgr.devicemgr, type, x, y, idx); - free(screenshot); - g_screenshot = NULL; + while (_eflutil.wl.devmgr.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - if (_eflutil.wl.shot.screenshooter) - screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL); + ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); + _eflutil.wl.devmgr.request_notified = -1; - return EFL_UTIL_ERROR_NONE; + return ret; } -API tbm_surface_h -efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot) +API int +efl_util_input_generate_pointer(efl_util_inputgen_h inputgen_h, int buttons, efl_util_input_pointer_type_e pointer_type, int x, int y) { - tbm_surface_h t_surface = NULL; - struct wl_buffer *buffer = NULL; - Efl_Util_Wl_Output_Info *output; - int ret = 0; + int ret; + enum tizen_input_device_manager_pointer_event_type type; - if (screenshot != g_screenshot) - { - set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); - return NULL; - } + EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(buttons > 0, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL((x >= 0 && y >= 0), EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE); - output = eina_list_nth(_eflutil.wl.shot.output_list, 0); - if (!output) - { - fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */ - goto fail; - } + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); - t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888); - if (!t_surface) + switch(pointer_type) { - fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */ - goto fail; + case EFL_UTIL_INPUT_POINTER_BUTTON_DOWN: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN; + break; + case EFL_UTIL_INPUT_POINTER_MOVE: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE; + break; + case EFL_UTIL_INPUT_POINTER_BUTTON_UP: + type = TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END; + break; + default: + return EFL_UTIL_ERROR_INVALID_PARAMETER; } - buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface); - if (!buffer) + tizen_input_device_manager_generate_pointer(_eflutil.wl.devmgr.devicemgr, type, x, y, buttons); + + 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; + + return ret; +} + +API int +efl_util_input_generate_wheel(efl_util_inputgen_h inputgen_h, efl_util_input_pointer_wheel_type_e wheel_type, int value) +{ + int ret, version; + enum tizen_input_device_manager_pointer_event_type type; + + EINA_SAFETY_ON_NULL_RETURN_VAL(inputgen_h, EFL_UTIL_ERROR_INVALID_PARAMETER); + EINA_SAFETY_ON_FALSE_RETURN_VAL(inputgen_h->init_type & EFL_UTIL_INPUT_DEVTYPE_POINTER, EFL_UTIL_ERROR_NO_SUCH_DEVICE); + + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.devicemgr, EFL_UTIL_ERROR_INVALID_PARAMETER); + version = tizen_input_device_manager_get_version(_eflutil.wl.devmgr.devicemgr); + EINA_SAFETY_ON_FALSE_RETURN_VAL((version >= 3), EFL_UTIL_ERROR_NOT_SUPPORTED); + + switch(wheel_type) { - fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */ - goto fail; + case EFL_UTIL_INPUT_POINTER_WHEEL_VERT: + type = TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_WHEEL; + break; + case EFL_UTIL_INPUT_POINTER_WHEEL_HORZ: + type = TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_HWHEEL; + break; + default: + return EFL_UTIL_ERROR_INVALID_PARAMETER; } - screenshooter_shoot(_eflutil.wl.shot.screenshooter, output->output, buffer); + tizen_input_device_manager_generate_axis(_eflutil.wl.devmgr.devicemgr, type, wl_fixed_from_int(value)); - screenshot->shot_done = EINA_FALSE; - while (!screenshot->shot_done && ret != -1) - ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + while (_eflutil.wl.devmgr.request_notified == -1) + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); - if (ret == -1) + ret = _efl_util_input_convert_input_generator_error(_eflutil.wl.devmgr.request_notified); + _eflutil.wl.devmgr.request_notified = -1; + + return ret; +} + + + +struct _efl_util_screenshot_h +{ + int width; + int height; + + Eina_Bool shot_done; + + /* 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: screenshooter_shoot\n"); /* LCOV_EXCL_LINE */ - goto fail; + fprintf(stderr, "[screenshot] fail: mutex init"); /*LCOV_EXCL_LINE*/ + return EINA_FALSE; /*LCOV_EXCL_LINE*/ } - wl_buffer_destroy(buffer); + shot_mutex_init = EINA_TRUE; - /* reset shot_done for next screenshot */ - screenshot->shot_done = EINA_FALSE; + return EINA_TRUE; +} - return t_surface; +static Eina_Bool +_screenshot_mutex_destory(void) +{ + if (!shot_mutex_init) + return EINA_TRUE; -fail: - if (t_surface) - tbm_surface_destroy(t_surface); - if (buffer) - wl_buffer_destroy(buffer); + if (pthread_mutex_destroy(&shot_lock)) + { + fprintf(stderr, "[screenshot] fail: mutex destory"); /*LCOV_EXCL_LINE*/ + return EINA_FALSE; /*LCOV_EXCL_LINE*/ + } - set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL); + 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); +} + +static Eina_Bool +_efl_util_wl_screenshooter_init() +{ + struct wl_display *display_wrapper = NULL; + struct wl_registry *registry = NULL; + int ret = 0; + + if (_wl_init() == EINA_FALSE) + return EINA_FALSE; + + wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_RETURN_VAL(display_wrapper, EINA_FALSE); + + _eflutil.wl.shot.queue = wl_display_create_queue(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.queue, fail_create_queue); + + wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.shot.queue); + + registry = wl_display_get_registry(display_wrapper); + EINA_SAFETY_ON_NULL_GOTO(registry, fail_get_registry); + + wl_registry_add_listener(registry, &_wl_reg_screenshooter_listener, NULL); + + ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); + EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_roundtrip); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_roundtrip); + + _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_tbm_client_init); + + wl_registry_destroy(registry); + wl_proxy_wrapper_destroy(display_wrapper); + + if (_eflutil.wl.shot.noti == 0) + { + fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */ + return EINA_FALSE; + } + + return EINA_TRUE; + +fail_tbm_client_init: + tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter); + _eflutil.wl.shot.tz_screenshooter = NULL; +fail_roundtrip: + wl_registry_destroy(registry); +fail_get_registry: + wl_event_queue_destroy(_eflutil.wl.shot.queue); + _eflutil.wl.shot.queue = NULL; +fail_create_queue: + wl_proxy_wrapper_destroy(display_wrapper); + + return EINA_FALSE; +} + +static void +_efl_util_wl_screenshooter_deinit() +{ + if (_eflutil.wl.shot.tbm_client) + { + wayland_tbm_client_deinit(_eflutil.wl.shot.tbm_client); + _eflutil.wl.shot.tbm_client = NULL; + } + + if (_eflutil.wl.shot.tz_screenshooter) + { + tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter); + _eflutil.wl.shot.tz_screenshooter = NULL; + } + + if (_eflutil.wl.shot.queue) + { + wl_event_queue_destroy(_eflutil.wl.shot.queue); + _eflutil.wl.shot.queue = NULL; + } +} + +API efl_util_screenshot_h +efl_util_screenshot_initialize(int width, int height) +{ + efl_util_screenshot_h screenshot = NULL; + + if (width <= 0 || height <= 0) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + return NULL; + } + + _screenshot_mutex_lock(); + + if (g_screenshot) + { + if (g_screenshot->width != width || g_screenshot->height != height) + { + g_screenshot->width = width; + g_screenshot->height = height; + } + set_last_result(EFL_UTIL_ERROR_NONE); + + _screenshot_mutex_unlock(); + + return g_screenshot; + } + + screenshot = calloc(1, sizeof(struct _efl_util_screenshot_h)); + if (screenshot == NULL) + { + set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); + + _screenshot_mutex_unlock(); + + return NULL; + } + + if (!_eflutil.wl.shot.tz_screenshooter) + { + if (_efl_util_wl_screenshooter_init() == EINA_FALSE) + { + if (_eflutil.wl.shot.noti == 0) + set_last_result(EFL_UTIL_ERROR_PERMISSION_DENIED); + else + set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL); + + free(screenshot); + + _screenshot_mutex_unlock(); + + return NULL; + } + } + + 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_get_bufmgr); + + g_screenshot = screenshot; + set_last_result(EFL_UTIL_ERROR_NONE); + + tizen_screenshooter_set_user_data(_eflutil.wl.shot.tz_screenshooter, &screenshot->shot_done); + + _screenshot_mutex_unlock(); + + return g_screenshot; + +/* LCOV_EXCL_START */ +fail_get_bufmgr: + set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL); + _screenshot_mutex_unlock(); + efl_util_screenshot_deinitialize(screenshot); + + return NULL; +/* LCOV_EXCL_STOP */ +} + +API int +efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot) +{ + _screenshot_mutex_lock(); + + if (!screenshot) + { + _screenshot_mutex_unlock(); + _screenshot_mutex_destory(); + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + free(screenshot); + g_screenshot = NULL; + + _efl_util_wl_screenshooter_deinit(); + + _screenshot_mutex_unlock(); + _screenshot_mutex_destory(); + + return EFL_UTIL_ERROR_NONE; +} + + +API tbm_surface_h +efl_util_screenshot_take_tbm_surface(efl_util_screenshot_h screenshot) +{ + tbm_surface_h t_surface = NULL; + struct wl_buffer *buffer = NULL; + 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; + } + + output = eina_list_nth(_eflutil.wl.shot.output_list, 0); + if (!output) + { + fprintf(stderr, "[screenshot] fail: no output for screenshot\n"); /* LCOV_EXCL_LINE */ + goto fail; + } + + t_surface = tbm_surface_create(screenshot->width, screenshot->height, TBM_FORMAT_XRGB8888); + if (!t_surface) + { + fprintf(stderr, "[screenshot] fail: tbm_surface_create\n"); /* LCOV_EXCL_LINE */ + goto fail; + } + + buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, t_surface); + if (!buffer) + { + fprintf(stderr, "[screenshot] fail: create wl_buffer for screenshot\n"); /* LCOV_EXCL_LINE */ + goto fail; + } + + tizen_screenshooter_shoot(_eflutil.wl.shot.tz_screenshooter, output->output, buffer); + + screenshot->shot_done = EINA_FALSE; + + while (!screenshot->shot_done && ret != -1) + ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); + + if (ret == -1) + { + fprintf(stderr, "[screenshot] fail: tizen_screenshooter_shoot\n"); /* LCOV_EXCL_LINE */ + goto fail; + } + + wayland_tbm_client_destroy_buffer(_eflutil.wl.shot.tbm_client, buffer); + + /* 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: + if (t_surface) + tbm_surface_destroy(t_surface); + if (buffer) + wayland_tbm_client_destroy_buffer(_eflutil.wl.shot.tbm_client, buffer); + + set_last_result(EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL); + + _screenshot_mutex_unlock(); + + return NULL; +} + +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_START */ +struct _efl_util_screenmirror_h +{ + struct tizen_screenmirror *tz_screenmirror; + pthread_t thread; + int width; + int height; + + tbm_bufmgr bufmgr; + Eina_List *buffer_list; + + Eina_Bool mirror_working; + Eina_Bool cb_start; + Eina_Bool cb_stop; + Eina_Bool cb_content; + efl_util_screenmirror_handler user_func; + void *user_data; +}; + +typedef struct _efl_util_mirror_buffer efl_util_mirror_buffer; +struct _efl_util_mirror_buffer +{ + struct wl_buffer *buffer; + int w, h; + tbm_surface_h t_surface; +}; + +static efl_util_screenmirror_h g_screenmirror; + +static void * +_efl_util_screenmirror_loop(void *data) +{ + efl_util_screenmirror_h screenmirror; + int ret = 0; + + screenmirror = (efl_util_screenmirror_h)data; + + while (1) + { + if (!screenmirror->mirror_working) + break; + + ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); + if (ret == -1) + { + fprintf(stderr, "[screenmirror] fail: dispatch_queue\n"); + break; + } + } + + return NULL; +} + +static efl_util_mirror_buffer * +_efl_util_create_mirror_buffer(efl_util_screenmirror_h screenmirror) +{ + efl_util_mirror_buffer *mbuffer; + + mbuffer = calloc(1, sizeof(struct _efl_util_mirror_buffer)); + EINA_SAFETY_ON_NULL_RETURN_VAL(mbuffer, NULL); + + mbuffer->w = screenmirror->width; + mbuffer->h = screenmirror->height; + + mbuffer->t_surface = tbm_surface_internal_create_with_flags(mbuffer->w, + mbuffer->h, TBM_FORMAT_ARGB8888, TBM_BO_SCANOUT); + EINA_SAFETY_ON_NULL_GOTO(mbuffer->t_surface, fail_create_surface); + + mbuffer->buffer = wayland_tbm_client_create_buffer(_eflutil.wl.shot.tbm_client, mbuffer->t_surface); + EINA_SAFETY_ON_NULL_GOTO(mbuffer->buffer, fail_create_buffer); + + return mbuffer; + +fail_create_buffer: + tbm_surface_destroy(mbuffer->t_surface); +fail_create_surface: + free(mbuffer); return NULL; } + +static void +_efl_util_destroy_mirror_buffer(efl_util_mirror_buffer *mbuffer) +{ + EINA_SAFETY_ON_NULL_RETURN(mbuffer); + + if (mbuffer->buffer) + wl_buffer_destroy(mbuffer->buffer); + + free(mbuffer); +} + +static void +_efl_util_screenmirror_handle_dequeued(void *data, + struct tizen_screenmirror *tz_screenmirror, struct wl_buffer *buffer) +{ + efl_util_screenmirror_h screenmirror; + efl_util_mirror_buffer *mbuffer; + Eina_List *l, *ll; + + screenmirror = (efl_util_screenmirror_h)data; + screenmirror->cb_start = EINA_TRUE; + + EINA_LIST_FOREACH_SAFE(screenmirror->buffer_list, l, ll, mbuffer) + { + if (mbuffer->buffer == buffer) + { + if (mbuffer->w != screenmirror->width || mbuffer->h != screenmirror->height || + !screenmirror->mirror_working) + tbm_surface_destroy(mbuffer->t_surface); + else + screenmirror->user_func(screenmirror, mbuffer->t_surface, screenmirror->user_data); + + screenmirror->buffer_list = eina_list_remove_list(screenmirror->buffer_list, l); + _efl_util_destroy_mirror_buffer(mbuffer); + + break; + } + } + + mbuffer = _efl_util_create_mirror_buffer(screenmirror); + if (mbuffer == NULL) + { + fprintf(stderr, "[screenmirror] fail: buffer create\n"); + return; + } + screenmirror->buffer_list = eina_list_append(screenmirror->buffer_list, mbuffer); + tizen_screenmirror_queue(screenmirror->tz_screenmirror, mbuffer->buffer); +} + +static void +_efl_util_screenmirror_handle_content(void *data, + struct tizen_screenmirror *tz_screenmirror, uint32_t content) +{ + efl_util_screenmirror_h screenmirror = NULL; + + screenmirror = (efl_util_screenmirror_h)data; + screenmirror->cb_content = EINA_TRUE; +} + +static void +_efl_util_screenmirror_handle_stop(void *data, struct tizen_screenmirror *tz_screenmirror) +{ + efl_util_screenmirror_h screenmirror = NULL; + + screenmirror = (efl_util_screenmirror_h)data; + screenmirror->cb_stop = EINA_TRUE; +} + +static const struct tizen_screenmirror_listener efl_util_screenmirror_listener = { + _efl_util_screenmirror_handle_dequeued, + _efl_util_screenmirror_handle_content, + _efl_util_screenmirror_handle_stop +}; + +API efl_util_screenmirror_h +efl_util_screenmirror_initialize(int width, int height) +{ + efl_util_screenmirror_h screenmirror = NULL; + efl_util_mirror_buffer *mbuffer; + Efl_Util_Wl_Output_Info *output; + int ret = 0, i; + + if (width <= 0 || height <= 0) + { + set_last_result(EFL_UTIL_ERROR_INVALID_PARAMETER); + return NULL; + } + + _screenshot_mutex_lock(); + + if (g_screenmirror) + { + if (g_screenmirror->mirror_working) + { + set_last_result(EFL_UTIL_ERROR_INVALID_OPERATION); + _screenshot_mutex_unlock(); + return NULL; + } + else + { + g_screenmirror->width = width; + g_screenmirror->height = height; + set_last_result(EFL_UTIL_ERROR_NONE); + _screenshot_mutex_unlock(); + return g_screenmirror; + } + } + + screenmirror = calloc(1, sizeof(struct _efl_util_screenmirror_h)); + if (screenmirror == NULL) + { + set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); + _screenshot_mutex_unlock(); + return NULL; + } + + if (!_eflutil.wl.shot.tz_screenshooter) + { + if (_efl_util_wl_screenshooter_init() == EINA_FALSE) + { + if (_eflutil.wl.shot.noti == 0) + set_last_result(EFL_UTIL_ERROR_PERMISSION_DENIED); + else + set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL); + + goto fail_wl_init; + } + } + + output = eina_list_nth(_eflutil.wl.shot.output_list, 0); + if (!output) + { + set_last_result(EFL_UTIL_ERROR_NO_RESOURCE_AVAILABLE); + fprintf(stderr, "[screenmirror] fail: no output for screenmirror\n"); + goto fail_get_output; + } + + screenmirror->tz_screenmirror = tizen_screenshooter_get_screenmirror(_eflutil.wl.shot.tz_screenshooter, output->output); + wl_proxy_set_queue((struct wl_proxy *)screenmirror->tz_screenmirror, _eflutil.wl.shot.queue); + tizen_screenmirror_add_listener(screenmirror->tz_screenmirror, &efl_util_screenmirror_listener, screenmirror); + tizen_screenmirror_set_stretch(screenmirror->tz_screenmirror, TIZEN_SCREENMIRROR_STRETCH_KEEP_RATIO); + screenmirror->width = width; + screenmirror->height = height; + + g_screenmirror = screenmirror; + + for (i = 0; i < 1; i++) + { + mbuffer = _efl_util_create_mirror_buffer(screenmirror); + if (mbuffer) + { + screenmirror->buffer_list = eina_list_append(screenmirror->buffer_list, mbuffer); + tizen_screenmirror_queue(screenmirror->tz_screenmirror, mbuffer->buffer); + } + else + fprintf(stderr, "[screenmirror] fail: buffer create %d\n", i); + } + while (!screenmirror->cb_content && ret != -1) + ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); + + _screenshot_mutex_unlock(); + + return screenmirror; + +fail_get_output: +fail_wl_init: + free(screenmirror); + _screenshot_mutex_unlock(); + return NULL; +} + +API int +efl_util_screenmirror_deinitialize(efl_util_screenmirror_h screenmirror) +{ + efl_util_mirror_buffer *mbuffer; + Eina_List *l; + + _screenshot_mutex_lock(); + + if (!screenmirror || (screenmirror != g_screenmirror)) + { + _screenshot_mutex_unlock(); + _screenshot_mutex_destory(); + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + + if (screenmirror->mirror_working) + { + fprintf(stderr, "[screenmirror] fail: execute stop before deinit\n"); + _screenshot_mutex_unlock(); + _screenshot_mutex_destory(); + return EFL_UTIL_ERROR_INVALID_OPERATION; + } + + EINA_LIST_FOREACH(screenmirror->buffer_list, l, mbuffer) + { + tbm_surface_destroy(mbuffer->t_surface); + _efl_util_destroy_mirror_buffer(mbuffer); + } + eina_list_free(screenmirror->buffer_list); + + tizen_screenmirror_destroy(screenmirror->tz_screenmirror); + free(screenmirror); + g_screenmirror = NULL; + + _efl_util_wl_screenshooter_deinit(); + + _screenshot_mutex_unlock(); + _screenshot_mutex_destory(); + + return EFL_UTIL_ERROR_NONE; +} + +API int +efl_util_screenmirror_set_handler(efl_util_screenmirror_h screenmirror, + efl_util_screenmirror_handler func, void *data) +{ + _screenshot_mutex_lock(); + + if (!screenmirror || (screenmirror != g_screenmirror) || !func) + { + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + screenmirror->user_func = func; + screenmirror->user_data = data; + + _screenshot_mutex_unlock(); + + return EFL_UTIL_ERROR_NONE; +} + +API int +efl_util_screenmirror_start(efl_util_screenmirror_h screenmirror) +{ + int ret = 0; + + _screenshot_mutex_lock(); + + if (!screenmirror || (screenmirror != g_screenmirror)) + { + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + else if (!screenmirror->user_func) + { + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL; + } + else if (screenmirror->mirror_working) + { + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_NONE; + } + + screenmirror->cb_start = EINA_FALSE; + screenmirror->mirror_working = EINA_TRUE; + tizen_screenmirror_start(screenmirror->tz_screenmirror); + while (!screenmirror->cb_start && ret != -1) + ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); + if (ret == -1) + { + fprintf(stderr, "[screenmirror] fail: tizen_screenmirror_start\n"); + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL; + } + + ret = pthread_create(&screenmirror->thread, NULL, _efl_util_screenmirror_loop, screenmirror); + if (ret < 0) + { + fprintf(stderr, "[screenmirror] fail: thread create fail\n"); + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL; + } + + pthread_setname_np(screenmirror->thread, "e_util_mirror"); + + _screenshot_mutex_unlock(); + + return EFL_UTIL_ERROR_NONE; +} + +API int +efl_util_screenmirror_stop(efl_util_screenmirror_h screenmirror) +{ + int ret = 0; + + _screenshot_mutex_lock(); + + if (!screenmirror || (screenmirror != g_screenmirror)) + { + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_INVALID_PARAMETER; + } + else if (!screenmirror->mirror_working) + { + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_NONE; + } + screenmirror->mirror_working = EINA_FALSE; + pthread_join(screenmirror->thread, NULL); + tizen_screenmirror_stop(screenmirror->tz_screenmirror); + screenmirror->cb_stop = EINA_FALSE; + + while (!screenmirror->cb_stop && ret != -1) + ret = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); + if (ret == -1) + { + fprintf(stderr, "[screenmirror] fail: tizen_screenmirror_stop\n"); + _screenshot_mutex_unlock(); + return EFL_UTIL_ERROR_SCREENSHOT_EXECUTION_FAIL; + } + + _screenshot_mutex_unlock(); + + 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_defaultqueue.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_defaultqueue.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_defaultqueue.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_defaultqueue.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_defaultqueue.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 efl_util_error_e +_efl_util_gesture_verify_request_notified() +{ + int ret = EFL_UTIL_ERROR_NONE; + + while (_eflutil_defaultqueue.wl.gesture.request_notified == -1) + wl_display_dispatch(_eflutil_defaultqueue.wl.dpy); + + ret = _efl_util_gesture_convert_error(_eflutil_defaultqueue.wl.gesture.request_notified); + _eflutil_defaultqueue.wl.gesture.request_notified = -1; + + return ret; +} + +static int +_efl_util_gesture_grab_edge_swipe(efl_util_gesture_data data, Eina_Bool grabbed) +{ + 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_defaultqueue.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; + + if (grabbed) + tizen_gesture_grab_edge_swipe(_eflutil_defaultqueue.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point); + else + tizen_gesture_ungrab_edge_swipe(_eflutil_defaultqueue.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point); + + ret = _efl_util_gesture_verify_request_notified(); + + return ret; +} + +static int +_efl_util_gesture_grab_edge_drag(efl_util_gesture_data data, Eina_Bool grabbed) +{ + 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_defaultqueue.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; + + if (grabbed) + tizen_gesture_grab_edge_drag(_eflutil_defaultqueue.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point); + else + tizen_gesture_ungrab_edge_drag(_eflutil_defaultqueue.wl.gesture.proto, fingers, edge, edge_size, start_point, end_point); + + ret = _efl_util_gesture_verify_request_notified(); + + return ret; +} + +static int +_efl_util_gesture_grab_tap(efl_util_gesture_data data, Eina_Bool grabbed) +{ + 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_defaultqueue.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; + + if (grabbed) + tizen_gesture_grab_tap(_eflutil_defaultqueue.wl.gesture.proto, fingers, repeats); + else + tizen_gesture_ungrab_tap(_eflutil_defaultqueue.wl.gesture.proto, fingers, repeats); + + ret = _efl_util_gesture_verify_request_notified(); + + return ret; +} + +static int +_efl_util_gesture_grab_palm_cover(efl_util_gesture_data data, Eina_Bool grabbed) +{ + 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_defaultqueue.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); + + if (grabbed) + tizen_gesture_grab_palm_cover(_eflutil_defaultqueue.wl.gesture.proto); + else + tizen_gesture_ungrab_palm_cover(_eflutil_defaultqueue.wl.gesture.proto); + + ret = _efl_util_gesture_verify_request_notified(); + + return ret; +} +/* LCOV_EXCL_STOP */ + +API efl_util_gesture_h +efl_util_gesture_initialize(void) +{ + efl_util_gesture_h gesture_h = NULL; + + 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_default_queue() == (int)EINA_FALSE) + { + set_last_result(EFL_UTIL_ERROR_NOT_SUPPORTED); /* LCOV_EXCL_LINE */ + goto out; /* LCOV_EXCL_LINE */ + } + + while (!_eflutil_defaultqueue.wl.gesture.proto) + wl_display_dispatch(_eflutil_defaultqueue.wl.dpy); /* LCOV_EXCL_LINE */ + + if (_eflutil_defaultqueue.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(); + } + _eflutil_defaultqueue.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_defaultqueue.wl.gesture.event_init--; + + if (_eflutil_defaultqueue.wl.gesture.event_init <= 0) + { + _eflutil_defaultqueue.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; + } + + 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, EINA_TRUE); + break; + case TIZEN_GESTURE_TYPE_EDGE_DRAG: + ret = _efl_util_gesture_grab_edge_drag(data, EINA_TRUE); + break; + case TIZEN_GESTURE_TYPE_TAP: + ret = _efl_util_gesture_grab_tap(data, EINA_TRUE); + break; + case TIZEN_GESTURE_TYPE_PALM_COVER: + ret = _efl_util_gesture_grab_palm_cover(data, EINA_TRUE); + 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_grab_edge_swipe(data, EINA_FALSE); + break; + case TIZEN_GESTURE_TYPE_EDGE_DRAG: + ret = _efl_util_gesture_grab_edge_drag(data, EINA_FALSE); + break; + case TIZEN_GESTURE_TYPE_TAP: + ret = _efl_util_gesture_grab_tap(data, EINA_FALSE); + break; + case TIZEN_GESTURE_TYPE_PALM_COVER: + ret = _efl_util_gesture_grab_palm_cover(data, EINA_FALSE); + 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_defaultqueue.wl.gesture.proto, surface); + + ret = _efl_util_gesture_verify_request_notified(); + + 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_defaultqueue.wl.gesture.proto, surface); + + ret = _efl_util_gesture_verify_request_notified(); + + 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_defaultqueue.wl.gesture.proto, NULL, type, active); + + ret = _efl_util_gesture_verify_request_notified(); + + 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_defaultqueue.wl.gesture.proto, surface, type, active); + + ret = _efl_util_gesture_verify_request_notified(); + + return ret; +}