Ubuntu – application-specific power management


I listen to lots of music while doing non-computer related stuff and my laptop falls asleep after 30 mins, as per my power settings, so I have to go back to the laptop to wiggle the mouse every now and then.

I've noticed that when Totem plays a video, it overrides the power settings – screen remains on all the time and I don't have to do anything.

Is this a specific feature of Totem, or is there any way I can do the same with my sound applications? What about, say, a Flash or HTML5 video player inside a browser?

I'm using a distro based on Ubuntu 10.10, players used are Clementine and Spotify for Linux. Totem came as default on my distro which is why I suspect it's some sort of system preset involved.

Best Answer

There are no "presets". Totem simply asks the GNOME session manager to temporarily disable the "session idle" check.

If your music player does not have full GNOME support (as is often the case with desktop environment-agnostic software), you will have to use an external tool; I have written gnome-mpris-inhibit for MPRIS v2-capable players which will inhibit idle as long as music is playing: (requires libnet-dbus-perl)

$ setsid ./gnome-mpris-inhibit clementine
$ setsid ./gnome-mpris-inhibit spotify

(The MPRIS bus name usually matches the program's actual name, but check using the mpris tool just in case. The two examples above are already checked.)

For Flash, the Caffeine tool (ppa) claims to be able to detect video playback. It does not work for HTML 5 yet, though, but it seems to have a clickable manual activation applet. (I don't have Ubuntu so I cannot test it here.)

If all else fails, this gnome-inhibit script can be used to pause the idle check manually:

$ gnome-inhibit --what=idle
gnome-inhibit: pausing until signal; use Ctrl-C to interrupt

Update: GNOME itself now has an equivalent command:

$ gnome-session-inhibit --inhibit-only
Inhibiting until Ctrl+C is pressed...
Related Question