Ever since I switched to LXDE my power button won't work anymore. I would love to be able to display a fancy logout menu like the one in Unity and similar DEs. How can I achieve this?
Ubuntu – My power button doesn’t work under LXDE. How to fix this
acpilogoutlubuntulxdeshutdown
Best Answer
The ACPID way
Overview
There are numerous ways of fixing this issue. If you look through the web you will find suggestions on installing power managers used in other desktop environments (DEs) like
xfce4-power-manager
orgnome-settings-daemon
. However, as an LXDE user you are probably striving for a lightweight solution. One lightweight way to display a logout menu on power button press is to utilize an ACPID script.What is ACPID?
From the ArchWiki:
Installation
Configuration
Open
/etc/acpi/powerbtn.sh
in a text editor of your choice, e.g. leafpad:At the end of the file you will find the following passage:
Just before this passage add the following snippet:
Most of the snippet consists of functions and commands that make sure that a graphical application like the logout menu can be run by ACPID (setting environment variables like
XUSER
andDISPLAY
).Note: If you have GNOME components running in your LXDE session (e.g. nautilus, various daemons) the session detection might go wrong. In these cases I would advise you to insert the code in the following way:
Troubleshooting
For some unknown reason these functions don't always work. In that case you will have to replace the snippet above with the following one:
The environment variables are hard-coded in this one. Make sure to substitute
user
for your own user name. It should work for most single-user system configurations.Here's another workaround, just in case none of the variants above work. Replace the
getXuser
function with the following passage:What does it do?
The
powerbtn.sh
script is triggered by ACPID each time the power button is pressed. As you can see it already includes a number of checks for common DEs like Unity, GNOME and KDE. These checks are there to make sure that the shutdown event is handled by the respective power manager. Alas, LXDE doesn't have one of those built in.That's why we added a snippet of our own that does the checking for ACPID. If it detects an LXDE session it makes sure that your PC isn't just shut down right away and instead launches the logout menu you should be familiar with.
With these changes you should now be able to launch your logout menu with your hardware power button - without needing to install a bulky power manager. And even better, this does not interfere with other DEs in any way.
Sources
http://www.ollie-reardon.co.uk/lxde-tip-power-button-not-working/
https://wiki.archlinux.org/index.php/Acpid
http://forum.lxde.org/viewtopic.php?f=8&t=205
Further reading
Lubuntu - power button doesn't turn off computer,
Laptop power button not working
https://bugs.launchpad.net/xfce4-power-manager/+bug/1008650
https://unix.stackexchange.com/questions/87259/why-wont-this-shutdown-script-work-when-executed-by-acpid