Page MenuHomePhabricator
Paste P255

ref for T5494
ActivePublic

Authored by zmike on Mon, Jan 7, 11:32 AM.
diff --git a/src/lib/ecore/efl_app.c b/src/lib/ecore/efl_app.c
index 8c5bf7ca8b..f7707faea6 100644
--- a/src/lib/ecore/efl_app.c
+++ b/src/lib/ecore/efl_app.c
@@ -28,6 +28,7 @@ struct _Efl_App_Data
Eina_Bool can_write : 1;
} fd;
int read_listeners;
+ Eina_Value exit_on_windows_close;
};
Efl_Version _app_efl_version = { 0, 0, 0, 0, NULL, NULL };
@@ -61,6 +62,16 @@ _parent_read_listeners_modify(Efl_App_Data *pd, int mod)
}
}
+static void
+_cb_event_standby(void *data, const Efl_Event *event EINA_UNUSED)
+{
+ Efl_App_Data *pd = data;
+
+ if (eina_value_type_get(&pd->exit_on_windows_close))
+ efl_loop_quit(_mainloop_singleton, pd->exit_on_windows_close);
+
+}
+
static void
_cb_event_callback_add(void *data, const Efl_Event *event)
{
@@ -106,7 +117,8 @@ _cb_in(void *data, const Efl_Event *event EINA_UNUSED)
EFL_CALLBACKS_ARRAY_DEFINE(_event_callback_watch,
{ EFL_EVENT_CALLBACK_ADD, _cb_event_callback_add },
- { EFL_EVENT_CALLBACK_DEL, _cb_event_callback_del });
+ { EFL_EVENT_CALLBACK_DEL, _cb_event_callback_del },
+ { EFL_APP_EVENT_STANDBY, _cb_event_standby });
//////////////////////////////////////////////////////////////////////////
@@ -401,6 +413,24 @@ _efl_app_efl_task_priority_get(const Eo *obj, Efl_App_Data *pd EINA_UNUSED)
return pri;
}
+EOLIAN static const Eina_Value *
+_efl_app_exit_on_windows_close_get(const Eo *obj EINA_UNUSED, Efl_App_Data *pd)
+{
+ return &pd->exit_on_windows_close;
+}
+
+EOLIAN static void
+_efl_app_exit_on_windows_close_set(Eo *obj EINA_UNUSED, Efl_App_Data *pd, const Eina_Value *exit_code)
+{
+ const Eina_Value_Type *type = eina_value_type_get(exit_code);
+
+ if (type)
+ eina_value_copy(exit_code, &pd->exit_on_windows_close);
+ else
+ eina_value_flush(&pd->exit_on_windows_close);
+}
+
+
//////////////////////////////////////////////////////////////////////////
#include "efl_app.eo.c"
diff --git a/src/lib/ecore/efl_app.eo b/src/lib/ecore/efl_app.eo
index 303d1a6d01..13f8ca315f 100644
--- a/src/lib/ecore/efl_app.eo
+++ b/src/lib/ecore/efl_app.eo
@@ -35,10 +35,20 @@ class Efl.App (Efl.Loop)
@cref version: Efl.Version; [[Efl version]]
}
}
+ @property exit_on_windows_close {
+ [[Loop's exit on all windows closed state.
+
+ When set, the loop will quit with the passed exit code once all windows have been closed.
+ ]]
+ values {
+ exit_code: const(any_value_ptr); [[The exit code to use when exiting]]
+ }
+ }
}
events {
pause: void; [[Called when the application is not going be displayed or otherwise used by a user for some time]]
resume: void; [[Called before a window is rendered after a pause event]]
+ standby: void; [[Called when the application's windows are all destroyed]]
terminate: void; [[Called before starting the shutdown of the application]]
signal,usr1: void; [[System specific, but on unix maps to SIGUSR1 signal to the process - only called on main loop object]]
signal,usr2: void; [[System specific, but on unix maps to SIGUSR2 signal to the process - only called on main loop object]]
diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c
index 02ac728dd2..13c4ce6dd6 100644
--- a/src/lib/elementary/efl_ui_win.c
+++ b/src/lib/elementary/efl_ui_win.c
@@ -272,6 +272,8 @@ struct _Efl_Ui_Win_Data
Eina_Bool ctor : 1; /**< legacy constructor: elm_win~add */
} legacy;
+ Eina_Value exit_on_close;
+
Eina_Bool first_draw : 1;
Eina_Bool deferred_resize_job : 1;
Eina_Bool urgent : 1;
@@ -2985,10 +2987,13 @@ _efl_ui_win_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Win_Data *sd)
efl_canvas_group_del(efl_super(obj, MY_CLASS));
- if ((!_elm_win_list) &&
- (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED))
+ if (eina_value_type_get(&sd->exit_on_close))
+ efl_loop_quit(efl_loop_get(obj), sd->exit_on_close);
+ else if (!_elm_win_list)
{
- _elm_win_flush_cache_and_exit(obj);
+ if (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED)
+ _elm_win_flush_cache_and_exit(obj);
+ efl_event_callback_call(efl_app_main_get(EFL_APP_CLASS), EFL_APP_EVENT_STANDBY, NULL);
}
}
@@ -5881,6 +5886,23 @@ _efl_ui_win_icon_object_get(const Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd)
return sd->icon;
}
+EOLIAN static const Eina_Value *
+_efl_ui_win_exit_on_close_get(const Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd)
+{
+ return &sd->exit_on_close;
+}
+
+EOLIAN static void
+_efl_ui_win_exit_on_close_set(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd, const Eina_Value *exit_code)
+{
+ const Eina_Value_Type *type = eina_value_type_get(exit_code);
+
+ if (type)
+ eina_value_copy(exit_code, &sd->exit_on_close);
+ else
+ eina_value_flush(&sd->exit_on_close);
+}
+
/* Only for C API */
EAPI void
elm_win_autodel_set(Eo *obj, Eina_Bool autodel)
diff --git a/src/lib/elementary/efl_ui_win.eo b/src/lib/elementary/efl_ui_win.eo
index 000b4e9ebc..a122b209b6 100644
--- a/src/lib/elementary/efl_ui_win.eo
+++ b/src/lib/elementary/efl_ui_win.eo
@@ -299,6 +299,16 @@ class Efl.Ui.Win (Efl.Ui.Widget, Efl.Canvas.Scene, Efl.Access.Window,
itself when closed.]]
}
}
+ @property exit_on_close {
+ [[Window's exit on close state.
+
+ When set, the window's loop object will exit using the passed exit code if the
+ window is closed.
+ ]]
+ values {
+ exit_code: const(any_value_ptr); [[The exit code to use when exiting]]
+ }
+ }
@property icon_object {
set {
[[Set a window object's icon.
diff --git a/src/tests/elementary/elm_test_win.c b/src/tests/elementary/elm_test_win.c
index 9e6dc156ba..f38fc037cf 100644
--- a/src/tests/elementary/elm_test_win.c
+++ b/src/tests/elementary/elm_test_win.c
@@ -39,6 +39,14 @@ _timer_delete_request_cb(void *data)
return EINA_FALSE;
}
+static Eina_Bool
+_timer_del_window_cb(void *data)
+{
+ Eo *win = (Eo*) data;
+ evas_object_del(win);
+ return EINA_FALSE;
+}
+
static Eina_Bool
_timer_hide_window_cb(void *data)
{
@@ -177,6 +185,48 @@ EFL_START_TEST (elm_win_policy_quit_last_window_hidden)
}
EFL_END_TEST
+EFL_START_TEST (elm_win_test_exit_on_close)
+{
+ Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
+ Eina_Value val, *exit_val;
+ int code;
+
+ val = eina_value_int_init(66);
+ efl_ui_win_exit_on_close_set(win, &val);
+ efl_gfx_entity_visible_set(win, EINA_TRUE);
+
+ Eina_Bool fail_flag = EINA_FALSE;
+ ecore_timer_add(_timeout1, _timer_del_window_cb, win);
+ ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
+
+ exit_val = efl_loop_begin(efl_loop_get(win));
+ ck_assert(eina_value_int_get(exit_val, &code));
+ ck_assert_int_eq(code, 66);
+}
+EFL_END_TEST
+
+EFL_START_TEST (elm_win_test_app_exit_on_windows_close)
+{
+ Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
+ Eo *app = efl_app_main_get(EFL_APP_CLASS);
+ Eina_Value val, *exit_val;
+ int code;
+
+ val = eina_value_int_init(66);
+ efl_app_exit_on_windows_close_set(app, &val);
+ efl_gfx_entity_visible_set(win, EINA_TRUE);
+
+ Eina_Bool fail_flag = EINA_FALSE;
+ ecore_timer_add(_timeout1, _timer_del_window_cb, win);
+ ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
+
+ exit_val = efl_loop_begin(efl_loop_get(win));
+ ck_assert(eina_value_int_get(exit_val, &code));
+ ck_assert_int_eq(code, 66);
+ efl_app_exit_on_windows_close_set(app, &EINA_VALUE_EMPTY);
+}
+EFL_END_TEST
+
EFL_START_TEST (elm_win_autohide_and_policy_quit_last_window_hidden)
{
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
@@ -405,6 +455,8 @@ void elm_test_win(TCase *tc)
tcase_add_test(tc, elm_atspi_role_get);
tcase_add_test(tc, elm_atspi_component_screen_position);
tcase_add_test(tc, elm_win_policy_quit_last_window_hidden);
+ tcase_add_test(tc, elm_win_test_exit_on_close);
+ tcase_add_test(tc, elm_win_test_app_exit_on_windows_close);
tcase_add_test(tc, efl_ui_win_multi_touch_inputs);
#ifdef HAVE_ELEMENTARY_X
tcase_add_test(tc, elm_win_autohide);
zmike created this paste.Mon, Jan 7, 11:32 AM
zmike created this object with visibility "Public (No Login Required)".
zmike mentioned this in T5494: EO: elm policy API.
zmike edited the content of this paste. (Show Details)Thu, Jan 10, 12:35 PM