Skip to content

Instantly share code, notes, and snippets.

@pheaver
Last active August 29, 2015 14:01
Show Gist options
  • Save pheaver/a3e397f7154ad924a14e to your computer and use it in GitHub Desktop.
Save pheaver/a3e397f7154ad924a14e to your computer and use it in GitHub Desktop.
laptop dock/undock
#!/bin/sh
# not sure what dock.0 is, but dock.1 seems to be the right one.
DOCKED=$(cat /sys/devices/platform/dock.1/docked)
case "$DOCKED" in
"0")
#undocked event
xrandr --output LVDS1 --auto --primary
;;
"1")
#docked event
# Get each display name and whether it is connected/disconnected
displays=$(xrandr -q | grep ' connected' | cut -d ' ' -f1)
xrandr --output LVDS1 --off
prev=
for x in HDMI3 HMDI2; do
if echo $displays | grep -q $x; then
if [ -z $prev ]; then
xrandr --output $x --auto --primary
else
xrandr --output $x --auto --right-of $prev
fi
prev=$x
else
xrandr --output $x --off
fi
done
;;
esac
@pheaver
Copy link
Author

pheaver commented May 9, 2014

$ xrandr -q
Screen 0: minimum 320 x 200, current 5440 x 1080, maximum 32767 x 32767
LVDS1 connected 1600x900+0+0 (normal left inverted right x axis y axis) 310mm x 174mm
1600x900 60.0_+
1440x900 59.9
1360x768 59.8 60.0
1152x864 60.0
1024x768 60.0
800x600 60.3 56.2
640x480 59.9
VGA1 disconnected (normal left inverted right x axis y axis)
HDMI1 disconnected (normal left inverted right x axis y axis)
DP1 disconnected (normal left inverted right x axis y axis)
HDMI2 connected primary 1920x1080+3520+0 (normal left inverted right x axis y axis) 510mm x 287mm
1920x1080 60.0_+
1680x1050 59.9
1280x1024 75.0 60.0
1440x900 75.0 59.9
1280x800 59.9
1152x864 75.0
1024x768 75.1 70.1 60.0
800x600 72.2 75.0 60.3
640x480 72.8 75.0 60.0
720x400 70.1
HDMI3 connected 1920x1080+1600+0 (normal left inverted right x axis y axis) 510mm x 287mm
1920x1080 60.0*+
1680x1050 59.9
1280x1024 75.0 60.0
1440x900 75.0 59.9
1280x800 59.9
1152x864 75.0
1024x768 75.1 70.1 60.0
800x600 72.2 75.0 60.3
640x480 72.8 75.0 60.0
720x400 70.1
DP2 disconnected (normal left inverted right x axis y axis)
DP3 disconnected (normal left inverted right x axis y axis)
VIRTUAL1 disconnected (normal left inverted right x axis y axis)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment