On Sat, Mar 24, 2012 at 15:21, Jeff Hoogland <jeffhoogl...@linux.com> wrote:
> Would it be possible to add a "shut down below percentage" to the battery
> gadget? Had a few users request this over the months as some of them don't
> care to hibernate their systems.
>
> --
> ~Jeff Hoogland <http://jeffhoogland.com/>
> Thoughts on Technology <http://jeffhoogland.blogspot.com/>, Tech Blog
> Bodhi Linux <http://bodhilinux.com/>, Enlightenment for your Desktop
> ------------------------------------------------------------------------------
> This SF email is sponsosred by:
> Try Windows Azure free for 90 days Click Here
> http://p.sf.net/sfu/sfd2d-msazure
> _______________________________________________
> enlightenment-devel mailing list
> enlightenment-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Hello Jeff,

I took the liberty to write a patch to support multiple suspend methods.
I'm sitting on a desktop without battery here and can't test, it would
be nice if you could do that for me. If it works for you, I'll send
the patch to the list for official review.

I hope the attachment reaches the list, alternatively it is available here:
http://gstaedtner.net/e_battery_suspend_methods.patch

~thomasg
From f1a375c7fd4683edeeb31646a496bb4cded64ad8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20Gst=C3=A4dtner?= <tho...@gstaedtner.net>
Date: Sun, 25 Mar 2012 21:08:01 +0200
Subject: [PATCH] battery: add support for different suspend methods

Allow the user to select what to do when the battery runs low:
Suspend, Hibernate or Shutdown.

diff --git a/src/modules/battery/e_mod_config.c 
b/src/modules/battery/e_mod_config.c
index 048b6c6..75f8861 100644
--- a/src/modules/battery/e_mod_config.c
+++ b/src/modules/battery/e_mod_config.c
@@ -13,6 +13,7 @@ struct _E_Config_Dialog_Data
    int dismiss_alert;
    int alert_timeout;
    int suspend_below;
+   int suspend_method;
    int force_mode; // 0 == auto, 1 == batget, 2 == subsystem
 #ifdef HAVE_ENOTIFY
    int desktop_notifications;
@@ -76,6 +77,7 @@ _fill_data(E_Config_Dialog_Data *cfdata)
    cfdata->poll_interval = battery_config->poll_interval;
    cfdata->alert_timeout = battery_config->alert_timeout;
    cfdata->suspend_below = battery_config->suspend_below;
+   cfdata->suspend_method = battery_config->suspend_method;
    cfdata->force_mode = battery_config->force_mode;
 #ifdef HAVE_EEZE
    cfdata->fuzzy = battery_config->fuzzy;
@@ -236,11 +238,19 @@ _advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, 
Evas *evas, E_Config_D
                             NULL, &(cfdata->poll_interval), 100);
    e_widget_table_object_append(o, ob, 0, 1, 1, 1, 1, 0, 1, 0);
    
-   ob = e_widget_label_add(evas, _("Hibernate when below:"));
+   rg = e_widget_radio_group_new(&(cfdata->suspend_method));
+   ob = e_widget_radio_add(evas, _("Suspend when below:"), 0, rg);
+   e_widget_on_change_hook_set(ob, _cb_radio_changed, cfdata);
    e_widget_table_object_append(o, ob, 0, 2, 1, 1, 1, 0, 1, 0);
+   ob = e_widget_radio_add(evas, _("Hibernate when below:"), 1, rg);
+   e_widget_on_change_hook_set(ob, _cb_radio_changed, cfdata);
+   e_widget_table_object_append(o, ob, 0, 3, 1, 1, 1, 0, 1, 0);
+   ob = e_widget_radio_add(evas, _("Shutdown when below:"), 2, rg);
+   e_widget_on_change_hook_set(ob, _cb_radio_changed, cfdata);
+   e_widget_table_object_append(o, ob, 0, 4, 1, 1, 1, 0, 1, 0);
    ob = e_widget_slider_add(evas, 1, 0, _("%1.0f %%"), 0, 50, 1, 0, 
                             NULL, &(cfdata->suspend_below), 100);
-   e_widget_table_object_append(o, ob, 0, 3, 1, 1, 1, 0, 1, 0);
+   e_widget_table_object_append(o, ob, 0, 5, 1, 1, 1, 0, 1, 0);
    
    e_widget_toolbook_page_append(otb, NULL, _("Polling"), o, 1, 0, 1, 0, 
                                  0.5, 0.0);
@@ -334,6 +344,7 @@ _advanced_apply_data(E_Config_Dialog *cfd __UNUSED__, 
E_Config_Dialog_Data *cfda
 
    battery_config->force_mode = cfdata->force_mode;
    battery_config->suspend_below = cfdata->suspend_below;
+   battery_config->suspend_method = cfdata->suspend_method;
 
    _battery_config_updated();
    e_config_save_queue();
@@ -352,6 +363,7 @@ _advanced_check_changed(E_Config_Dialog *cfd __UNUSED__, 
E_Config_Dialog_Data *c
           (cfdata->poll_interval != battery_config->poll_interval) ||
           (cfdata->alert_timeout != battery_config->alert_timeout) ||
           (cfdata->suspend_below != battery_config->suspend_below) ||
+          (cfdata->suspend_method != battery_config->suspend_method) ||
 #ifdef HAVE_EEZE
            (cfdata->fuzzy != battery_config->fuzzy) ||
 #endif           
diff --git a/src/modules/battery/e_mod_main.c b/src/modules/battery/e_mod_main.c
index 3cf9671..b29a1aa 100644
--- a/src/modules/battery/e_mod_main.c
+++ b/src/modules/battery/e_mod_main.c
@@ -610,7 +610,14 @@ _battery_update(int full, int time_left, int time_full, 
Eina_Bool have_battery,
         if ((have_battery) && (!have_power) && (full >= 0) &&
             (battery_config->suspend_below > 0) &&
             (full < battery_config->suspend_below))
-           e_sys_action_do(E_SYS_HIBERNATE, NULL);
+         {
+            if (battery_config->suspend_method == SUSPEND) 
+               e_sys_action_do(E_SYS_SUSPEND, NULL);
+            else if (battery_config->suspend_method == HIBERNATE)
+              e_sys_action_do(E_SYS_HIBERNATE, NULL);
+            else if (battery_config->suspend_method == SHUTDOWN)
+              e_sys_action_do(E_SYS_HALT, NULL);
+         }
      }
    if (!have_battery)
      e_powersave_mode_set(E_POWERSAVE_MODE_LOW);
diff --git a/src/modules/battery/e_mod_main.h b/src/modules/battery/e_mod_main.h
index 6f347c8..d1bf8ec 100644
--- a/src/modules/battery/e_mod_main.h
+++ b/src/modules/battery/e_mod_main.h
@@ -19,6 +19,10 @@ typedef struct _Config       Config;
 #define NOSUBSYSTEM 1
 #define SUBSYSTEM 2
 
+#define SUSPEND 0
+#define HIBERNATE 1
+#define SHUTDOWN 2
+
 #define POPUP_DEBOUNCE_CYCLES  2
 
 struct _Config
@@ -28,7 +32,8 @@ struct _Config
    int              alert;     /* Alert on minutes remaining */
    int             alert_p;    /* Alert on percentage remaining */
    int              alert_timeout;  /* Popup dismissal timeout */
-   int              suspend_below;  /* Suspend if batter drops below this 
level */
+   int              suspend_below;  /* Suspend if battery drops below this 
level */
+   int              suspend_method; /* Method used to suspend the machine */
    int              force_mode; /* force use of batget or hal */
    /* just config state */
    E_Module        *module;
-- 
1.7.8.5

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to