#!/bin/bash ########################################################################### # # # Powersave Daemon # # # # Copyright (C) 2005,2006 SUSE Linux Products GmbH # # # # Author(s): Based on code by Stefan Seyfried # # Hotkey support by Alex Solovey, solovey@us.ibm.com # # Enhancements (docking station support) by Holger Macht # # # # 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 # # # ########################################################################### # # thinkpad_acpi_events - process ThinkPad specific ACPI events generated by # ibm_acpi driver and log them to syslog # # Configuration changes required for the script to work with powersave package: # 1) Set EVENT_OTHER="thinkpad_acpi_events" in /etc/sysconfig/powersave/events # 2) Place this script into /usr/lib/powersave/scripts directory # ######################################################################### # # Customized by Huahai Yang to support Thinkpad X61 ACPI keys on KDE. # Added on screen visual feedback for key press, the following keys are # supported on top of existing powersaved supported keys: # - Fn+F1 to start wireless connection # - Fn+F2 to lock desktop # - Fn+F3, F6, F8 to switch among Powersave, Performance and Presentation # mode # - Fn+F7 to toggle external display # - Fn+F11 to start LAN connection # - Fn+Home, Fn+End to increase, decrease LCD brightness # - Fn+Space to toggle screen resolution # - ThinkVantage to open konsole # ######################################################################### PATH=/bin:/usr/bin:/usr/X11R6/bin:/sbin:/usr/sbin # be paranoid, we're running as root. # First, we pull in the helper functions. . ${0%/*}/helper_functions # `dirname $0`/helper_functions # get_x_user comes from here... . ${0%/*}/x_helper_functions # `dirname $0`/x_helper_functions export PATH ME=${0##*/} # basename $0 # argument $4 is set to $EV_ID in helper_functions which is included above if [ -z "$EV_ID" ]; then DEBUG "$ME 'Sorry, not enough arguments: $4 is empty.'" WARN $SCRIPT_RETURN $EV_ID 1 "$ME finished unsuccessful." exit 1 fi # this script run as root, so we need to pretend we are the user, or # X functionalities won't work. run_on_xserver() { get_x_user DEBUG "User $X_USER display $DISP $1 " INFO su - $X_USER -c "DISPLAY=$DISP $1" } HOTKEY=$3 TYPE=$1 DEBUG "Custom event script for ThinkPad ibm_acpi driver" INFO # we discard $2 which is the name of the current scheme. set $HOTKEY # powersaved gives us "other '' ''" # so we must split $3 to get the contents of /proc/acpi/event. EVENT=$1 # "ibm/hotkey" ACPI=$2 # "HOTK" WHAT=$3 # "00000080" SERIAL=$4 # "0000100c" Fn+F12 # it is easier to deal with numerical values (for me :-) declare -i VAL VAL=0x$WHAT # hex -> decimal declare -i SER SER=0x$SERIAL # hex -> decimal # on screen display, it's always good to have visual feedback OSD="DISPLAY=:0.0 /usr/bin/osd_cat -d 1 -p bottom -o 80 -A center -c blue -l 1 " OSD_PERCENT="$OSD -b percentage -P $PERCENT" #LOCK_SCREEN="xscreensaver-command -lock" LOCK_SCREEN="dcop kdesktop KScreensaverIface lock" if [ "$EVENT" = "ibm/hotkey" ]; then ACTION="log event" if [ "$VAL" -eq 128 ]; then case $SER in 4097) HOTKEY="Fn+F1" # /home/directory/bin/wireless.sh & # ACTION="make wireless connection" ;; 4098) HOTKEY="Fn+F2" run_on_xserver "$LOCK_SCREEN" ACTION="lock screen" ;; 4099) HOTKEY="Fn+F3" powersave -e Powersave run_on_xserver "echo 'Power Save Mode' | $OSD" & ACTION="enter powersave mode" ;; 4100) HOTKEY="Fn+F4" ACTION="suspend-to-ram" run_on_xserver "$LOCK_SCREEN" & run_on_xserver "xset dpms force suspend" . $SYSCONF_DIR/sleep [ "$DISABLE_USER_SUSPEND2RAM" != "yes" ] && powersave "--$ACTION" ;; 4101) HOTKEY="Fn+F5" if [ -x /opt/thinkpad/ac/onscreen_ac.sh ] ; then run_on_xserver "/opt/thinkpad/ac/onscreen_ac.sh start" & ACTION="start onscreen_ac applet" elif grep -q "status.*disabled" /proc/acpi/ibm/bluetooth ; then echo enable > /proc/acpi/ibm/bluetooth ACTION="enable blooetooth" else echo disable > /proc/acpi/ibm/bluetooth ACTION="disable blooetooth" fi ;; 4102) HOTKEY="Fn+F6" powersave -e Performance run_on_xserver "echo 'Full Performance Mode' | $OSD" & ACTION="enter full performance mode" ;; 4103) HOTKEY="Fn+F7" ACTION="toggle external display" if run_on_xserver "xrandr -q" | grep "VGA connected"; then if run_on_xserver "xrandr -q" | grep "VGA connected [0-9]\+"; then run_on_xserver "echo 'Turn OFF External VGA Display' | $OSD" & run_on_xserver "xrandr --output VGA --off" else run_on_xserver "echo 'Turn ON External VGA Display' | $OSD" & run_on_xserver "xrandr --output VGA --auto" fi else run_on_xserver "echo 'External VGA Display is DISCONNECTED' | $OSD" & fi ;; 4104) HOTKEY="Fn+F8" powersave -e Presentation run_on_xserver "echo 'Presentation Mode' | $OSD" & ACTION="enter presentation mode" ;; 4105) HOTKEY="Fn+F9" ACTION="undock" echo undock > /proc/acpi/ibm/dock ;; 4106) HOTKEY="Fn+F10" ;; 4107) HOTKEY="Fn+F11" ACTION="make NIC connection" # run_on_xserver "echo 'Connecting LAN...' | $OSD" & # /home/directory/bin/nic.sh & ;; 4108) HOTKEY="Fn+F12" ACTION="suspend-to-disk" run_on_xserver "$LOCK_SCREEN" & . $SYSCONF_DIR/sleep [ "$DISABLE_USER_SUSPEND2DISK" != "yes" ] && powersave "--$ACTION" ;; 4109) HOTKEY="Fn+Backspace" ;; 4110) HOTKEY="Fn+Insert" ;; 4111) HOTKEY="Fn+Delete" ;; 4112) HOTKEY="Fn+Home" # powersave -ku xbacklight -d :0 -inc 12 run_on_xserver "$OSD_PERCENT $(xbacklight -d :0 -get)" & ACTION="brighter display" ;; 4113) HOTKEY="Fn+End" # powersave -kd xbacklight -d :0 -dec 12 run_on_xserver "$OSD_PERCENT $(xbacklight -d :0 -get)" & ACTION="dimmer display" ;; 4116) HOTKEY="Fn+Zoom" ACTION="toggle screen resolution" # run_on_xserver "/home/directory/bin/toggle-zoom.sh" ;; 4120) HOTKEY="Thinkpad" run_on_xserver "konsole" & ACTION="launch konsole" ;; *) HOTKEY="Unidentified" ;; esac else HOTKEY="Unidentified" fi elif [ "$EVENT" = "ibm/bay" ]; then case $VAL in 1) HOTKEY="Eject lever inserted" ;; 3) HOTKEY="Eject Request" ;; *) HOTKEY="Unidentified" ;; esac elif [ "$EVENT" = "ibm/dock" ]; then case $VAL in 0) if [ $SER -eq 3 ]; then # X32 has strange dock code HOTKEY="Dock requested" ACTION="Docking" echo dock > /proc/acpi/ibm/dock 2>&1 fi ;; 1) HOTKEY="Dock requested" ACTION="Docking" echo dock > /proc/acpi/ibm/dock 2>&1 ;; 3) HOTKEY="Undock requested" ACTION="Undocking" echo undock > /proc/acpi/ibm/dock 2>&1 ;; esac DEBUG "$HOTKEY: keycode $VAL serial $SER. action: $ACTION " INFO else DEBUG "Unidentified event: $EVENT $ACPI $WHAT $SERIAL" INFO fi $SCRIPT_RETURN $EV_ID 0 "$ME finished" EXIT 0