GNOME Power Manager without GNOME desktop

Vincent Bernat

When I in­stalled my new lap­top, I de­cided to switch from sleepd to GNOME Power Man­ager (GPM). The ra­tio­nale be­hind this de­ci­sion was to get screen dim­ming for free while keep­ing other fea­tures be­cause GPM uses UPower which uses pm-suspend and pm-powersave un­der the hood. This means that it is easy to ex­e­cute scripts on sus­pend or when the AC is un­plugged by putting them in /etc/pm.

I don’t use a full GNOME desk­top. My desk­top is run­ning FVWM which is just a win­dow man­ager. How­ever, I al­ready use some parts of the GNOME en­vi­ronment:

  • GDM as a dis­play man­ager be­cause it is the only one that is able to han­dle ConsoleKit cor­rectly. This means that GDM is able to reg­is­ter your ses­sion to ConsoleKit and make it ac­tive. With­out that, you won’t be con­sid­ered as the user sit­ting in front of the screen and DBus won’t al­low you to in­ter­act with most of your hard­ware un­less you add your­self to a lot of groups. ConsoleKit en­ables the at_console prop­erty used by most policies.

  • Net­work Man­ager to han­dle both wired and wire­less con­nec­tions. Con­nect­ing to some ran­dom AP us­ing only com­mand line tools is rather cum­ber­some (as­sume that the AP is us­ing WPA). Con­nect­ing to a broad­band net­work with a 3G don­gle is even more cum­bersome.

  • GNOME blue­tooth ap­plet be­cause in­ter­act­ing with BlueZ blue­tooth stack is now done with DBus only and the com­mand line tools have been re­moved. There­fore, you need to write your own tools or use this small ap­plet that does most of the work for you.

What’s working#

It hap­pens that most of the fea­tures just do not work. How­ever, sus­pend when clos­ing the lid works fine. The icon in the systray works fine too (but there is a small bug). The screen dim­ming fea­ture on idle also works (but there are an­noy­ing bugs with it). The vis­ual feed­back when press­ing bright­ness keys works too.

What is not working#

It seems that I am not the only one to have prob­lems with GPM: there are cur­rently 115 bugs opened in the De­bian BTS. If you want to get some de­bug out­put from gnome-power-manager, run it with --verbose flag. --debug flag does noth­ing (and su­per­sedes --verbose).

Nothing happens when pressing the power button#

I have con­fig­ured GPM to ask me what to do when I press the power but­ton. But when I press the but­ton, noth­ing hap­pens. Look­ing at the source, here is the snip­pet of code that is executed:

if (policy == GPM_ACTION_POLICY_INTERACTIVE) {
    GpmSession *session;
    egg_debug ("logout, reason: %s", reason);
    session = gpm_session_new ();
    gpm_session_logout (session);
    g_object_unref (session);
}

In fact, this is not GPM that will ask you the ques­tion, but GNOME ses­sion man­ager be­cause GPM trig­gers lo­gout. If you do not run a full GNOME ses­sion, noth­ing will happen.

My work­around is just to set the ac­tion to “Suspend.”

Does not sleep when idle#

GPM is con­fig­ured to go to sleep af­ter 2 hours on AC or 30 min­utes on bat­tery. This does not work for me be­cause idle de­tec­tion is del­e­gated to ex­ter­nal pro­grams. There are four vari­ables used by GPM to de­ter­mine if we are idle:

  • session_idle which is the idle hint from ConsoleKit
  • idle_inhibited which is set when an­other pro­gram asks to dis­able idle de­tec­tion (a video player which does not want the screen to be dimmed)
  • suspend_inhibited which means a pro­gram does not want us go­ing to sleep (a mu­sic player for example)
  • x_idle which tells if X is idle or not (some­one is mov­ing the mouse or typ­ing on the keyboard)

To al­low GPM to sus­pend when we are idle, x_idle and session_idle must be true while suspend_inhibited and idle_inhibited must be false. For screen-dim­ming pur­poses, you just need to have x_idle set to true and idle_inhibited set to false.

Cur­rently, only GNOME Screen­saver seems to tell ConsoleKit if the ses­sion is idle or not. XScreenSaver does not con­tain any­thing about this. I am us­ing xautolock with xlock and I am pretty sure they will not tell GPM if I am idle.

You can use dbus-send to cir­cum­vent this problem:

$ dbus-send --system --dest=org.freedesktop.ConsoleKit \
>   --type=method_call --print-reply --reply-timeout=2000 \
>   /org/freedesktop/ConsoleKit/Manager \
>   org.freedesktop.ConsoleKit.Manager.GetCurrentSession
method return sender=:1.6 -> dest=:1.106 reply_serial=2
   object path "/org/freedesktop/ConsoleKit/Session1"
$ dbus-send --system --dest=org.freedesktop.ConsoleKit \
>   --type=method_call --print-reply --reply-timeout=2000 \
>   /org/freedesktop/ConsoleKit/Session1 \
>   org.freedesktop.ConsoleKit.Session.SetIdleHint boolean:true
method return sender=:1.6 -> dest=:1.108 reply_serial=2

While I un­der­stand what the ra­tio­nale be­hind these choices is (no code du­pli­cate and al­low­ing ex­ter­nal pro­grams to hin­der power man­age­ment), it lacks some fall­back in case you do not use GNOME Screen­saver (which is the key com­po­nent here).

I first thought this was bug #594706 but this is not the case. I have opened (and closed) bug #628755.

Up­date (2011-06)

Jump to the con­clu­sion for an up­dated so­lu­tion for this problem.

Brightness is not restored to the previous value after idle#

When GPM undims the screen, it does not re­store the pre­vi­ous value. It seems to be bug #617310 which is marked as fixed in up­stream. I did not in­ves­tigate it.

Wrong number of batteries reported#

I only have one bat­tery but af­ter one suspend/resume cy­cle, GPM thinks I have two. Maybe this is a bug of UPower. Maybe this is bug #606434. I did not in­ves­ti­gate it. Maybe there is a happy in­ter­ac­tion with bug #456280.

Inability to set configure actions when the UPS runs out of battery#

This is bug #390602. In ad­di­tion to lap­top bat­ter­ies, UPower also sup­ports UPS. In this case, GPM dis­plays a spe­cial icon to tell if the UPS is fully charged. How­ever, there is no pos­si­bil­ity to ex­e­cute spe­cial ac­tions when the UPS is un­plugged, like hi­ber­nate af­ter 10 min­utes or some­thing like this. This seems to be a prob­lem with the in­ter­face be­cause look­ing with gconftool-2, we can spot vari­ables like low_ups or critical_ups which al­lows us to set ac­tions when the UPS is al­most out of battery.

More­over, the UPS icon only dis­plays af­ter one suspend/resume cy­cle but I am too lazy to re­port and de­bug this is­sue. Since the icon dis­ap­pears if I restart GPM, I am con­fi­dent that the bug is in GPM.

Conclusion#

The con­clu­sion is that GPM is not re­ally that buggy but it re­ally needs to be run in a full-blown GNOME desk­top. The main prob­lem is not re­ally GPM. New tech­nolo­gies like UPower and ConsoleKit get pushed by freedesktop.org ini­tia­tive, they get im­ple­mented by GNOME (and, I sup­pose, KDE) be­cause they have tons of peo­ple fol­low­ing the ap­pro­pri­ate mail­ing lists and any al­ter­na­tive just gets crushed by all these un­pub­li­cized changes.


Up­date (2011-06)

I got sev­eral help­ful com­ments about this prob­lem. There are two pos­si­ble so­lu­tions, ex­posed below.

  1. Use xfce4-power-manager. It han­dles bright­ness con­trol in a bet­ter way and does not need an ex­ter­nal pro­gram to tell when the cur­rent ses­sion is idle. It still needs a ses­sion man­ager to ask what to do when us­ing the power but­ton. The draw­back to this so­lu­tion is that you start to pull an­other desk­top en­vi­ron­ment into your en­vi­ron­ment. You had some parts of GNOME and now you have some parts of XFCE. This so­lu­tion was pro­posed by Syl­vain Collilieux.

  2. Use gnome-session, gnome-screensaver and keep gnome-power-manager. As pointed by Julien Val­roff, gnome-screensaver needs gnome-session to de­tect idle­ness. How­ever, gnome-session starts a whole GNOME desk­top. Again, there are two so­lu­tions. The first one is to re­place gnome-session by some­thing lighter im­ple­ment­ing the bare min­i­mum to make gnome-screensaver happy. An­other sug­ges­tion is to con­fig­ure gnome-session to start your fa­vorite en­vi­ronment.

I start mine from ~/.xsession and here is what I have added at the top of it:

# If not done, restart ourself with gnome-session
if [ -z "$SESSION_MANAGER" ]; then
    [ -d ~/.config/autostart ] || mkdir ~/.config/autostart
    rm -f ~/.config/autostart/*
    cat <<EOF > ~/.config/autostart/xsession.desktop
[Desktop Entry]
Name=Xsession
Comment=Start .xsession
Exec=$(readlink -f $0)
Type=Application
X-GNOME-Autostart-enabled=true
EOF
    exec gnome-session --autostart=$HOME/.config/autostart
fi
# Otherwise, keep starting stuff
# […]
exec fvwm-crystal