xf=$(mktemp)
xrandr >$xf
-m() { printf "$script_name: %s\n" "$*"; "$@"; }
-if $dry_run; then
- m() { printf "$script_name: %s\n" "$*"; }
-fi
+m() {
+ if $dry_run; then
+ printf "$script_name: dry run: %s\n" "$*"
+ else
+ printf "$script_name: %s\n" "$*"; "$@"
+ fi
+}
tall=true
fi
-if $downres && (( target_x > 2560 )); then
- target_x=2560
- target_y=1440
- target_res=${target_x}x$target_y
-fi
-
-
-half_x=$(( target_x / 2 ))
-half_y=$(( target_y / 2 ))
-
-
##### begin command line parsing ########
##### end command line parsing ########
+
+if $downres && (( target_x > 2560 )); then
+ target_x=2560
+ target_y=1440
+ target_res=${target_x}x$target_y
+fi
+
+
+half_x=$(( target_x / 2 ))
+half_y=$(( target_y / 2 ))
+
+
for mon_suffix in TOP-LEFT BOTTOM-LEFT LEFT RIGHT; do
if xrandr --listmonitors | awk '$2 == "MON-'$mon_suffix\" |grep . >/dev/null; then
m xrandr --delmonitor MON-$mon_suffix
fi
done
+if [[ ! $secondary_out ]] || grep -A1 disconnected $xf | grep '^[[:space:]]'; then
+ # gets rid of leftover secondary
+ m xrandr --auto
+fi
-if [[ $secondary_out ]]; then
- if $restart; then
- m xrandr --output $secondary_out --off
- m sleep 2
- fi
-else
- # disables any leftover secondary.
- xrandr --auto
+if [[ $secondary_out ]] && $restart; then
+ m xrandr --output $secondary_out --off
+ m sleep 2
fi
if [[ $secondary_out || $primary_res != "$target_res" ]]; then