Implement window event callback 79/70779/4 accepted/tizen/common/20160524.150808 accepted/tizen/ivi/20160525.003501 accepted/tizen/mobile/20160525.003615 accepted/tizen/tv/20160525.003450 accepted/tizen/wearable/20160525.003550 submit/tizen/20160524.092228
authorDaehyeon Jung <darrenh.jung@samsung.com>
Fri, 20 May 2016 12:21:59 +0000 (21:21 +0900)
committerDaehyeon Jung <darrenh.jung@samsung.com>
Tue, 24 May 2016 07:49:50 +0000 (16:49 +0900)
Change-Id: I3792b4762b14ec655943d44d7d06291fc7a65e1d
Signed-off-by: Daehyeon Jung <darrenh.jung@samsung.com>
src/widget_app.c

index 491ca1c..c8e3764 100755 (executable)
@@ -246,19 +246,29 @@ static int __instance_resume(widget_class_h handle, const char *id, bundle *b)
        widget_context_s *wc = __find_context_by_id(id);
        int ret;
 
-       if (wc) {
-               if (handle->ops.resume)
-                       handle->ops.resume(wc, handle->user_data);
-
-               wc->state = WC_RUNNING;
-               _D("%s is resumed", id);
-               ret = __send_update_status(handle->classid, wc->id,
-                       WIDGET_INSTANCE_EVENT_RESUME, NULL, 0);
-       } else {
+       if (!wc) {
                _E("context not found: %s", id);
-               ret = -1;
+               return -1;
+       }
+
+       if (wc->state == WC_RUNNING) {
+               _D("%s is already in running state", id);
+               return 0;
        }
 
+       if (wc->state == WC_TERMINATED) {
+               _D("%s is in terminated state", id);
+               return 0;
+       }
+
+       if (handle->ops.resume)
+               handle->ops.resume(wc, handle->user_data);
+
+       wc->state = WC_RUNNING;
+       _D("%s is resumed", id);
+       ret = __send_update_status(handle->classid, wc->id,
+               WIDGET_INSTANCE_EVENT_RESUME, NULL, 0);
+
        return ret;
 }
 
@@ -267,56 +277,49 @@ static int __instance_pause(widget_class_h handle, const char *id, bundle *b)
        widget_context_s *wc = __find_context_by_id(id);
        int ret;
 
-       if (wc) {
-               if (handle->ops.pause)
-                       handle->ops.pause(wc, handle->user_data);
-
-               wc->state = WC_PAUSED;
-               _D("%s is paused", id);
-               ret = __send_update_status(handle->classid, wc->id,
-                       WIDGET_INSTANCE_EVENT_PAUSE, NULL, 0);
-       } else {
+       if (!wc) {
                _E("context not found: %s", id);
-               ret = -1;
+               return -1;
        }
 
+       if (wc->state == WC_PAUSED) {
+               _D("%s is already in paused state", id);
+               return 0;
+       }
+
+       if (wc->state == WC_TERMINATED) {
+               _D("%s is in terminated state", id);
+               return 0;
+       }
+
+       if (handle->ops.pause)
+               handle->ops.pause(wc, handle->user_data);
+
+       wc->state = WC_PAUSED;
+       _D("%s is paused", id);
+       ret = __send_update_status(handle->classid, wc->id,
+               WIDGET_INSTANCE_EVENT_PAUSE, NULL, 0);
+
        return ret;
 }
 
-static int __instance_resize(widget_class_h handle, const char *id, bundle *b)
+static int __instance_resize(widget_class_h handle, const char *id, int w, int h, bundle *b)
 {
        widget_context_s *wc = __find_context_by_id(id);
        int ret;
-       int w;
-       int h;
-       char *w_str = NULL;
-       char *h_str = NULL;
-       char *remain = NULL;
-
-       if (wc) {
-               bundle_get_str(b, WIDGET_K_WIDTH, &w_str);
-               bundle_get_str(b, WIDGET_K_HEIGHT, &h_str);
 
-               if (w_str)
-                       w = (int)g_ascii_strtoll(w_str, &remain, 10);
-               else
-                       w = -1;
-
-               if (h_str)
-                       h = (int)g_ascii_strtoll(h_str, &remain, 10);
-               else
-                       h = -1;
-
-               if (handle->ops.resize)
-                       handle->ops.resize(wc, w, h, handle->user_data);
-               _D("%s is resized to %dx%d", id, w, h);
-               ret = __send_update_status(handle->classid, wc->id,
-                       WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL, 0);
-       } else {
+       if (!wc) {
                _E("context not found: %s", id);
-               ret = -1;
+               return -1;
        }
 
+       if (handle->ops.resize)
+               handle->ops.resize(wc, w, h, handle->user_data);
+
+       _D("%s is resized to %dx%d", id, w, h);
+       ret = __send_update_status(handle->classid, wc->id,
+               WIDGET_INSTANCE_EVENT_SIZE_CHANGED, NULL, 0);
+
        return ret;
 }
 
@@ -393,23 +396,24 @@ static int __instance_destroy(widget_class_h handle, const char *id,
        widget_context_s *wc = __find_context_by_id(id);
        int ret = 0;
 
-       if (wc) {
-               wc->state = WC_TERMINATED;
-               handle->ops.destroy(wc, (widget_app_destroy_type_e)reason, b,
-                               handle->user_data);
+       if (!wc) {
+               _E("could not find widget obj: %s", id);
+               return WIDGET_ERROR_INVALID_PARAMETER;
+       }
 
-               ret = __send_update_status(handle->classid, id,
-                               WIDGET_INSTANCE_EVENT_TERMINATE, b, 0);
+       wc->state = WC_TERMINATED;
+       handle->ops.destroy(wc, (widget_app_destroy_type_e)reason, b,
+                       handle->user_data);
 
-               contexts = g_list_remove(contexts, wc);
+       ret = __send_update_status(handle->classid, id,
+                       WIDGET_INSTANCE_EVENT_TERMINATE, b, 0);
 
-               if (wc->id)
-                       free(wc->id);
-               free(wc);
-       } else {
-               _E("could not find widget obj: %s", id);
-               ret = WIDGET_ERROR_INVALID_PARAMETER;
-       }
+       contexts = g_list_remove(contexts, wc);
+
+       if (wc->id)
+               free(wc->id);
+
+       free(wc);
 
        return ret;
 }
@@ -432,6 +436,38 @@ static widget_class_h __find_class_handler(const char *class_id,
        return NULL;
 }
 
+static void __resize_window(char *id, bundle *b)
+{
+       widget_context_s *wc = __find_context_by_id(id);
+       char *w_str = NULL;
+       char *h_str = NULL;
+       char *remain = NULL;
+       int w;
+       int h;
+
+       bundle_get_str(b, WIDGET_K_WIDTH, &w_str);
+       bundle_get_str(b, WIDGET_K_HEIGHT, &h_str);
+
+       if (w_str) {
+               w = (int)g_ascii_strtoll(w_str, &remain, 10);
+       } else {
+               _E("unable to get width");
+               return;
+       }
+
+       if (h_str) {
+               h = (int)g_ascii_strtoll(h_str, &remain, 10);
+       } else {
+               _E("unable to get height");
+               return;
+       }
+
+       if (wc->win)
+               evas_object_resize(wc->win, w, h);
+       else
+               _E("unable to find window of %d", wc->id);
+}
+
 static void __control(bundle *b)
 {
        char *class_id = NULL;
@@ -464,7 +500,7 @@ static void __control(bundle *b)
        if (strcmp(operation, "create") == 0) {
                __instance_create(handle, id, b);
        } else if (strcmp(operation, "resize") == 0) {
-               __instance_resize(handle, id, b);
+               __resize_window(id, b);
        } else if (strcmp(operation, "update") == 0) {
                __instance_update(handle, id, b);
        } else if (strcmp(operation, "destroy") == 0) {
@@ -490,21 +526,24 @@ static void __resume_cb(const char *id, void *data)
 {
        widget_context_s *cxt = __find_context_by_id(id);
 
-       if (cxt)
-               __instance_resume(cxt->provider, id, NULL);
-       else
+       if (!cxt) {
                _E("invalid context id:%s", id);
+               return;
+       }
 
+       __instance_resume(cxt->provider, id, NULL);
 }
 
 static void __pause_cb(const char *id, void *data)
 {
        widget_context_s *cxt = __find_context_by_id(id);
 
-       if (cxt)
-               __instance_pause(cxt->provider, id, NULL);
-       else
+       if (!cxt) {
                _E("invalid context id:%s", id);
+               return;
+       }
+
+       __instance_pause(cxt->provider, id, NULL);
 }
 
 static void __pause_all()
@@ -582,8 +621,23 @@ static Eina_Bool __hide_cb(void *data, int type, void *event)
 static Eina_Bool __visibility_cb(void *data, int type, void *event)
 {
        Ecore_Wl_Event_Window_Visibility_Change *ev = event;
+       widget_context_s *cxt = __find_context_by_win(ev->win);
+
        LOGD("visiblity change: %d %d", (unsigned int)ev->win,  (unsigned int)ev->fully_obscured);
-       /* this is not working so far*/
+
+       if (!cxt) {
+               LOGE("unknown window error: %d", ev->win);
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       if (cxt->state == WC_PAUSED && ev->fully_obscured == 0) {
+               __instance_resume(cxt->provider, cxt->id, NULL);
+       } else if (cxt->state == WC_RUNNING && ev->fully_obscured == 1) {
+               __instance_pause(cxt->provider, cxt->id, NULL);
+       } else {
+               LOGD("cxt:%s state:%d obscured:%d", cxt->id, cxt->state, ev->fully_obscured);
+       }
+
        return ECORE_CALLBACK_RENEW;
 }
 
@@ -593,12 +647,32 @@ static Eina_Bool __lower_cb(void *data, int type, void *event)
        return ECORE_CALLBACK_RENEW;
 }
 
+static Eina_Bool __configure_cb(void *data, int type, void *event)
+{
+       Ecore_Wl_Event_Window_Configure *ev = event;
+       widget_context_s *cxt = __find_context_by_win(ev->win);
+
+       LOGD("configure: %d %d", ev->w, ev->h);
+
+       if (!cxt) {
+               LOGE("unknown window error: %d", ev->win);
+               return ECORE_CALLBACK_RENEW;
+       }
+
+       if (cxt->state == WC_PAUSED || cxt->state == WC_RUNNING)
+               __instance_resize(cxt->provider, cxt->id, ev->w, ev->h, NULL);
+       LOGD("cxt:%s resized to %dx%d", cxt->id, ev->w, ev->h);
+
+       return ECORE_CALLBACK_RENEW;
+}
+
 static void __add_climsg()
 {
        ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_SHOW, __show_cb, NULL);
        ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_HIDE, __hide_cb, NULL);
        ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, __visibility_cb, NULL);
        ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_LOWER, __lower_cb, NULL);
+       ecore_event_handler_add(ECORE_WL_EVENT_WINDOW_CONFIGURE, __configure_cb, NULL);
 }
 
 static int __aul_handler(aul_type type, bundle *b, void *data)
@@ -703,9 +777,13 @@ static int __before_loop(int argc, char **argv)
                if (xdg_runtime_dir)
                        setenv("XDG_RUNTIME_DIR", xdg_runtime_dir, 1);
 
+               _D("xdg_runtime_dir:%s", xdg_runtime_dir);
+
                if (wayland_display)
                        setenv("WAYLAND_DISPLAY", wayland_display, 1);
 
+               _D("wayland_display:%s", wayland_display);
+
                bundle_free(kb);
                kb = NULL;
        } else {