#!/bin/bash ########################################################################### # # # Powersave Daemon # # # # Copyright (C) 2006 SUSE Linux Products GmbH # # # # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the # # Free Software Foundation; either version 2 of the License, or (at you # # option) any later version. # # # # This program is distributed in the hope that it will be useful, but # # WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # # General Public License for more details. # # # # You should have received a copy of the GNU General Public License along # # with this program; if not, write to the Free Software Foundation, Inc., # # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # # # ########################################################################### # HotKey Script Configured for ASUS A3N laptop, running Debian # Based on files found in a HowTo for PLDLinux at Linux Laptops, # on debug_events logs at /var/log/messages # on help found at /usr/share/doc/powersaved ("Mapping Scripts to Events") # and on example scripts therein (contrib dir) by Manfred Tremmel and Stefan Seyfried. # # REQUIRES asus_acpi (kernel module) # # 10-2006 J. Vasconcelos PATH=/bin:/usr/bin:/sbin # be paranoid, we're running as root. MYNAME=${0##*/} # basename $0 DCOPEXEC=$KDE_BINDIR/dcop KDIALOGEXEC=$KDE_BINDIR/kdialog KWIFIEXEC=$KDE_BINDIR/kwifimanager KSCDEXEC=$KDE_BINDIR/kscd POWERSAVEEXEC=/usr/bin/powersave AMIXEREXEC=/usr/bin/amixer IFUPEXEC=/sbin/ifup IFDOWNEXEC=/sbin/ifdown SYNCLIENTEXEC=/usr/bin/synclient MAILPROGEXEC=/usr/bin/thunderbird WEBBROWSEREXEC=/usr/bin/firefox # first get helper functions (e.g. DEBUG, load_scheme, ...) . "${0%/*}/helper_functions" # get_x_user comes from here... . "${PUB_SCRIPT_DIR}/x_helper_functions" run_on_xserver() { get_x_user # $LOGGER "User $X_USER Display $DISP $1" su $X_USER -c "DISPLAY=$DISP $1" } TYPE=$1 set $3 # powersaved gives us "other 'schemename' ''" so we must split it. EVENT=$1 # "hotkey" ACPI=$2 # "HOTK" WHAT=$3 # "00000052" SERIAL=$4 # "0000001c" if [ "$EVENT" = "hotkey" ]; then case "$WHAT" in 0000002e|0000001f|00000033|00000034|00000061)#Brightness Up/Down, LCD On/Off, LCD/Monitor hotkeys :#These hotkeys are managed by powersave ;; 00000032)# Mute button $AMIXEREXEC set Master toggle ;; 00000030)# Volume up button $AMIXEREXEC set Master 1+ ;; 00000031)# Volume down button $AMIXEREXEC set Master 1- ;; 00000050)#Mail Button run_on_xserver "$MAILPROGEXEC" & ;; 00000051)#Browser Button run_on_xserver "$WEBBROWSEREXEC" & ;; 00000040)#Back Button run_on_xserver "$DCOPEXEC kscd CDPlayer previous" ;; 00000041)#Forward Button run_on_xserver "$DCOPEXEC kscd CDPlayer next" ;; 00000043)#Stop Button if [ "`run_on_xserver "$DCOPEXEC kscd CDPlayer playing"`" = "true" ] ; then run_on_xserver "$DCOPEXEC kscd CDPlayer stop" :#kscd playing - Stop Playing else eject cdrom :#kscd not playing Eject CD Tray fi; ;; 00000045)#Play button if [ "`run_on_xserver "$DCOPEXEC" | grep kscd`" = "kscd" ] ; then run_on_xserver "$DCOPEXEC kscd CDPlayer play" : #kscd running Toggle Play/Pause else run_on_xserver "$KSCDEXEC -s" & : #kscd not running Start KsCD fi; ;; 0000005c)#Powersave Button # run_on_xserver "/usr/bin/konqueror ." & POWERSAVESTATE=`$POWERSAVEEXEC -x | grep active | awk -F " " '{print $1}'` case "$POWERSAVESTATE" in Performance) NEWPOWERSAVESTATE="Acoustic" ;; Acoustic) NEWPOWERSAVESTATE="Presentation" ;; Presentation) NEWPOWERSAVESTATE="Powersave" ;; Powersave) NEWPOWERSAVESTATE="Performance" ;; *) NEWPOWERSAVESTATE="Powersave"#Default ;; esac /usr/bin/powersave -e ${NEWPOWERSAVESTATE} #run_on_xserver "$KDIALOGEXEC --passivepopup \"New Powersave state ${NEWPOWERSAVESTATE}\" 2" & #You can enable Notifications in KPowerSave # switching powersave states ;; 0000006b)#Enable/Disable TouchPad Button # run_on_xserver "/usr/bin/konsole" & #SHMConfig must be enabled in xorg.conf PadOn=`${SYNCLIENTEXEC} -l | grep -c "TouchpadOff.*0"` if [ "${PadOn}" = "1" ] ; then ${SYNCLIENTEXEC} TouchpadOff=1 echo 1 > /proc/acpi/asus/mled :#Enable Touchpad else ${SYNCLIENTEXEC} TouchpadOff=0 echo 0 > /proc/acpi/asus/mled :#Disable Touchpad fi; ;; 0000005d)#Wireless Button #Enable/Disabel Wireless Interface and/or KWifiManager #Output information to tty12 WINTERFACE="`cat /proc/net/wireless | grep -m 1 'eth' | awk '/eth/ {printf("%.4s",$1)}'`" #Wireless Interface KWifiId=`run_on_xserver "$DCOPEXEC" | grep -m 1 kwifimanager` #KWifiManager PID if [ -n "$WINTERFACE" ] ; then #If there is a network interface and ifup is not running if [ -z "`cat /etc/network/run/ifstate | grep -m 1 $WINTERFACE`" ] ; then if [ -n "`ps -A | grep -m 1 'ifup'`" ] ; then logger "ACPI Wireless Hotkey pressed - ifup already running" else $IFUPEXEC -v $WINTERFACE > /dev/tty12 if [ -z "$KWifiId" ] ; then run_on_xserver "$KWIFIEXEC" & sleep 1 KWifiId=`run_on_xserver "$DCOPEXEC" | grep -m 1 kwifimanager` run_on_xserver "$DCOPEXEC $KWifiId mainWindow hide" :#Run KWifiManager on System Tray fi; fi; :#Wireless Interface Up else if [ -n "`ps -A | grep -m 1 'ifdown'`" ] ; then logger "ACPI Wireless Hotkey pressed - ifdown already running" else $IFDOWNEXEC -v $WINTERFACE > /dev/tty12 if [ -n "$KWifiId" ] ; then run_on_xserver "$DCOPEXEC $KWifiId MainApplication-Interface quit" :#Quit KWifiManager fi; fi; :#Wireless Interface Down fi; :#Wireless Interface Exists else logger "ACPI Wireless Hotkey pressed - no wireless interface found" :#Wireless Interface Not Found fi; #logger "ACPI Wireless hotkey pressed - no action defined" ;; *) logger "ACPI hotkey $WHAT is not defined" ;; esac else logger -t $MYNAME "non-hotkey-event: $TYPE $EVENT $ACPI $WHAT $SERIAL" # do not exit here, we need to execute SCRIPT_RETURN_HELPER fi; # always call $SCRIPT_RETURN before exiting: $SCRIPT_RETURN $EV_ID 0 "ASUS A3N hotkey script succeeded" EXIT 0