Feb 17, 2012

Kubuntu 12.04: Waking up Lenovo X220 w/ or w/o multiple monitor connected

I use my Lenovo X220 laptop in two modes:

1. In the docking station with monitor connected
2. Without the docking station just with the display

I had problems with this setup when suspending / waking up in Kubuntu 12.04. When I suspend without docking station connected and wake up without docking station connected, everything goes well. But when I wake up in the docking station it has problems with recognizing the monitor. All I can do is to restart the Xserver. It means it is useless to suspend.

So I wrote the script to detect whether the laptop is in docking station or not while it is wakeing up.

Create new file:

$ sudo nano /etc/pm/sleep.d/90_switch_display

With this content:

#!/bin/bash

. /usr/lib/pm-utils/functions

case "$1" in
    hibernate|suspend)
        ;;
    thaw|resume)
        export DISPLAY=:0
        export XAUTHORITY=/home/<username>/.Xauthority
        xrandr --auto
        if xrandr | grep -q -e "HDMI2 connected"; then
          xrandr --output LVDS1 --off
          xrandr --output HDMI2 --auto --primary
        else
          xrandr --output HDMI2 --off
          xrandr --output LVDS1 --auto --primary
        fi
        ;;
    *)
        ;;
esac

exit

Than save it and set it executable:

$ sudo chmod 755  /etc/pm/sleep.d/90_switch_display

And that's it. Waking up behaves well ;-)