I have a Dell XPS 13 (2015 model), and I'm using Ubuntu 15.10 with Xmonad. I have xfce4-power-manager
running and gnome-screensaver
is used to lock the screen. In the settings dialog of xfce4-power-manager, there is a setting "When laptop lid is closed", which has three options (separately for when on battery and when plugged in): Switch off display, Suspend, and Lock Screen.
If I choose "Switch off display", the screen doesn't get locked when closing the lid. I'd like to have the screen locked when I close the lid. However, when I select "Lock Screen", the display doesn't seem to be switched off. To save battery, I'd like to switch the display off, too. What would be a good (easy and/or somewhat canonical) way to get both?
The question
Lock screen after blanking with gnome-screensaver and XFCE
may be related, but it doesn't have answers.
Best Answer
I don't think it is possible to do that in XFCE power manager. However, you can make a script to both lock screen and turn it off, and make it so that it is launched as soon as you close your lid, overriding power manager's settings.
How to launch a custom script is reported in the official Ubuntu help page. I'll write the passages sequentially, to understand the reason of each step read the original post. Maybe it's not the easiest process around (it is pretty easy anyway, as you just have to input a series of specified commands and fill files with precise content), but I think it is the only way to go. Also, is pretty canonical, both with the lower-case and capital C, as the solution is in Ubuntu's official help.
First, create a script to make environment variables available for root, so that it can launch commands in your normal user's environment. (I put
mousepad
in the commands as it's the default text editor for XFCE. Replace it withGEdit
,SciTE
,Emacs
,nano
,vim
or whatever editor you use)With the following content
And make it executable
Add it in
Settings
→Session and Startup
→Application autostart
to Set it to run on startup.Create
/etc/acpi/events/lm_lid
With this content
This will execute
/etc/api/lid.sh
when lid button is triggered. Let's create it(obviously replace
%user
with your username)This means the script will execute
/home/%user/lid_event
. Let's create it tooThis will execute
~/open
if the lid is opened and~/close
if it's closed. Again, let's create them:Since to turn screen off you need
xset dpms force off
and to lock it you needxflock4
, will write this insideclose
:Inside open, as suggested by Ubuntu's help, you can play a sound of your choice (I made a test with Barney Gumble's burp)
Let's make them all executable
Restart acpid
Launch
~/export_x_info
(or restart your laptop so that it is autolaunched on startup) and close/open your lid to see if it works.Note: in my laptop, locking screen would also turn it off, so I couldn't 100% test the double action, but it worked in locking it. Also, the help page puts, as an example, an action to change Pidgin's status as away when you close the lid and as "I'm here" when you open it, very useful.
TL;DR (if this issue should ever occur to a lazy person or a newbie): input the commands in the gray background (
#
means you need elevated root privileges, or simply typesudo
before the command, while$
means you should input the command as regular user). When the command invokes a text editor (i.e.,mousepad
) copy and paste the part in the yellow background in your editor, then save and close.