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:
chmod 755 ~/bin/sleep-kde-screen
Then I edited it to contain the following:
#!/bin/sh qdbus org.freedesktop.ScreenSaver /ScreenSaver Lock sudo /usr/sbin/pm-suspend
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:
%admin ALL=NOPASSWD: /usr/sbin/pm-suspend
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!
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)
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
Save and test.
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?
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.
Comments feed for this article
Trackback link: https://www.tolaris.com/2009/11/10/enabling-the-sleep-button-on-a-dell-laptop-in-kubuntu-karmic/trackback/