Xfce - Lock the screen on suspend but not on hibernate

I am trying to get xfce to lock my screen on suspend, but not on hibernate.
As I am using full disk encryption, I need to enter a password after hibernation to unlock my SSD (and I don't want to enter two passwords), but after suspending, my system currently does not require a password.

The "Lock screen when system is going to sleep" option under security in the xfce power manager only works for both suspending and hibernating, not for just suspending. Is there a way to achieve this just for suspending?

Nope, because hibernation uses the exact same process as sleep but just saves everything to disk.
I.E. "Hibernation" = "Deep sleep"


I was thinking about a systemd service executing xflock4 to be run before suspend.target or a hook in /usr/lib/systemd/system-sleep doing the same, but the latter just gives me an error without locking the screen:
Failed to init libxfconf: Error spawning command line “dbus-launch --autolaunch=0a99d35340e147cdadb587d93a3c56ab --binary-syntax --close-stderr”: Child process exited with code 1.
Do you know of any way to make xflock4 work from within a systemd service or hook?

So, this is definitely not an ideal solution, but until I get a proper solution (e.g. using systemd) to work, I have settled for creating a script (see below) for locking the screen and then suspending, which I mapped to keyboard shortcuts (Super+S for suspend, Super+A for hybrid-sleep, Super+W for suspend-then-hibernate) for quick access.
It's better than nothing, but if someone finds an actual solution instead of this workaround, I'd highly appreciate them sharing it.
The mentioned script:

#! /bin/bash
# ===.lock_and_suspend.sh===
# Locks the screen by calling "xflock4"
# (plus "sleep 1" to ensure that the screen is locked properly)
# and then suspends the system by calling "systemctl suspend".
# Can be given "hybrid-sleep" or "suspend-then-hibernate" as first argument
# to execute the according action after locking the screen instead of simply suspending.

sleep 1
if [[ $# -ge 1 ]]
	case $1 in
			systemctl hybrid-sleep	
			systemctl suspend-then-hibernate
systemctl suspend

I would say that counts as a solution!


It's still not ideal, especially in regards to situations where my laptop automatically suspends, such as low battery, a certain time of inactivity when not charging, or closing the lid, which would likely be solved by a method using systemd, but it works for the moment.

1 Like

So, yesterday I accidentally stumbled accross this thread on askubuntu.com, and one of the answer uses dm-tool lock ( after setting XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0) to lock the screen from a script in /lib/systemd/system-sleep/.
After adapting this a bit, I came up with the following script:


if [[ "$1" == "pre" ]]; then
	pkill intel-virtual
	sleep 1
	if [[ "$2" != "hibernate" ]]; then
		XDG_SEAT_PATH="/org/freedesktop/DisplayManager/Seat0" dm-tool lock 
	sleep 1

(Note: pkill intel-virtual; sleep 1 is only necessary due to my specific hardware setup using Nvidia hybrid graphics. Most other people should be able to delete those lines.)

Putting this in an executable script in /lib/systemd/system-sleep/finally solves my issue for good.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.

Forum kindly sponsored by