[ltp] How does a uevent work for dock/undock on thinkpads?

Steven King linux-thinkpad@linux-thinkpad.org
Sun, 8 Feb 2009 13:43:56 -0800


On Sunday, February 08, 2009 4:56:54 Daniel Castro wrote:
> Hello!
>
> I have a T61(and a T61p) running Ubuntu 8.10 (2.6.27-11-generic) and I have
> a advanced mini
> dock<http://www.thinkwiki.org/wiki/ThinkPad_Advanced_Mini_Dock>which
> works great. The eject button will release usb devices attached and
> docking back in just works. It is a 1 second dock/undock experience (with
> external monitor) compared with the more than 10 seconds it takes in
> Windows.
> At work I undock and dock a lot, and there are certain tasks I would like
> tu run when I do this. So I would like to run a script when I undock and
> another one when I dock.
>
> I asked here a few days ago if the dock/undock was handled by an acpi event
> and the answer was *no*, it is handled by a uevent (udev or HAL).
>
> I know nothing about udev or HAL. Is there a simple way to do what I want
> to do?

For my x61 tablet running Fedora and x6ultrabase, to catch the udev event, I 
have a file /etc/udev/55-thinkpad-x61t.rules which contains:

KERNEL=="dock.0", ATTR{docked}=="1", RUN+="/etc/thinkpad/dock.sh 1"
KERNEL=="dock.0", ATTR{docked}=="0", RUN+="/etc/thinkpad/dock.sh 0"

in actual practice, for either docking or undocking, the ATTR{docked} always 
initially equals 1, so my /etc/thinkpad/dock.sh looks like:

#!/bin/sh
# wait for the dock state to change
sleep 1
DOCKED=$(cat /sys/devices/platform/dock.0/docked)

case "$DOCKED" in
        "0")
                xrandr -d :0.0 --output VGA --off
                ;;
        "1")
                xrandr -d :0.0 --output VGA --auto
                xrandr -d :0.0 --output LVDS --auto --right-of VGA
                ;;
esac
exit 0

For your T61 I would imagine it would be very similar or the same.

I think more recent versions of HAL (0.5.12?) have dock support included.