Remake old APIs using new APIs
[platform/core/appfw/app-core.git] / src / ui_base / appcore_ui_base.c
index baf80cd..31da1ef 100644 (file)
@@ -389,7 +389,7 @@ static void __finish_wl(void)
 
 static void __set_bg_state(void)
 {
-       if (__init_wl() < 0)
+       if (!tz_policy && __init_wl() < 0)
                return;
 
        tizen_policy_set_background_state(tz_policy, getpid());
@@ -407,7 +407,6 @@ static void __unset_bg_state(void)
        wl_display_roundtrip(dsp);
        bg_state = false;
        _DBG("bg state: %d", bg_state);
-       __finish_wl();
 }
 
 static void __do_start(bundle *b)
@@ -431,14 +430,19 @@ static void __do_start(bundle *b)
                return;
        }
 
-       if ((__context.hint & APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL) &&
-               bg_state) {
+       if (__context.hint & APPCORE_UI_BASE_HINT_BG_LAUNCH_CONTROL) {
                bg_launch = bundle_get_val(b, AUL_SVC_K_BG_LAUNCH);
-               if (!bg_launch || strcmp(bg_launch, "enable"))
-                       __unset_bg_state();
+               if (bg_launch && strcmp(bg_launch, "enable") == 0) {
+                       if (!bg_state && __context.state != AS_RUNNING)
+                               __set_bg_state();
+               } else {
+                       if (bg_state)
+                               __unset_bg_state();
+               }
        }
 
-       __raise_win();
+       if (!bg_state)
+               __raise_win();
 }
 
 EXPORT_API int appcore_ui_base_on_receive(aul_type type, bundle *b)
@@ -461,7 +465,9 @@ EXPORT_API int appcore_ui_base_on_receive(aul_type type, bundle *b)
                __do_start(b);
                break;
        case AUL_RESUME:
-               __do_resume();
+               if (bg_state)
+                       __unset_bg_state();
+               __raise_win();
                break;
        case AUL_TERMINATE:
                break;
@@ -505,22 +511,6 @@ EXPORT_API int appcore_ui_base_on_terminate(void)
        }
 
        __context.state = AS_DYING;
-       if (__context.hshow)
-               ecore_event_handler_del(__context.hshow);
-       if (__context.hhide)
-               ecore_event_handler_del(__context.hhide);
-       if (__context.hvchange)
-               ecore_event_handler_del(__context.hvchange);
-       if (__context.hlower)
-               ecore_event_handler_del(__context.hlower);
-
-       elm_shutdown();
-
-       /* Check loader case */
-       if (getenv("AUL_LOADER_INIT")) {
-               unsetenv("AUL_LOADER_INIT");
-               elm_shutdown();
-       }
 
        appcore_base_on_terminate();
 
@@ -548,10 +538,22 @@ EXPORT_API int appcore_ui_base_on_control(bundle *b)
 
 static void __group_attach()
 {
-       static bool attached = false;
+       if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
+               return;
+
+       appcore_ui_base_group_add();
+}
 
+static void __group_lower()
+{
        if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
                return;
+       appcore_ui_base_group_remove();
+}
+
+EXPORT_API void appcore_ui_base_group_add()
+{
+       static bool attached = false;
 
        _DBG("__group_attach");
        if (attached)
@@ -567,13 +569,10 @@ static void __group_attach()
        attached = true;
 }
 
-static void __group_lower()
+EXPORT_API void appcore_ui_base_group_remove()
 {
        int exit = 0;
 
-       if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))
-               return;
-
        _DBG("__group_lower");
        aul_app_group_lower(&exit);
        if (exit) {
@@ -599,7 +598,9 @@ EXPORT_API void appcore_ui_base_window_on_show(int type, void *event)
                __add_win((unsigned int)ev->win, (unsigned int)ev->data[0]);
        else
                __update_win((unsigned int)ev->win, (unsigned int)ev->data[0], FALSE);
-       __group_attach();
+
+       if (ev->data[0] != 0)
+               __group_attach();
 }
 
 static bool __check_visible(void)
@@ -727,6 +728,25 @@ EXPORT_API int appcore_ui_base_init(appcore_ui_base_ops ops, int argc, char **ar
 EXPORT_API void appcore_ui_base_fini(void)
 {
        appcore_base_fini();
+
+       if (__context.hshow)
+               ecore_event_handler_del(__context.hshow);
+       if (__context.hhide)
+               ecore_event_handler_del(__context.hhide);
+       if (__context.hvchange)
+               ecore_event_handler_del(__context.hvchange);
+       if (__context.hlower)
+               ecore_event_handler_del(__context.hlower);
+
+       __finish_wl();
+       elm_shutdown();
+
+       /* Check loader case */
+       if (getenv("AUL_LOADER_INIT")) {
+               unsetenv("AUL_LOADER_INIT");
+               elm_shutdown();
+       }
+
        free(__context.appid);
        __context.appid = NULL;
 }
@@ -752,6 +772,16 @@ EXPORT_API void appcore_ui_base_exit(void)
                __context.ops.base.exit(__context.data);
 }
 
+EXPORT_API unsigned int appcore_ui_base_get_main_window(void)
+{
+       return __get_main_window();
+}
+
+EXPORT_API unsigned int appcore_ui_base_get_main_surface(void)
+{
+       return __get_main_surface();
+}
+
 static int __on_receive(aul_type type, bundle *b, void *data)
 {
        return appcore_ui_base_on_receive(type, b);