3

I'm using xubuntu and I cannot enable the screenlock when suspending the machine.

How do I enable the lock on suspend?

1

Xubuntu uses gnome-screensaver. First, you must replace gnome-screensaver with xscreensaver. The tool that locks the screen on suspend uses xscreensaver. On top of that, if you use an external monitor with gnome-screensaver on a laptop, and lock the screen, it will be delayed in switching to the external monitor's resolution, or not do it all, unlike xscreensaver (in my personal experience).

To remove gnome-screensaver run:

sudo apt-get remove gnome-screensaver

Then, install xscreensaver:

sudo apt-get install xscreensaver

Xscreensaver will be automatically added to your list of startup programs as the default screensaver program once gnome-screensaver is removed and it's installed in its place. If it's not, add the command xscreensaver -nosplash to your to your list of applications to be ran upon login. You can change xscreensaver's setting in the XFCE settings manager. To have all extra available screensavers for xscreensaver, run sudo apt-get install unicode-screensaver xscreensaver-gl-extra rss-glx xscreensaver-data-extra.

Next, you need to install xss-lock. This program will invoke the xscreensaver lock screen upon system suspend.

To do this, run:

sudo apt-get install xss-lock

Next, you need to run xss-lock on start and tell it to suspend the lid when closed. This part is weird, but follow me. I don't know exactly WHY you have to do this, but it won't work otherwise. You need to create an executable with the command to do this instead of just have it run that command on login. To do this, I created a file simply called suspendwhenlidclosed, and pasted the command in there.

That command is:

xss-lock -- xscreensaver-command -lock &

Next, give it permission to run as a program, in this example, the file suspendwhenlidclosed is in the home directory.

sudo chmod +x ~/suspendwhenlidclosed

Next, copy the file to /usr/bin so that it can be ran from the command line, for conveniences sake.

sudo mv ~/suspendwhenlidclosed /usr/bin

Now, add the command to list of commands to be ran upon login, you can do this from the XFCE settings manager. Open the program named Settings Manager in Settings category in the Whisker Menu, or the Application Menu if you use that, and from within the Settings Manager, open Session and Startup, and go to the tab Application Autostart. There is also a shortcut to Session and Startup in the Settings category. Click the add button and add suspendwhenlidclosed to the list like in the screenshot below.

enter image description here

Lastly, if you log in and out, another instance of xss-lock will be created for each time you do that, and each extra instance will have high CPU usage. To prevent this, you must run the command killall xss-lock during logout. To achieve this, create another file, in this example I call it killxsslock and it is also placed in my home directory.

Create the file killxsslock, copy this command into it, and save it.

killall xss-lock

Next, give it permission to run as a program:

sudo chmod +x ~/killxsslock

Move it to /usr/bin so it can be ran as a command:

sudo mv ~/killxsslock /usr/bin

To have killxsslock ran on logout so extra instances of xss-lock aren't created when logging in and out, you need to add two lines to your lightdm config file.

Open the file with:

sudo mousepad /etc/lightdm/lightdm.conf 

Next, add these lines:

[SeatDefaults] 
session-cleanup-script=/usr/bin/killxsslock

And save. Then log in and out. Xscreensaver will now be your default screensaver and your laptop will automatically run the lock screen upon suspend. I hope this helps someone! :D

OP had added this to their question - moved the content here as CW

| improve this answer | |
0

Go to Session and startup > Advance and mark the Lock screen before sleep option

enter image description here

Don't worry.I am sure that it will work in Xubutnu as mint is made from it.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.