Running X-based programs in ACPI-scripts on 11.1 ?

Using OpenSuSE 11.1 (x64) I tried to make the ACPI multimedia keys on my Asus V1S working. So I started to write the needed script, which is started correctly when I press the key. For testing purposes I simply used amixer to (un)mute audio, which works fine too. The script is located in /usr/lib/acpid/.

Now I wanted to use kdialog zu show a notification, but this doesn’t work because it’s based on X.

Is used the following code fragment, which needs the “helper_functions”.


#PATH=/bin:/usr/bin # be paranoid, we’re running as root.

first get helper functions (e.g. DEBUG, load_scheme, …), extend $PATH,

set variables etc. We get $SCRIPT_RETURN from here

. ${0%/*}/helper_functions # dirname $0/helper_functions

get_x_user comes from here…

. ${PUB_SCRIPT_DIR}/x_helper_functions

export PATH

run_on_xserver() {
get_x_user
su $X_USER -c “DISPLAY=$DISP $1”
}

To me it seems that these “helper_functions” are not available on my system. I didn’t find any file with that name, also I don’t have the folder “/usr/lib/powersave” as mentioned in some other posts.

Is it possible that these “helper_functions” doesn’t exist on 11.1 ? Also didn’t found any RPM.
How can I can run X-based programs in such an ACPI-script? I also wanted to use “qdbus” which also depends on X and so this didn’t work either.

Thanks for any help,
Ingmar

In opensuse 10.3, i made some tweaks to use these acpi callback functions for my asus w1n :

In /etc/powersave/events (which actually links to /etc/sysconfig/powersave/events) i have edited this :

EVENT_OTHER="asus_acpi_events"

You can also edit this via Yast2 > System > /etc/sysconfig editor .

Then you have to edit /usr/lib/powersave/scripts/hotkey_handler (i might be wrong on that one…) by adding this section :


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 

And then i made this script called asus_acpi_events in /usr/lib/powersave/scripts/ :


#!/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" # powergear , 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[li]}]]}
[/li]			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

Hope that helps.

Thanks for the info, unfortunately I couldn’t solve it that way.
It seems something is changed in 11.1. I simply don’t find any of the needed files on my fresh installed SuSE.
I don’t have the directory /etc/powersave, /usr/lib/powersave nor /etc/sysconfig/powersave…
I know these from 10.x, but now it seems changed. Maybe someone know how this is handled in 11.1?

Thanks,
ingmar3