#!/bin/sh
# /etc/acpi/lidswitch.sh
# Re-activates the screen when the lid is opened again

LID_STATE="/proc/acpi/button/lid/LID/state"
LCD_STATE="/proc/acpi/video/VID/LCD/state"
VT_NR=/tmp/lid_sh

if [ -e /tmp/acpi_sleep ]; then
        rm /tmp/acpi_sleep
        exit
fi

grep -q open "$LID_STATE"

if [ $? -eq 0 ]; then
        #open the lid
        vbetool dpms on
        if [ -e "$VT_NR" ]; then
                #we closed the lid in X
                chvt $(cat $VT_NR)
                rm -f "$VT_NR"
        fi
else
        # closing the lid
        # remember the current vt
        echo $(fgconsole) > $VT_NR
        #chvt 1					#just make resume slower

		#if you have kde and want it to lock the screen when you close the lid uncomment below
		#dcop --all-users --all-sessions kdesktop KScreensaverIface quit > /dev/null 
		#dcop --all-users --all-sessions kdesktop KScreensaverIface lock > /dev/null

fi

