Use external monitor automatically, when started in Docking Station

5,151

Solution 1

I adjusted myself a script I found to my needs.

You can ignore the wacom commands. Those are just to match the input layer of the tablet to the screen orientation.

#!/bin/bash
#!/bin/sh
# wait for the dock state to change
sleep 2.0
DOCKED=$(cat /sys/devices/platform/dock.0/docked)
case "$DOCKED" in
    "0")
       #undocked event - lets remove all connected outputs apart from LVDS
       for output in $(/usr/bin/xrandr -d :0.0 --verbose|grep " connected"|grep -v LVDS|awk '{print $1}')
         do
         /usr/bin/xrandr -d :0.0 --output $output --off
       done
    xrandr --output LVDS1 --rotation normal
        xsetwacom set "Wacom ISDv4 90 Pen stylus" MapToOutput LVDS1
    xsetwacom set "Wacom ISDv4 90 Pen eraser" MapToOutput LVDS1
    # rotates the tablet input to the according position (half=180°, (c)cw=(counter)clockwise, none=normal)
    xsetwacom set "Wacom ISDv4 90 Pen stylus" rotate none
    # if multiouch present set: xsetwacom set "Wacom ISDv4 E6 Finger touch" rotate half
    xsetwacom set "Wacom ISDv4 90 Pen eraser" rotate none
    ;;
    "1")
    ## rotates internal Laptop Display LVDS1 to inverted
    xrandr --output HDMI2 --auto --above LVDS1
    xrandr --output LVDS1 --rotation inverted
    xsetwacom set "Wacom ISDv4 90 Pen stylus" MapToOutput LVDS1
    xsetwacom set "Wacom ISDv4 90 Pen eraser" MapToOutput LVDS1
    # rotates the tablet input to the according position (half=180°, (c)cw=(counter)clockwise, none=normal)
    xsetwacom set "Wacom ISDv4 90 Pen stylus" rotate half
    # if multiouch present set: xsetwacom set "Wacom ISDv4 E6 Finger touch" rotate half
    xsetwacom set "Wacom ISDv4 90 Pen eraser" rotate half
    ;;
esac
exit 0

It identifies a status file in /sys/devices/platform/dock.0 wheter it has the value 1 for docked or 0 for undocked an triggers xrandr to adjust the display output to an extended dektop using the inbuilt display LVDS1 an configuring the external display HDMI2 above.

Solution 2

There are some tools to automate it like RandR, disper, displex or this one http://gnomefiles.org/content/show.php/Laptop+external+display+hotplugging?content=138742

Share:
5,151

Related videos on Youtube

user63899
Author by

user63899

Updated on September 18, 2022

Comments

  • user63899
    user63899 over 1 year

    I am using a Thinkpad T510 and I often boot it in a ThinkPad Mini Dock Plus Series 3 (EU). The problem is that if I boot it with the lid closed, I can see grub, I can see the Ubuntu boot splash, but after that my external monitor (connected via VGA) turns off, and I have to open the lid and tell the NVIDIA driver manually to use the external screen and turn off the built in LCD panel. Is there a way to put it into an udev rule, or something like that to avoid the manual switching?