This picture intentionally left blank 😉

This is a continuation of my instructions on installing Gentoo on the Libretto 110ct.  After I got xorg-server running properly, I noticed that screen blanking and LCD powerdown did not work correctly.  They produced very strange effects and did not ultimately blank the screen or power down the backlight.  This is an old computer but I intend to leave it running constantly so I want to make sure to preserve the life of the backlight as long as possible.

First off, make sure the Toshiba experimental ACPI driver is compiled into the kernel.  It’s included by default in the 3.0 and many of the earlier kernel versions.  Then you’ll want to grab toshset.  Toshset is the key to this whole process.  You can test the driver by typing:

cat /proc/toshiba

You can test it further after installing toshset by typing:

toshset -q

If all that stuff works, you are ready to move forward.

I searched the Internet high and low and could not find what I needed.  What I wanted was something extremely light weight that would use the hooks already built into xorg-server to invoke toshset.  I still feel like this must be possible even though we went a different direction.

In my search I came across exactly one person on the Internet who sounded like she ran across the same problem as me.  On her page she said:

“So what if you really do want your backlight to turn off after a specific interval? There doesn’t seem to be a way to get Xorg to do it directly. But you can cheat: Write a script that calls vbetool dpms off. Then set that script to be your screensaver. “

Sounded close, so after more searching I finally gave up and emailed Akkana and asked her how she did it.  Turns out she didn’t remember but after a couple of email exchanges, we came up with an idea together of how to do this pretty easily.  I had the idea to use a python script to poll the mouse and keyboard nodes out of ‘/dev/inputs’.  I was really pleased when Akkana emailed me back the next day and said something like “Ya, good idea, here it is!”

She sent a script that monitored the everything in ‘/dev/inputs’ and then invokes a system command(whatever you specify) when the idle time counts up to a certain point.  I modified the script a bit so that it would also run another program when activity in those nodes is detected.

When the screen is not blanked, the polling interval is 5 seconds to keep things REALLY light weight.  I tweaked it to up the polling interval when the screen is blanked to 5 times per second so there is no perceivable lag when waking up the screen.

Did I mention this script is REALLY light weight?  It doesn’t even show up in top when it’s on the 5 second polling interval.  (I haven’t ssh’d in yet to check the .2 second interval yet).  So after all that buildup, here’s the script:

#! /usr/bin/env python

# idlerunner -- run a screensaver-type program when input devices are idle.
# By Akkana Peck, akkana  shallowsky (dot) com
# based on an idea from Geordy Rostad, geordy  hotmail (dot) com
# Copyright 2011, please re-use, share and improve under the terms
# of the GPLv2 or later.

import sys, os, select
import time

# how long to wait before firing the screensaver:
TIME_THRESH = 60 * 5   # seconds * minutes

# Global polling interval
interval = 5

# Read from every /dev/input device:
INPUTDIR = "/dev/input"
inputdevs = []
for devname in os.listdir(INPUTDIR) :
   try :
       inputdevs.append(open(os.path.join(INPUTDIR, devname)))
   except :
       pass
#      print "Not watching", devname
# uncomment for troubleshooting ^^^

last_event_time = time.time()

while True :
   time.sleep(interval)
   inp, outp, err = select.select(inputdevs, [], [], .5)

   if not inp or len(inp) == 0 :
       # we're idle! But for how long?
       idletime = time.time() - last_event_time
       if idletime > TIME_THRESH :
#          print "Firing screensaver!"
# uncomment for troubleshooting ^^^
# command to blank the screen
	   SCREENSAVER = "toshset -bl off"
# Set polling to a really quick interval when screen is blanked so it wakes quickly
           interval = .2
           os.system(SCREENSAVER)
           # Let this wait until the screensaver process finishes,
           # so we won't keep checking and fire up another copy.
       else:
           pass
#          print "Idle but only for", idletime, "secs"
# uncomment for troubleshooting ^^^
       continue

   # There's apparently no way to flush input without reading it:
   SCREENSAVER = "toshset -bl on > /dev/null"
# Switch back to longer polling interval when screen saver is off
   interval = 5
   os.system(SCREENSAVER)
#  print "There's something there in", len(inp), "devices"
# uncomment for troubleshooting ^^^
   last_event_time = time.time()
   for f in inp :
       os.read(f.fileno(), 4096)

I’d stick idlerunner.py in ‘/usr/local/source’ (along with toshset).  Make sure to set it executable.  You’ll want to add a file to your ‘/etc/local.d’ directory to start idlerunner in the background.

echo “/usr/local/idlerunner.py &” > /etc/local.d/idlerunner.start && chmod 755 /etc/local.d/idlerunner.start

Next, in your xorg.conf file, you’ll need to add some lines to your xorg.conf file.  These lines will prevent the odd behavior from the built in stuff from occurring.

In the Monitor section add: 

        Option          "DPMS"

In the ServerLayout section, add:

        Option          "BlankTime"     "0"
        Option          "StandbyTime"   "0"
        Option          "SuspendTime"   "0"
        Option          "OffTime"       "0"

This all turned out even better than I had hoped because it’s independent of X entirely and blanks the local consoles as well.  Props to Akkana for generously spending her time to help a complete stranger with a problem on a 15 year old computer.



If you like the content on this site, please support it by using this link to order from Amazon. You know you were going to go there and buy stuff anyhow so why not help me pay the hosting bill.