From 54d12149408b0df611261455f86ee8958bdf837c Mon Sep 17 00:00:00 2001 From: Daehyeon Jung Date: Tue, 8 Mar 2016 19:15:05 +0900 Subject: [PATCH] Add widget_toolkit for common compositor Change-Id: I70720993f3e2fbafcd984d1b0de47a51bed0ac6e Signed-off-by: Daehyeon Jung --- CMakeLists.txt | 4 + packaging/libwidget_viewer.spec | 79 ++++++- watch-control/CMakeLists.txt | 48 ++++ .../include/watch_control.h | 19 +- watch-control/src/control.c | 168 ++++++++++++++ watch-control/watch-control.pc.in | 12 + widget_toolkit/CMakeLists.txt | 48 ++++ widget_toolkit/include/compositor.h | 39 ++++ widget_toolkit/src/compositor.c | 202 +++++++++++++++++ widget_toolkit/widget_toolkit.pc.in | 12 + widget_viewer_evas/CMakeLists.txt | 13 +- widget_viewer_evas/src/widget_viewer_evas.c | 249 ++------------------- widget_viewer_evas/widget_viewer_evas.pc.in | 4 +- 13 files changed, 640 insertions(+), 257 deletions(-) create mode 100644 watch-control/CMakeLists.txt rename {widget_viewer_evas => watch-control}/include/watch_control.h (56%) create mode 100644 watch-control/src/control.c create mode 100644 watch-control/watch-control.pc.in create mode 100644 widget_toolkit/CMakeLists.txt create mode 100644 widget_toolkit/include/compositor.h create mode 100644 widget_toolkit/src/compositor.c create mode 100644 widget_toolkit/widget_toolkit.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 6af2714..6ace108 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +ADD_SUBDIRECTORY(widget_toolkit) ADD_SUBDIRECTORY(widget_viewer) ADD_SUBDIRECTORY(widget_viewer_evas) ADD_SUBDIRECTORY(widget_viewer_sdk) +ADD_SUBDIRECTORY(watch-control) +ADD_DEPENDENCIES(widget_viewer_evas widget_toolkit) +ADD_DEPENDENCIES(watch-control widget_toolkit) ADD_DEPENDENCIES(widget_viewer_sdk widget_viewer_evas) diff --git a/packaging/libwidget_viewer.spec b/packaging/libwidget_viewer.spec index bd11023..19cb4e9 100644 --- a/packaging/libwidget_viewer.spec +++ b/packaging/libwidget_viewer.spec @@ -27,6 +27,7 @@ BuildRequires: pkgconfig(efl-extension) BuildRequires: pkgconfig(wayland-client) BuildRequires: pkgconfig(libtbm) BuildRequires: pkgconfig(libpepper-efl) +BuildRequires: pkgconfig(libtzplatform-config) %description API for creating a new instance of the widget and managing its life-cycle. @@ -45,7 +46,7 @@ cp %{SOURCE1001} . cp %{SOURCE1002} . %build -%cmake . -DWIDGET_ENABLED=On +%cmake . -DWIDGET_ENABLED=On -DTZ_SYS_SHARE=%{TZ_SYS_SHARE} make %{?jobs:-j%jobs} %install @@ -56,21 +57,42 @@ rm -rf %{buildroot} %postun -n %{name} -p /sbin/ldconfig %files -n %{name} -%defattr(-,root,root,-) -%{_libdir}/%{name}.so* +%attr(0644,root,root)%{_libdir}/%{name}.so* %{_datarootdir}/license/%{name} %files devel -%defattr(-,root,root,-) %{_includedir}/widget_viewer/widget_viewer.h %{_libdir}/pkgconfig/widget_viewer.pc +################################################ +# libwidget_toolkit +%package -n widget_toolkit +Summary: APIs to develop the widget viewer libraries +Version: 0.0.1 +License: FLora-1.1 +Group: Applications/Core Applications + +%description -n widget_toolkit +A sset of APIs to implement widget libraries + +%package -n widget_toolkit-devel +Summary: APIs to develop the widget viewer libraries +Group: Development/Libraries +Requires: widget_toolkit + +%description -n widget_toolkit-devel +Header & package configuration files of widget_toolkit + +%post -n widget_toolkit -p /sbin/ldconfig +%postun -n widget_toolkit -p /sbin/ldconfig + ################################################# # libwidget_viewer_evas %package -n %{name}_evas Summary: Library for developing the widget viewer evas Group: Applications/Core Applications License: Flora-1.1 +Requires: widget_toolkit %description -n %{name}_evas Provider APIs to develop the widget viewer EFL application. @@ -101,28 +123,61 @@ While developing the widget applications, this viewer will load it and execute i %post -n org.tizen.widget_viewer_sdk -p /sbin/ldconfig %postun -n org.tizen.widget_viewer_sdk -p /sbin/ldconfig +################################################ +# libwatch_control +%package -n watch-control +Summary: APIs to control watch applications +Version: 0.0.1 +License: Flora-1.1 +Group: Applications/Core Applications +Requires: widget_toolkit + +%description -n watch-control +A set of APIs to control watch applications + +%package -n watch-control-devel +Summary: APIs to control watch applications +Group: Development/Libraries +Requires: watch-control + +%description -n watch-control-devel +Header & package configuration of watch-control + +%post -n watch-control -p /sbin/ldconfig +%postun -n watch-control -p /sbin/ldconfig + %files -n %{name}_evas -%manifest %{name}_evas.manifest -%defattr(-,root,root,-) -%{_libdir}/%{name}_evas.so* +%attr(0644,root,root) %{_libdir}/%{name}_evas.so* %{_datarootdir}/license/%{name}_evas -%{_datadir}/widget_viewer_evas/res/edje/widget_viewer_evas.edj -%{_datadir}/widget_viewer_evas/res/image/*.png +%{TZ_SYS_SHARE}/widget_viewer_evas/res/edje/widget_viewer_evas.edj +%{TZ_SYS_SHARE}/widget_viewer_evas/res/image/*.png %files -n %{name}_evas-devel %manifest %{name}_evas.manifest -%defattr(-,root,root,-) %{_includedir}/widget_viewer_evas/widget_viewer_evas.h -%{_includedir}/widget_viewer_evas/watch_control.h %{_libdir}/pkgconfig/widget_viewer_evas.pc %files -n org.tizen.widget_viewer_sdk %manifest org.tizen.widget_viewer_sdk.manifest -%defattr(-,root,root,-) %attr(-,app,app) %dir /opt/usr/apps/org.tizen.widget_viewer_sdk/data %{_datarootdir}/packages/org.tizen.widget_viewer_sdk.xml %{_datarootdir}/license/org.tizen.widget_viewer_sdk %{_prefix}/apps/org.tizen.widget_viewer_sdk/* +%files -n widget_toolkit +%{_libdir}/libwidget_toolkit.so* + +%files -n widget_toolkit-devel +%{_includedir}/widget_toolkit/*.h +%{_libdir}/pkgconfig/widget_toolkit.pc + +%files -n watch-control +%{_libdir}/libwatch-control.so* + +%files -n watch-control-devel +%{_includedir}/watch-control/*.h +%{_libdir}/pkgconfig/watch-control.pc + + # End of a file diff --git a/watch-control/CMakeLists.txt b/watch-control/CMakeLists.txt new file mode 100644 index 0000000..6411635 --- /dev/null +++ b/watch-control/CMakeLists.txt @@ -0,0 +1,48 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(watch-control C) + +SET(PREFIX "${CMAKE_INSTALL_PREFIX}") +SET(PROJECT_NAME "${PROJECT_NAME}") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(VERSION_MAJOR 1) +SET(VERSION "${VERSION_MAJOR}.0.0") + +INCLUDE(FindPkgConfig) +pkg_check_modules(watch-control REQUIRED + dlog + elementary + pkgmgr-info + capi-system-info + capi-appfw-application + aul +) + +SET(BUILD_SOURCE + src/control.c +) + +FOREACH(flag ${watch-control_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../widget_toolkit/include) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${BUILD_SOURCE}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${watch-control_LDFLAGS} "-lpthread" widget_toolkit) + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/watch_control.h DESTINATION include/${PROJECT_NAME}) diff --git a/widget_viewer_evas/include/watch_control.h b/watch-control/include/watch_control.h similarity index 56% rename from widget_viewer_evas/include/watch_control.h rename to watch-control/include/watch_control.h index 22dee93..6d5c0c1 100644 --- a/widget_viewer_evas/include/watch_control.h +++ b/watch-control/include/watch_control.h @@ -1,3 +1,20 @@ +/* + * Samsung API + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #ifndef __WATCH_MANAGER_H__ #define __WATCH_MANAGER_H__ @@ -23,7 +40,7 @@ typedef struct watch_control_s *watch_control_h; typedef int (*watch_control_callback)(watch_control_h watch_control, void *data); -extern int watch_manager_init(Evas_Object *win, void *data); +extern int watch_manager_init(Evas_Object *win); extern int watch_manager_fini(); extern int watch_manager_add_handler(watch_control_event e, watch_control_callback cb, void *data); extern int watch_manager_get_app_control(const char *app_id, app_control_h *app_control); diff --git a/watch-control/src/control.c b/watch-control/src/control.c new file mode 100644 index 0000000..657bd3e --- /dev/null +++ b/watch-control/src/control.c @@ -0,0 +1,168 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include "watch_control.h" + +#define API __attribute__((visibility("default"))) + +#undef LOG_TAG +#define LOG_TAG "WATCH_CONTROL" + +#ifdef LOGE +#define _E LOGE +#endif + +#ifdef LOGD +#define _D LOGD +#endif + +struct watch_control_s { + Evas_Object *evas_obj; +}; + +static int __watch_viewer_initialized = 0; + +static watch_control_h __default_control = NULL; +static watch_control_callback __default_handler = NULL; +static void *__default_data = NULL; +static int __watch_size_policy = WATCH_POLICY_HINT_EXPAND; + +static int __watch_viewer_init(Evas_Object *win) +{ + if (__watch_viewer_initialized) + return 0; + + if (win == NULL) { + _E("invalid arguments"); + return -1; + } + + _compositor_init(win); + + __watch_viewer_initialized = 1; + + return 0; +} + +static void __watch_viewer_fini() +{ + _compositor_fini(); +} + +API int watch_manager_init(Evas_Object *win) +{ + __watch_viewer_init(win); + + return 0; +} + +API Evas_Object *watch_control_get_evas_object(watch_control_h control) +{ + return control->evas_obj; +} + +API int watch_manager_add_handler(watch_control_event e, watch_control_callback cb, void *data) +{ + switch (e) { + case WATCH_OBJ_ADD: + __default_handler = cb; + __default_data = data; + break; + case WATCH_OBJ_DEL: + /* TODO */ + break; + } + + return 0; +} + +static int __watch_screen_get_width() +{ + if (__watch_size_policy == WATCH_POLICY_HINT_EXPAND) + return 360; /* TODO get width from win */ + + return 0; +} + +static int __watch_screen_get_height() +{ + if (__watch_size_policy == WATCH_POLICY_HINT_EXPAND) + return 360; /* TODO get width from win */ + + return 0; +} + +static void __obj_added_cb(const char *app_id, Evas_Object *obj, void *data) +{ + int w, h, x, y; + Evas_Object *surface = obj; + evas_object_geometry_get(surface, &x, &y, &w, &h); + + _E("obj added"); + _E("w: %d, h: %d, x: %d y: %d", w, h, x, y); + if (__default_control && __default_handler) { + __default_control->evas_obj = surface; + __default_handler(__default_control, __default_data); + _E("default handler called"); + } +} + +API int watch_manager_get_app_control(const char *app_id, app_control_h *app_control) +{ + char buf[10]; + bundle *b = NULL; + app_control_create(app_control); + app_control_set_app_id(*app_control, app_id); + + __default_control = (watch_control_h)malloc(sizeof(struct watch_control_s)); + + snprintf(buf, sizeof(buf), "%d", __watch_screen_get_width()); + app_control_add_extra_data(*app_control, "WATCH_WIDTH", buf); + snprintf(buf, sizeof(buf), "%d", __watch_screen_get_height()); + app_control_add_extra_data(*app_control, "WATCH_HEIGHT", buf); + + app_control_add_extra_data(*app_control, "WAYLAND_DISPLAY", getenv("WAYLAND_DISPLAY")); + app_control_add_extra_data(*app_control, "XDG_RUNTIME_DIR", getenv("XDG_RUNTIME_DIR")); + + app_control_set_operation(*app_control, APP_CONTROL_OPERATION_MAIN); + + _compositor_set_handler(app_id, __obj_added_cb, NULL); + + app_control_to_bundle(*app_control, &b); + aul_svc_set_loader_id(b, 1); + + return 0; +} + +API int watch_manager_fini() +{ + __watch_viewer_fini(); + + return 0; +} + +API int watch_policy_set_size_hint(watch_policy_size_hint hint) +{ + __watch_size_policy = hint; + + return 0; +} + diff --git a/watch-control/watch-control.pc.in b/watch-control/watch-control.pc.in new file mode 100644 index 0000000..5696143 --- /dev/null +++ b/watch-control/watch-control.pc.in @@ -0,0 +1,12 @@ +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: watch-control +Description: Support development of the Watch Viewer +Version: @VERSION@ +Requires: widget_toolkit +Libs: -L${libdir} -lpepper-efl -lwidget_toolkit -lwatch-control +Cflags: -I${includedir} +cppflags: -I${includedir} diff --git a/widget_toolkit/CMakeLists.txt b/widget_toolkit/CMakeLists.txt new file mode 100644 index 0000000..bae810e --- /dev/null +++ b/widget_toolkit/CMakeLists.txt @@ -0,0 +1,48 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(widget_toolkit C) + +SET(PREFIX "${CMAKE_INSTALL_PREFIX}") +SET(PROJECT_NAME "${PROJECT_NAME}") +SET(LIBDIR ${LIB_INSTALL_DIR}) +SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") +SET(VERSION_MAJOR 1) +SET(VERSION "${VERSION_MAJOR}.0.0") + +INCLUDE(FindPkgConfig) +pkg_check_modules(widget_toolkit REQUIRED + dlog + elementary + pkgmgr-info + capi-system-info + libpepper-efl + capi-appfw-application + aul +) + +SET(BUILD_SOURCE + src/compositor.c +) + +FOREACH(flag ${widget_toolkit_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline") + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${BUILD_SOURCE}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${widget_toolkit_LDFLAGS} "-lpthread") + +CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) +SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/compositor.h DESTINATION include/${PROJECT_NAME}) diff --git a/widget_toolkit/include/compositor.h b/widget_toolkit/include/compositor.h new file mode 100644 index 0000000..a822a75 --- /dev/null +++ b/widget_toolkit/include/compositor.h @@ -0,0 +1,39 @@ +/* + * Samsung API + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef __COMPOSITOR_H__ +#define __COMPOSITOR_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +const char *_compositor_init(Evas_Object *win); +void _compositor_fini(); +int _compositor_set_handler(const char *app_id, void (*cb)(const char *app_id, Evas_Object *obj, void *data), void *data); +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); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/widget_toolkit/src/compositor.c b/widget_toolkit/src/compositor.c new file mode 100644 index 0000000..503ec84 --- /dev/null +++ b/widget_toolkit/src/compositor.c @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * Licensed under the Flora License, Version 1.1 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://floralicense.org/license/ + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + +#ifndef _E +#define _E LOGE +#endif + +#ifndef _D +#define _D LOGD +#endif + +#undef LOG_TAG +#define LOG_TAG "WIDGET_TOOLKIT" + +#define API __attribute__((visibility("default"))) + +struct compositor_handler { + char *app_id; + void (*cb)(const char *, Evas_Object *, void *); + void *data; + Evas_Object *evas_obj; +}; + +const char *__compositor_name = NULL; +GHashTable *__appid_tbl = NULL; + +static void __obj_added_cb(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *added = (Evas_Object *)event_info; + const char *app_id; + struct compositor_handler *handler; + + _E("object added"); + + if (!added) { + _E("invalid parameter"); + return; + } + + app_id = pepper_efl_object_app_id_get(added); + if (!app_id) { + _E("can't get app_id of (%d)", pepper_efl_object_pid_get(added)); + return; + } + + handler = g_hash_table_lookup(__appid_tbl, app_id); + if (!handler) { + _E("can't find compositor handler for %s", app_id); + /* workaround */ + char buf[255] = {0,}; + aul_app_get_appid_bypid(pepper_efl_object_pid_get(added), buf, sizeof(buf)); + handler = g_hash_table_lookup(__appid_tbl, buf); + if (!handler) + return; + } + + handler->evas_obj = added; + + if (handler->cb) + handler->cb(handler->app_id, added, handler->data); +} + +static void __obj_deleted_cb(void *data, Evas_Object *obj, void *event_info) +{ + _E("object removed"); + /* TODO */ +} + +static void __handler_free(gpointer val) +{ + struct compositor_handler *handler = (struct compositor_handler *)val; + + if (handler) { + if (handler->app_id) + g_free(handler->app_id); + + g_free(handler); + } +} + +static void __set_runtime_dir(void) +{ + char buf[256]; + + snprintf(buf, sizeof(buf) - 1, "/run/user/%d", getuid()); + if (setenv("XDG_RUNTIME_DIR", buf, 0) < 0) { + _E("Unable to set XDB_RUNTIME_DIR: %s (%s)\n", buf, strerror(errno)); + } +} + +API const char *_compositor_init(Evas_Object *win) +{ + static const char *compositor_name = NULL; + char app_id[255]; + + if (__compositor_name) + return __compositor_name; + + if (aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id)) != AUL_R_OK) { + _E("failed to get appid of pid: %d", getpid()); + return NULL; + } + + __set_runtime_dir(); + + compositor_name = pepper_efl_compositor_create(win, app_id); + if (compositor_name == NULL) { + _E("failed to create wayland display"); + return NULL; + } + + if (setenv("WAYLAND_DISPLAY", compositor_name, 1) < 0) { + _E("failed to set WAYLAND_DISPLAY: %s\n", strerror(errno)); + } + + evas_object_smart_callback_add(win, PEPPER_EFL_OBJ_ADD, __obj_added_cb, NULL); + evas_object_smart_callback_add(win, PEPPER_EFL_OBJ_DEL, __obj_deleted_cb, NULL); + + __appid_tbl = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __handler_free); + if (!__appid_tbl) + _E("failed to create table"); + + __compositor_name = compositor_name; + + return __compositor_name; +} + +API void _compositor_fini() +{ + if (__compositor_name) + pepper_efl_compositor_destroy(__compositor_name); + + if (__appid_tbl) + g_hash_table_destroy(__appid_tbl); +} + +API int _compositor_set_handler(const char *app_id, void (*cb)(const char *app_id, Evas_Object *obj, void *data), void *data) +{ + struct compositor_handler *handler; + if (!app_id || !cb) { + _E("inavlid parameter"); + return -1; + } + + handler = (struct compositor_handler *)g_malloc0(sizeof(struct compositor_handler)); + if (!handler) { + _E("out of memory"); + return -1; + } + + handler->app_id = g_strdup(app_id); + handler->cb = cb; + handler->data = data; + + g_hash_table_insert(__appid_tbl, handler->app_id, handler); + + return 0; +} + +API int _compositor_unset_handler(const char *app_id) +{ + g_hash_table_remove(__appid_tbl, app_id); + + return 0; +} + +API const char *_compositor_get_title(Evas_Object *obj) +{ + return pepper_efl_object_title_get(obj); +} + +API const char *_compositor_get_app_id(Evas_Object *obj) +{ + return pepper_efl_object_app_id_get(obj); +} + +API int _compositor_get_pid(Evas_Object *obj) +{ + return pepper_efl_object_pid_get(obj); +} + diff --git a/widget_toolkit/widget_toolkit.pc.in b/widget_toolkit/widget_toolkit.pc.in new file mode 100644 index 0000000..b2278cf --- /dev/null +++ b/widget_toolkit/widget_toolkit.pc.in @@ -0,0 +1,12 @@ +prefix=@PREFIX@ +exec_prefix=@EXEC_PREFIX@ +libdir=@LIBDIR@ +includedir=@INCLUDEDIR@ + +Name: widget_toolkit +Description: Support development of the widget Viewer Library +Version: @VERSION@ +Requires: libpepper-efl +Libs: -L${libdir} -lpepper-efl -lwidget_toolkit +Cflags: -I${includedir} +cppflags: -I${includedir} diff --git a/widget_viewer_evas/CMakeLists.txt b/widget_viewer_evas/CMakeLists.txt index 6b01e6e..07e0745 100644 --- a/widget_viewer_evas/CMakeLists.txt +++ b/widget_viewer_evas/CMakeLists.txt @@ -8,9 +8,9 @@ SET(LIBDIR ${LIB_INSTALL_DIR}) SET(INCLUDEDIR "\${prefix}/include/${PROJECT_NAME}") SET(VERSION_MAJOR 1) SET(VERSION "${VERSION_MAJOR}.0.0") -SET(EDJDIR "/usr/share/${PROJECT_NAME}/res/edje") -SET(IMGDIR "/usr/share/${PROJECT_NAME}/res/image") -SET(LOCALEDIR "/usr/share/${PROJECT_NAME}/res/locale") +SET(EDJDIR "${TZ_SYS_SHARE}/${PROJECT_NAME}/res/edje") +SET(IMGDIR "${TZ_SYS_SHARE}/${PROJECT_NAME}/res/image") +SET(LOCALEDIR "${TZ_SYS_SHARE}/${PROJECT_NAME}/res/locale") INCLUDE(FindPkgConfig) pkg_check_modules(viewer_evas REQUIRED @@ -19,7 +19,6 @@ pkg_check_modules(viewer_evas REQUIRED elementary pkgmgr-info capi-system-info - libpepper-efl capi-appfw-application aul ) @@ -31,7 +30,7 @@ SET(BUILD_SOURCE FOREACH(flag ${viewer_evas_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline -g") +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall -Werror -Winline") SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") @@ -45,12 +44,13 @@ ADD_DEFINITIONS("-DWIDGET_EVAS_RESOURCE_PO=\"${LOCALEDIR}\"") ADD_DEFINITIONS("-DPKGNAME=\"${PROJECT_NAME}\"") INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../widget_toolkit/include) ADD_LIBRARY(${PROJECT_NAME} SHARED ${BUILD_SOURCE}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${VERSION_MAJOR}) SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${viewer_evas_LDFLAGS} "-lpthread") +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${viewer_evas_LDFLAGS} "-lpthread" widget_toolkit) CONFIGURE_FILE(${PROJECT_NAME}.pc.in ${PROJECT_NAME}.pc @ONLY) SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME}.pc") @@ -58,7 +58,6 @@ SET_DIRECTORY_PROPERTIES(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PROJECT_NAME} INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/${PROJECT_NAME}.h DESTINATION include/${PROJECT_NAME}) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/watch_control.h DESTINATION include/${PROJECT_NAME}) INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE DESTINATION /usr/share/license RENAME "lib${PROJECT_NAME}") ADD_SUBDIRECTORY(res) diff --git a/widget_viewer_evas/src/widget_viewer_evas.c b/widget_viewer_evas/src/widget_viewer_evas.c index c5333ff..fc0b09a 100644 --- a/widget_viewer_evas/src/widget_viewer_evas.c +++ b/widget_viewer_evas/src/widget_viewer_evas.c @@ -34,8 +34,7 @@ #include #include -#include -#include "watch_control.h" +#include #if defined(LOG_TAG) #undef LOG_TAG @@ -134,13 +133,11 @@ static struct info { int w; int h; Evas_Object *win; - const char *compositor_name; GHashTable *widget_table; } s_info = { .w = 0, .h = 0, .win = NULL, - .compositor_name = NULL, .widget_table = NULL, }; @@ -178,50 +175,17 @@ static inline bool is_widget_feature_enabled(void) return feature; } -static void set_runtime_dir(void) -{ - char buf[256]; - - snprintf(buf, sizeof(buf) - 1, "/run/user/%d", getuid()); - if (setenv("XDG_RUNTIME_DIR", buf, 0) < 0) { - ErrPrint("Unable to set XDB_RUNTIME_DIR: %s (%s)\n", buf, strerror(errno)); - } -} - -static void object_deleted_cb(void *data, Evas_Object *obj, void *event_info) -{ - ErrPrint("Object is deleted.\n"); - /** - * @todo - * ... - */ -} - -static void object_added_cb(void *data, Evas_Object *obj, void *event_info) +static void widget_added_cb(const char *instance_id, Evas_Object *obj, void *data) { struct widget_info *info; Evas_Object *surface; - const char *instance_id; - surface = event_info; + surface = obj; if (!surface) { ErrPrint("Invalid parameters\n"); return; } - /** - * @note - * Current version of Pepper only supports to pass the title of surface. - * So we should find the infomation data using this title. - * This title will be used as an instance id of the widget. - */ - instance_id = pepper_efl_object_title_get(surface); - if (!instance_id) { - ErrPrint("Instance Id is not valid\n"); - evas_object_del(surface); - return; - } - info = g_hash_table_lookup(s_info.widget_table, instance_id); if (!info) { ErrPrint("Unable to find a proper object\n"); @@ -239,32 +203,22 @@ static void object_added_cb(void *data, Evas_Object *obj, void *event_info) EAPI int widget_viewer_evas_init(Evas_Object *win) { + char app_id[255]; + if (!is_widget_feature_enabled()) { return WIDGET_ERROR_NOT_SUPPORTED; } s_info.win = win; - /** - * @todo - * What should I set to initialize widget subsystem?? - */ - widget_instance_init("WHAT I HAVE TO SET FOR THIS?"); - - set_runtime_dir(); + _compositor_init(win); /* YOU MUST CALL _compositor_init() PRIOR TO widget_instance_init() */ - s_info.compositor_name = pepper_efl_compositor_create(win, NULL); - if (!s_info.compositor_name) { - ErrPrint("failed to create widget compositor"); - return WIDGET_ERROR_FAULT; - } - - if (setenv("WAYLAND_DISPLAY", s_info.compositor_name, 1) < 0) { - ErrPrint("Failed to set WAYLAND_DISPLAY: %s\n", strerror(errno)); + if (aul_app_get_appid_bypid(getpid(), app_id, sizeof(app_id)) != AUL_R_OK) { + ErrPrint("failed to get appid of pid:%d", getpid()); + return -1; } - evas_object_smart_callback_add(win, PEPPER_EFL_OBJ_ADD, object_added_cb, NULL); - evas_object_smart_callback_add(win, PEPPER_EFL_OBJ_DEL, object_deleted_cb, NULL); + widget_instance_init(app_id); s_info.widget_table = g_hash_table_new(g_str_hash, g_str_equal); @@ -277,11 +231,7 @@ EAPI int widget_viewer_evas_fini(void) return WIDGET_ERROR_NOT_SUPPORTED; } - if (s_info.win && s_info.compositor_name) { - pepper_efl_compositor_destroy(s_info.compositor_name); - s_info.compositor_name = NULL; - } - + _compositor_fini(); widget_instance_fini(); return WIDGET_ERROR_NONE; @@ -349,6 +299,7 @@ static void resize_cb(void *data, Evas *e, Evas_Object *layout, void *event_info * @note * Create a new instance in this case. */ + _compositor_set_handler(info->instance_id, widget_added_cb, NULL); info->pid = widget_instance_launch(info->widget_id, info->instance_id, info->b, w, h); if (info->pid < 0) { ErrPrint("Failed to launch an widget\n"); @@ -366,7 +317,7 @@ static inline struct widget_info *create_info(Evas_Object *parent, const char *w { struct widget_info *info; - info = (struct widget_info *)malloc(sizeof(*info)); + info = (struct widget_info *)calloc(1, sizeof(*info)); if (!info) { ErrPrint("malloc: %s\n", strerror(errno)); return NULL; @@ -408,6 +359,7 @@ static inline struct widget_info *create_info(Evas_Object *parent, const char *w if (elm_layout_file_set(info->layout, WIDGET_VIEWER_EVAS_RESOURCE_EDJ, "layout") == EINA_FALSE) { evas_object_del(info->layout); + if (info->content_info) free(info->content_info); @@ -825,177 +777,4 @@ EAPI void widget_viewer_evas_set_permanent_delete(Evas_Object *widget, int flag) return; } -#include -#include -#include - -#undef LOG_TAG -#define LOG_TAG "WATCH_CONTROL" - -#ifdef LOGE -#define _E LOGE -#endif - -#ifdef LOGD -#define _D LOGD -#endif - -struct watch_control_s { - Evas_Object *evas_obj; -}; - -static const char *compositor_name = NULL; - -static int __watch_viewer_initialized = 0; - -static watch_control_h __default_control = NULL; -static watch_control_callback __default_handler = NULL; -static void *__default_data = NULL; -static int __watch_size_policy = WATCH_POLICY_HINT_EXPAND; - -static void __set_runtime_dir() -{ - char buf[256]; - - snprintf(buf, sizeof(buf) - 1, "/run/user/%d", getuid()); - if (setenv("XDG_RUNTIME_DIR", buf, 0) < 0) - _E("Unable to set XDG_RUNTIME_DIR: %s (%s)\n", buf, strerror(errno)); -} - -void __obj_added_cb(void *data, Evas_Object *obj, void *event_info) -{ - _E("obj added"); - int w, h, x, y; - Evas_Object *surface = (Evas_Object *)event_info; - evas_object_geometry_get(surface, &x, &y, &w, &h); - _E("w: %d, h: %d, x: %d y: %d", w, h, x, y); - if (__default_control && __default_handler) { - __default_control->evas_obj = surface; - __default_handler(__default_control, __default_data); - _E("default handler called"); - } -} - -void __obj_deleted_cb(void *data, Evas_Object *obj, void *event_info) -{ - _E("obj removed"); - /* TODO */ -} - -static int __watch_viewer_init(Evas_Object *win) -{ - if (__watch_viewer_initialized) - return 0; - - if (win == NULL) { - _E("invalid arguments"); - return -1; - } - - __set_runtime_dir(); - _D("init pepper"); - compositor_name = pepper_efl_compositor_create(win, "watchview"); - if (compositor_name == NULL) { - _E("failed to create watch compositor"); - return -1; - } - - if (setenv("WAYLAND_DISPLAY", compositor_name, 1) < 0) { - _E("failed to set wayland display: %s", strerror(errno)); - } - - evas_object_smart_callback_add(win, PEPPER_EFL_OBJ_ADD, __obj_added_cb, NULL); - evas_object_smart_callback_add(win, PEPPER_EFL_OBJ_DEL, __obj_deleted_cb, NULL); - _D("pepper init done"); - __watch_viewer_initialized = 1; - - return 0; -} - -static void __watch_viewer_fini() -{ - -} - -EAPI int watch_manager_init(Evas_Object *win, void *data) -{ - __watch_viewer_init(win); - - return 0; -} - -EAPI Evas_Object *watch_control_get_evas_object(watch_control_h control) -{ - return control->evas_obj; -} - -EAPI int watch_manager_add_handler(watch_control_event e, watch_control_callback cb, void *data) -{ - switch (e) { - case WATCH_OBJ_ADD: - __default_handler = cb; - __default_data = data; - break; - case WATCH_OBJ_DEL: - /* TODO */ - break; - } - - return 0; -} - -static int __watch_screen_get_width() -{ - if (__watch_size_policy == WATCH_POLICY_HINT_EXPAND) - return 360; /* TODO get width from win */ - - return 0; -} - -static int __watch_screen_get_height() -{ - if (__watch_size_policy == WATCH_POLICY_HINT_EXPAND) - return 360; /* TODO get width from win */ - - return 0; -} - -EAPI int watch_manager_get_app_control(const char *app_id, app_control_h *app_control) -{ - char buf[10]; - bundle *b = NULL; - app_control_create(app_control); - app_control_set_app_id(*app_control, app_id); - - __default_control = (watch_control_h)malloc(sizeof(struct watch_control_s)); - - snprintf(buf, sizeof(buf), "%d", __watch_screen_get_width()); - app_control_add_extra_data(*app_control, "WATCH_WIDTH", buf); - snprintf(buf, sizeof(buf), "%d", __watch_screen_get_height()); - app_control_add_extra_data(*app_control, "WATCH_HEIGHT", buf); - - app_control_add_extra_data(*app_control, "WAYLAND_DISPLAY", getenv("WAYLAND_DISPLAY")); - app_control_add_extra_data(*app_control, "XDG_RUNTIME_DIR", getenv("XDG_RUNTIME_DIR")); - - app_control_set_operation(*app_control, APP_CONTROL_OPERATION_MAIN); - - app_control_to_bundle(*app_control, &b); - aul_svc_set_loader_id(b, 1); - - return 0; -} - -EAPI int watch_manager_fini() -{ - __watch_viewer_fini(); - - return 0; -} - -EAPI int watch_policy_set_size_hint(watch_policy_size_hint hint) -{ - __watch_size_policy = hint; - - return 0; -} /* End of a file */ diff --git a/widget_viewer_evas/widget_viewer_evas.pc.in b/widget_viewer_evas/widget_viewer_evas.pc.in index a37683b..a321bc7 100644 --- a/widget_viewer_evas/widget_viewer_evas.pc.in +++ b/widget_viewer_evas/widget_viewer_evas.pc.in @@ -6,7 +6,7 @@ includedir=@INCLUDEDIR@ Name: widget_viewer_evas Description: Support development of the widget Viewer EVAS Frontend library Version: @VERSION@ -Requires: widget_service -Libs: -L${libdir} -lwidget_viewer_evas +Requires: widget_service widget_toolkit +Libs: -L${libdir} -lwidget_viewer_evas -lwidget_toolkit Cflags: -I${includedir} cppflags: -I${includedir} -- 2.7.4