From fab247c6f176db2dca6c0c7ef5eb095b07c30780 Mon Sep 17 00:00:00 2001 From: Kwangyoun Kim Date: Thu, 3 Nov 2016 09:47:44 +0900 Subject: [PATCH] Fix foreground check logic Change-Id: Iaa3669707d0ee7cc1b6820b56dd4f616ebddf0fe --- client/vc.c | 44 ++++++++++++++++++++++++++++---------------- client/vc_widget.c | 16 ++++++++++++++-- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/client/vc.c b/client/vc.c index 46ef551..8ea8acc 100644 --- a/client/vc.c +++ b/client/vc.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -42,6 +43,9 @@ static Ecore_Timer* g_connect_timer = NULL; +static Ecore_Event_Handler* g_focus_in_handler = NULL; +static Ecore_Event_Handler* g_focus_out_handler = NULL; + static vc_h g_vc = NULL; static int g_daemon_pid = 0; @@ -233,13 +237,12 @@ static Eina_Bool __notify_auth_changed_cb(void *data) return EINA_FALSE; } -static int __vc_app_state_changed_cb(int app_state, void *data) +static Eina_Bool __focus_changed_cb(void *data, int type, void *event) { - int ret = -1; - SLOG(LOG_DEBUG, TAG_VCC, "===== [Client] app state changed"); + SLOG(LOG_DEBUG, TAG_VCC, "===== Focus changed"); - /* Set current pid */ - if (STATUS_VISIBLE == app_state) { + int ret; + if (ECORE_WL_EVENT_FOCUS_IN == type) { SLOG(LOG_DEBUG, TAG_VCC, "===== Set foreground"); ret = vc_dbus_set_foreground(getpid(), true); if (0 != ret) { @@ -262,8 +265,8 @@ static int __vc_app_state_changed_cb(int app_state, void *data) /* notify auth changed cb */ ecore_timer_add(0, __notify_auth_changed_cb, NULL); } - } else if (STATUS_BG == app_state) { - SLOG(LOG_DEBUG, TAG_VCC, "===== Set background"); + } else if (ECORE_WL_EVENT_FOCUS_OUT == type) { + SLOG(LOG_DEBUG, TAG_VCW, "===== Set background"); ret = vc_dbus_set_foreground(getpid(), false); if (0 != ret) { SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set foreground (false) : %d", ret); @@ -286,13 +289,13 @@ static int __vc_app_state_changed_cb(int app_state, void *data) ecore_timer_add(0, __notify_auth_changed_cb, NULL); } } else { - SLOG(LOG_DEBUG, TAG_VCC, "===== App state is NOT valid"); + SLOG(LOG_DEBUG, TAG_VCC, "===== type(%d) is NOT valid", type); } SLOG(LOG_DEBUG, TAG_VCC, "====="); - SLOG(LOG_DEBUG, TAG_VCC, " "); + SLOG(LOG_DEBUG, TAG_VCC, ""); - return 0; + return ECORE_CALLBACK_RENEW; } int vc_initialize(void) @@ -378,6 +381,14 @@ static void __vc_internal_unprepare(void) SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to request finalize : %s", __vc_get_error_code(ret)); } + if (NULL != g_focus_in_handler) { + ecore_event_handler_del(g_focus_in_handler); + g_focus_in_handler = NULL; + } + if (NULL != g_focus_out_handler) { + ecore_event_handler_del(g_focus_out_handler); + g_focus_out_handler = NULL; + } ret = vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_FOREGROUND); if (0 != ret) @@ -492,13 +503,14 @@ static Eina_Bool __vc_connect_daemon(void *data) g_connect_timer = NULL; - ret = aul_add_status_local_cb(__vc_app_state_changed_cb, NULL); - if (0 != ret) { - SLOG(LOG_ERROR, TAG_VCC, "[ERROR] Fail to set app stae changed callback"); - } + g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL); + g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL); + + char appid[255] = {'\0',}; + aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)); - int status = aul_app_get_status_bypid(getpid()); - if (STATUS_FOCUS == status || STATUS_VISIBLE == status) { + int status = aul_app_get_status(appid); + if (STATUS_FOCUS == status) { SLOG(LOG_DEBUG, TAG_VCC, "===== Set foreground"); ret = vc_dbus_set_foreground(getpid(), true); if (0 != ret) { diff --git a/client/vc_widget.c b/client/vc_widget.c index 6714f40..3089ab4 100644 --- a/client/vc_widget.c +++ b/client/vc_widget.c @@ -32,6 +32,9 @@ static Ecore_Timer* g_w_connect_timer = NULL; +static Ecore_Event_Handler* g_focus_in_handler = NULL; +static Ecore_Event_Handler* g_focus_out_handler = NULL; + static Ecore_Timer* g_w_start_timer = NULL; static Ecore_Timer* g_w_tooltip_timer = NULL; @@ -162,6 +165,15 @@ static void __vc_widget_internal_unprepare() SLOG(LOG_WARN, TAG_VCW, "[ERROR] Fail to request finalize : %s", __vc_widget_get_error_code(ret)); } + if (NULL != g_focus_in_handler) { + ecore_event_handler_del(g_focus_in_handler); + g_focus_in_handler = NULL; + } + if (NULL != g_focus_out_handler) { + ecore_event_handler_del(g_focus_out_handler); + g_focus_out_handler = NULL; + } + ret = vc_cmd_parser_delete_file(getpid(), VC_COMMAND_TYPE_WIDGET); if (0 != ret) SLOG(LOG_ERROR, TAG_VCW, "[ERROR] Fail to delete file, type(%d), ret(%d)", VC_COMMAND_TYPE_WIDGET, ret); @@ -286,8 +298,8 @@ static Eina_Bool __vc_widget_connect_daemon(void *data) vc_widget_client_set_service_state(g_vc_w, (vc_service_state_e)service_state); - ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL); - ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL); + g_focus_in_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_IN, __focus_changed_cb, NULL); + g_focus_out_handler = ecore_event_handler_add(ECORE_WL_EVENT_FOCUS_OUT, __focus_changed_cb, NULL); char appid[255] = {'\0',}; aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)); -- 2.7.4