File:  [NetBSD Developer Wiki] / wikisrc / tutorials / how_to_blank_and_unblank_screens_on_lid_close__92__open.mdwn
Revision 1.1: download - view: text, annotated - select for diffs
Sun Nov 20 20:55:21 2011 UTC (2 years, 4 months ago) by mspo
Branches: MAIN
CVS tags: HEAD
import all of the how-to articles from the pkgsrc.se wiki

The [powerd(8)](http://netbsd.gw.com/cgi-bin/man-cgi?powerd+8+NetBSD-current) daemon acts upon power management events posted by the kernel's power management facility, translating the events into a script name and arguments. These scripts are found in `/etc/powerd/scripts/`. 

The `lid_switch` script is called on lid-open and -close events. An event of `pressed` means the lid has been closed, and `released` that the lid has been opened. 

The following `lid_switch` uses [xset(1)](http://netbsd.gw.com/cgi-bin/man-cgi?xset+1+NetBSD-current) to forcibly blank the screen on lid-close, and refresh the screen on lid-open: 
    
#!/bin/sh
    # arguments passed by powerd(8): device event
    # debugging: exec 1>>/tmp/lid_switch.log 2>&1
    if [ -z "$DISPLAY" ]; then export DISPLAY=:0; fi
    case "${2}" in
     pressed)    # lid closed
       /usr/X11R6/bin/xset dpms force off
       exit 0
       ;;
     released)   # lid opened
       # need to both force dpms and reset screensaver
       /usr/X11R6/bin/xset dpms force on
       /usr/X11R6/bin/xset s reset
       exit 0
       ;;
     *)
       logger -p warning "${0}: unsupported event ${2} on device ${1}" >&1
       exit 1
       ;;
    esac
    

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb