--- configure.ac.orig 2014-06-09 10:45:41.199518449 +0200 +++ configure.ac 2014-06-09 10:45:44.934471756 +0200 @@ -238,6 +238,11 @@ else echo " * Gnome Keyring support: no" fi +if test x"$SYSTEMD_FOUND" = x"yes"; then +echo " * Systemd support: yes" +else +echo " * Systemd support: no" +fi echo " * Backend: ${with_backend}" echo --- xfce4-session/xfsm-systemd.c.orig 2014-06-09 10:46:12.215130701 +0200 +++ xfce4-session/xfsm-systemd.c 2014-06-09 10:49:29.445664980 +0200 @@ -24,6 +24,7 @@ #include #include +#include #include @@ -33,9 +34,12 @@ #define SYSTEMD_DBUS_INTERFACE "org.freedesktop.login1.Manager" #define SYSTEMD_REBOOT_ACTION "Reboot" #define SYSTEMD_POWEROFF_ACTION "PowerOff" +#define SYSTEMD_SUSPEND_ACTION "Suspend" +#define SYSTEMD_HIBERNATE_ACTION "Hibernate" #define SYSTEMD_REBOOT_TEST "org.freedesktop.login1.reboot" #define SYSTEMD_POWEROFF_TEST "org.freedesktop.login1.power-off" - +#define SYSTEMD_SUSPEND_TEST "org.freedesktop.login1.suspend" +#define SYSTEMD_HIBERNATE_TEST "org.freedesktop.login1.hibernate" static void xfsm_systemd_finalize (GObject *object); @@ -94,6 +98,20 @@ static gboolean +xfsm_systemd_lock_screen (GError **error) +{ + XfconfChannel *channel; + gboolean ret = TRUE; + + channel = xfsm_open_config (); + if (xfconf_channel_get_bool (channel, "/shutdown/LockScreen", FALSE)) + ret = g_spawn_command_line_async ("xflock4", error); + + return ret; +} + + +static gboolean xfsm_systemd_can_method (XfsmSystemd *systemd, gboolean *can_method, const gchar *method, @@ -205,6 +223,34 @@ gboolean +xfsm_systemd_try_suspend (XfsmSystemd *systemd, + GError **error) +{ + if (!xfsm_systemd_lock_screen (error)) + return FALSE; + + return xfsm_systemd_try_method (systemd, + SYSTEMD_SUSPEND_ACTION, + error); +} + + + +gboolean +xfsm_systemd_try_hibernate (XfsmSystemd *systemd, + GError **error) +{ + if (!xfsm_systemd_lock_screen (error)) + return FALSE; + + return xfsm_systemd_try_method (systemd, + SYSTEMD_HIBERNATE_ACTION, + error); +} + + + +gboolean xfsm_systemd_can_restart (XfsmSystemd *systemd, gboolean *can_restart, GError **error) @@ -227,3 +273,39 @@ SYSTEMD_POWEROFF_TEST, error); } + + + +gboolean +xfsm_systemd_can_suspend (XfsmSystemd *systemd, + gboolean *can_suspend, + gboolean *auth_suspend, + GError **error) +{ + gboolean ret = FALSE; + + ret = xfsm_systemd_can_method (systemd, + can_suspend, + SYSTEMD_SUSPEND_TEST, + error); + *auth_suspend = *can_suspend; + return ret; +} + + + +gboolean +xfsm_systemd_can_hibernate (XfsmSystemd *systemd, + gboolean *can_hibernate, + gboolean *auth_hibernate, + GError **error) +{ + gboolean ret = FALSE; + + ret = xfsm_systemd_can_method (systemd, + can_hibernate, + SYSTEMD_HIBERNATE_TEST, + error); + *auth_hibernate = *can_hibernate; + return ret; +} --- xfce4-session/xfsm-systemd.h.orig 2014-06-09 10:49:46.759448528 +0200 +++ xfce4-session/xfsm-systemd.h 2014-06-09 10:50:59.902534113 +0200 @@ -42,6 +42,12 @@ gboolean xfsm_systemd_try_shutdown (XfsmSystemd *systemd, GError **error); +gboolean xfsm_systemd_try_suspend (XfsmSystemd *systemd, + GError **error); + +gboolean xfsm_systemd_try_hibernate (XfsmSystemd *systemd, + GError **error); + gboolean xfsm_systemd_can_restart (XfsmSystemd *systemd, gboolean *can_restart, GError **error); @@ -50,6 +56,16 @@ gboolean *can_shutdown, GError **error); +gboolean xfsm_systemd_can_suspend (XfsmSystemd *systemd, + gboolean *can_suspend, + gboolean *auth_suspend, + GError **error); + +gboolean xfsm_systemd_can_hibernate (XfsmSystemd *systemd, + gboolean *can_hibernate, + gboolean *auth_hibernate, + GError **error); + G_END_DECLS #endif /* __XFSM_SYSTEMD_H__ */ --- xfce4-session/xfsm-shutdown.c.orig 2014-06-09 10:51:12.047382282 +0200 +++ xfce4-session/xfsm-shutdown.c 2014-06-09 10:58:25.934957941 +0200 @@ -70,6 +70,7 @@ #include #ifdef HAVE_SYSTEMD +#define LOGIND_RUNNING() (access ("/run/systemd/seats/", F_OK) >= 0) #include #else #include @@ -142,7 +143,10 @@ XfceKiosk *kiosk; #ifdef HAVE_SYSTEMD - shutdown->systemd = xfsm_systemd_get (); + if (LOGIND_RUNNING()) + shutdown->systemd = xfsm_systemd_get (); + else + shutdown->systemd = NULL; #else shutdown->consolekit = xfsm_consolekit_get (); #endif @@ -165,7 +169,8 @@ XfsmShutdown *shutdown = XFSM_SHUTDOWN (object); #ifdef HAVE_SYSTEMD - g_object_unref (G_OBJECT (shutdown->systemd)); + if (LOGIND_RUNNING()) + g_object_unref (G_OBJECT (shutdown->systemd)); #else g_object_unref (G_OBJECT (shutdown->consolekit)); #endif @@ -662,7 +667,10 @@ return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_RESTART, error); else #ifdef HAVE_SYSTEMD - return xfsm_systemd_try_restart (shutdown->systemd, error); + if (LOGIND_RUNNING()) + return xfsm_systemd_try_restart (shutdown->systemd, error); + else + return FALSE; #else return xfsm_consolekit_try_restart (shutdown->consolekit, error); #endif @@ -683,7 +691,10 @@ return xfsm_shutdown_sudo_try_action (shutdown, XFSM_SHUTDOWN_SHUTDOWN, error); else #ifdef HAVE_SYSTEMD - return xfsm_systemd_try_shutdown (shutdown->systemd, error); + if (LOGIND_RUNNING()) + return xfsm_systemd_try_shutdown (shutdown->systemd, error); + else + return FALSE; #else return xfsm_consolekit_try_shutdown (shutdown->consolekit, error); #endif @@ -696,7 +707,12 @@ GError **error) { g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE); - +#ifdef HAVE_SYSTEMD + if (LOGIND_RUNNING()) + return xfsm_systemd_try_suspend (shutdown->systemd, error); + else + return FALSE; +#else #if UP_CHECK_VERSION(0, 99, 0) if (shutdown->helper_state == SUDO_AVAILABLE) { @@ -708,6 +724,7 @@ #else return xfsm_upower_try_suspend (shutdown->upower, error); #endif +#endif } @@ -717,7 +734,12 @@ GError **error) { g_return_val_if_fail (XFSM_IS_SHUTDOWN (shutdown), FALSE); - +#ifdef HAVE_SYSTEMD + if (LOGIND_RUNNING()) + return xfsm_systemd_try_hibernate (shutdown->systemd, error); + else + return FALSE; +#else #if UP_CHECK_VERSION(0, 99, 0) if (shutdown->helper_state == SUDO_AVAILABLE) { @@ -729,6 +751,7 @@ #else return xfsm_upower_try_hibernate (shutdown->upower, error); #endif +#endif } @@ -747,7 +770,7 @@ } #ifdef HAVE_SYSTEMD - if (xfsm_systemd_can_restart (shutdown->systemd, can_restart, error)) + if (LOGIND_RUNNING() && xfsm_systemd_can_restart (shutdown->systemd, can_restart, error)) #else if (xfsm_consolekit_can_restart (shutdown->consolekit, can_restart, error)) #endif @@ -778,7 +801,7 @@ } #ifdef HAVE_SYSTEMD - if (xfsm_systemd_can_shutdown (shutdown->systemd, can_shutdown, error)) + if (LOGIND_RUNNING() && xfsm_systemd_can_shutdown (shutdown->systemd, can_shutdown, error)) #else if (xfsm_consolekit_can_shutdown (shutdown->consolekit, can_shutdown, error)) #endif @@ -808,7 +831,13 @@ *can_suspend = FALSE; return TRUE; } - +#ifdef HAVE_SYSTEMD + if (LOGIND_RUNNING()) + return xfsm_systemd_can_suspend (shutdown->systemd, can_suspend, + auth_suspend, error); + else + return FALSE; +#else #if UP_CHECK_VERSION(0, 99, 0) *can_suspend = xfsm_shutdown_fallback_can_suspend (); return TRUE; @@ -816,6 +845,7 @@ return xfsm_upower_can_suspend (shutdown->upower, can_suspend, auth_suspend, error); #endif +#endif } @@ -833,7 +863,13 @@ *can_hibernate = FALSE; return TRUE; } - +#ifdef HAVE_SYSTEMD + if (LOGIND_RUNNING()) + return xfsm_systemd_can_hibernate (shutdown->systemd, can_hibernate, + auth_hibernate, error); + else + return FALSE; +#else #if UP_CHECK_VERSION(0, 99, 0) *can_hibernate = xfsm_shutdown_fallback_can_hibernate (); return TRUE; @@ -841,6 +877,7 @@ return xfsm_upower_can_hibernate (shutdown->upower, can_hibernate, auth_hibernate, error); #endif +#endif }