From 52f74fd0748b8ea6f913fa5399d4fea0461b6c85 Mon Sep 17 00:00:00 2001 From: Sangyoon Jang Date: Mon, 1 Jun 2015 21:15:31 +0900 Subject: [PATCH] Add pause, terminate bgapp event TODO: support pause for wayland Change-Id: I75f3b52b77a9ded28f99feced7db9cbe4084e6dc Signed-off-by: Sangyoon Jang --- include/appcore-internal.h | 3 +++ src/appcore-X.c | 36 ++++++++++++++++++++++++++++++++++++ src/appcore-efl.c | 38 +++++++++++++++++++++----------------- src/appcore.c | 30 ++++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+), 17 deletions(-) diff --git a/include/appcore-internal.h b/include/appcore-internal.h index f4d2ccd..c898e56 100755 --- a/include/appcore-internal.h +++ b/include/appcore-internal.h @@ -108,9 +108,11 @@ enum app_event { AE_UNKNOWN, AE_CREATE, AE_TERMINATE, + AE_TERMINATE_BGAPP, AE_PAUSE, AE_RESUME, AE_RAISE, + AE_LOWER, AE_RESET, AE_LOWMEM_POST, AE_MEM_FLUSH, @@ -163,6 +165,7 @@ void update_region(void); /* appcore-X.c */ extern int x_raise_win(pid_t pid); +extern int x_pause_win(pid_t pid); /* appcore-util.c */ /* extern void stack_trim(void);*/ diff --git a/src/appcore-X.c b/src/appcore-X.c index 7eecf5c..c0a7e66 100755 --- a/src/appcore-X.c +++ b/src/appcore-X.c @@ -169,3 +169,39 @@ EXPORT_API int x_raise_win(pid_t pid) return r; } + +int x_pause_win(pid_t pid) +{ + int r; + Display *d; + Window win; + Eina_List *list_win = NULL; + + if (pid < 1) { + errno = EINVAL; + return -1; + } + + r = kill(pid, 0); + if (r == -1) { + errno = ESRCH; + return -1; + } + + d = XOpenDisplay(NULL); + _retv_if(d == NULL, -1); + + win = XDefaultRootWindow(d); + if (!a_pid) + a_pid = XInternAtom(d, "_NET_WM_PID", True); + + __foreach_win(&list_win, d, &win, pid); + r = __iconify_win(list_win, d); + + XCloseDisplay(d); + + if (list_win) + eina_list_free(list_win); + + return r; +} diff --git a/src/appcore-efl.c b/src/appcore-efl.c index 6dfc5a1..1415824 100644 --- a/src/appcore-efl.c +++ b/src/appcore-efl.c @@ -265,6 +265,14 @@ static void __do_app(enum app_event event, void *data, bundle * b) return; } + if (event == AE_LOWER) { +#ifdef X11 + x_pause_win(getpid()); + return; +#endif + /* TODO: wayland support */ + } + _ret_if(ui->ops == NULL); switch (event) { @@ -329,6 +337,18 @@ static void __do_app(enum app_event event, void *data, bundle * b) ui->name); _send_to_resourced(PROC_STATUS_FOREGRD); break; + case AE_TERMINATE_BGAPP: + if (ui->state == AS_PAUSED) { + _DBG("[APP %d] is paused. TERMINATE", _pid); + ui->state = AS_DYING; + aul_status_update(STATUS_DYING); + elm_exit(); + } else if (ui->state == AS_RUNNING) { + _DBG("[APP %d] is running.", _pid); + } else { + _DBG("[APP %d] is another state", _pid); + } + break; default: /* do nothing */ break; @@ -555,24 +575,9 @@ static Eina_Bool __hide_cb(void *data, int type, void *event) { #ifdef WAYLAND Ecore_Wl_Event_Window_Hide *ev; - int bvisibility = 0; - - ev = event; - - _DBG("[EVENT_TEST][EVENT] GET HIDE EVENT!!!. WIN:%x\n", ev->win); - - if (__find_win((unsigned int)ev->win)) { - __delete_win((unsigned int)ev->win); - - bvisibility = __check_visible(); - if (!bvisibility && b_active == TRUE) { - _DBG(" Go to Pasue state \n"); - b_active = FALSE; - __do_app(AE_PAUSE, data, NULL); - } - } #else Ecore_X_Event_Window_Hide *ev; +#endif int bvisibility = 0; ev = event; @@ -588,7 +593,6 @@ static Eina_Bool __hide_cb(void *data, int type, void *event) __do_app(AE_PAUSE, data, NULL); } } -#endif return ECORE_CALLBACK_RENEW; } diff --git a/src/appcore.c b/src/appcore.c index 94d3693..711629b 100644 --- a/src/appcore.c +++ b/src/appcore.c @@ -172,6 +172,18 @@ static int __app_terminate(void *data) return 0; } +static int __bgapp_terminate(void *data) +{ + struct appcore *ac = data; + + _retv_if(ac == NULL || ac->ops == NULL, -1); + _retv_if(ac->ops->cb_app == NULL, 0); + + ac->ops->cb_app(AE_TERMINATE_BGAPP, ac->ops->data, NULL); + + return 0; +} + static gboolean __prt_ltime(gpointer data) { int msec; @@ -206,6 +218,16 @@ static int __app_resume(void *data) return 0; } +static int __app_pause(void *data) +{ + struct appcore *ac = data; + _retv_if(ac == NULL || ac->ops == NULL, -1); + _retv_if(ac->ops->cb_app == NULL, 0); + + ac->ops->cb_app(AE_LOWER, ac->ops->data, NULL); + return 0; +} + static int __sys_do_default(struct appcore *ac, enum sys_event event) { int r; @@ -422,6 +444,14 @@ static int __aul_handler(aul_type type, bundle *b, void *data) _DBG("[APP %d] AUL event: AUL_TERMINATE", _pid); __app_terminate(data); break; + case AUL_TERMINATE_BGAPP: + _DBG("[APP %d] AUL event: AUL_TERMINATE_BGAPP", _pid); + __bgapp_terminate(data); + break; + case AUL_PAUSE: + _DBG("[APP %d] AUL event: AUL_PAUSE", _pid); + __app_pause(data); + break; default: _DBG("[APP %d] AUL event: %d", _pid, type); /* do nothing */ -- 2.7.4