On Wed, 11 Nov 2020 23:09:33 -0800 Dave Andreoli <d...@gurumeditation.it> said:

perfect! seeing this made me smile. good effort in power saving here. :) right
thing to do. ...

BUT... you should look at using e_powersave_* api. ... this is actually intended
to be used in threads. so you would:

on setup e_powersave_sleeper_new() then spawn some thread.
while running sit in a loop and call e_powersave_sleeper_sleep() to sleep for a
while then when this returns, wake up and read/poll whatever you were gong to
poll and use the ecore thread mechanism to send a result back to mainloop to
show (i use ecore_thread_feedback_run() for this).

e_powersave will actually make the sleep really long (1hr - this may change in
future but the idea is to not totally stop but to slow down so much that it
essentially stoped) if in very low power mode (it tracks powersave mode to do
this and e's screenblanking handling sets power state when screen is off so it
should drop to polling every hr then on its own). if powersave mode changes
(like screen unblanks) all the sleeping powersave threads wake up immediately
so they can update. i can add to this code to slightly slow down a little if on
slightly power saving (on battery vs on ac) but the code isn't there now... but
it's central so everything using powersave gets this behaviour when added.

i do need to clean up some things here i missed, but take a look at powersave
and how it's used. i'll do some improvements to make freeing/cancelling better,
but take a look.

> davemds pushed a commit to branch master.
> 
> http://git.enlightenment.org/enlightenment/modules/places.git/commit/?id=efe3ca51151cc6c79f019f53ddfa5c5a9b8d41b9
> 
> commit efe3ca51151cc6c79f019f53ddfa5c5a9b8d41b9
> Author: Dave Andreoli <d...@gurumeditation.it>
> Date:   Thu Nov 12 08:08:46 2020 +0100
> 
>     Do not poll freespace while the screensaver is on
> ---
>  src/e_mod_places.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/src/e_mod_places.c b/src/e_mod_places.c
> index 75755da..d2d1810 100644
> --- a/src/e_mod_places.c
> +++ b/src/e_mod_places.c
> @@ -33,6 +33,10 @@ static const char *_places_human_size_get(unsigned long
> long size); static void _places_volume_object_update(Volume *vol, Evas_Object
> *obj); static void _places_run_fm_external(const char *fm, const char
> *directory); 
> +/* EcoreEvent callbacks */
> +static Eina_Bool _places_screensaver_on_cb(void *data, int type, void
> *event); +static Eina_Bool _places_screensaver_off_cb(void *data, int type,
> void *event); +
>  /* Edje callbacks */
>  void _places_icon_activated_cb(void *data, Evas_Object *o, const char
> *emission, const char *source); void _places_custom_icon_activated_cb(void
> *data, Evas_Object *o, const char *emission, const char *source); @@ -44,6
> +48,9 @@ static char theme_file[PATH_MAX]; static Eina_List *volumes = NULL;
>  static Ecore_Timer *freespace_timer = NULL;
>  static Ecore_Thread *freespace_thread = NULL;
> +static Ecore_Event_Handler *places_screensaver_on_handler = NULL;
> +static Ecore_Event_Handler *places_screensaver_off_handler = NULL;
> +#define PLACES_FREESPACE_INTERVAL 3.0
>  
>  
>  /* Implementation */
> @@ -66,12 +73,31 @@ places_init(void)
>  
>     snprintf(theme_file, PATH_MAX, "%s/e-module-places.edj",
>              places_conf->module->dir);
> -   freespace_timer = ecore_timer_add(3.0, _places_freespace_timer_cb, NULL);
> +
> +   places_screensaver_on_handler = 
> +      ecore_event_handler_add(E_EVENT_SCREENSAVER_ON, 
> +                              _places_screensaver_on_cb, NULL);
> +   places_screensaver_off_handler = 
> +      ecore_event_handler_add(E_EVENT_SCREENSAVER_OFF, 
> +                              _places_screensaver_off_cb, NULL);
> +
> +   freespace_timer = ecore_timer_add(PLACES_FREESPACE_INTERVAL, 
> +                                     _places_freespace_timer_cb, NULL);
>  }
>  
>  void
>  places_shutdown(void)
>  {
> +   if (places_screensaver_on_handler)
> +     {
> +        ecore_event_handler_del(places_screensaver_on_handler);
> +        places_screensaver_on_handler = NULL;
> +     }
> +   if (places_screensaver_off_handler)
> +     {
> +        ecore_event_handler_del(places_screensaver_off_handler);
> +        places_screensaver_off_handler = NULL;
> +     }
>     if (freespace_timer) 
>       {
>          ecore_timer_del(freespace_timer);
> @@ -615,6 +641,7 @@ _places_freespace_timer_cb(void *data EINA_UNUSED)
>     Eina_List *l, *tdl = NULL;
>     FreespaceThreadData *td = NULL;
>  
> +   // printf("PLACES: TIMER %.1f\n", ecore_time_get());
>     if (freespace_thread) 
>       {
>          // printf("PLACES: *** SOMETHING WRONG *** thread:%p still running...
> \n", freespace_thread); @@ -643,6 +670,28 @@ _places_freespace_timer_cb(void
> *data EINA_UNUSED) return ECORE_CALLBACK_RENEW;
>  }
>  
> +static Eina_Bool
> +_places_screensaver_on_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void
> *event EINA_UNUSED) +{
> +   if (freespace_timer)
> +     {
> +        ecore_timer_del(freespace_timer);
> +        freespace_timer = NULL;
> +     }
> +
> +   return ECORE_CALLBACK_PASS_ON;
> +}
> +
> +static Eina_Bool
> +_places_screensaver_off_cb(void *data EINA_UNUSED, int type EINA_UNUSED,
> void *event EINA_UNUSED) +{
> +   if (!freespace_timer)
> +     freespace_timer = ecore_timer_add(PLACES_FREESPACE_INTERVAL, 
> +                                       _places_freespace_timer_cb, NULL);
> +
> +   return ECORE_CALLBACK_PASS_ON;
> +}
> +
>  static const char *
>  _places_human_size_get(unsigned long long size)
>  {
> 
> -- 
> 
> 


-- 
------------- Codito, ergo sum - "I code, therefore I am" --------------
Carsten Haitzler - ras...@rasterman.com



_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to