theatertime- hold power-saving to get through a flick

Getting down to watching you favorite movie on your computer? Start the movie, sit down, grab your snack and ten or so minutes later the screen goes blank. This happens in Linux because the desktop has built-in defaults for display power management (DPMS) and screensaving. Timeout settings can vary from distribution to distribution but they all got them. Here’s a basic script that can toggle DPMS and screensaving on and off.

Xorg Server Settings

You can set the values of blank, standby, suspend, and off in the the xorg server configuration file. The defaults are: 15, 20, 30, and 40 minutes. Personally I like to set these to better match how I use my computer:

Section "Monitor"
  Identifier  "Monitor0"
  Option      "DPMS"    "true"  # display power management on (true/false)
EndSection

Section "ServerFlags"
  Option "BlankTime"    "13"    # LED still on, no + (0 disables)
  Option "StandbyTime"  "15"    # turns off LED
  Option "SuspendTime"  "0"     # turns off LED, and most power
  Option "OffTime"      "50"    # turns off all power
EndSection

BlankTime is just a cheap screensaver and only real use for me is to tell me that I forgot to disable dpms while watching a movie. Doing this saves me a few seconds that StandbyTime requires to turn on the display again. SuspendTime and StandbyTime are nearly the same thing so I don’t bother setting SuspendTime.

Movietime

Here’s movietime. Movietime should work with just about any type of desktop environment (at least any system with dbus installed which really all of them do). If you aren’t familiar with having your own scripts and how to run them, take a look at this page).

#!/bin/bash
# movietime - disables power savings to watch movies.

# Movietime options
#  Resume time - resume normal display pm and suspend after set time.
# 0 = disabled, time in minutes
resumetime=0
if [ $resumetime = 0 ]; then 
  resumetime=1440 # Re-enable resume after a full day
fi

# Check that values for 'resumetime' are numbers
if [ $(echo $resumetime | sed 's/^[-+0-9][0-9]*//' | wc -c) != 1 ]; then
  echo "$warn variable 'resumetime' is not a number.  Exiting."
  exit
fi

# Name of suspend script
tmploc="/tmp"
suspinhscript="$tmploc"/"movietime-suspend-inhibit"

# Program name from it's filename.
prog=${0##*/}

# Text color variables
txtund=$(tput sgr 0 1)          # Underline
txtbld=$(tput bold)             # Bold
bldblu=${txtbld}$(tput setaf 4) #  blue
bldwht=${txtbld}$(tput setaf 7) #  white
bldred=${txtbld}$(tput setaf 1) #  red
txtrst=$(tput sgr0)             # Reset
info=${bldwht}*${txtrst}        # Feedback
pass=${bldblu}*${txtrst}
warn=${bldred}*${txtrst}

# Check that Xorg server is running
if [[ -z $(ps aux | grep /usr/bin/X) ]]; then
  echo "$warn The Xorg server is not running."
  exit
fi

# Check if user is regular user
if [ $(whoami) == "root" ]; then
  echo "$warn You are the root user, must be a regular user."
  exit
fi

# Current DPMS times (in minutes)
dispdpms=$(xset -q | grep "DPMS is" | awk '{ printf $3 }') # Enab. or Disb.
dispstand=$(xset -q | grep "^  Standby: " | awk '{ printf $2/60 }')
dispsusp=$(xset -q | grep "^  Standby: " | awk '{ printf $4/60 }')
dispoff=$(xset -q | grep "^  Standby: " | awk '{ printf $6/60 }')
dispblank=$(xset -q | grep "^  timeout:  " | awk '{ printf $2/60 }')

# Resume time in hours
resumetimehr=$(echo "scale=1;${resumetime}/60" | bc)

# Display help
case $1 in
  -h | --help | h | help )
    # Help message.
    echo
    echo "  $prog disables screen blanking and screensaver to allow viewing a video.  Running the program again will enable them.  If the 'resumetime' variable is set after that time $prog will resume normal powersaving values." | fmt -c -w 76
    echo

    # Display current values of power management and movietime.
    suspinhtest=$(ps aux | grep -v grep | grep $suspinhscript)
    suspinhval=$([ -n "$suspinhtest" ] && echo "Disabled" || echo "Desktop settings")
    
    # DPMS disabled information
    echo "   ${txtbld}Current settings ${txtrst}(in minutes, 0 = disabled):"
    if [[ "$dispdpms" == "Disabled" ]]; then
      echo "   DPMS:         $dispdpms"
      echo "   Suspend:      $suspinhval"
    fi

    # DPMS enabled information
    if [[ "$dispdpms" == "Enabled" ]]; then
      echo "   DPMS:         $dispdpms"
      echo "   DPMS times:   Blank: ${dispblank}; Standby: ${dispstand}; Suspend: ${dispsusp}; Offtime: ${dispoff}"
      echo "   Suspend:      $suspinhval"
    fi
    echo
    echo "   ${txtbld}$prog settings${txtrst}:"
    echo "   Resume after: $resumetimehr hours"
    echo
    exit
    ;;
  [a-g,i-z,A-G,I-Z,0-9,-]* )
    echo " Use '-h' for help"
    exit
    ;;
esac

# Suspend inhibit script (must be run as seperate process)
suspinhibit () {
    echo '#!/bin/bash
    for time in $(seq 1 '$resumetime'); do
    # Simulate user activity every minute
    dbus-send --print-reply --type=method_call --dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
    sleep 60
    done'
}

# Toggle powersaving
if [[ "$dispdpms" == "Enabled" ]] && [ -z "$suspinhtest" ]; then
  # Disable blanking, screen power saving
  xset s off; xset -dpms
  # Create script in tmp
  suspinhibit > "$suspinhscript"
  # Make script executable
  chmod u+x "$suspinhscript"
  # Run script
  nohup "$suspinhscript" &> /dev/null &
  echo "$pass $prog started, powersaving disabled."
else
  # Enable blanking, screen power saving
  xset s on; xset +dpms
  # Kill script
  if [ -n $suspinhtest ]; then
    echo "$info $prog stopped, powersaving enabled."
    kill -s 9 $(pgrep movietime-susp) &> /dev/null
  fi
fi

Turn off all cellphones and enjoy the show!

9 thoughts on “theatertime- hold power-saving to get through a flick

  1. Jim

    Actually, you’ll be surprised to learn that there are substantial power savings for a black screen instead of a white one.

    The major savings are CRTS, but LCDs also use less power.

    http://www.blackle.com/
    (I thought that this was a joke originally, but apparently not)

    Reply
  2. Gen2ly Post author

    Yeah, but who really uses CRT’s anymore? As for LCD’s the light is on, or it isn’t on so with a black screen I don’t see how there is going to to be any power savings. I’ve read several posts that pointed this out, if you can prove me wrong I’ll be glad to edit the post.

    Reply
  3. Pete

    In the case of Blackle, it is worth noting that they have saved:
    1,436,380.485 Watt hours

    This seems like a big number, but do note the decimal point… to express thousandths of a watt-hour, a rather useless amount of power, since when you use a 40-watt fluorescent, you are actually requiring 40,000 thousandths of a watt. The number would be more clearly expressed as 1,436 kWatt-hours, where a kWatt-hour will cost between $0.06 and $0.25 (this is the unit of energy used on electrical bills).

    Reply
  4. Todd Partridge

    To be able to do inhibit suspend with Gnome and KDE you can use dbus-send command instead of qtbus. For example:

    dbus-send --system --print-reply --dest= org.freedesktop.PowerManagement /org/freedesktop/PowerManagement org.freedesktop.PowerManagement.Inhibit.Inhibit "movieview" "Playing Movie"
    Reply
  5. Chris

    It doesn’t work for me… I installed the movietime script and using the wrapper script provided by Chris. I run blank-me-not.sh firefox but BBC iplayer still goes to a blank to a black screen after about 10 mins :-(

    Reply
  6. Chris

    @Other Chris: Sorry to hear you’re having trouble. I’m using it on Debian Squeeze KDE4/Xfce, and it’s worked well so far in my environment. Distros like Ubuntu are doing some hacky stuff movietime may not be expecting, but I’ll leave that up to the author.

    Reply

Leave a reply to Chris Cancel reply