Last active
December 18, 2015 09:38
-
-
Save seanf/5762396 to your computer and use it in GitHub Desktop.
ThinkPad docking script (copied from http://www.thinkwiki.org/wiki/Docking_Solutions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# save as /etc/udev/rules.d/81-thinkpad-dock.rules | |
KERNEL=="dock.0", ACTION=="change", RUN+="/usr/local/sbin/thinkpad-dock.sh" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -ex | |
# save as /usr/local/sbin/thinkpad-dock.sh | |
# wait for the dock state to change | |
sleep 0.5 | |
DOCKED=$(cat /sys/devices/platform/dock.1/docked) | |
# invoke from XSetup with NO_KDM_REBOOT otherwise you'll end up in a KDM reboot loop | |
NO_KDM_REBOOT=0 | |
for p in $*; do | |
case "$p" in | |
"NO_KDM_REBOOT") | |
NO_KDM_REBOOT=1 | |
;; | |
"SWITCH_TO_LOCAL") | |
DOCKED=0 | |
;; | |
esac | |
done | |
function switch_to_local { | |
export DISPLAY=$1 | |
#export XAUTHORITY=$(find /var/run/kdm -name "A${DISPLAY}-*") | |
# Turn off all external displays | |
for output in $(/usr/bin/xrandr --verbose|grep "+"|grep connected| grep -v LVDS|awk '{print $1}'); do | |
echo $output | |
logger -t DOCKING "Switching off $DISPLAY" | |
/usr/bin/xrandr --output $output --off | |
done | |
# Turn on local display | |
logger -t DOCKING "Switching on LVDS1" | |
/usr/bin/xrandr --output LVDS1 --auto | |
} | |
function switch_to_external { | |
export DISPLAY=$1 | |
#export XAUTHORITY=$(find /var/run/kdm -name "A${DISPLAY}-*") | |
# The Display port on the docking station is on HDMI2 - let's use it and turn off local display | |
logger -t UNDOCKING "Switching off LVDS1 and turning on HDMI2/3" | |
/usr/bin/xrandr --output HDMI2 --primary --auto --rotate left --right-of LVDS1 && | |
/usr/bin/xrandr --output LVDS1 --off | |
/usr/bin/xrandr --output HDMI3 --auto --left-of HDMI2 | |
#/usr/bin/xrandr --output HDMI3 --auto --left-of HDMI2 | |
#/usr/bin/xrandr --output LVDS1 --off | |
#/usr/bin/xrandr --output HDMI2 --primary --auto --rotate left | |
#/usr/bin/xrandr --output HDMI3 --primary --right-of LVDS1 | |
#/usr/bin/xrandr --output LVDS1 --off | |
#/usr/bin/xrandr --output HDMI2 --right-of HDMI3 --auto --rotate left | |
#/usr/bin/xrandr --output HDMI2 --primary --left-of LVDS1 | |
#/usr/bin/xrandr --output HDMI3 --left-of HDMI2 | |
#/usr/bin/xrandr --output LVDS1 --off | |
#/usr/bin/xrandr --output HDMI2 --primary --auto | |
} | |
case "$DOCKED" in | |
"0") | |
#undocked event | |
switch_to_local :0 | |
;; | |
"1") | |
#docked event | |
switch_to_external :0 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment