Created
March 13, 2017 21:33
-
-
Save rpromyshlennikov/7d6d2432242eca596eb543d35702e742 to your computer and use it in GitHub Desktop.
xrandr (thinkpad monitor switcher) bound to XF86Display button
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 | |
#For identifying our monitors use xrandr tool and view output | |
LVDS=LVDS1 # could be another one like: LVDS, LVDS-1, etc | |
HDMI=HDMI1 # could be another one like: HDMI, HDMI-1, etc | |
EXTRA="--right-of $LVDS" # addtional info while dual display | |
# Lets check both LVDS and HDMI state from the string "$display connected " | |
xrandr | grep -q "$LVDS connected " && LVDS_IS_CON=1 || LVDS_IS_CON=0 | |
xrandr | grep -q "$HDMI connected " && HDMI_IS_CON=1 || HDMI_IS_CON=0 | |
xrandr --listmonitors | grep -q "$LVDS" && LVDS_IS_ON=1 || LVDS_IS_ON=0 | |
xrandr --listmonitors | grep -q "$HDMI" && HDMI_IS_ON=1 || HDMI_IS_ON=0 | |
# Output switch cycle | |
if [ $HDMI_IS_ON -eq 1 ]; then | |
#Go to state 0 -> just LVDS | |
echo "HDMI is ON, turn LVDS on" | |
xrandr --output $LVDS --auto | |
xrandr --output $HDMI --off | |
# beep | |
elif [ $LVDS_IS_ON -eq 1 ] && [ $HDMI_IS_CON ]; then | |
#Go to state 1 -> just HDMI | |
echo "LVDS is ON, turn HDMI on" | |
xrandr --output $LVDS --off | |
xrandr --output $HDMI --mode 1920x1080 | |
xrandr --output $HDMI --auto | |
else | |
#This should never be reached but just in case.. | |
xrandr --output $LVDS --auto | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment