raster pushed a commit to branch master. http://git.enlightenment.org/core/elementary.git/commit/?id=f18fda182e6cf7bddc1dd9c8e6a07a336e0a4c95
commit f18fda182e6cf7bddc1dd9c8e6a07a336e0a4c95 Author: Carsten Haitzler (Rasterman) <[email protected]> Date: Thu Sep 4 15:09:10 2014 +0900 elm process state - add events and state get function this adds the ability to query current process state, and get events idicating a change in process state and what change that was. @feature --- src/lib/elm_general.h | 35 ++++++++++++++++++++++++++ src/lib/elm_main.c | 6 +++++ src/lib/elm_win.c | 69 +++++++++++++++++++++++++++++++-------------------- 3 files changed, 83 insertions(+), 27 deletions(-) diff --git a/src/lib/elm_general.h b/src/lib/elm_general.h index 03adee7..88d9ff1 100644 --- a/src/lib/elm_general.h +++ b/src/lib/elm_general.h @@ -50,6 +50,20 @@ EAPI extern int ELM_EVENT_CONFIG_ALL_CHANGED; EAPI extern int ELM_EVENT_POLICY_CHANGED; /** + * Emitted when nothing is visible and the process as a whole should go into + * a background state. + * @since 1.12 + */ +EAPI extern int ELM_EVENT_PROCESS_BACKGROUND; + +/** + * Emitted when going from nothing being visible to at least one window + * being visible. + * @since 1.12 + */ +EAPI extern int ELM_EVENT_PROCESS_FOREGROUND; + +/** * @typedef Elm_Event_Policy_Changed * * Data on the event when an Elementary policy has changed @@ -350,6 +364,27 @@ EAPI int elm_policy_get(unsigned int policy); */ EAPI void elm_language_set(const char *lang); +typedef enum _Elm_Process_State +{ + ELM_PROCESS_STATE_FOREGROUND, /*< The process is in a foreground/active/running state - work as normal. @since 1.12 */ + ELM_PROCESS_STATE_BACKGROUND /*< The process is in the bacgkround, so you may want to stop animating, fetching data as often etc. @since 1.12 */ +} Elm_Process_State; /** The state of the process as a whole. @since 1.12 */ + +/** + * Get the process state as a while + * + * @return The current process state + * + * The process may logically be some runnable state. a "foreground" application + * runs as normal and may be user-visible or "active" in some way. A + * background application is not user-visible or otherwise important and + * likely should release resources and not wake up often or process much. + * + * @ingroup General + * @since 1.12 + */ +EAPI Elm_Process_State elm_process_state_get(void); + /** * @} */ diff --git a/src/lib/elm_main.c b/src/lib/elm_main.c index 905db62..ee73d8a 100644 --- a/src/lib/elm_main.c +++ b/src/lib/elm_main.c @@ -65,6 +65,8 @@ const char *_elm_lib_dir = NULL; int _elm_log_dom = -1; EAPI int ELM_EVENT_POLICY_CHANGED = 0; +EAPI int ELM_EVENT_PROCESS_BACKGROUND = 0; +EAPI int ELM_EVENT_PROCESS_FOREGROUND = 0; static int _elm_init_count = 0; static int _elm_sub_init_count = 0; @@ -612,6 +614,10 @@ elm_quicklaunch_init(int argc, memset(_elm_policies, 0, sizeof(_elm_policies)); if (!ELM_EVENT_POLICY_CHANGED) ELM_EVENT_POLICY_CHANGED = ecore_event_type_new(); + if (!ELM_EVENT_PROCESS_BACKGROUND) + ELM_EVENT_PROCESS_BACKGROUND = ecore_event_type_new(); + if (!ELM_EVENT_PROCESS_FOREGROUND) + ELM_EVENT_PROCESS_FOREGROUND = ecore_event_type_new(); ecore_file_init(); eio_init(); diff --git a/src/lib/elm_win.c b/src/lib/elm_win.c index a5f93ed..1de2075 100644 --- a/src/lib/elm_win.c +++ b/src/lib/elm_win.c @@ -345,6 +345,15 @@ _win_noblank_eval(void) #endif } +static Elm_Process_State _elm_process_state = ELM_PROCESS_STATE_FOREGROUND; + +EAPI Elm_Process_State +elm_process_state_get(void) +{ + return _elm_process_state; +} + + static void _elm_win_state_eval(void *data EINA_UNUSED) { @@ -353,6 +362,7 @@ _elm_win_state_eval(void *data EINA_UNUSED) int _elm_win_count_shown = 0; int _elm_win_count_iconified = 0; int _elm_win_count_withdrawn = 0; + Eina_Bool throttle = EINA_FALSE; _elm_win_state_eval_job = NULL; @@ -397,41 +407,46 @@ _elm_win_state_eval(void *data EINA_UNUSED) if (((_elm_config->auto_throttle) && (elm_policy_get(ELM_POLICY_THROTTLE) != ELM_POLICY_THROTTLE_NEVER)) || (elm_policy_get(ELM_POLICY_THROTTLE) == ELM_POLICY_THROTTLE_HIDDEN_ALWAYS)) + throttle = EINA_TRUE; + if (_elm_win_count == 0) { - if (_elm_win_count == 0) + if (_elm_win_auto_throttled) { - if (_elm_win_auto_throttled) + _elm_process_state = ELM_PROCESS_STATE_FOREGROUND; + ecore_event_add(ELM_EVENT_PROCESS_FOREGROUND, NULL, NULL, NULL); + if (throttle) + ecore_throttle_adjust(-_elm_config->auto_throttle_amount); + _elm_win_auto_throttled = EINA_FALSE; + } + } + else + { + EINA_LIST_FOREACH(_elm_win_list, l, obj) + { + if (elm_win_withdrawn_get(obj)) _elm_win_count_withdrawn++; + else if (elm_win_iconified_get(obj)) _elm_win_count_iconified++; + else if (evas_object_visible_get(obj)) _elm_win_count_shown++; + } + if (_elm_win_count_shown <= 0) + { + if (!_elm_win_auto_throttled) { - ecore_throttle_adjust(-_elm_config->auto_throttle_amount); - _elm_win_auto_throttled = EINA_FALSE; + _elm_process_state = ELM_PROCESS_STATE_BACKGROUND; + ecore_event_add(ELM_EVENT_PROCESS_BACKGROUND, NULL, NULL, NULL); + if (throttle) + ecore_throttle_adjust(_elm_config->auto_throttle_amount); + _elm_win_auto_throttled = EINA_TRUE; } } else { - EINA_LIST_FOREACH(_elm_win_list, l, obj) - { - if (elm_win_withdrawn_get(obj)) - _elm_win_count_withdrawn++; - else if (elm_win_iconified_get(obj)) - _elm_win_count_iconified++; - else if (evas_object_visible_get(obj)) - _elm_win_count_shown++; - } - if (_elm_win_count_shown <= 0) - { - if (!_elm_win_auto_throttled) - { - ecore_throttle_adjust(_elm_config->auto_throttle_amount); - _elm_win_auto_throttled = EINA_TRUE; - } - } - else + if (_elm_win_auto_throttled) { - if (_elm_win_auto_throttled) - { - ecore_throttle_adjust(-_elm_config->auto_throttle_amount); - _elm_win_auto_throttled = EINA_FALSE; - } + _elm_process_state = ELM_PROCESS_STATE_FOREGROUND; + ecore_event_add(ELM_EVENT_PROCESS_FOREGROUND, NULL, NULL, NULL); + if (throttle) + ecore_throttle_adjust(-_elm_config->auto_throttle_amount); + _elm_win_auto_throttled = EINA_FALSE; } } } --
