Skip to content

Instantly share code, notes, and snippets.

@toc21c
Created May 18, 2016 02:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toc21c/7edbbf897e02ac21f0625089028db7a9 to your computer and use it in GitHub Desktop.
Save toc21c/7edbbf897e02ac21f0625089028db7a9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# origin:
# https://bbs.archlinux.org/viewtopic.php?id=171655
#inspired of:
# http://unix.stackexchange.com/questions/4489/a-tool-for-automatically-applying-randr-configuration-when-external-display-is-p
# http://ozlabs.org/~jk/docs/mergefb/
# http://superuser.com/questions/181517/how-to-execute-a-command-whenever-a-file-changes/181543#181543
# arandr script
# xrandr --output HDMI2 --off --output HDMI1 --mode 1920x1080 --pos 1920x0 --rotate normal --output DP1 --off --output eDP1 --mode 1920x1080 --pos 0x0 --rotate normal --output VIRTUAL1 --off
export MONITOR2=/sys/class/drm/card0-HDMI-A-1/status
while inotifywait -e modify,create,delete,open,close,close_write,access $MONITOR2;
dmode="$(cat $MONITOR2)"
do
if [ "${dmode}" = disconnected ]; then
/usr/bin/xrandr --auto
echo "${dmode}"
elif [ "${dmode}" = connected ];then
/usr/bin/xrandr --output eDP1 --mode 1920x1080 --pos 0x0 --output HDMI1 --mode 1920x1080 --pos 1920x0
echo "${dmode}"
else /usr/bin/xrandr --auto
echo "${dmode}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment