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.
This commit is contained in:
Carsten Haitzler 2015-02-15 10:48:47 +09:00
parent e50b8e5933
commit c37a55d573
1 changed files with 40 additions and 0 deletions

View 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);