summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2019-01-31 11:54:58 -0500
committerMike Blumenkrantz <zmike@samsung.com>2019-01-31 11:54:58 -0500
commit2a218e28c3e53954915e11ebfc27d1ff6d9d4e9b (patch)
tree44e96a7245800921fb50350fbf0261b44bc51cd4
parent9b129b5c7a9b74b2261066b55037c7891f10c12d (diff)
efl_ui_win: add 'exit_on_close' property and unit test
Summary: this property can enable the associated window to quit the main loop with the passed exit code when the window is destroyed @feature fix T5494 Depends on D7594 Reviewers: cedric Reviewed By: cedric Subscribers: #reviewers, #committers Tags: #efl Maniphest Tasks: T5494 Differential Revision: https://phab.enlightenment.org/D7595
-rw-r--r--src/lib/elementary/efl_ui_win.c23
-rw-r--r--src/lib/elementary/efl_ui_win.eo13
-rw-r--r--src/tests/elementary/elm_test_win.c21
3 files changed, 56 insertions, 1 deletions
diff --git a/src/lib/elementary/efl_ui_win.c b/src/lib/elementary/efl_ui_win.c
index a54e4520b6..152eb1ce20 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
272 Eina_Bool ctor : 1; /**< legacy constructor: elm_win~add */ 272 Eina_Bool ctor : 1; /**< legacy constructor: elm_win~add */
273 } legacy; 273 } legacy;
274 274
275 Eina_Value exit_on_close;
276
275 Eina_Bool first_draw : 1; 277 Eina_Bool first_draw : 1;
276 Eina_Bool deferred_resize_job : 1; 278 Eina_Bool deferred_resize_job : 1;
277 Eina_Bool urgent : 1; 279 Eina_Bool urgent : 1;
@@ -2986,7 +2988,9 @@ _efl_ui_win_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Win_Data *sd)
2986 2988
2987 efl_canvas_group_del(efl_super(obj, MY_CLASS)); 2989 efl_canvas_group_del(efl_super(obj, MY_CLASS));
2988 2990
2989 if (!_elm_win_list) 2991 if (eina_value_type_get(&sd->exit_on_close))
2992 efl_loop_quit(efl_loop_get(obj), sd->exit_on_close);
2993 else if (!_elm_win_list)
2990 { 2994 {
2991 if (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED) 2995 if (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED)
2992 _elm_win_flush_cache_and_exit(obj); 2996 _elm_win_flush_cache_and_exit(obj);
@@ -5920,6 +5924,23 @@ _efl_ui_win_icon_object_get(const Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd)
5920 return sd->icon; 5924 return sd->icon;
5921} 5925}
5922 5926
5927EOLIAN static const Eina_Value *
5928_efl_ui_win_exit_on_close_get(const Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd)
5929{
5930 return &sd->exit_on_close;
5931}
5932
5933EOLIAN static void
5934_efl_ui_win_exit_on_close_set(Eo *obj EINA_UNUSED, Efl_Ui_Win_Data *sd, const Eina_Value *exit_code)
5935{
5936 const Eina_Value_Type *type = eina_value_type_get(exit_code);
5937
5938 if (type)
5939 eina_value_copy(exit_code, &sd->exit_on_close);
5940 else
5941 eina_value_flush(&sd->exit_on_close);
5942}
5943
5923/* Only for C API */ 5944/* Only for C API */
5924EAPI void 5945EAPI void
5925elm_win_autodel_set(Eo *obj, Eina_Bool autodel) 5946elm_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 5f5085e107..148eaeb805 100644
--- a/src/lib/elementary/efl_ui_win.eo
+++ b/src/lib/elementary/efl_ui_win.eo
@@ -299,6 +299,19 @@ class Efl.Ui.Win extends Efl.Ui.Widget implements Efl.Canvas.Scene, Efl.Access.W
299 itself when closed.]] 299 itself when closed.]]
300 } 300 }
301 } 301 }
302 @property exit_on_close {
303 [[Enable quitting the main loop when this window is closed.
304
305 When set, the window's loop object will exit using the passed exit code if the
306 window is closed.
307
308 The Eina.Value passed should be $EMPTY to unset this state or an int value to be
309 used as the exit code.
310 ]]
311 values {
312 exit_code: const(any_value_ptr); [[The exit code to use when exiting]]
313 }
314 }
302 @property icon_object { 315 @property icon_object {
303 set { 316 set {
304 [[Set a window object's icon. 317 [[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 2b0ec55b2c..0c346911e9 100644
--- a/src/tests/elementary/elm_test_win.c
+++ b/src/tests/elementary/elm_test_win.c
@@ -208,6 +208,26 @@ EFL_START_TEST(elm_win_policy_quit_last_window_hidden)
208} 208}
209EFL_END_TEST 209EFL_END_TEST
210 210
211EFL_START_TEST(elm_win_test_exit_on_close)
212{
213 Eo *win = win_add(NULL, "win", ELM_WIN_BASIC);
214 Eina_Value val, *exit_val;
215 int code;
216
217 val = eina_value_int_init(66);
218 efl_ui_win_exit_on_close_set(win, &val);
219 efl_gfx_entity_visible_set(win, EINA_TRUE);
220
221 Eina_Bool fail_flag = EINA_FALSE;
222 ecore_timer_add(_timeout1, _timer_del_window_cb, win);
223 ecore_timer_add(_timeout_fail, _timer_fail_flag_cb, &fail_flag);
224
225 exit_val = efl_loop_begin(efl_loop_get(win));
226 ck_assert(eina_value_int_get(exit_val, &code));
227 ck_assert_int_eq(code, 66);
228}
229EFL_END_TEST
230
211EFL_START_TEST(elm_win_autohide_and_policy_quit_last_window_hidden) 231EFL_START_TEST(elm_win_autohide_and_policy_quit_last_window_hidden)
212{ 232{
213 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN); 233 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN);
@@ -436,6 +456,7 @@ void elm_test_win(TCase *tc)
436 tcase_add_test(tc, elm_atspi_role_get); 456 tcase_add_test(tc, elm_atspi_role_get);
437 tcase_add_test(tc, elm_atspi_component_screen_position); 457 tcase_add_test(tc, elm_atspi_component_screen_position);
438 tcase_add_test(tc, elm_win_policy_quit_last_window_hidden); 458 tcase_add_test(tc, elm_win_policy_quit_last_window_hidden);
459 tcase_add_test(tc, elm_win_test_exit_on_close);
439 tcase_add_test(tc, elm_win_test_app_exit_on_windows_close); 460 tcase_add_test(tc, elm_win_test_app_exit_on_windows_close);
440 tcase_add_test(tc, efl_ui_win_multi_touch_inputs); 461 tcase_add_test(tc, efl_ui_win_multi_touch_inputs);
441#ifdef HAVE_ELEMENTARY_X 462#ifdef HAVE_ELEMENTARY_X