You are not logged in.

#1 2008-03-19 22:33:51

jarda-wien
Member
Registered: 2008-03-13
Posts: 104

thinkpad keys once and for all

There are lots of people out there having problems to get thinkpad keys to work. I would like to solve this issue and potencially write a wiki page about that.
Here is the information I got till today:

1. the ibm-acpi module is renamed to thinkpad-acpi module

2. both modules create a proc interface under /proc/acpi/ibm/ which sometimes needs to be chrooted 666 to be able to control thinkpad functions from bash.

3. doing echo enable,0x0000 > /proc/acpi/ibm/hotkey sends key events to the thinkpad firmware (nvram module has to be loaded). Mostly this doesn't work thou...

4. doing echo enable,0xfffffffff > /proc/acpi/ibm/hotkey sends key events to acpid. This has to be started and does things according to the /etc/acpi/handler.sh script. This seems to work for me (T41). Here's my script:

#!/bin/sh
# Default acpi script that takes an entry for all actions

set $*

ev_type=`echo "$1" | cut -d/ -f1`

# We have to take special care for events send by ibm/hotkey:
if [ "$ev_type" = "ibm" ]; then
    ev_type=`echo "$1" | cut -d/ -f1`
    event=`echo "$1" | cut -d/ -f2`
    key="$2"\ "$3"\ "$4"
else 
    # Take care about the way events are reported
    ev_type=`echo "$1" | cut -d/ -f1`
    if [ "$ev_type" = "$1" ]; then
        event="$2";
    else
        event=`echo "$1" | cut -d/ -f2`
    fi
fi

case "$ev_type" in
    button)
        case "$event" in
            power)
        logger "acpid: power button pressed; starting shutdown"
#                logger "acpid: received a shutdown request"
                /sbin/init 0
        break
                ;;
        sleep)
        logger "acpid: sleep button pressed; initiating hibernate-ram"
#        logger "acpid: received hibernate request"
        /usr/sbin/pm-suspend
        ;;
            lid)
        logger "acpid: lid event" 
        ;;
        *)
                logger "acpid: action $2 is not defined"
                ;;
        esac
    ;;

# BEGIN customization for ibm/hotkey:
   ibm)
    case "$event" in
        hotkey)
            case "$key" in
                "HKEY 00000080 00001002")
                    logger "acpid: lock button (Fn+F2) pressed"
                    ;;
                 "HKEY 00000080 00001003")
                                logger "acpid: blank screen (Fn+F3) pressed; switching display off"
                    xset dpms force off
                    ;;
                "HKEY 00000080 00001004")
                                logger "acpid: sleep button (Fn+F4) pressed; initiating hibernate-ram"
                    /usr/sbin/pm-suspend
                    ;;
                "HKEY 00000080 00001005")
                                logger "acpid: bluetooth button (Fn+F5) pressed; toggling bluetooth"
        # echo 3 > /proc/acpi/ibm/beep
        if grep -q enabled /proc/acpi/ibm/bluetooth ; then
            echo disable > /proc/acpi/ibm/bluetooth
        elif grep -q disabled /proc/acpi/ibm/bluetooth ; then
            echo enable > /proc/acpi/ibm/bluetooth
        fi
                    ;;
                "HKEY 00000080 00001007")
                                logger "acpid: screen toggle button (Fn+F7) pressed"
                    ;;
                
                "HKEY 00000080 0000100c")
                                logger "acpid: hibernate button (Fn+F12) pressed; initiating hibernate"
                     /usr/sbin/pm-hibernate
                    ;;
                
                "HKEY 00000080 00005001")
                    # This is the lid CLOSE event
                    # as of now it is already handled above
                                ;;
                "HKEY 00000080 00005002")
                                # This is the lid OPEN event
                                # as of now it is already handled above
                                ;;
                *)
                    logger "acpid: $ev_type/$event $key is not defined"
                    ;;
            esac
              ;;            
        dock)
                case "$key" in
                "GDCK 00000003 00000001")
                    logger "acpid: Dock eject request"
                    ;;
                    "GDCK 00000003 00000002")
                    logger "acpid: laptop was undocked"
                    ;;
                "GDCK 00000000 00000003")    
                    logger "acpid: laptop was docked"
                    ;;
                *)
                    logger "acpid: $ev_typ $event event $key is not defined"
                    ;;
            esac
            ;;
        bay)
            case "$key" in
                "MSTR 00000003 00000000")
                    logger "acpid: got ultrabay eject request"
                    ;;
                    "MSTR 00000001 00000000")
                    logger "acpid: ultrabay eject lever inserted"
                    ;;
            esac
            ;;
    esac
    ;;    
    *)
        logger "ACPI group $1 / action $2 is not defined"
        ;;
esac

I have found it here http://priyadi.net/archives/2004/12/20/ … kpad-t41p/.

5. Allthou thinkpad-acpi should in time be able to handle all keys, as of today, one still needs tpb for some of them. KDE has a module in the control center that has similar functionality and doesn't depend on tpb. I have not yet tried to get all working.



Any other contribution would be welcome. The handler.sh script can probably be adapted or somehow rewritten, some of this info may be wrong...

Last edited by jarda-wien (2008-03-28 16:17:24)

Offline

#2 2008-03-28 16:23:49

jarda-wien
Member
Registered: 2008-03-13
Posts: 104

Re: thinkpad keys once and for all

ok I have done some research and here's the news:
point 4 of my previous thread => there is no need to load the module with any special parameters. everything should work of-the-box.

point 5 => on my T41 thinkpad-acpi sends key events from ALL function keys, so there is no need to use any other external app. all keys can be configured via /etc/acpi/handler.sh as of now I am trying to convince acpid to lauch kmail after pressing the blue Access IBM key...

Offline

#3 2008-04-07 09:48:54

mik
Member
Registered: 2008-04-07
Posts: 7

Re: thinkpad keys once and for all

I've followed this guide and it works well on my T60, but i still have problem about command execute (try to lock desktop by pressing Fn-F2) in handler.sh

# BEGIN customization for ibm/hotkey:
   ibm)
    case "$event" in
        hotkey)
            case "$key" in
                "HKEY 00000080 00001002")
                    logger "acpid: lock button (Fn+F2) pressed"
                    su myusername -c "gnome-screensaver-command -l"
                    ;;

Restart my computer, Fn-F2 doesnt work. cat /var/log/acpid.log shows me that handler.sh was be called for HKEY 00000080 00001002 (it should be no problem at all) <--- i dont know why it doesnt work sad
Change to root account and restart acpid with /etc/rc.d/acpid restart . Now all Fn-keys work perfectly.......until next restart <--- i dont understand why sad
Im sure that acpid was be loaded successfully with another booting process

Can anyone help me to find a better solution ? Thanks very much

Offline

#4 2008-04-07 12:51:06

hennes
Member
Registered: 2008-03-31
Posts: 50

Re: thinkpad keys once and for all

Sorry, no solution, but I noticed the same behaviour on my X61s.

Here's my handler.sh. It's pretty much the same, but it also takes care of turning on an external VGA display (if connected), adjusting the brightness per custom script, changing the cpu frequency scaling governor on AC plug/unplug and suspending to RAM on LID close. It could be improved at certain points I guess.

#!/bin/sh
# Default acpi script that takes an entry for all actions

# NOTE: This is a 2.6-centric script.  If you use 2.4.x, you'll have to
#       modify it to not use /sys

set $*

case "$1" in
    ibm/hotkey)
        case "$2" in
            HKEY)
                case "$4" in
                    00001002) # Lock screen
                        xscreensaver-command -lock
                        ;;
                    #00001003) # Battery icon
                    #    ;;
                    00001004) # Suspend to RAM
                        hibernate -F /etc/hibernate/ususpend-ram.conf
                        ;;
                    00001005) # Switch Bluetooth
                        if [ "$(grep "status.*enabled" /proc/acpi/ibm/bluetooth)" ]; then
                            echo "disable" > /proc/acpi/ibm/bluetooth
                        else
                            echo "enable" > /proc/acpi/ibm/bluetooth
                        fi
                        ;;
                    00001007) # Toggle external display
                        if [ "$(xrandr -q | grep "VGA connected")" ]; then
                            if [ "$(xrandr -q | grep "VGA connected [0-9]")" ]; then
                                xrandr --output VGA --off
                            else
                                xrandr --output VGA --auto
                            fi
                        else
                            xrandr --output VGA --off
                        fi
                        ;;
                    #00001008) # Toggle Trackpoint/Touchpad
                    #    ;;
                    #00001009) # Eject from dock
                    #    ;;
                    0000100c) # Hibernate
                        hibernate -F /etc/hibernate/ususpend-disk.conf
                        ;;
                    #00001014) # Toggle zoom
                    #    ;;
                    #00001018) # ThinkVantage button
                    #    ;;
                esac
                ;;
        esac
        ;;
    button/lid)
        case "$2" in
            LID)
                case "$3" in
                    00000080) # Lid opened/closed
                        grep open /proc/acpi/button/lid/LID/state || hibernate -F /etc/hibernate/ususpend-ram.conf
                        ;;
                esac
                ;;
        esac
        ;;
    ac_adapter)
        case "$2" in
            AC)
                case "$4" in
                    00000001) # AC plugged
                        echo -n performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
                        ;;
                    00000000) # AC unplugged
                        echo -n ondemand > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
                        ;;
                esac
                ;;
        esac
        ;;
    video)
        case "$2" in
            LCD0)
                case "$3" in
                    00000086) # Brightness up
                        brightness +
                        ;;
                    00000087) # Brightness down
                        brightness -
                        ;;
                esac
                ;;
        esac
        ;;
esac

Here's my brightness script too:

#!/bin/bash
# This script adjusts the display brightness on my ThinkPad X61s.
# Usage: brightness +/-

[ "$UID" != 0 ] && echo "err, you need to be root" && exit 1

ctrl_file=/sys/class/backlight/acpi_video1/brightness
max_file=/sys/class/backlight/acpi_video1/max_brightness

brightness=$(cat $ctrl_file)
max=$(cat $max_file)
min=20

if [ "$1" = "+" ]; then
    if [ $brightness -ge $max ]; then
        brightness=$max
    else
        brightness=$(($brightness+$max/10))
        [ $brightness -gt $max ] && brightness=$max
    fi
elif [ "$1" = "-" ]; then
    if [ $brightness -le $min ]; then
        brightness=$min
    else
        brightness=$(($brightness-$max/10))
        [ $brightness -lt $min ] && brightness=$min
    fi
else
    echo $brightness && exit 0
fi

echo $brightness > $ctrl_file

Of course this could be incorporated within the handler.sh itself as well.

Offline

#5 2008-11-07 11:07:36

filou.linux
Member
From: Zurich
Registered: 2008-04-17
Posts: 87

Re: thinkpad keys once and for all

Hi

I'm experiencing the same problem. All acpid related stuff doesn't work until /etc/rc.d/acpid restart. The daemon is started properly (or rather is being started by hal), events appear in the log, but the actions aren't executed as expected. Obviously many others are experiencing similar problems. Is it an Issue in acpid?

I'm thankful for every hint/idea!

Cheers

Offline

#6 2008-11-07 13:48:37

Daenyth
Forum Fellow
From: Boston, MA
Registered: 2008-02-24
Posts: 1,244

Re: thinkpad keys once and for all

I thought all you had to do to get it working was to select the thinkpad keyboard variant in xorg.conf?

Offline

#7 2008-11-07 14:07:08

filou.linux
Member
From: Zurich
Registered: 2008-04-17
Posts: 87

Re: thinkpad keys once and for all

o_O that sounds great, except I haven't got a thinkpad ;-) I'm running an HP Compaq nw8240. But do you think that's an xorg configuration issue?

Offline

#8 2008-11-07 19:53:19

Dheart
Member
From: Sofia, Bulgaria
Registered: 2006-10-26
Posts: 956

Re: thinkpad keys once and for all

filou.linux wrote:

o_O that sounds great, except I haven't got a thinkpad ;-) I'm running an HP Compaq nw8240. But do you think that's an xorg configuration issue?

Well.. I got my Dell special keys working by selecting keyboard model in xorg.conf...


My victim you are meant to be
No, you cannot hide nor flee
You know what I'm looking for
Pleasure your torture, I will endure...

Offline

#9 2008-11-07 22:55:56

honahursey
Member
Registered: 2008-08-18
Posts: 32

Re: thinkpad keys once and for all

I have the same issue with acpid.  To fix it all I had to do was have acpid restart every time I boot.  It's kinda hackish, but it works.

.xinitrc

...
xhost local:root
sudo /etc/rc.d/acpid restart
...

The sudo is probably not needed, but it works.

Offline

#10 2008-11-09 13:40:22

filou.linux
Member
From: Zurich
Registered: 2008-04-17
Posts: 87

Re: thinkpad keys once and for all

Dheart wrote:

Well.. I got my Dell special keys working by selecting keyboard model in xorg.conf...

Ok, but how do I figure out
a.) Which keyboard types that are availible
b.) Which one's in my notebook

Thanks anyway. Now I got at least an idea which direction the problem goes into.

Offline

#11 2009-03-02 15:03:59

jarda-wien
Member
Registered: 2008-03-13
Posts: 104

Re: thinkpad keys once and for all

I realise this is an old thread, but I think I might have a solution, or at least the reason why this is happening.

If you restart acpid using sudo, acpid becomes a child process of your own terminal, including any global variables that your own terminal might have, especially DISPLAY and XAUTHORITY. Those variables are not given to startup processes by default (in case of the two mentioned, they are created only during X startup). So as long as you don't want acpid to iteract with a running X server, everything is fine. Interacting with X applications requires those two variables to be set (which is exactly what happens when you restart acpid from, e.g. xterm using sudo) OR using su youruser in the sript itself. After rebooting, those variables are not present and that is why it is not working.

I have posted my latest handler.sh here: http://bbs.archlinux.org/viewtopic.php?id=66595
There is a workaround for X interaction in it.
Also, feel free to add your opinion in the linked thread.

Offline

Board footer

Powered by FluxBB