#!/usr/bin/perl -w
use strict;

#
#  This handy script watches when the screensaver activates and
#  toggles the lcd backlight.  You won't see more than a 
#  second of the screensaver, so you might as well chose one
#  which consumes few mips.
#

$ENV{'PATH'} = '/bin:/usr/bin';
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};

$<=0;  # become root not just effective root

open(XS,"/usr/bin/xscreensaver-command -watch|") or die;
while(<XS>) {
   if(/^BLANK/i) {
      system("/usr/bin/sudo /usr/sbin/radeontool light off");
   } elsif(/^UNBLANK/i) {
      system("/usr/bin/sudo /usr/sbin/radeontool light on");
   }
}
