From 0ec02ab953fa3b1500c0cb274ffead58181b6b24 Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Thu, 16 Jun 2016 21:42:52 +0900 Subject: [PATCH] Add pepper visibility callback - Supports visibility change callback for widget/watch Change-Id: I9de7fb712f5e39220802ee31670980704c500754 --- watch-control/src/control.c | 2 + widget_toolkit/include/compositor.h | 11 +++ widget_toolkit/src/compositor.c | 129 ++++++++++++++++++++++++++++ widget_viewer_evas/src/widget_viewer_evas.c | 27 +++++- 4 files changed, 167 insertions(+), 2 deletions(-) diff --git a/watch-control/src/control.c b/watch-control/src/control.c index 147681a..d6d5479 100644 --- a/watch-control/src/control.c +++ b/watch-control/src/control.c @@ -70,6 +70,7 @@ static int __watch_viewer_init(Evas_Object *win) __win = win; _compositor_init(win); + _compositor_start_visibility_notify(); __win_resized(NULL, NULL, win, NULL); /* init */ evas_object_event_callback_add(win, EVAS_CALLBACK_RESIZE, __win_resized, NULL); @@ -84,6 +85,7 @@ static void __watch_viewer_fini() if (__win) evas_object_event_callback_del(__win, EVAS_CALLBACK_RESIZE, __win_resized); + _compositor_stop_visibility_notify(); _compositor_fini(); } diff --git a/widget_toolkit/include/compositor.h b/widget_toolkit/include/compositor.h index b048aaf..59bb1d9 100644 --- a/widget_toolkit/include/compositor.h +++ b/widget_toolkit/include/compositor.h @@ -24,6 +24,12 @@ extern "C" { #endif +typedef enum { + VISIBILITY_TYPE_UNOBSCURED = 0, + VISIBILITY_TYPE_PARTIALLY_OBSCURED, + VISIBILITY_TYPE_FULLY_OBSCURED, +} visibility_type; + typedef void (*_compositor_handler_cb)(const char *app_id, const char *event, Evas_Object *obj, void *data); const char *_compositor_init(Evas_Object *win); @@ -33,6 +39,11 @@ int _compositor_unser_handler(const char *app_id); const char *_compositor_get_title(Evas_Object *obj); const char *_compositor_get_app_id(Evas_Object *obj); int _compositor_get_pid(Evas_Object *obj); +int _compositor_set_visibility(Evas_Object *obj, visibility_type type); +int _compositor_freeze_visibility(Evas_Object *obj, visibility_type type); +int _compositor_thaw_visibility(Evas_Object *obj); +int _compositor_stop_visibility_notify(); +int _compositor_start_visibility_notify(); #ifdef __cplusplus } diff --git a/widget_toolkit/src/compositor.c b/widget_toolkit/src/compositor.c index 5dd0879..e21bb26 100644 --- a/widget_toolkit/src/compositor.c +++ b/widget_toolkit/src/compositor.c @@ -22,6 +22,8 @@ #include #include #include "compositor.h" +#include +#include #ifndef _E #define _E LOGE @@ -41,11 +43,15 @@ struct compositor_handler { _compositor_handler_cb cb; void *data; Evas_Object *evas_obj; + int freeze; }; const char *__compositor_name = NULL; GHashTable *__appid_tbl = NULL; GHashTable *__evas_tbl = NULL; +Ecore_Wl_Window *__window = NULL; +unsigned int __window_id = 0; +Ecore_Event_Handler *__visibility_listener = NULL; static void __obj_added_cb(void *data, Evas_Object *obj, void *event_info) { @@ -166,6 +172,9 @@ API const char *_compositor_init(Evas_Object *win) return NULL; } + __window = elm_win_wl_window_get(win); + __window_id = ecore_wl_window_id_get(__window); + __set_runtime_dir(); compositor_name = pepper_efl_compositor_create(win, app_id); @@ -222,6 +231,7 @@ API int _compositor_set_handler(const char *app_id, _compositor_handler_cb cb, v handler->app_id = g_strdup(app_id); handler->cb = cb; handler->data = data; + handler->freeze = 0; g_hash_table_remove(__appid_tbl, app_id); g_hash_table_insert(__appid_tbl, handler->app_id, handler); @@ -251,3 +261,122 @@ API int _compositor_get_pid(Evas_Object *obj) return pepper_efl_object_pid_get(obj); } +API int _compositor_set_visibility(Evas_Object *obj, visibility_type type) +{ + int obscured; + int ret; + + switch (type) { + case VISIBILITY_TYPE_UNOBSCURED: + obscured = PEPPER_EFL_VISIBILITY_TYPE_UNOBSCURED; + break; + case VISIBILITY_TYPE_PARTIALLY_OBSCURED: + obscured = PEPPER_EFL_VISIBILITY_TYPE_PARTIALLY_OBSCURED; + break; + case VISIBILITY_TYPE_FULLY_OBSCURED: + obscured = PEPPER_EFL_VISIBILITY_TYPE_FULLY_OBSCURED; + break; + default: + return -1; + } + + ret = pepper_efl_object_visibility_set(obj, obscured); + + if (ret) /* EINA_TRUE on success */ + return 0; + + return -1; +} + +API int _compositor_freeze_visibility(Evas_Object *obj, visibility_type type) +{ + struct compositor_handler *handler; + + handler = (struct compositor_handler *)g_hash_table_lookup(__evas_tbl, obj); + + if (!handler) { + _E("obj not found"); + return -1; + } + + handler->freeze = 1; + + return _compositor_set_visibility(obj, type); +} + +API int _compositor_thaw_visibility(Evas_Object *obj) +{ + struct compositor_handler *handler; + + handler = (struct compositor_handler *)g_hash_table_lookup(__evas_tbl, obj); + + if (!handler) { + _E("obj not found"); + return -1; + } + + handler->freeze = 0; + + return 0; +} + +static void __send_visibility(gpointer key, gpointer value, gpointer user_data) +{ + struct compositor_handler *handler = (struct compositor_handler *)value; + Evas_Object *evas_obj = (Evas_Object *)key; + unsigned int event = GPOINTER_TO_INT(user_data); + int ret; + Pepper_Efl_Visibility_Type type; + + if (handler->freeze) + return; + + if (event) + type = PEPPER_EFL_VISIBILITY_TYPE_FULLY_OBSCURED; + else + type = PEPPER_EFL_VISIBILITY_TYPE_UNOBSCURED; + + ret = pepper_efl_object_visibility_set(evas_obj, type); + if (!ret) { + _E("failed to set pepper efl object visibility set %p to %d", + evas_obj, type); + } +} + +static Eina_Bool __visibility_cb(void *data, int type, void *event) +{ + Ecore_Wl_Event_Window_Visibility_Change *ev = event; + + _D("visibility change: %d %d", (unsigned int)ev->win, + (unsigned int)ev->fully_obscured); + + if (ev->win != __window_id || !__evas_tbl) + return ECORE_CALLBACK_RENEW; + + g_hash_table_foreach(__evas_tbl, __send_visibility, + GINT_TO_POINTER(ev->fully_obscured)); + + return ECORE_CALLBACK_RENEW; +} + +API int _compositor_start_visibility_notify() +{ + if (__visibility_listener) + return 0; + + __visibility_listener = ecore_event_handler_add( + ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, __visibility_cb, NULL); + + return 0; +} + +API int _compositor_stop_visibility_notify() +{ + if (!__visibility_listener) + return 0; + + ecore_event_handler_del(__visibility_listener); + __visibility_listener = NULL; + + return 0; +} diff --git a/widget_viewer_evas/src/widget_viewer_evas.c b/widget_viewer_evas/src/widget_viewer_evas.c index a001d7e..5788100 100644 --- a/widget_viewer_evas/src/widget_viewer_evas.c +++ b/widget_viewer_evas/src/widget_viewer_evas.c @@ -431,6 +431,7 @@ EAPI int widget_viewer_evas_init(Evas_Object *win) s_info.win = win; _compositor_init(win); /* YOU MUST CALL _compositor_init() PRIOR TO widget_instance_init() */ + _compositor_start_visibility_notify(); if (aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id)) != AUL_R_OK) { ErrPrint("failed to get appid of pid:%d", getpid()); @@ -785,6 +786,13 @@ EAPI int widget_viewer_evas_set_option(widget_evas_conf_e type, int value) return WIDGET_ERROR_INVALID_PARAMETER; } + if (type == WIDGET_VIEWER_EVAS_MANUAL_PAUSE_RESUME) { + if (value) + _compositor_stop_visibility_notify(); + else + _compositor_start_visibility_notify(); + } + return WIDGET_ERROR_NONE; } @@ -1275,6 +1283,7 @@ EAPI int widget_viewer_evas_freeze_visibility(Evas_Object *widget, widget_visibi { struct widget_info *info; int ret = 0; + Evas_Object *pepper_obj; if (!is_widget_feature_enabled()) return WIDGET_ERROR_NOT_SUPPORTED; @@ -1295,15 +1304,21 @@ EAPI int widget_viewer_evas_freeze_visibility(Evas_Object *widget, widget_visibi return WIDGET_ERROR_INVALID_PARAMETER; } + pepper_obj = elm_object_part_content_get(widget, "pepper,widget"); + if (!pepper_obj) { + ErrPrint("widget object is invalid\n"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + if (status == WIDGET_VISIBILITY_STATUS_SHOW_FIXED) { - ret = widget_instance_resume(info->widget_id, info->instance_id); + ret = _compositor_freeze_visibility(pepper_obj, VISIBILITY_TYPE_UNOBSCURED); if (ret < 0) { ErrPrint("Fail to resume the widget(%p):(%d)\n", widget, ret); return ret; } info->visibility_freeze = status; } else if (status == WIDGET_VISIBILITY_STATUS_HIDE_FIXED) { - ret = widget_instance_pause(info->widget_id, info->instance_id); + ret = _compositor_freeze_visibility(pepper_obj, VISIBILITY_TYPE_FULLY_OBSCURED); if (ret < 0) { ErrPrint("Fail to pause the widget(%p):(%d)\n", widget, ret); return ret; @@ -1320,6 +1335,7 @@ EAPI int widget_viewer_evas_freeze_visibility(Evas_Object *widget, widget_visibi EAPI int widget_viewer_evas_thaw_visibility(Evas_Object *widget) { struct widget_info *info; + Evas_Object *pepper_obj; if (!is_widget_feature_enabled()) return WIDGET_ERROR_NOT_SUPPORTED; @@ -1340,6 +1356,13 @@ EAPI int widget_viewer_evas_thaw_visibility(Evas_Object *widget) return WIDGET_ERROR_INVALID_PARAMETER; } + pepper_obj = elm_object_part_content_get(widget, "pepper,widget"); + if (!pepper_obj) { + ErrPrint("widget object is invalid\n"); + return WIDGET_ERROR_INVALID_PARAMETER; + } + + _compositor_thaw_visibility(pepper_obj); info->visibility_freeze = 0; return WIDGET_ERROR_NONE; -- 2.7.4