I have programmed a little script to handle my asus w1n laptop acpi events on my opensuse 10.2 . This script is actually launched by powersave each time it intercepts an acpi events .
This way i can use the shortcut buttons to increase/decrease volume, launch a browser, etc....
In the /usr/lib/powersave/scripts directory, the script hotkey_handler has to be modified this way :
Code:
#!/bin/bash
# comments...
# first get helper functions (e.g. DEBUG, load_scheme, ...)
. "${0%/*}/helper_functions"
if [ -d /proc/acpi/ibm ]; then
****if [ -x $PUB_SCRIPT_DIR/thinkpad_acpi_events ]; then
********DEBUG "executing thinkpad_acpi_events" DEBUG
********# pass over the acpi event line from $3
**** ****exec $PUB_SCRIPT_DIR/thinkpad_acpi_events "$@"
****fi
fi ****
if [ -d /proc/acpi/asus ]; then
****if [ -x $PUB_SCRIPT_DIR/asus_acpi_events ]; then
********DEBUG "executing asus_acpi_events" DEBUG
********# pass over the acpi event line from $3
**** ****exec $PUB_SCRIPT_DIR/asus_acpi_events "$@"
****fi
fi
EXIT 0
And then add this script in the same directory :
Code:
#!/bin/bash
###########################################################################
#************************************************************************ #
#************************ Powersave Daemon********************************#
#************************************************************************ #
# Author(s): Christophe de Rivière christophe.dr@free.fr******************#
#************Based on code from Suse's thinkpad_acpi_events************** #
#************************************************************************ #
#************************************************************************ #
# 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******************#
#************************************************************************ #
###########################################################################
#
# asus_acpi_events - processes asus specific ACPI events generated by
# asus_acpi driver and log them to syslog
#
# Configuration changes required for the script to work with powersave package:
# 1) Set EVENT_OTHER="asus_acpi_events" in /etc/sysconfig/powersave/events
# 2) Place this script into /usr/lib/powersave/scripts directory
#
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
run_on_xserver() {
****get_x_user
****DEBUG "User $X_USER display $DISP $1 " INFO
****#echo $1 >> tmp/asus_acpi
****su $X_USER -c "DISPLAY=$DISP $1"
}
run_dcop_command_on_xserver() {
****get_x_user
****#SESSION=$(su $X_USER -c "dcop --user $X_USER --list-sessions|grep DCOP")
****#echo $SESSION >> /tmp/asus_acpi
****DEBUG "User $X_USER display $DISP dcop $1 " INFO
****su $X_USER -c "DISPLAY=$DISP /opt/kde3/bin/dcop --user $X_USER --session .DCOPserver_darwin__0 $1"
}
HOTKEY=$3
TYPE=$1
DEBUG "Custom event script for asus_acpi driver" INFO
# we discard $2 which is the name of the current scheme.
set $HOTKEY**# powersaved gives us "other '<current_scheme_name>' '<content of /proc/acpi/event>'"
********# so we must split $3 to get the contents of /proc/acpi/event.
EVENT=$1** # "asus/hotkey"
ACPI=$2****# "ATKD"
WHAT=$3****# "00000030" Fn+F12
SERIAL=$4**# "00000001" first time typed
echo $EVENT $ACPI $WHAT $SERIAL > /tmp/asus_acpi
if [ "$EVENT" = "hotkey" ]; then
****ACTION="log event"
****case $WHAT in
****00000030) HOTKEY="Fn+F12" # volume up
********amixer set PCM 10+
********volume=$(run_on_xserver "/opt/kde3/bin/dcop kmix Mixer0 absoluteVolume 2")
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayProgress \"Volume Up\" $[ $volume * 100 / 255 ]" &
****;;
****00000031) HOTKEY="Fn+F11" # volume down
********amixer set PCM 10-
********volume=$(run_on_xserver "/opt/kde3/bin/dcop kmix Mixer0 absoluteVolume 2")
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayProgress \"Volume Down\" $[ $volume * 100 / 255 ]" &
****;;
****00000032) HOTKEY="Fn+F10" # toggle mute
********amixer set PCM toggle
********muted=$(run_on_xserver "/opt/kde3/bin/dcop kmix Mixer0 mute 2")
********if [ $muted = "true" ]; then
************run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Mute\""
********else
************run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Unmute\""
********fi
****;;
****00000051) HOTKEY="browser" # browser , side hotkey number 1 on w1n
********run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' konqueror [ ]" &
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Browser\""
********ACTION="browser"
****;;
****00000050) HOTKEY="mailer" # mailer , side hotkey number 2 on w1n
********run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' kontact [ ]" &
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Mailer\""
********ACTION="browser"
****;;
****0000005c) HOTKEY="powergear" # powegear , side hotkey number 3 on w1n
********governors=($(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors))
********governor=$(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor)
********i=0
********for gov in ${governors[@]}; do
************i=$[$i+1]
************if [ "$gov" = "$governor" ]; then
****************newgovernor=${governors[$[$i % ${#governors[*]}]]}
************fi
********done
********cpufreq-set -g $newgovernor
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Profil $newgovernor\""
********ACTION="powergear"
****;;
****0000006a) HOTKEY="padon" # touchpad on , side hotkey number 4 on w1n
********synclient TouchpadOff=0
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Touchpad On\""
********ACTION="padon"
****;;
****0000006b) HOTKEY="padoff" # touchpad off , side hotkey number 4 on w1n
********synclient TouchpadOff=1
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Touchpad Off\""
********ACTION="padoff"
****;;
****00000071) HOTKEY="musicoff" # music off , side hotkey number 5 on w1n
********if [ "$(ps -Ae|grep amarok|wc -l)" = "0" ]; then
************run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' amarokapp [ ]" &
************run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Amarok\""
********else
************run_on_xserver "/opt/kde3/bin/dcop amarok player pause" &
************run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Music Off\""
********fi
********ACTION="musicoff"
****;;
****00000072) HOTKEY="musicon" # music on , side hotkey number 5 on w1n
********if [ "$(ps -Ae|grep amarok|wc -l)" = "0" ]; then
************run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' amarokapp [ ]" &
************run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Amarok\"" &
********else
************run_on_xserver "/opt/kde3/bin/dcop amarok player play" &
************run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Music**On\"" &
********fi
********ACTION="musicon"
****;;
****0000005d) HOTKEY="Fn+F2" # wlan toggle
********ACTION="wlan"
****;;
****00000061) HOTKEY="Fn+F8" # switch display lcd/output
********ACTION="displayswitch"
****;;
****00000033) HOTKEY="Fn+F7" # lcd toggle
********ACTION="lcd"
****;;
****00000052) HOTKEY="Fn+1" #****
********run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' /usr/bin/unison [ ]" &
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Synchro\""
********ACTION="Synchro"
********echo $ACTION >> tmp/asus_acpi
****;;
****00000053) HOTKEY="Fn+2" #
********run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' vlc [ freetvMultiposte.m3u ]" &
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"tv\""
********ACTION="tv"
****;;
****00000054) HOTKEY="Fn+3" #
********run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' konsole [ ]" &
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"terminal\""
********ACTION="terminal"
****;;
****00000055) HOTKEY="Fn+4" #
********run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' konqueror [ --profile filemanagement ]" &
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Home\""
********ACTION="Home"
****;;
****00000056) HOTKEY="Fn+5" #
********run_dcop_command_on_xserver "klauncher klauncher 'kdeinit_exec(QString,QStringList)' kaffeine [ ]" &
********run_on_xserver "/opt/kde3/bin/dcop kded kmilod displayText \"Kaffeine\""
********ACTION="Kaffeine"
****;;
*****)******HOTKEY="Unidentified";;
****esac
****DEBUG "$HOTKEY 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
Any improvements/suggestions are welcome .
Is there a place i could post this script so that it is usable for next opensuse 10.3 ?