让你的Thinkpad在SUSE下工作得更好更完美(2)

think vantage键空着不爽......
让每电脑每部分的硬件都发挥作用多好阿...偏偏thinkpad多了这个标准没有的键,就这样空着很无聊啊.想想能让它发挥点作用多完美.于是我便动手了.根据thinkwiki的介绍,这个功能早就实现了,只要内核带有thinkpad_acpi(前身是ibm_acpi)模块.但怎样控制呢,通过google,线索指向/etc/acpi.进去看一看,里面有个thinkpad文件:

event=ibm/.*
action=/usr/lib/acpid/thinkpad_handler "%e"

原来event指的是/proc/acpi/下各种事件(硬件以文件方式表示事件), action就是根据这个事件而发生的动作
根据上面描述,找到thinkpad_handler这个文件:

#!/bin/bash

HOTKEY=$1
set $HOTKEY
EVENT=$1 # "ibm/hotkey"
ACPI=$2 # "HOTK"
WHAT=$3 # "00000080"
SERIAL=$4 # "0000100c" Fn+F12
# bluetooth
if [ "$WHAT" = "00000080" -a "$SERIAL" = "00001005" ]; then
ACTION="disable"
grep -q "disabled" "/proc/acpi/ibm/bluetooth" && ACTION="enable"
echo $ACTION > "/proc/acpi/ibm/bluetooth"
fi

看来这个脚本只处理了蓝牙,其他热键则在内核其他地方处理了.不管了,在这照葫芦自己写一下一段

# thinkvantage
if [ "$WHAT" = "00000080" -a "$SERIAL" = "00001018" ]; then
ACTION="vantage"
yast2 &
echo "start yast2" >>/var/log/usr_local.log
fi

我把thinkvantage功能做成调用yast,真是和SUSE绝配的想法....恩,但怎么不行呢.....经过调试和google, 是 X 协议的问题,这个问题很难解决最后用了个粗暴的方法直接 xhost +后可以运行了.最终我将脚本改成这样:

#!/bin/bash

HOTKEY=$1
set $HOTKEY
EVENT=$1 # "ibm/hotkey"
ACPI=$2 # "HOTK"
WHAT=$3 # "00000080"
SERIAL=$4 # "0000100c" Fn+F12

echo "thinkpad_acpi_events $EVENT $ACPI $WHAT $SERIAL" >>/var/log/usr_local.log

# based on /etc/acpi/screenblank.sh (Ubuntu 7.10)
# . /usr/share/acpi-support/power-funcs # for getXuser
getXuser() {
user=`finger| grep -m1 ":$displaynum " | awk '{print $1}'`
if [ x"$user" = x"" ]; then
user=`finger| grep -m1 ":$displaynum" | awk '{print $1}'`
fi
if [ x"$user" != x"" ]; then
userhome=`getent passwd $user | cut -d: -f6`
export XAUTHORITY=$userhome/.Xauthority
else
export XAUTHORITY=""
fi
}

# end of getXuser from /usr/share/acpi-support/power-funcs
#
for x in /tmp/.X11-unix/*; do
displaynum=`echo $x | sed s#/tmp/.X11-unix/X##`
getXuser;
export DISPLAY=":$displaynum"
done

# bluetooth
if [ "$WHAT" = "00000080" -a "$SERIAL" = "00001005" ]; then
ACTION="disable"
grep -q "disabled" "/proc/acpi/ibm/bluetooth" && ACTION="enable"
echo $ACTION > "/proc/acpi/ibm/bluetooth"
echo "bluetooth switch" >>/var/log/usr_local.log
fi

# thinkvantage
if [ "$WHAT" = "00000080" -a "$SERIAL" = "00001018" ]; then
ACTION="vantage"
su $user -c "gnomesu -c /sbin/yast2" &
echo "start yast2" >>/var/log/usr_local.log
fi

# Fn+F3
if [ "$WHAT" = "00000080" -a "$SERIAL" = "00001003" ]; then
ACTION="off screen"
su $user -c "xset dpms force off" &
echo "turn off screen" >>/var/log/usr_local.log
fi

# Fn+F7
#if [ "$WHAT" = "00000080" -a "$SERIAL" = "00001007" ]; then
# ACTION="switch screen"
# echo video_switch > /proc/acpi/ibm/video
# echo "swith screen" >>/var/log/usr_local.log
#fi

# Fn+F9
if [ "$WHAT" = "00000080" -a "$SERIAL" = "00001009" ]; then
ACTION="eject cdrom"
eject /dev/cdrom &
echo "eject cdrom" >>/var/log/usr_local.log
fi

# Fn+Space
if [ "$WHAT" = "00000080" -a "$SERIAL" = "00001014" ]; then
ACTION="terminal"
su $user -c "gnome-terminal" &
echo "run a terminal" >>/var/log/usr_local.log
fi

unset DISPLAY
unset XAUTHORITY

里面我将一些suse本来不支持的热键也增加了:
其中Fn+F3本来在suse gnome中关闭screen safer后就失效,我增加后就一直可以使用了.
Fn+Space设置成打开gnome-terminal,这下方便我了
Fn+F9用来*出光驱
每个热键的键码在/usr/src/linux-2.6.xxxx/Documentation/laptop/thinkpad-acpi.txt文面找到.最后,在gnome-session中添加一个autostartup "xhost +"让用户每次登录后自动执行

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/27948.html