Commit f2d07a37 authored by Michael Weiser's avatar Michael Weiser Committed by Sean Davis

Add systemd sleep inhibitor (bug #15929)

Looking at the timestamps in debug output it seems to me that systemd is simply suspending too fast for xfce4-screensaver to activate the lock screen.

Adding a sleep delay inhibitor lock makes the problem go away since it gives xfce4-screensaver time to activate the lock screen before allowing systemd to continue suspending the system.
Signed-off-by: Sean Davis's avatarSean Davis <>
parent 69c32a11
......@@ -99,6 +99,7 @@ struct GSListenerPrivate {
guint32 ck_throttle_cookie;
int sleep_inhibitor;
typedef struct {
......@@ -498,6 +499,76 @@ listener_ref_entry_check (GSListener *listener,
static void
add_sleep_inhibit (GSListener *listener) {
DBusMessage *message = NULL, *reply = NULL;
DBusMessageIter iter, reply_iter;
DBusError error;
const gchar *what = "sleep";
const gchar *who = "xfce4-screensaver";
const gchar *why = "Locking screen before sleep";
const gchar *mode = "delay";
g_return_if_fail (listener != NULL);
dbus_error_init (&error);
#if defined(WITH_SYSTEMD) || defined(WITH_ELOGIND)
message = dbus_message_new_method_call (LOGIND_SERVICE,
#elif defined(WITH_CONSOLE_KIT)
message = dbus_message_new_method_call (CK_NAME,
if (message == NULL) {
gs_debug ("Couldn't allocate the dbus message");
dbus_message_iter_init_append (message, &iter);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &what);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &who);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &why);
dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &mode);
reply = dbus_connection_send_with_reply_and_block (listener->priv->system_connection,
dbus_message_unref (message);
if (dbus_error_is_set (&error)) {
gs_debug ("%s raised:\n %s\n\n",, error.message);
dbus_error_free (&error);
dbus_message_iter_init (reply, &reply_iter);
if (DBUS_TYPE_UNIX_FD == dbus_message_iter_get_arg_type(&reply_iter))
dbus_message_iter_get_basic (&reply_iter, &listener->priv->sleep_inhibitor);
dbus_message_unref (reply);
static void
remove_sleep_inhibit (GSListener *listener) {
g_return_if_fail (listener != NULL);
if (listener->priv->sleep_inhibitor < 0) {
gs_debug ("Can't remove sleep inhibitor: Lock not acquired");
if (close(listener->priv->sleep_inhibitor) < 0) {
gs_debug ("Can't close file descriptor");
static void
add_session_inhibit (GSListener *listener,
GSListenerRefEntry *entry) {
......@@ -1382,10 +1453,16 @@ listener_dbus_handle_system_message (DBusConnection *connection,
if (listener->priv->prefs->sleep_activation_enabled) {
gs_debug ("Logind requested session lock");
g_signal_emit (listener, signals[LOCK], 0);
gs_debug ("Releasing sleep inhibitor");
remove_sleep_inhibit (listener);
} else {
gs_debug ("Logind requested session lock, but lock on suspend is disabled");
} else {
gs_debug ("Reinstating logind sleep inhibitor lock");
add_sleep_inhibit (listener);
gs_debug ("Logind requested session unlock");
// FIXME: there is no signal to request password prompt
g_signal_emit (listener, signals[SHOW_MESSAGE], 0, NULL, NULL, NULL);
......@@ -2077,6 +2154,9 @@ gs_listener_init (GSListener *listener) {
gs_debug ("Acquiring logind sleep inhibitor lock");
add_sleep_inhibit (listener);
static void
......@@ -2099,6 +2179,7 @@ gs_listener_finalize (GObject *object) {
g_free (listener->priv->session_id);
remove_sleep_inhibit (listener);
G_OBJECT_CLASS (gs_listener_parent_class)->finalize (object);
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