From da47c366c70e71856277e74664529c24ac17e0f4 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Fri, 13 Nov 2009 17:56:17 +0100 Subject: [PATCH] run x-monitors twice Signed-off-by: Nico Schottelius --- x-monitors.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/x-monitors.sh b/x-monitors.sh index 0daa927..93ba297 100755 --- a/x-monitors.sh +++ b/x-monitors.sh @@ -32,12 +32,22 @@ main="$(cat ~/.x-monitors-main)" positions="left-of right-of above below" prefix=".x-monitors-" -# search for all possible monitors in all positions -for position in $positions; do - posfile="${HOME}/${prefix}${position}" - if [ -f "${posfile}" ]; then - while read output; do - xrandr --output "${output}" --${position} "${main}" --auto - done < "${posfile}" - fi +i=0 + +# Needs to run twice: xrandr may not be able to +# enable a newly connected monitor, because a disconnected one +# is still enabled. The first runs disables disconnected monitors, the +# second one enables all connected ones. +while [ "${i}" -lt 2 ]; do + # search for all possible monitors in all positions + for position in $positions; do + posfile="${HOME}/${prefix}${position}" + if [ -f "${posfile}" ]; then + while read output; do + xrandr --output "${output}" --${position} "${main}" --auto + done < "${posfile}" + fi + done + + i=$(($i+1)) done