add a slider for backlight dimming on a timer in dpms controls
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 24 Jan 2012 10:01:28 +0000 (10:01 +0000)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 24 Jan 2012 10:01:28 +0000 (10:01 +0000)
as I have no devices which contain a controllable backlight, someone else will have to test/fix this

SVN revision: 67487

src/bin/e_backlight.c
src/bin/e_config.c
src/bin/e_config.h
src/modules/conf_display/e_int_config_dpms.c

index e9c4d33..eb7806a 100644 (file)
@@ -17,10 +17,23 @@ static E_Backlight_Mode bl_mode = E_BACKLIGHT_MODE_NORMAL;
 static int sysmode = MODE_NONE;
 static Ecore_Animator *bl_anim = NULL;
 
+static Ecore_Event_Handler *_e_backlight_handler_config_mode = NULL;
+static Ecore_Event_Handler *_e_backlight_handler_border_fullscreen = NULL;
+static Ecore_Event_Handler *_e_backlight_handler_border_unfullscreen = NULL;
+static Ecore_Event_Handler *_e_backlight_handler_border_remove = NULL;
+static Ecore_Event_Handler *_e_backlight_handler_border_iconify = NULL;
+static Ecore_Event_Handler *_e_backlight_handler_border_uniconify = NULL;
+static Ecore_Event_Handler *_e_backlight_handler_border_desk_set = NULL;
+static Ecore_Event_Handler *_e_backlight_handler_desk_show = NULL;
+
+static Ecore_Timer *_e_backlight_timer = NULL;
+
 static void _e_backlight_update(E_Zone *zone);
 static void _e_backlight_set(E_Zone *zone, double val);
 static Eina_Bool _bl_anim(void *data, double pos);
 static Eina_Bool bl_avail = EINA_FALSE;
+static Eina_Bool _e_backlight_handler(void *d, int type, void *ev);
+static Eina_Bool _e_backlight_timer_cb(void *d);
 #ifdef HAVE_EEZE
 static const char *bl_sysval = NULL;
 static Ecore_Event_Handler *bl_sys_exit_handler = NULL;
@@ -45,6 +58,30 @@ e_backlight_init(void)
 //   bl_avail = ecore_x_randr_output_backlight_available();
    bl_avail = EINA_TRUE;
 
+   _e_backlight_handler_config_mode = ecore_event_handler_add
+     (E_EVENT_CONFIG_MODE_CHANGED, _e_backlight_handler, NULL);
+
+   _e_backlight_handler_border_fullscreen = ecore_event_handler_add
+     (E_EVENT_BORDER_FULLSCREEN, _e_backlight_handler, NULL);
+
+   _e_backlight_handler_border_unfullscreen = ecore_event_handler_add
+     (E_EVENT_BORDER_UNFULLSCREEN, _e_backlight_handler, NULL);
+
+   _e_backlight_handler_border_remove = ecore_event_handler_add
+     (E_EVENT_BORDER_REMOVE, _e_backlight_handler, NULL);
+
+   _e_backlight_handler_border_iconify = ecore_event_handler_add
+     (E_EVENT_BORDER_ICONIFY, _e_backlight_handler, NULL);
+
+   _e_backlight_handler_border_uniconify = ecore_event_handler_add
+     (E_EVENT_BORDER_UNICONIFY, _e_backlight_handler, NULL);
+
+   _e_backlight_handler_border_desk_set = ecore_event_handler_add
+     (E_EVENT_BORDER_DESK_SET, _e_backlight_handler, NULL);
+
+   _e_backlight_handler_desk_show = ecore_event_handler_add
+     (E_EVENT_DESK_SHOW, _e_backlight_handler, NULL);
+
 //   if (bl_avail == EINA_TRUE)
      {
         e_backlight_update();
@@ -68,6 +105,53 @@ e_backlight_shutdown(void)
    bl_sys_pending_set = EINA_FALSE;
    eeze_shutdown();
 #endif
+   if (_e_backlight_handler_config_mode)
+     {
+        ecore_event_handler_del(_e_backlight_handler_config_mode);
+        _e_backlight_handler_config_mode = NULL;
+     }
+
+   if (_e_backlight_handler_border_fullscreen)
+     {
+        ecore_event_handler_del(_e_backlight_handler_border_fullscreen);
+        _e_backlight_handler_border_fullscreen = NULL;
+     }
+
+   if (_e_backlight_handler_border_unfullscreen)
+     {
+        ecore_event_handler_del(_e_backlight_handler_border_unfullscreen);
+        _e_backlight_handler_border_unfullscreen = NULL;
+     }
+
+   if (_e_backlight_handler_border_remove)
+     {
+        ecore_event_handler_del(_e_backlight_handler_border_remove);
+        _e_backlight_handler_border_remove = NULL;
+     }
+
+   if (_e_backlight_handler_border_iconify)
+     {
+        ecore_event_handler_del(_e_backlight_handler_border_iconify);
+        _e_backlight_handler_border_iconify = NULL;
+     }
+
+   if (_e_backlight_handler_border_uniconify)
+     {
+        ecore_event_handler_del(_e_backlight_handler_border_uniconify);
+        _e_backlight_handler_border_uniconify = NULL;
+     }
+
+   if (_e_backlight_handler_border_desk_set)
+     {
+        ecore_event_handler_del(_e_backlight_handler_border_desk_set);
+        _e_backlight_handler_border_desk_set = NULL;
+     }
+
+   if (_e_backlight_handler_desk_show)
+     {
+        ecore_event_handler_del(_e_backlight_handler_desk_show);
+        _e_backlight_handler_desk_show = NULL;
+     }
    return 1;
 }
 
@@ -86,19 +170,43 @@ e_backlight_update(void)
    E_Container *con;
    E_Zone *zone;
 
-   if (bl_avail == EINA_TRUE)
+   if (bl_avail == EINA_FALSE) return;
+
+   EINA_LIST_FOREACH(e_manager_list(), m, man)
      {
-        EINA_LIST_FOREACH(e_manager_list(), m, man)
+        EINA_LIST_FOREACH(man->containers, c, con)
           {
-             EINA_LIST_FOREACH(man->containers, c, con)
+             EINA_LIST_FOREACH(con->zones, z, zone)
                {
-                  EINA_LIST_FOREACH(con->zones, z, zone)
-                    {
-                       _e_backlight_update(zone);
-                    }
+                  _e_backlight_update(zone);
                }
           }
      }
+
+   /* idle dimming disabled: clear timer */
+   if (!e_config->backlight.idle_dim)
+     {
+        if (_e_backlight_timer)
+          ecore_timer_del(_e_backlight_timer);
+        _e_backlight_timer = NULL;
+        return;
+     }
+   /* dimming enabled, timer active: update interval and reset */
+   if (_e_backlight_timer)
+     {
+        if (e_config->backlight.timer != ecore_timer_interval_get(_e_backlight_timer))
+          ecore_timer_interval_set(_e_backlight_timer, e_config->backlight.timer);
+        ecore_timer_reset(_e_backlight_timer);
+        return;
+     }
+   /* dimming enabled, timer inactive: */
+
+   /* timer is 0 seconds: return */
+   if (!e_config->backlight.timer) return;
+   /* current mode is dimmed: undim */
+   if (bl_mode == E_BACKLIGHT_MODE_DIM)
+     e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_NORMAL);
+   _e_backlight_timer = ecore_timer_add(e_config->backlight.timer, _e_backlight_timer_cb, NULL);
 }
 
 EAPI void
@@ -164,6 +272,21 @@ e_backlight_mode_get(E_Zone *zone __UNUSED__)
 
 /* local subsystem functions */
 
+static Eina_Bool
+_e_backlight_handler(void *d __UNUSED__, int type __UNUSED__, void *ev __UNUSED__)
+{
+   e_backlight_update();
+   return ECORE_CALLBACK_PASS_ON;
+}
+
+static Eina_Bool
+_e_backlight_timer_cb(void *d __UNUSED__)
+{
+   e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_DIM);
+   _e_backlight_timer = NULL;
+   return EINA_FALSE;
+}
+
 static void
 _e_backlight_update(E_Zone *zone)
 {
index c67f6f8..9ed39f0 100644 (file)
@@ -882,6 +882,8 @@ e_config_init(void)
    E_CONFIG_VAL(D, T, backlight.normal, DOUBLE);
    E_CONFIG_VAL(D, T, backlight.dim, DOUBLE);
    E_CONFIG_VAL(D, T, backlight.transition, DOUBLE);
+   E_CONFIG_VAL(D, T, backlight.idle_dim, UCHAR);
+   E_CONFIG_VAL(D, T, backlight.timer, DOUBLE);
 
    E_CONFIG_VAL(D, T, deskenv.load_xrdb, UCHAR);
    E_CONFIG_VAL(D, T, deskenv.load_xmodmap, UCHAR);
@@ -1159,6 +1161,8 @@ e_config_load(void)
         COPYVAL(backlight.normal);
         COPYVAL(backlight.dim);
         COPYVAL(backlight.transition);
+        COPYVAL(backlight.idle_dim);
+        COPYVAL(backlight.timer);
         IFCFGEND;
 
         IFCFG(0x0145);
index 9f96b9b..86e278f 100644 (file)
@@ -33,7 +33,7 @@ typedef struct _E_Event_Config_Icon_Theme   E_Event_Config_Icon_Theme;
 /* increment this whenever a new set of config values are added but the users
  * config doesn't need to be wiped - simply new values need to be put in
  */
-#define E_CONFIG_FILE_GENERATION 0x0147
+#define E_CONFIG_FILE_GENERATION 0x0148
 #define E_CONFIG_FILE_VERSION    ((E_CONFIG_FILE_EPOCH << 16) | E_CONFIG_FILE_GENERATION)
 
 struct _E_Config
@@ -312,6 +312,8 @@ struct _E_Config
       double normal; // GUI
       double dim; // GUI
       double transition; // GUI
+      unsigned char idle_dim; // GUI
+      double timer; // GUI
    } backlight;
    
    struct {
index 2d4afba..29431ec 100644 (file)
@@ -9,6 +9,7 @@ static Evas_Object  *_advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas,
 static void _cb_standby_slider_change(void *data, Evas_Object *obj);
 static void _cb_suspend_slider_change(void *data, Evas_Object *obj);
 static void _cb_off_slider_change(void *data, Evas_Object *obj);
+static void _cb_backlight_slider_change(void *data, Evas_Object *obj);
 
 static int _e_int_config_dpms_available(void);
 static int _e_int_config_dpms_capable(void);
@@ -22,11 +23,13 @@ struct _E_Config_Dialog_Data
    Evas_Object *standby_slider;
    Evas_Object *suspend_slider;
    Evas_Object *off_slider;
+   Evas_Object *backlight_slider;
 
    int enable_dpms;
    int enable_standby;
    int enable_suspend;
    int enable_off;
+   int enable_idle_dim;
 
    /*
     * The following timeouts are represented as minutes
@@ -39,6 +42,7 @@ struct _E_Config_Dialog_Data
    
    double backlight_normal;
    double backlight_dim;
+   double backlight_timeout;
    double backlight_transition;
 };
 
@@ -142,6 +146,8 @@ _fill_data(E_Config_Dialog_Data *cfdata)
    cfdata->backlight_normal = e_config->backlight.normal * 100.0;
    cfdata->backlight_dim = e_config->backlight.dim * 100.0;
    cfdata->backlight_transition = e_config->backlight.transition;
+   cfdata->enable_idle_dim = e_config->backlight.idle_dim;
+   cfdata->backlight_timeout = e_config->backlight.timer;
 }
 
 static void
@@ -192,6 +198,7 @@ _apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
    e_config->backlight.normal = cfdata->backlight_normal / 100.0;
    e_config->backlight.dim = cfdata->backlight_dim / 100.0;
    e_config->backlight.transition = cfdata->backlight_transition;
+   e_config->backlight.timer = cfdata->backlight_timeout;
 
    e_backlight_mode_set(NULL, E_BACKLIGHT_MODE_NORMAL);
    e_backlight_level_set(NULL, e_config->backlight.normal, -1.0);
@@ -214,7 +221,8 @@ _advanced_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *c
          (e_config->dpms_off_timeout / 60 != cfdata->off_timeout) ||
           (e_config->backlight.normal * 100.0 != cfdata->backlight_normal) ||
           (e_config->backlight.dim * 100.0 != cfdata->backlight_dim) ||
-          (e_config->backlight.transition != cfdata->backlight_transition);
+          (e_config->backlight.transition != cfdata->backlight_transition) ||
+          (e_config->backlight.timer != cfdata->backlight_timeout);
 }
 
 static int
@@ -301,6 +309,16 @@ _advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_D
                            &(cfdata->backlight_dim), NULL, 100);
    e_widget_list_object_append(o, ob, 1, 1, 0.5);
    
+   ob = e_widget_check_add(evas, _("Idle Fade Time"), &(cfdata->enable_off));
+   e_widget_list_object_append(o, ob, 1, 1, 0.5);
+   e_widget_disabled_set(ob, cfdata->enable_idle_dim); // set state from saved config
+   ob = e_widget_slider_add(evas, 1, 0, _("%1.0f minutes"), 0.5, 90.0, 1.0, 0,
+                           &(cfdata->backlight_timeout), NULL, 100);
+   e_widget_on_change_hook_set(ob, _cb_backlight_slider_change, cfdata);
+   cfdata->backlight_slider = ob;
+   e_widget_disabled_set(ob, cfdata->enable_idle_dim); // set state from saved config
+   e_widget_list_object_append(o, ob, 1, 1, 0.5);
+   
    ob = e_widget_label_add(evas, _("Fade Time"));
    e_widget_list_object_append(o, ob, 1, 1, 0.5);
    ob = e_widget_slider_add(evas, 1, 0, _("%1.1f sec"), 0.0, 5.0, 0.1, 0,
@@ -362,6 +380,30 @@ _cb_suspend_slider_change(void *data, Evas_Object *obj __UNUSED__)
 }
 
 static void
+_cb_backlight_slider_change(void *data, Evas_Object *obj __UNUSED__)
+{
+   E_Config_Dialog_Data *cfdata = data;
+
+   /* off-slider */
+   if (cfdata->backlight_timeout < cfdata->suspend_timeout)
+     {
+        cfdata->suspend_timeout = cfdata->backlight_timeout;
+        if (cfdata->suspend_slider)
+          e_widget_slider_value_double_set(cfdata->suspend_slider,
+               cfdata->suspend_timeout);
+
+        if (cfdata->suspend_timeout < cfdata->backlight_timeout)
+          {
+             cfdata->backlight_timeout = cfdata->suspend_timeout;
+             if (cfdata->backlight_slider)
+               e_widget_slider_value_double_set(cfdata->backlight_slider,
+             cfdata->backlight_timeout);
+          }
+     }
+   e_backlight_update();
+}
+
+static void
 _cb_off_slider_change(void *data, Evas_Object *obj __UNUSED__)
 {
    E_Config_Dialog_Data *cfdata = data;
@@ -369,18 +411,18 @@ _cb_off_slider_change(void *data, Evas_Object *obj __UNUSED__)
    /* off-slider */
    if (cfdata->off_timeout < cfdata->suspend_timeout)
      {
-       cfdata->suspend_timeout = cfdata->off_timeout;
-       if (cfdata->suspend_slider)
-         e_widget_slider_value_double_set(cfdata->suspend_slider,
-                                          cfdata->suspend_timeout);
-
-       if (cfdata->suspend_timeout < cfdata->standby_timeout)
-         {
-            cfdata->standby_timeout = cfdata->suspend_timeout;
-            if (cfdata->standby_slider)
-              e_widget_slider_value_double_set(cfdata->standby_slider,
-                                               cfdata->standby_timeout);
-         }
+        cfdata->suspend_timeout = cfdata->off_timeout;
+        if (cfdata->suspend_slider)
+          e_widget_slider_value_double_set(cfdata->suspend_slider,
+               cfdata->suspend_timeout);
+
+        if (cfdata->suspend_timeout < cfdata->standby_timeout)
+          {
+             cfdata->standby_timeout = cfdata->suspend_timeout;
+             if (cfdata->standby_slider)
+               e_widget_slider_value_double_set(cfdata->standby_slider,
+             cfdata->standby_timeout);
+          }
      }
 }