fix dryrun logic
authorIan Kelling <ian@iankelling.org>
Sat, 22 Jun 2024 04:44:52 +0000 (00:44 -0400)
committerIan Kelling <ian@iankelling.org>
Sat, 22 Jun 2024 04:44:52 +0000 (00:44 -0400)
myx

diff --git a/myx b/myx
index f3aefe6bc82281807bb9c2598506f60966aba296..79b9fadb2134704194192b8081a98f13dc75ba94 100755 (executable)
--- a/myx
+++ b/myx
@@ -105,10 +105,13 @@ restart=false
 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
+}
 
 
 
@@ -157,17 +160,6 @@ elif (( target_x <= 1920 )); then
   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 ########
 
@@ -208,21 +200,32 @@ done
 
 ##### 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