actions - add smart suspend + hibernate actions for laptop usage
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sun, 15 Feb 2015 01:48:47 +0000 (10:48 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Sun, 15 Feb 2015 01:53:54 +0000 (10:53 +0900)
this adds 2 actions that only suspend a laptop (or hibernate) if there
are no external screens enabled. if there is no lid screen eg like a
desktop, then it will still go on as usual.

src/bin/e_actions.c

index a04d492e7614eacb34555d360fbdbea09ef84bf2..203734ff7f9f878c58bdc9a66aa762ccb3a9f51f 100644 (file)
@@ -2369,6 +2369,32 @@ ACT_FN_GO(suspend, )
    e_dialog_show(suspend_dialog);
 }
 
+static Eina_Bool
+_have_lid_and_external_screens_on(void)
+{
+   Eina_List *l;
+   E_Randr2_Screen *s;
+   int lids = 0;
+   int ext_screens = 0;
+
+   EINA_LIST_FOREACH(e_randr2->screens, l, s)
+     {
+        if (s->info.is_lid) lids++;
+        else if ((s->config.enabled) &&
+                 (s->config.geom.w > 0) &&
+                 (s->config.geom.h > 0))
+          ext_screens++;
+     }
+   if ((lids > 0) && (ext_screens > 0)) return EINA_TRUE;
+   return EINA_FALSE;
+}
+
+ACT_FN_GO(suspend_smart, __UNUSED__)
+{
+   if (!_have_lid_and_external_screens_on())
+     e_sys_action_do(E_SYS_SUSPEND, NULL);
+}
+
 /***************************************************************************/
 static E_Dialog *hibernate_dialog = NULL;
 
@@ -2431,6 +2457,12 @@ ACT_FN_GO(hibernate, )
    e_dialog_show(hibernate_dialog);
 }
 
+ACT_FN_GO(hibernate_smart, __UNUSED__)
+{
+   if (!_have_lid_and_external_screens_on())
+     e_sys_action_do(E_SYS_HIBERNATE, NULL);
+}
+
 /***************************************************************************/
 ACT_FN_GO(pointer_resize_push, )
 {
@@ -3399,6 +3431,10 @@ e_actions_init(void)
    e_action_predef_name_set(N_("System"), N_("Suspend"), "suspend",
                             NULL, NULL, 0);
 
+   ACT_GO(suspend_smart);
+   e_action_predef_name_set(N_("System"), N_("Suspend Intelligently"), "suspend_smart",
+                            NULL, NULL, 0);
+
    ACT_GO(hibernate);
    e_action_predef_name_set(N_("System"), N_("Hibernate"), "hibernate",
                             NULL, NULL, 0);
@@ -3407,6 +3443,10 @@ e_actions_init(void)
    e_action_predef_name_set(N_("System"), N_("Hibernate Now"), "hibernate_now",
                             NULL, NULL, 0);
 
+   ACT_GO(hibernate_smart);
+   e_action_predef_name_set(N_("System"), N_("Hibernate Intelligently"), "hibernate_smart",
+                            NULL, NULL, 0);
+
    ACT_GO(pointer_resize_push);
    ACT_GO(pointer_resize_pop);