summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2014-12-03 15:24:33 -0200
committerLarry Jr <larry.olj@gmail.com>2015-03-19 15:34:51 -0300
commitfcfc481eefadca7a098089d4857a60f62870cf48 (patch)
tree2a788eaf5affdac3831121f9787dd19af50c1c2a
parent841fcdfb18a414a7381910bcbb0b0ef4807bc5c2 (diff)
elementary: Added autohide and ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN to elm_win
Added the "autohide" property to elm_win.eo. This property, when set to EINA_TRUE, automatically hides the window upon a "delete,request" signal. Created ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN, a new quit policy that automatically exit from the elm_run loop when all windows are hidden. It is an alternative to autodel to conciliates the memory management framework of Eo with any memory management model the program may be using (e.g. RAII principles of C++). Created the auxiliary function "_elm_win_policy_quit_triggered" to check triggering of quit policies. Calling it in "_elm_win_evas_object_smart_del" and "_elm_win_evas_object_smart_hide". The check on "smart_hide" is now necessary, since ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN can be triggered when a window is hidden. Created the auxiliary function "_elm_win_flush_cache_and_exit" to avoid code repetition for exiting the elm_run loop. Small updated on documentation to mention the new autohide property.
-rw-r--r--src/lib/elm_general.h9
-rw-r--r--src/lib/elm_win.c64
-rw-r--r--src/lib/elm_win.eo34
-rw-r--r--src/lib/elm_win.h2
4 files changed, 98 insertions, 11 deletions
diff --git a/src/lib/elm_general.h b/src/lib/elm_general.h
index 86eba3bef..9c0235ad9 100644
--- a/src/lib/elm_general.h
+++ b/src/lib/elm_general.h
@@ -107,9 +107,12 @@ typedef enum
107{ 107{
108 ELM_POLICY_QUIT_NONE = 0, /**< never quit the application 108 ELM_POLICY_QUIT_NONE = 0, /**< never quit the application
109 * automatically */ 109 * automatically */
110 ELM_POLICY_QUIT_LAST_WINDOW_CLOSED /**< quit when the 110 ELM_POLICY_QUIT_LAST_WINDOW_CLOSED, /**< quit when the
111 * application's last 111 * application's last
112 * window is closed */ 112 * window is closed */
113 ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN /**< quit when the
114 * application's last
115 * window is hidden */
113} Elm_Policy_Quit; 116} Elm_Policy_Quit;
114 117
115/** 118/**
diff --git a/src/lib/elm_win.c b/src/lib/elm_win.c
index 27eb1168e..bc50a0703 100644
--- a/src/lib/elm_win.c
+++ b/src/lib/elm_win.c
@@ -203,6 +203,7 @@ struct _Elm_Win_Data
203 Eina_Bool modal : 1; 203 Eina_Bool modal : 1;
204 Eina_Bool demand_attention : 1; 204 Eina_Bool demand_attention : 1;
205 Eina_Bool autodel : 1; 205 Eina_Bool autodel : 1;
206 Eina_Bool autohide : 1;
206 Eina_Bool constrain : 1; 207 Eina_Bool constrain : 1;
207 Eina_Bool resizing : 1; 208 Eina_Bool resizing : 1;
208 Eina_Bool iconified : 1; 209 Eina_Bool iconified : 1;
@@ -485,6 +486,41 @@ _elm_win_state_eval(void *data EINA_UNUSED)
485 _win_noblank_eval(); 486 _win_noblank_eval();
486} 487}
487 488
489static Eina_Bool
490_elm_win_policy_quit_triggered(Eo* triggering_obj)
491{
492 if ((!_elm_win_list) &&
493 (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED))
494 {
495 return EINA_TRUE;
496 }
497
498 if (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN)
499 {
500 Eina_List *l;
501 Evas_Object *win;
502
503 EINA_LIST_FOREACH(_elm_win_list, l, win)
504 if (win != triggering_obj && evas_object_visible_get(win) == EINA_TRUE)
505 {
506 return EINA_FALSE;
507 }
508 return EINA_TRUE;
509 }
510
511 return EINA_FALSE;
512}
513
514static void
515_elm_win_flush_cache_and_exit(Eo *obj)
516{
517 edje_file_cache_flush();
518 edje_collection_cache_flush();
519 evas_image_cache_flush(evas_object_evas_get(obj));
520 evas_font_cache_flush(evas_object_evas_get(obj));
521 elm_exit();
522}
523
488static void 524static void
489_elm_win_state_eval_queue(void) 525_elm_win_state_eval_queue(void)
490{ 526{
@@ -1491,6 +1527,9 @@ _elm_win_evas_object_smart_hide(Eo *obj, Elm_Win_Data *sd)
1491 evas_object_hide(sd->pointer.obj); 1527 evas_object_hide(sd->pointer.obj);
1492 ecore_evas_hide(sd->pointer.ee); 1528 ecore_evas_hide(sd->pointer.ee);
1493 } 1529 }
1530
1531 if (_elm_win_policy_quit_triggered(obj))
1532 _elm_win_flush_cache_and_exit(obj);
1494} 1533}
1495 1534
1496static void 1535static void
@@ -1812,14 +1851,9 @@ _elm_win_evas_object_smart_del(Eo *obj, Elm_Win_Data *sd)
1812 1851
1813 eo_do_super(obj, MY_CLASS, evas_obj_smart_del()); 1852 eo_do_super(obj, MY_CLASS, evas_obj_smart_del());
1814 1853
1815 if ((!_elm_win_list) && 1854 if (_elm_win_policy_quit_triggered(obj))
1816 (elm_policy_get(ELM_POLICY_QUIT) == ELM_POLICY_QUIT_LAST_WINDOW_CLOSED))
1817 { 1855 {
1818 edje_file_cache_flush(); 1856 _elm_win_flush_cache_and_exit(obj);
1819 edje_collection_cache_flush();
1820 evas_image_cache_flush(evas_object_evas_get(obj));
1821 evas_font_cache_flush(evas_object_evas_get(obj));
1822 elm_exit();
1823 } 1857 }
1824} 1858}
1825 1859
@@ -1933,6 +1967,8 @@ _elm_win_delete_request(Ecore_Evas *ee)
1933 sd->autodel_clear = &autodel; 1967 sd->autodel_clear = &autodel;
1934 evas_object_ref(obj); 1968 evas_object_ref(obj);
1935 evas_object_smart_callback_call(obj, SIG_DELETE_REQUEST, NULL); 1969 evas_object_smart_callback_call(obj, SIG_DELETE_REQUEST, NULL);
1970 if (sd->autohide)
1971 evas_object_hide(obj);
1936 // FIXME: if above callback deletes - then the below will be invalid 1972 // FIXME: if above callback deletes - then the below will be invalid
1937 if (autodel) evas_object_del(obj); 1973 if (autodel) evas_object_del(obj);
1938 else sd->autodel_clear = NULL; 1974 else sd->autodel_clear = NULL;
@@ -2734,6 +2770,8 @@ _elm_win_frame_cb_close(void *data,
2734 sd->autodel_clear = &autodel; 2770 sd->autodel_clear = &autodel;
2735 evas_object_ref(win); 2771 evas_object_ref(win);
2736 evas_object_smart_callback_call(win, SIG_DELETE_REQUEST, NULL); 2772 evas_object_smart_callback_call(win, SIG_DELETE_REQUEST, NULL);
2773 if (sd->autohide)
2774 evas_object_hide(win);
2737 // FIXME: if above callback deletes - then the below will be invalid 2775 // FIXME: if above callback deletes - then the below will be invalid
2738 if (autodel) evas_object_del(win); 2776 if (autodel) evas_object_del(win);
2739 else sd->autodel_clear = NULL; 2777 else sd->autodel_clear = NULL;
@@ -3800,6 +3838,18 @@ _elm_win_autodel_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3800} 3838}
3801 3839
3802EOLIAN static void 3840EOLIAN static void
3841_elm_win_autohide_set(Eo *obj EINA_UNUSED, Elm_Win_Data *sd, Eina_Bool autohide)
3842{
3843 sd->autohide = autohide;
3844}
3845
3846EOLIAN static Eina_Bool
3847_elm_win_autohide_get(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3848{
3849 return sd->autohide;
3850}
3851
3852EOLIAN static void
3803_elm_win_activate(Eo *obj EINA_UNUSED, Elm_Win_Data *sd) 3853_elm_win_activate(Eo *obj EINA_UNUSED, Elm_Win_Data *sd)
3804{ 3854{
3805 TRAP(sd, activate); 3855 TRAP(sd, activate);
diff --git a/src/lib/elm_win.eo b/src/lib/elm_win.eo
index c6cfccf26..911d05af1 100644
--- a/src/lib/elm_win.eo
+++ b/src/lib/elm_win.eo
@@ -55,6 +55,40 @@ class Elm_Win (Elm_Widget, Elm_Interface_Atspi_Window,
55 closed */ 55 closed */
56 } 56 }
57 } 57 }
58 autohide {
59 set {
60 /*@
61 Set the window's autohide state.
62
63 This property works similarly to @p autodel, automatically handling
64 "delete,request" signals when set to @c EINA_TRUE, with the difference
65 that it will hide the window, instead of destroying it.
66
67 It is specially designed to work together with @p ELM_POLICY_QUIT_LAST_WINDOW_HIDDEN
68 which allows exiting Elementary's main loop when all the windows
69 are hidden.
70
71 @see elm_win_autodel_set()
72
73 @note @p autodel and @autohide are not mutually exclusive. The window
74 will be destructed if both autodel and autohide is set to @c EINA_TRUE.
75
76 @ingroup Win */
77 }
78 get {
79 /*@
80 Get the window's autohide state.
81
82 @return If the window will be automatically hidden when closed
83
84 @see elm_win_autohide_set()
85
86 @ingroup Win */
87 }
88 values {
89 bool autohide;
90 }
91 }
58 override { 92 override {
59 set { 93 set {
60 /*@ 94 /*@
diff --git a/src/lib/elm_win.h b/src/lib/elm_win.h
index 3b43b1811..b94f6f9ad 100644
--- a/src/lib/elm_win.h
+++ b/src/lib/elm_win.h
@@ -69,7 +69,7 @@
69 * Signals that you can add callbacks for are: 69 * Signals that you can add callbacks for are:
70 * 70 *
71 * @li "delete,request": the user requested to close the window. See 71 * @li "delete,request": the user requested to close the window. See
72 * elm_win_autodel_set(). 72 * elm_win_autodel_set() and elm_win_autohide_set().
73 * @li "focus,in": window got focus (deprecated. use "focused" instead.) 73 * @li "focus,in": window got focus (deprecated. use "focused" instead.)
74 * @li "focus,out": window lost focus (deprecated. use "unfocused" instead.) 74 * @li "focus,out": window lost focus (deprecated. use "unfocused" instead.)
75 * @li "moved": window that holds the canvas was moved 75 * @li "moved": window that holds the canvas was moved