3

For as long as I can remember locking screen with screensaver had never been working good. The problem that had always been there is that when I move the mouse or press a key screensaver disappears making the screen visible, then a second passes and only after it the lock screen appears - this looks and feels like a bug and can be very undesirable if you don't want other people to see what you were doing when you have left the desk.

Now, as I have installed the latest Xubuntu with XFCE 4.12 there is another problem (in addition to the first one described above): it either does not lock the screen at all or does it twice (so I have to enter the password 2 times to unlock it)

The first problem has been discussed many times already and nobody seems to have found a solution so far.

But I have found it accidentally yesterday:

calling xscreensaver-command -lock launches the screensaver, locks the screen and does it the right way - the desktop is not exposed when the screensaver disappears if launched this way.

So I would like to disable the desktop environment / display manager native screensaver/lockscreen management features and let it just run the command I define when I am away, simple as this, pretty "unix way"-ish. How can this be achieved?

  • Are you using gnome-screensaver or xscreensaver? I think xfce uses gnome-screensaver by default. It might be worth trying to remove gnome-screensaver and install xscreensaver. You could then force it to run with -lock by writing a script called xscreensaver-command which calls /path/to/xscreensaver-command -lock. If the script is first in your path, it might do what you want. Let me know if that works and I can write up an answer. – terdon Jan 24 '16 at 15:36
0

The approach I thought of was an infinite loop bash script that checks idle time and runs the lock command if it's not already running. This won't work with xscreensaver as it's a client/server model but since you said "custom command" in your question I took the liberty of using the very simple screenlocker slock instead.

You'll need to install two packages for this to work. xprintidle and slock. Both are available in apt.

Place the following script somewhere and make it executable. Adjust LOCK as desired. 600000 = 10 minutes.

#!/bin/sh
DISPLAY=":0"
# in ms
LOCK=600000
while :
do
  IDLE=$(xprintidle)
  if [ $IDLE -gt $LOCK ]; then
    slock
  fi
  sleep 1
done

According to the this arch wiki https://wiki.archlinux.org/index.php/Xfce#Startup_applications you can add the script to your startup like so:

To launch custom applications when Xfce starts up, click the Applications Menu Settings > Settings Manager and then choose the Session and Startup option and click the tab Application Autostart. You will see a list of programs that get launched on startup. To add an entry, click the Add button and fill out the form, specifying the path to an executable you want to run.

You'll of course want to make sure xscreensaver is disabled.

EDIT: Originally I backgrounded slock and used pgrep to see if the process was running. I realized that was unnecessary and just allowed slock to be a blocking process instead. Changed accordingly.

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.