Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a (seemingly rather exotic) Dell Latitude XT2 notebook running Lubuntu 12.04, fresh install. Tried to get the power button to work as expected (opening the logout dialog lubuntu-logout), but no success: power button does nothing but forced power-off on long press.

The power button itself is detected and works. In xfce4-power-manager-settings, when I set the power button action from "Ask" (= open lubuntu-logout) to "Shutdown", the laptop shuts down successfully; pressing the power button is recognized and processed correctly.

Edit: I removed a bunch of info from the question, as it seems not to be related to the problem.

share|improve this question
    
This q&a pertains to stock lxde (doesn't come with a power manager) but might be useful for Lubuntu users as well: askubuntu.com/questions/334168/… –  Glutanimate Aug 18 '13 at 21:20
add comment

2 Answers 2

Install acpi and acpi-support, if not already installed.

  • Go to /etc/acpi/events.
  • There should be a file named powerbtn (if not, make it). The contents of the file in my installation are:
# /etc/acpi/events/powerbtn
# This is called when the user presses the power button and calls
# /etc/acpi/powerbtn.sh for further processing.

# Optionally you can specify the placeholder %e. It will pass
# through the whole kernel event message to the program you've
# specified.

# We need to react on "button power.*" and "button/power.*" because
# of kernel changes.

event=button[ /]power
action=/etc/acpi/powerbtn.sh
  • You can associate an action with the powerbutton by editing the action variable in this file.
  • In my installation, the contents of /etc/acpi/powerbtn.sh are:
#!/bin/sh
# /etc/acpi/powerbtn.sh
# Initiates a shutdown when the power putton has been
# pressed.

[ -r /usr/share/acpi-support/power-funcs ] && . /usr/share/acpi-support/power-funcs

# getXuser gets the X user belonging to the display in $displaynum.
# If you want the foreground X user, use getXconsole!
getXuser() {
        user=`pinky -fw | awk '{ if ($2 == ":'$displaynum'" || $(NF) == ":'$displaynum'" ) { print $1; exit; } }'`
        if [ x"$user" = x"" ]; then
                startx=`pgrep -n startx`
                if [ x"$startx" != x"" ]; then
                        user=`ps -o user --no-headers $startx`
                fi
        fi
        if [ x"$user" != x"" ]; then
                userhome=`getent passwd $user | cut -d: -f6`
                export XAUTHORITY=$userhome/.Xauthority
        else
                export XAUTHORITY=""
        fi
        export XUSER=$user
}

# Skip if we just in the middle of resuming.
test -f /var/lock/acpisleep && exit 0

# If the current X console user is running a power management daemon that
# handles suspend/resume requests, let them handle policy This is effectively
# the same as 'acpi-support's '/usr/share/acpi-support/policy-funcs' file.

[ -r /usr/share/acpi-support/power-funcs ] && getXconsole
PMS="gnome-settings-daemon kpowersave xfce4-power-manager"
PMS="$PMS guidance-power-manager.py dalston-power-applet"

if pidof x $PMS > /dev/null; then
        exit
elif test "$XUSER" != "" && pidof dcopserver > /dev/null && test -x /usr/bin/dcop && /usr/bin/dcop --user $XUSER kded kded loadedModules | grep -q klaptopdaemon; then
        exit
elif test "$XUSER" != "" && test -x /usr/bin/qdbus; then
        kded4pid=$(pgrep -n -u $XUSER kded4)
        if test "$kded4pid" != ""; then
                dbusaddr=$(su - $XUSER -c "grep -z DBUS_SESSION_BUS_ADDRESS /proc/$kded4pid/environ")
                if test "$dbusaddr" != "" && su - $XUSER -c "export $dbusaddr; qdbus org.kde.kded" | grep -q powerdevil; then
                        exit
                fi
        fi
fi

# If all else failed, just initiate a plain shutdown.
/sbin/shutdown -h now "Power button pressed"
share|improve this answer
    
I do not have a folder /etc/acpi. o.O –  dyp Sep 26 '12 at 17:49
    
try creating one. –  green7 Sep 26 '12 at 17:58
    
Already done ^^ using just the last line of your script (which hopefully doesn't break it) -- and still nothing (yes, I rebooted). –  dyp Sep 26 '12 at 18:01
    
acpid was not installed. Installed it, yet no difference. –  dyp Sep 26 '12 at 18:11
    
try /etc/init.d/acpid restart –  green7 Sep 26 '12 at 18:24
show 8 more comments
up vote 1 down vote accepted

It seems to be a known bug in Lubuntu. In xfce4-power-manager-settings, there are several actions to select for the Power Button being pressed. When you select "Shut Down", it works as expected, but when you select "Ask", nothing happens.

A workaround is in the comment #10. It works for me. Seems there's an underlying problem between xfce4 and LXDE.

You can create the same behaviour with an (additional) acpi daemon, like green7 said. The version in his answer shuts down the PC w/o a dialog, but we discussed in chat that you can start lubuntu-logout from the script instead of simply shutting down the computer. This needs some work, though, as you have to start the logout application as a user who is allowed to connect to X, and provide the necessary environment variables (like $DISPLAY). As the env variables seem to vary between the distros, I think you had to look them up carefully for LXDE.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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