# thinkpad-acpi

## BK201

I am having several problems with the thinkpad-acpi, tp_smapi and hdaps drivers (all seem to be related hence one post) on my x61s. I have tried both in kernel and portage versions and both give me the same results.

1) when loaded, the hdaps driver causes the touchpoint to glitch out. The mouse stays stuck at the center of the screen and as soon as you try and move it the mouse glitches right back to the middle. I have not tried to test whether the driver actually works because of this problem.

2) function keys don't seem to all be working. Fn+F4 for suspend and Fn+F12 for hibernate both work along with the lid using

/etc/acpi/events/functions

```
event=ibm/hotkey HKEY 00000080 0000100c

action=hibernate

event=ibm/hotkey HKEY 00000080 00001004

action=hibernate-ram

event=button/lid

action=hibernate-ram
```

Fn+F5 also works out of the box to toggle the wireless lan as do the screen brightness, multimedia, thinklight and zoom function keys.

None of the other keys (Fn+ F2, F3, F7, F8, F9) work. xev shows that the functions are at least recognized by X. It seems that most of the function keys are managed in hardware, and specifically suspend and hibernate (F4, F12) are managed differently than the others in acpi which leads me to think nothing is actually configured right and the working keys work only because they are independent of software. Thinkwiki has tons of info on this but I've yet to get everything working 100%.

----------

## dmpogo

Fn-Fn keys generate ACPI events,   not keyboard events (which would be seen by xev).  USE acpi_listen   to see them.

Some of the keys are handled at a low (kernel) level, the others, if your desktop environment does not handle them, need to be managed by acpid daemon and

some scripts.

----------

## BK201

according to acpi_listen all function keys are generating the correct acpi events. Why then would some of my scripts in /etc/acpi/events work (hibernation, suspend) while others do not?

----------

## dmpogo

 *BK201 wrote:*   

> according to acpi_listen all function keys are generating the correct acpi events. Why then would some of my scripts in /etc/acpi/events work (hibernation, suspend) while others do not?

 

My recollection is that what is in /etc/acpi/events are not actually handling scripts, but small scriplets which tell which ACPI code is handled by what script.

If I remember, actual scripts are one directory up in /etc/acpi, and it is by default one script with cases.  I can post my own one from laptop, after I get access to it later today

----------

## BK201

actually that is how I did it.

/etc/acpi/lock.sh

```
#!/bin/bash

su <username> -c 'xlock'
```

/etc/acpi/events

```
# lock screen on Fn+F2

event=ibm/hotkey HKEY 00000080 00001002

action=/etc/acpi/lock.sh
```

the script is simple for the sake of testing and works fine if executed as root. Using Fn+F2 generates the right acpi event but my script is not being run.

----------

## dmpogo

 *BK201 wrote:*   

> actually that is how I did it.
> 
> /etc/acpi/lock.sh
> 
> ```
> ...

 

This is actually quite a non-trivial case, because using X windows (via xlock) as user is only possible if scripts finds an appropriate a

Xauthority file.  Here is how I do it all

```

>> cat /etc/acpi/ibm.sh

#!/bin/sh                       

# Specific signal handling      

THINKPAD_ACPI_DIR=/sys/devices/platform/thinkpad_acpi

X_USER=`who | sed -ne "s/^\([^[:space:]]*\)[[:space:]]*:0.*/\1/p"`

if [ -n "$X_USER" ]; then                                         

   export DISPLAY=":0.0"                                          

   export XAUTHORITY=/home/${X_USER}/.Xauthority                  

fi                                                                

function x_info () {

        if [ -n "$XAUTHORITY" ]; then

                echo $1 | osd_cat -d 3 -p bottom -A center -o -50 -s 2 -c $2 -f -adobe-courier-bold-r-normal--*-240-*-*-m-*-iso8859-1                           

        fi                                                                      

}                                                                               

case $4 in

        00001002)

                su $X_USER -c 'alock -bg shade:shade=20 -cursor theme:name=xtr -auth pam'                                                                       

                ;;                                                              

        00001004)                                                               

                # Fn-F4 suspends to RAM (standard)                              

                # loaded thinkpad_acpi always captures Fn-F4, even masked       

                /usr/sbin/hibernate-ram                                         

                ;;                                                              

        00001005)                                                               

                # Fn-F5 toggles radio through rfkill (standard)                

                ;;                                                              

        00001006)                                                               

                # Fn-F6 starts-stops wireless services (NON-standard)           

                # In my network config wlan stop comes with disabling radio     

                status=`/etc/init.d/net.wlan0 status`                           

                status=${status#* status:}                                      

                if   [ $status == started ] ; then                              

                        /etc/init.d/net.wlan0 --quiet stop                      

                elif [ $status == stopped ] ; then                              

                     if [ `cat ${THINKPAD_ACPI_DIR}/hotkey_radio_sw` == 1 ] ; then                                                                              

                        /etc/init.d/net.wlan0 --quiet start                     

                     else                                                       

                        x_info "Radio Kill Switch in the back is enabled" red   

                     fi                                                         

                elif [ $status == inactive ] ; then                             

                     # This perhaps can arise if there are no AP's              

                     /etc/init.d/net.wlan0 --quiet stop &                       

                     message="Stopping inactive WLAN. No AP's or a hang ?"      

                     x_info "$message" red                                      

                     logger "$message"                                          

                fi                                                              

                ;;                                                              

        00001007)                                                               

                # Fn-F7 cycles through monitors (standard)                      

                /usr/local/sbin/thinkpad-fn-f7 toggle                           

                ;;                                                              

        00001008)                                                               

                # Fn-F8 switches touchpad on and off (standard)                 

                if synclient -l | grep -q TouchpadOff[^[:alnum:]]*0 ; then      

                   synclient TouchpadOff=1                                      

                   status="TouchPad OFF"                                        

                else

                   synclient TouchpadOff=0

                   status="TouchPad ON"

                fi

                x_info "$status" green

                ;;

        0000100b)

                # Fn-F11 toggles bluetooth (non-standard)

                # On toggle auto loads driver (hotplug ??), off leaves it

                # Services are currently untouched

                if [ `cat ${THINKPAD_ACPI_DIR}/bluetooth_enable` == 1 ] ; then

                   echo 0 > ${THINKPAD_ACPI_DIR}/bluetooth_enable

                elif [ `cat ${THINKPAD_ACPI_DIR}/hotkey_radio_sw` == 1 ] ; then

                # we enable radio only if "hard" switch is on

                   echo 1 >  ${THINKPAD_ACPI_DIR}/bluetooth_enable

                fi

                ;;

        0000100c)

                # Fn-F12 hibernates (standard)

                /usr/sbin/hibernate

                ;;

        00001014)

                # Fn-Space zoom application (standard)

                # su $X_USER -c xmag

                ;;

        00007000)

                # Hard radio switch off (standard, but need to check if RFKILL does it correctly now)

                if [ `cat  ${THINKPAD_ACPI_DIR}/hotkey_radio_sw` == 0 ] ; then

                   status=`/etc/init.d/net.wlan0 status`

                   status=${status#* status:}

                   /etc/init.d/net.wlan0 stop

                   echo 0 >  ${THINKPAD_ACPI_DIR}/bluetooth_enable

                fi

                ;;

esac

```

and the correspondent /etc/acpi/event file fowards most of the events to this script

```

>> cat /etc/acpi/events/ibm

event=ibm/hotkey

action=/etc/acpi/ibm.sh %e

```

Some of the entries in ibm.sh is redundant now, for example Fn-F5 is handeled by kernel it seems. Note the XUSER ... game to set up Xauthority to be able to use X windows as user

----------

## BK201

Well the bluetooth toggle function works out of the box. The alock function does not however. Haven't tried any of the other ones yet.

----------

## dmpogo

 *BK201 wrote:*   

> Well the bluetooth toggle function works out of the box. The alock function does not however. Haven't tried any of the other ones yet.

 

on my thinkpad, Fn-F5, when started to work 'out of the box', toggles BOTH bluetooth and wireless.   I like to have separate control

----------

## BK201

For me Fn+F5 only toggles wireless and not bluetooth. Your script is working for bluetooth toggle though. Considering your script works for some of the function keys and not others is odd, especially since acpi_listen reports proper acpi calls from all of the keys.

----------

## dmpogo

 *BK201 wrote:*   

> For me Fn+F5 only toggles wireless and not bluetooth. Your script is working for bluetooth toggle though. Considering your script works for some of the function keys and not others is odd, especially since acpi_listen reports proper acpi calls from all of the keys.

 

well, it is easy to check

run in terminal as root

```

X_USER=`who | sed -ne "s/^\([^[:space:]]*\)[[:space:]]*:0.*/\1/p"` 

export DISPLAY=":0.0"                                          

export XAUTHORITY=/home/${X_USER}/.Xauthority 

su $X_USER -c 'alock -bg shade:shade=20 -cursor theme:name=xtr -auth pam'

```

does it work ? If it fails,  what does it say ?

also check that you actually have alock program installed !Last edited by dmpogo on Mon Apr 19, 2010 4:47 am; edited 1 time in total

----------

## BK201

The X_USER line is not working, echoing the value of X_USER back is returning nothing. Replacing X_USER with my username and running the rest of it as root works fine though.

----------

## dmpogo

 *BK201 wrote:*   

> The X_USER line is not working, echoing the value of X_USER back is returning nothing. Replacing X_USER with my username and running the rest of it as root works fine though.

 

well, if it is not a secret, could you send me (in a private message) an output of 'who' ?  I guess, the line is not robust enough to parse it, somehow

----------

## toralf

For a similar purpose I use the following code snippet to get a logged in X user :

```
function GetX11User() {

        DISPLAY="DISPLAY=:0.0"

        XUSR=$(w | grep -e xdm -e startx -e xinit | fgrep -v grep | cut -f1 -d' ' | sort -u | tail -n 1)

        if [[ -n "$XUSR" ]]; then

                if [[ "$XUSR" != "root" ]]; then

                        XUSR="su - $XUSR -c"

                else

                        XUSR="logger"

                fi

        else

                XUSR="logger"

        fi

}

```

which later is used in such way :

```

...

GetX11User

...

case $value in

        00001003)       $XUSR "$DISPLAY xset dpms force off"

```

eg. for the Fn+F3 key

----------

## BK201

In the end I gave up trying to use acpi events for running commands that don't need to be (and shouldn't be) run as root. xbindkeys works perfectly for this purpose as all my function keys also pass proper xf86 key codes.

----------

