Commit a6e3ee40 authored by Mario Limonciello's avatar Mario Limonciello Committed by Benjamin Berg

power: Add Suspend then Hibernate

Systemd recently merged supported for suspending then hibernate
which is a new sleep type that will suspend the system followed by
hibernate after a period of time.

If the system supports it (new enough systemd and hibernation supported)
choose this when the system is configured to suspend.
parent b9ca3571
......@@ -1946,6 +1946,36 @@ power_action (GsdMediaKeysManager *manager,
NULL, NULL);
}
static void
suspend_action (GsdMediaKeysManager *manager,
gboolean allow_interaction)
{
const gchar *action = "Suspend";
g_autoptr(GVariant) retval = NULL;
g_autoptr(GError) error = NULL;
retval = g_dbus_proxy_call_sync (manager->priv->logind_proxy,
"CanSuspendThenHibernate",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
&error);
if (retval == NULL) {
g_warning ("Failed to query CanSuspendThenHibernate: %s", error->message);
g_error_free (error);
} else {
const gchar *s2h = NULL;
g_variant_get (retval, "(s)", &s2h);
if (g_strcmp0 (s2h, "yes") == 0)
action = "SuspendThenHibernate";
}
g_debug ("Choosing suspend action: %s", action);
power_action (manager, action, allow_interaction);
}
static void
do_config_power_action (GsdMediaKeysManager *manager,
GsdPowerActionType action_type,
......@@ -1953,7 +1983,7 @@ do_config_power_action (GsdMediaKeysManager *manager,
{
switch (action_type) {
case GSD_POWER_ACTION_SUSPEND:
power_action (manager, "Suspend", !in_lock_screen);
suspend_action (manager, !in_lock_screen);
break;
case GSD_POWER_ACTION_INTERACTIVE:
if (!in_lock_screen)
......@@ -1991,7 +2021,7 @@ do_config_power_button_action (GsdMediaKeysManager *manager,
/* Always suspend tablets */
if (g_strcmp0 (manager->priv->chassis_type, "tablet") == 0) {
power_action (manager, "Suspend", !in_lock_screen);
suspend_action (manager, !in_lock_screen);
return;
}
......
......@@ -900,12 +900,35 @@ action_poweroff (GsdPowerManager *manager)
static void
action_suspend (GsdPowerManager *manager)
{
const gchar *action = "Suspend";
g_autoptr(GVariant) retval = NULL;
g_autoptr(GError) error = NULL;
if (manager->priv->logind_proxy == NULL) {
g_warning ("no systemd support");
return;
}
retval = g_dbus_proxy_call_sync (manager->priv->logind_proxy,
"CanSuspendThenHibernate",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
manager->priv->cancellable,
&error);
if (retval == NULL) {
g_warning ("Failed to query CanSuspendThenHibernate: %s", error->message);
} else {
const gchar *s2h = NULL;
g_variant_get (retval, "(s)", &s2h);
if (g_strcmp0 (s2h, "yes") == 0)
action = "SuspendThenHibernate";
}
g_debug ("Choosing suspend action: %s", action);
g_dbus_proxy_call (manager->priv->logind_proxy,
"Suspend",
action,
g_variant_new ("(b)", FALSE),
G_DBUS_CALL_FLAGS_NONE,
G_MAXINT,
......@@ -1061,6 +1084,7 @@ backlight_disable (GsdPowerManager *manager)
g_error_free (error);
}
g_debug("Is tablet: %d", manager->priv->is_tablet);
if (manager->priv->is_tablet)
action_suspend (manager);
else
......@@ -1073,6 +1097,7 @@ static void
do_power_action_type (GsdPowerManager *manager,
GsdPowerActionType action_type)
{
g_debug("Running power action type %d", action_type);
switch (action_type) {
case GSD_POWER_ACTION_SUSPEND:
action_suspend (manager);
......
  • I almost tore my hairs off trying understand why my system shuts down in 3hrs of sleep, how do you disable this behaviour?

  • We are having trouble with this as well. Can someone mention a sleep.conf override to revert to a pure suspend-to-mem behaviour?

  • I am actually considering to hide the change behind a compile time switch and default it to off.

    The reason is twofold:

    1. We seem to be unprepared to enable this by default (for a lot of reasons, from broken installers, to broken hardware).
    2. We only use the code in the case of "idle suspend" and "power button". All other common cases are unaffected ("lid action" and gnome-shell menu in particular).
  • mentioned in commit 17da9767

    Toggle commit list
  • mentioned in commit 3fdfe9db

    Toggle commit list
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment