From 4f29073b1d498da40df034b951084709c2ad9029 Mon Sep 17 00:00:00 2001 From: poma Date: Wed, 17 Aug 2016 02:07:25 +0200 Subject: [PATCH] Hybrid Sleep support - "hibernate" and suspend the system Hybrid Sleep initially only writes hibernation image to SWAP space, it does not power off the machine, as a whole Suspend To Disk (S4) does, it rather Suspend To RAM (S3). The benefit of this combination is pronto RESUME from S3, whilst in case of battery drained or interruptions in power supply of any kind, you ain't gonna lose your work. Hybrid Sleep is the feature of the Linux kernel. To test it directly via cli: echo suspend > /sys/power/disk ; echo disk > /sys/power/state However to make this feature work, both Suspend To RAM (S3) and Suspend To Disk (S4) must be provided by the hardware dmesg: ACPI: (supports ... S3 S4 ...) in working order. Furthermore Suspend To Disk (S4) requires a relatively simple configuration an appendix to kernel command line: resume= i.e. directive to utilize particular SWAP space man 7 dracut.cmdline Ref. https://www.kernel.org/doc/Documentation/power/swsusp.txt Hybrid Sleep support, here in the Xfce's panel - via Action Buttons, is dependent on Hybrid Sleep support in the Xfce's session manager. --- migrate/migrate-config.c | 3 +++ plugins/actions/actions.c | 27 +++++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/migrate/migrate-config.c b/migrate/migrate-config.c index d0d49e7..5d92d26 100644 --- a/migrate/migrate-config.c +++ b/migrate/migrate-config.c @@ -99,6 +99,9 @@ migrate_config_action_48_convert (gint action) case 7: /* ACTION_HIBERNATE */ return "+hibernate"; + case 8: /* ACTION_HYBRID_SLEEP */ + return "+hybrid-sleep"; + default: /* ACTION_DISABLED */ return "-switch-user"; /* something else */ } diff --git a/plugins/actions/actions.c b/plugins/actions/actions.c index 8aa38f4..7cc8742 100644 --- a/plugins/actions/actions.c +++ b/plugins/actions/actions.c @@ -113,9 +113,10 @@ typedef enum ACTION_TYPE_SWITCH_USER = 1 << 4, ACTION_TYPE_LOCK_SCREEN = 1 << 5, ACTION_TYPE_HIBERNATE = 1 << 6, - ACTION_TYPE_SUSPEND = 1 << 7, - ACTION_TYPE_RESTART = 1 << 8, - ACTION_TYPE_SHUTDOWN = 1 << 9 + ACTION_TYPE_HYBRID_SLEEP = 1 << 7, + ACTION_TYPE_SUSPEND = 1 << 8, + ACTION_TYPE_RESTART = 1 << 9, + ACTION_TYPE_SHUTDOWN = 1 << 10 } ActionType; @@ -183,6 +184,14 @@ static ActionEntry action_entries[] = N_("Hibernating computer in %d seconds."), "system-hibernate" }, + { ACTION_TYPE_HYBRID_SLEEP, + "hybrid-sleep", + N_("Hybrid Sleep"), + N_("_Hybrid Sleep"), + N_("Do you want to hibernate and suspend the system?"), + N_("Hibernating and Suspending computer in %d seconds."), + "system-hibernate" + }, { ACTION_TYPE_SUSPEND, "suspend", N_("Suspend"), @@ -813,7 +822,8 @@ actions_plugin_action_dbus_xfsm (const gchar *method, G_TYPE_INVALID, G_TYPE_INVALID); } else if (g_strcmp0 (method, "Suspend") == 0 - || g_strcmp0 (method, "Hibernate") == 0) + || g_strcmp0 (method, "Hibernate") == 0 + || g_strcmp0 (method, "HybridSleep") == 0) { retval = dbus_g_proxy_call (proxy, method, error, G_TYPE_INVALID, G_TYPE_INVALID); @@ -893,6 +903,9 @@ actions_plugin_actions_allowed (void) if (actions_plugin_action_dbus_can (proxy, "CanHibernate")) PANEL_SET_FLAG (allow_mask, ACTION_TYPE_HIBERNATE); + if (actions_plugin_action_dbus_can (proxy, "CanHybridSleep")) + PANEL_SET_FLAG (allow_mask, ACTION_TYPE_HYBRID_SLEEP); + g_object_unref (G_OBJECT (proxy)); } } @@ -959,6 +972,11 @@ actions_plugin_action_activate (GtkWidget *widget, FALSE, &error); break; + case ACTION_TYPE_HYBRID_SLEEP: + succeed = actions_plugin_action_dbus_xfsm ("HybridSleep", FALSE, + FALSE, &error); + break; + case ACTION_TYPE_SUSPEND: succeed = actions_plugin_action_dbus_xfsm ("Suspend", FALSE, FALSE, &error); @@ -1209,6 +1227,7 @@ actions_plugin_default_array (void) "+separator", "+suspend", "-hibernate", + "+hybrid-sleep", "-separator", "+shutdown", "-restart", -- 2.7.4