From: Joonbum Ko Date: Mon, 28 Apr 2025 07:21:12 +0000 (+0900) Subject: refactor codes related to initializing X-Git-Tag: accepted/tizen/unified/20250509.075345~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77b8fdfd894917564e0695e7084cc610092e91f3;p=platform%2Fcore%2Fapi%2Fefl-util.git refactor codes related to initializing - Removed duplicated code - Removed unnecessary registry binding - Fixed to manage the added input_device_list and release it properly Change-Id: I14574f605f38d0cd5af49885df1c3173180268cd Signed-off-by: Joonbum Ko --- diff --git a/src/efl_util.c b/src/efl_util.c index 1ac4e20..4d6273b 100644 --- a/src/efl_util.c +++ b/src/efl_util.c @@ -139,17 +139,20 @@ typedef struct _Efl_Util_Data 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_Bool init; + struct wl_event_queue *queue; + struct tizen_policy *tz_policy; + struct tizen_display_policy *tz_display_policy; + Eina_Hash *hash_brightness; Eina_Hash *hash_noti_lv; Eina_Hash *hash_scr_mode; } policy; struct { + Eina_Bool init; struct wl_event_queue *queue; struct tizen_screenshooter *tz_screenshooter; struct wayland_tbm_client *tbm_client; @@ -158,19 +161,15 @@ typedef struct _Efl_Util_Data } shot; struct { + Eina_Bool init; struct wl_event_queue *queue; Eina_List *seat_list; + Eina_List *input_device_list; struct tizen_input_device_manager *devicemgr; int request_notified; 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; @@ -218,11 +217,10 @@ static Efl_Util_Data _eflutil = { { EINA_FALSE, - NULL, NULL, NULL, - { 0, NULL, NULL, NULL }, /* tizen_policy protocol */ - { NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */ - { NULL, NULL, NULL, -1, 0, 0 }, /* tizen_input_device_manager protocol */ - { 0, NULL, NULL } /* display_policy protocol */ + NULL, NULL, + { EINA_FALSE, NULL, NULL, NULL, NULL, NULL, NULL }, /* tizen_policy protocol */ + { EINA_FALSE, NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */ + { EINA_FALSE, NULL, NULL, NULL, NULL, -1, 0, 0 }, /* tizen_input_device_manager protocol */ }, }; @@ -344,10 +342,6 @@ struct tizen_gesture_listener _wl_tz_gesture_listener = static Eina_Bool _wl_init(void) { - struct wl_display *display_wrapper = NULL; - struct wl_registry *reg = NULL; - int ret = 0; - if (_eflutil.wl.init) return EINA_TRUE; if (ecore_wl2_init() <= 0) return EINA_FALSE; @@ -357,43 +351,74 @@ _wl_init(void) _eflutil.wl.dpy = ecore_wl2_display_get(_eflutil.wl.wl2_display); EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.dpy, fail); + _eflutil.wl.init = EINA_TRUE; + + return EINA_TRUE; + +fail: + ecore_wl2_shutdown(); + return EINA_FALSE; +} + +static Eina_Bool +_handle_registry_events(struct wl_event_queue *queue, const struct wl_registry_listener *listener, void *data) +{ + struct wl_display *display_wrapper = NULL; + struct wl_registry *registry = NULL; + int ret; + display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy); EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail); - _eflutil.wl.queue = wl_display_create_queue(_eflutil.wl.dpy); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.queue, fail); - - wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue); + wl_proxy_set_queue((struct wl_proxy *)display_wrapper, queue); - reg = wl_display_get_registry(display_wrapper); + registry = wl_display_get_registry(display_wrapper); wl_proxy_wrapper_destroy(display_wrapper); display_wrapper = NULL; - EINA_SAFETY_ON_NULL_GOTO(reg, fail); + EINA_SAFETY_ON_NULL_GOTO(registry, fail); - wl_registry_add_listener(reg, &_wl_reg_listener, NULL); + wl_registry_add_listener(registry, listener, data); - ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, queue); EINA_SAFETY_ON_TRUE_GOTO(ret < 0, fail); - wl_registry_destroy(reg); - - _eflutil.wl.init = EINA_TRUE; + wl_registry_destroy(registry); return EINA_TRUE; + fail: - if (display_wrapper) - wl_proxy_wrapper_destroy(display_wrapper); + if (registry) wl_registry_destroy(registry); + + return EINA_FALSE; +} + +static Eina_Bool +_policy_init(void) +{ + Eina_Bool res; + + if (_eflutil.wl.policy.init) return EINA_TRUE; + + if (_wl_init() == EINA_FALSE) + return EINA_FALSE; - if (_eflutil.wl.queue) + _eflutil.wl.policy.queue = wl_display_create_queue(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.queue, EINA_FALSE); + + res = _handle_registry_events(_eflutil.wl.policy.queue, &_wl_reg_listener, NULL); + EINA_SAFETY_ON_FALSE_GOTO(res, fail); + + _eflutil.wl.policy.init = EINA_TRUE; + + return EINA_TRUE; + +fail: + if (_eflutil.wl.policy.queue) { - wl_event_queue_destroy(_eflutil.wl.queue); - _eflutil.wl.queue = NULL; + wl_event_queue_destroy(_eflutil.wl.policy.queue); + _eflutil.wl.policy.queue = NULL; } - if (reg) - wl_registry_destroy(reg); - - ecore_wl2_shutdown(); return EINA_FALSE; } @@ -530,30 +555,18 @@ _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")) - { - Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info)); - EINA_SAFETY_ON_NULL_RETURN(output); - - _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output); - - output->output = wl_registry_bind(reg, id, &wl_output_interface, version); - wl_output_add_listener(output->output, &output_listener, output); + _eflutil.wl.policy.tz_policy = proto; } else if (!strcmp(interface, "tizen_display_policy")) { - _eflutil.wl.display_policy.proto = wl_registry_bind(reg, id, &tizen_display_policy_interface, version); - if (!_eflutil.wl.display_policy.proto) return; + _eflutil.wl.policy.tz_display_policy = wl_registry_bind(reg, id, &tizen_display_policy_interface, version); + if (!_eflutil.wl.policy.tz_display_policy) return; - tizen_display_policy_add_listener(_eflutil.wl.display_policy.proto, + tizen_display_policy_add_listener(_eflutil.wl.policy.tz_display_policy, &_wl_tz_display_policy_listener, NULL); - _eflutil.wl.display_policy.hash_brightness = eina_hash_pointer_new(free); - _eflutil.wl.display_policy.id = id; + _eflutil.wl.policy.hash_brightness = eina_hash_pointer_new(free); } } /* LCOV_EXCL_START */ @@ -562,22 +575,21 @@ _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int id) { - /* 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) + if (_eflutil.wl.policy.tz_policy) { - _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); + tizen_policy_destroy(_eflutil.wl.policy.tz_policy); + _eflutil.wl.policy.tz_policy = NULL; } - else if (id == _eflutil.wl.display_policy.id) + + if (_eflutil.wl.policy.tz_display_policy) { - _eflutil.wl.display_policy.id = 0; - _eflutil.wl.display_policy.proto = NULL; - eina_hash_free(_eflutil.wl.display_policy.hash_brightness); + tizen_display_policy_destroy( _eflutil.wl.policy.tz_display_policy); + _eflutil.wl.policy.tz_display_policy = NULL; } + + eina_hash_free(_eflutil.wl.policy.hash_noti_lv); + eina_hash_free(_eflutil.wl.policy.hash_scr_mode); + eina_hash_free(_eflutil.wl.policy.hash_brightness); } /* LCOV_EXCL_STOP */ @@ -652,8 +664,16 @@ _cb_wl_reg_screenshooter_global(void *data, { _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); + } + else if (!strcmp(interface, "wl_output")) + { + Efl_Util_Wl_Output_Info *output = calloc(1, sizeof(Efl_Util_Wl_Output_Info)); + EINA_SAFETY_ON_NULL_RETURN(output); + + _eflutil.wl.shot.output_list = eina_list_append(_eflutil.wl.shot.output_list, output); - wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); + output->output = wl_registry_bind(reg, name, &wl_output_interface, version); + wl_output_add_listener(output->output, &output_listener, output); } } @@ -752,7 +772,7 @@ _cb_wl_tz_display_policy_brightness_done(void *data, { Efl_Util_Wl_Surface_Brightness_Info *brightness_info; - brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface); + brightness_info = eina_hash_find(_eflutil.wl.policy.hash_brightness, &surface); if (brightness_info) { brightness_info->brightness = brightness; @@ -791,7 +811,7 @@ efl_util_set_notification_window_level(Evas_Object *window, Ecore_Wl2_Window_Type wl_type; int ret_dispatch = 0; - res = _wl_init(); + res = _policy_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); @@ -805,7 +825,7 @@ efl_util_set_notification_window_level(Evas_Object *window, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE); } - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_NOT_SUPPORTED); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.tz_policy, EFL_UTIL_ERROR_NOT_SUPPORTED); surface = ecore_wl2_window_surface_get(wlwin); EINA_SAFETY_ON_NULL_RETURN_VAL(surface, @@ -836,7 +856,7 @@ efl_util_set_notification_window_level(Evas_Object *window, } - tizen_policy_set_notification_level(_eflutil.wl.policy.proto, + tizen_policy_set_notification_level(_eflutil.wl.policy.tz_policy, surface, (int)level); if (lv_info->wait_for_done) @@ -845,7 +865,7 @@ efl_util_set_notification_window_level(Evas_Object *window, ret_dispatch = 0; while (lv_info->wait_for_done && (count < NUM_EVENT_WAIT_DONE_COUNT) && (ret_dispatch != -1)) { - ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.policy.queue); count++; } @@ -881,9 +901,9 @@ efl_util_get_notification_window_level(Evas_Object *window, Ecore_Wl2_Window_Type wl_type; int ret_dispatch = 0; - res = _wl_init(); + res = _policy_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_NOT_SUPPORTED); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.tz_policy, EFL_UTIL_ERROR_NOT_SUPPORTED); wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); EINA_SAFETY_ON_NULL_RETURN_VAL(wlwin, EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE); @@ -909,7 +929,7 @@ efl_util_get_notification_window_level(Evas_Object *window, ret_dispatch = 0; while ((lv_info->wait_for_done) && (count < NUM_EVENT_WAIT_DONE_COUNT) && (ret_dispatch != -1)) { - ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.policy.queue); count++; } @@ -951,11 +971,11 @@ efl_util_set_window_opaque_state(Evas_Object *window, Ecore_Wl2_Window *wlwin; struct wl_surface *surface; - if (!_eflutil.wl.policy.proto) + if (!_eflutil.wl.policy.tz_policy) { - res = _wl_init(); + res = _policy_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_NOT_SUPPORTED); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.tz_policy, EFL_UTIL_ERROR_NOT_SUPPORTED); } wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); @@ -966,7 +986,7 @@ efl_util_set_window_opaque_state(Evas_Object *window, if (!surface) return EFL_UTIL_ERROR_NOT_SUPPORTED_WINDOW_TYPE; - tizen_policy_set_opaque_state(_eflutil.wl.policy.proto, surface, opaque); + tizen_policy_set_opaque_state(_eflutil.wl.policy.tz_policy, surface, opaque); return EFL_UTIL_ERROR_NONE; } @@ -986,9 +1006,9 @@ efl_util_set_window_screen_mode(Evas_Object *window, Eina_Bool res; int ret_dispatch = 0; - res = _wl_init(); + res = _policy_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_NOT_SUPPORTED); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.tz_policy, EFL_UTIL_ERROR_NOT_SUPPORTED); wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (wlwin) @@ -1019,7 +1039,7 @@ efl_util_set_window_screen_mode(Evas_Object *window, scr_mode_info->state = TIZEN_POLICY_ERROR_STATE_NONE; } - tizen_policy_set_window_screen_mode(_eflutil.wl.policy.proto, + tizen_policy_set_window_screen_mode(_eflutil.wl.policy.tz_policy, surface, (unsigned int)mode); if (scr_mode_info->wait_for_done) { @@ -1027,7 +1047,7 @@ efl_util_set_window_screen_mode(Evas_Object *window, ret_dispatch = 0; while (scr_mode_info->wait_for_done && (count < NUM_EVENT_WAIT_DONE_COUNT) && (ret_dispatch != -1)) { - ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.policy.queue); count++; } @@ -1063,9 +1083,9 @@ efl_util_get_window_screen_mode(Evas_Object *window, Eina_Bool res; int ret_dispatch = 0; - res = _wl_init(); + res = _policy_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_NOT_SUPPORTED); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.tz_policy, EFL_UTIL_ERROR_NOT_SUPPORTED); wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (wlwin) @@ -1082,7 +1102,7 @@ efl_util_get_window_screen_mode(Evas_Object *window, ret_dispatch = 0; while (scr_mode_info->wait_for_done && (ret_dispatch != -1)) { - ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.policy.queue); } } @@ -1117,9 +1137,9 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); EINA_SAFETY_ON_FALSE_RETURN_VAL(brightness <= 100, EFL_UTIL_ERROR_INVALID_PARAMETER); - res = _wl_init(); + res = _policy_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.proto, EFL_UTIL_ERROR_NOT_SUPPORTED); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.tz_policy, EFL_UTIL_ERROR_NOT_SUPPORTED); wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (wlwin) @@ -1128,7 +1148,7 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER); - brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface); + brightness_info = eina_hash_find(_eflutil.wl.policy.hash_brightness, &surface); if (!brightness_info) { brightness_info = calloc(1, sizeof(Efl_Util_Wl_Surface_Brightness_Info)); @@ -1139,7 +1159,7 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) brightness_info->wait_for_done = EINA_TRUE; brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE; - eina_hash_add(_eflutil.wl.display_policy.hash_brightness, + eina_hash_add(_eflutil.wl.policy.hash_brightness, &surface, brightness_info); } @@ -1150,7 +1170,7 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) brightness_info->state = TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE; } - tizen_display_policy_set_window_brightness(_eflutil.wl.display_policy.proto, + tizen_display_policy_set_window_brightness(_eflutil.wl.policy.tz_display_policy, surface, brightness); if (brightness_info->wait_for_done) { @@ -1158,7 +1178,7 @@ efl_util_set_window_brightness(Evas_Object *window, int brightness) ret_dispatch = 0; while (brightness_info->wait_for_done && (count < NUM_EVENT_WAIT_DONE_COUNT) && (ret_dispatch != -1)) { - ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.policy.queue); count++; } @@ -1192,9 +1212,9 @@ efl_util_get_window_brightness(Evas_Object *window, int *brightness) EINA_SAFETY_ON_NULL_RETURN_VAL(window, EFL_UTIL_ERROR_INVALID_PARAMETER); EINA_SAFETY_ON_NULL_RETURN_VAL(brightness, EFL_UTIL_ERROR_INVALID_PARAMETER); - res = _wl_init(); + res = _policy_init(); EINA_SAFETY_ON_FALSE_RETURN_VAL(res, EFL_UTIL_ERROR_INVALID_PARAMETER); - EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.display_policy.proto, EFL_UTIL_ERROR_NOT_SUPPORTED); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.policy.tz_display_policy, EFL_UTIL_ERROR_NOT_SUPPORTED); wlwin = (Ecore_Wl2_Window *)elm_win_wl_window_get(window); if (!wlwin) return EFL_UTIL_ERROR_INVALID_PARAMETER; @@ -1203,7 +1223,7 @@ efl_util_get_window_brightness(Evas_Object *window, int *brightness) EINA_SAFETY_ON_NULL_RETURN_VAL(surface, EFL_UTIL_ERROR_INVALID_PARAMETER); - brightness_info = eina_hash_find(_eflutil.wl.display_policy.hash_brightness, &surface); + brightness_info = eina_hash_find(_eflutil.wl.policy.hash_brightness, &surface); if (brightness_info) { if (brightness_info->wait_for_done) @@ -1211,7 +1231,7 @@ efl_util_get_window_brightness(Evas_Object *window, int *brightness) ret_dispatch = 0; while (brightness_info->wait_for_done && (ret_dispatch != -1)) { - ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + ret_dispatch = wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.policy.queue); } } *brightness = brightness_info->brightness; @@ -1241,6 +1261,7 @@ _cb_device_add(void *data EINA_UNUSED, (unsigned int)wl_proxy_get_id((struct wl_proxy *)tizen_input_device_manager), (unsigned int)wl_proxy_get_id((struct wl_proxy *)device), identifier); + _eflutil.wl.devmgr.input_device_list = eina_list_append(_eflutil.wl.devmgr.input_device_list, device); } static void @@ -1255,6 +1276,8 @@ _cb_device_remove(void *data EINA_UNUSED, (unsigned int)wl_proxy_get_id((struct wl_proxy *)tizen_input_device_manager), (unsigned int)wl_proxy_get_id((struct wl_proxy *)device), identifier); + + _eflutil.wl.devmgr.input_device_list = eina_list_remove(_eflutil.wl.devmgr.input_device_list, device); tizen_input_device_release(device); } @@ -1308,46 +1331,33 @@ _efl_util_input_convert_input_generator_error(int ret) static Eina_Bool _efl_util_wl_inputgen_init() { - struct wl_display *display_wrapper = NULL; - struct wl_registry *registry = NULL; - int ret = 0; + Eina_Bool res; + + if (_eflutil.wl.devmgr.init) return EINA_TRUE; if (_wl_init() == EINA_FALSE) return EINA_FALSE; - display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy); - EINA_SAFETY_ON_NULL_RETURN_VAL(display_wrapper, EINA_FALSE); - _eflutil.wl.devmgr.queue = wl_display_create_queue(_eflutil.wl.dpy); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.devmgr.queue, fail_create_queue); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.devmgr.queue, EINA_FALSE); - wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.devmgr.queue); + res = _handle_registry_events(_eflutil.wl.devmgr.queue, &_wl_reg_devicemgr_listener, NULL); + EINA_SAFETY_ON_FALSE_GOTO(res, fail); - registry = wl_display_get_registry(display_wrapper); - EINA_SAFETY_ON_NULL_GOTO(registry, fail_get_registry); - - wl_registry_add_listener(registry, &_wl_reg_devicemgr_listener, NULL); - - ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.devmgr.queue); - EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_roundtrip); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.devmgr.devicemgr, fail_roundtrip); - - wl_registry_destroy(registry); - wl_proxy_wrapper_destroy(display_wrapper); + _eflutil.wl.devmgr.init = EINA_TRUE; return EINA_TRUE; -fail_roundtrip: - wl_registry_destroy(registry); -fail_get_registry: - wl_event_queue_destroy(_eflutil.wl.devmgr.queue); - _eflutil.wl.devmgr.queue = NULL; -fail_create_queue: - wl_proxy_wrapper_destroy(display_wrapper); +fail: + if (_eflutil.wl.devmgr.queue) + { + wl_event_queue_destroy(_eflutil.wl.devmgr.queue); + _eflutil.wl.devmgr.queue = NULL; + } return EINA_FALSE; - } + static efl_util_inputgen_h _efl_util_input_create_inputgen(unsigned int dev_type, const char *name, int *ret, int with_name) { @@ -1500,6 +1510,7 @@ static void _efl_util_wl_inputgen_deinit() { struct wl_seat *seat; + struct tizen_input_device *device; Eina_List *l; EINA_LIST_FOREACH (_eflutil.wl.devmgr.seat_list, l, seat) @@ -1508,19 +1519,27 @@ _efl_util_wl_inputgen_deinit() } _eflutil.wl.devmgr.seat_list = eina_list_free(_eflutil.wl.devmgr.seat_list); + EINA_LIST_FOREACH (_eflutil.wl.devmgr.input_device_list, l, device) + { + tizen_input_device_release(device); + } + _eflutil.wl.devmgr.input_device_list = eina_list_free(_eflutil.wl.devmgr.input_device_list); + + wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.devmgr.queue); + if (_eflutil.wl.devmgr.devicemgr) { tizen_input_device_manager_destroy(_eflutil.wl.devmgr.devicemgr); _eflutil.wl.devmgr.devicemgr = NULL; } - wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.devmgr.queue); - if (_eflutil.wl.devmgr.queue) { wl_event_queue_destroy(_eflutil.wl.devmgr.queue); _eflutil.wl.devmgr.queue = NULL; } + + _eflutil.wl.devmgr.init = EINA_FALSE; } API int @@ -1929,54 +1948,55 @@ _screenshot_mutex_unlock(void) static Eina_Bool _efl_util_wl_screenshooter_init() { - struct wl_display *display_wrapper = NULL; - struct wl_registry *registry = NULL; - int ret = 0; + Eina_Bool res; + int ret; + + if (_eflutil.wl.shot.init) return EINA_TRUE; if (_wl_init() == EINA_FALSE) return EINA_FALSE; - 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); + EINA_SAFETY_ON_NULL_RETURN_VAL(_eflutil.wl.shot.queue, EINA_FALSE); - 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); + res = _handle_registry_events(_eflutil.wl.shot.queue, &_wl_reg_screenshooter_listener, NULL); + EINA_SAFETY_ON_FALSE_GOTO(res, fail); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail); _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); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail); - wl_registry_destroy(registry); - wl_proxy_wrapper_destroy(display_wrapper); + ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.shot.queue); + EINA_SAFETY_ON_TRUE_GOTO(ret < 0, fail); if (_eflutil.wl.shot.noti == 0) { fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */ - return EINA_FALSE; + goto fail; } + _eflutil.wl.shot.init = EINA_TRUE; + 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); +fail: + 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; + } return EINA_FALSE; } @@ -2003,6 +2023,8 @@ _efl_util_wl_screenshooter_deinit() wl_event_queue_destroy(_eflutil.wl.shot.queue); _eflutil.wl.shot.queue = NULL; } + + _eflutil.wl.shot.init = EINA_FALSE; } API efl_util_screenshot_h