You are not logged in.

#1 2011-12-19 12:03:36

culyun
Member
Registered: 2011-10-26
Posts: 5

Nvidia 2.85 driver backlight bug - auto dimming script

I hacked together a daemon that automatically dims the lcd backlight when xscreensaver locks the screen.
Ok, I know you guys want something that turns that backlight off, but this is the next best thing..

btw I didn't write the cool daemonising functions.
I copied them from here http://blog.n01se.net/?tag=bash
They appear to be public domain.

----

#!/bin/bash

scriptName="${0##*/}"

showHelp() {
  echo "$scriptName: Automatic LCD Backlight Dimming Daemon"
  echo "  Dims the backlight when xscreensaver locks the screen."
  echo "  Restores the backlight when xscreensaver unlocks the screen."
  echo ""
  echo "  Options:"
  echo "    '-d' : Daemonise"
  echo "    '-k' : Kill"
  echo "    '-h' : This help"
}

backLightDimmer() {
  trap "rm -f '/var/run/dimd.pid'" EXIT

  while read event data ; do
    case "$event" in
     'WATCH_STARTED') echo "$$ $data" > '/var/run/dimd.pid' ;;
     'LOCK')
        for lcd in `ls '/sys/class/backlight'` ; do
          echo 0 > "/sys/class/backlight/$lcd/brightness" ;
        done
     ;;
     *)
       for lcd in `ls '/sys/class/backlight'` ; do
         echo `cat "/sys/class/backlight/$lcd/max_brightness"` > "/sys/class/backlight/$lcd/brightness" ;
       done
     ;;
    esac
  done < <(echo "WATCH_STARTED $BASHPID" ; xscreensaver-command -watch)
}

# redirect tty fds to /dev/null
redirect-std() {
    [[ -t 0 ]] && exec </dev/null
    [[ -t 1 ]] && exec >/dev/null
    [[ -t 2 ]] && exec 2>/dev/null
}

# close all non-std* fds
close-fds() {
    eval exec {3..255}\>\&-
}

# full daemonization of external command with setsid
daemonize() {
    (                   # 1. fork
        redirect-std    # 2.1. redirect stdin/stdout/stderr before setsid
        cd /            # 3. ensure cwd isn't a mounted fs
        # umask 0       # 4. umask (leave this to caller)
        close-fds       # 5. close unneeded fds
        exec setsid "$@"
    ) &
}

case "$1" in
  '-d') daemonize "$0" ;;
  '-k') kill `cat '/var/run/dimd.pid'` ;;
  '-h') showHelp ;;
  *) backLightDimmer ;;
esac

exit 0

Offline

#2 2011-12-19 12:08:30

culyun
Member
Registered: 2011-10-26
Posts: 5

Re: Nvidia 2.85 driver backlight bug - auto dimming script

usage is pretty easy:

  sudo dimd -d # to daemonise, make sure dimd is in the path
  sudo dimd -k # to kill the two shells that make up the daemon

----

btw I failed to get this puppy to play with rc.d
can anyone give me some tips?? please

Offline

Board footer

Powered by FluxBB