From c37a55d5737efc78d022f879613c5efd039516b9 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Sun, 15 Feb 2015 10:48:47 +0900 Subject: [PATCH] actions - add smart suspend + hibernate actions for laptop usage 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 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/bin/e_actions.c b/src/bin/e_actions.c index a04d492e7..203734ff7 100644 --- a/src/bin/e_actions.c +++ b/src/bin/e_actions.c @@ -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);