Enabling the Sleep button on a Dell laptop in Kubuntu Karmic

Update 2010-05-02: See this comment.

I read an article in the Dec 2009 issue of Linux Magazine, one of several Linux-focused magazines we get at the office. I’d like to link directly to it, but it the magazine’s own website doesn’t offer the article or even a reliable permanent link to the issue number. Hint: hey guys, sort that out.

The article was about configuring ACPI hotkeys to support your specific laptop. IE, the buttons for “sleep”, “brightness up”, etc. For most laptops this already works on Ubuntu. On my Dell Vostro 1500, every button except for “sleep” worked right after install. This is Linux, so there is always some way to fix that.

Unfortunately, ACPI cannot even detect my keypress. The instructions in the article suggest starting acpid with -d for debug mode, which will print any keypresses that reach it. Pressing Fn+F1, the sleep button, prints nothing. So we’re going to use KDE’s hotkey support instead. Gnome users can use a similar method; only the menu instructions differ.

First, create a script somewhere your user can run. I have $HOME/bin in my $PATH, so I created a file there:

touch ~/bin/sleep-kde-screen
chmod 755 ~/bin/sleep-kde-screen

Then I edited it to contain the following:

This calls DBUS to lock the screensaver, then asks power-manager to suspend. This way you will be prompted for your password when you resume from suspend. If you prefer to hibernate, change “pm-suspend” to “pm-hibernate”.

Second, you need to tell sudo to allow your user to run this /usr/bin/pm-suspend without prompting for a password. Run sudo visudo to edit /etc/sudoers, and add this line at the bottom:

Finally, add this script to your K menu with a hotkey. Right-click on the K menu and select “Menu Editor”. Add a new item to the “System” menu, give it a name (I like “Sleep!” *), and tell it to call sleep-kde-screen (wherever you’ve put it). On the Advanced tab, select “Current shortcut key” and press the sleep button. Now save and close the menu editor.

* I imagine saying “Sleeeeeep!” like a hypnotist bad guy from an old movie on MST3K.

Press the sleep button, and you’ll suspend!

Tags: , , ,

  1. Gabor’s avatar

    Strange, but it does not work for me. I made everything you wrote, but when I lunch either the script, or “sudo /usr/sbin/pm-suspend” from KDE menu, it doesn’t do anything. In contrast, I can run it from Konsol, and it is OK, suspends/hibernates correctly without asking the password. Do you have an idea, what’s wrong? (KDE 4.3.2, Kubuntu 9.10 Karmic)

    Reply

  2. tyler’s avatar

    Gabor, it sounds like you don’t have the sudo permissions working. If you run it in Konsole and it works after prompting you for your password, then this is the problem. Most likely when you run it from the KDE menu, it is hanging on the sudo prompt.

    Reply

  3. Juliano’s avatar

    There is a much simpler way of doing that, without sudo, helper scripts, etc… it also plays nice with the desktop environment (it has time to disconnect online services before calling pm-suspend).

    1. Go to System Settings -> Input Actions.
    2. Click Edit -> New -> Global Shortcut -> D-Bus Command.
    3. Set a name for this action, assign the trigger to the “Sleep” button.
    4. Set the D-Bus action to:

    Remote application: org.freedesktop.PowerManagement
    Remote object: /org/freedesktop/PowerManagement
    Function: org.freedesktop.PowerManagement.Suspend
    Arguments:

    Save and test.

    Reply

  4. tyler’s avatar

    Thanks, Juliano. That is indeed better.

    Reply

  5. foo’s avatar

    I have a dell m1330, and my fn+f1 key combination didn’t work either. I noticed that on my girlfriend’s dell laptop, the sleep combination is fn+esc. I tried this on my laptop and it worked immediately. I think the key mapping is a little goofy on linux. So now to put my laptop to sleep I press fn+esc, although the little sleep icon is on the f1 key. Did you try pressing fn+esc?

    Reply

    1. tyler’s avatar

      Whoa! That worked. Thanks!

      Reply

    2. Tim’s avatar

      Thanks for a good thread. I tried both methods; they both worked and I learnt something in both approaches. dbus is less mysterious to me now.

      Reply

Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">