From 260594af01c1d0cabc119f5703b8fa36a9872864 Mon Sep 17 00:00:00 2001
From: Salt <rehashedsalt@cock.li>
Date: Tue, 31 Jul 2018 15:35:18 -0500
Subject: [PATCH] wmstartup: Polish up, add waiting code Conky was getting
 stuck behind xfdesktop. This fixes that

---
 .config/dtfscripts/wmstartup.sh | 35 +++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/.config/dtfscripts/wmstartup.sh b/.config/dtfscripts/wmstartup.sh
index 5024fc30..b8b8440c 100755
--- a/.config/dtfscripts/wmstartup.sh
+++ b/.config/dtfscripts/wmstartup.sh
@@ -45,31 +45,38 @@ xset s off
 xrdbupdate
 
 ## SERVICES AND DAEMONS
+# Kill everything
 printf "[INFO] Killing existing daemons\n"
-services="sxhkd polybar conky dunst compton"
+services="xfdesktop polybar compton conky sxhkd dunst"
 for service in $services; do
 	printf "  [INFO] Killing $service\n"
 	killall $service
 done
+# Wait for them to die
 for service in $services; do
-	while pgrep $service; do
+	while pgrep $service > /dev/null 2>&1; do
+		printf "  [INFO] Waiting for $service to die\n"
 		sleep 0.5
 	done
 done
 # Wallpaper management
 # Note that this MUST happen before the compositor starts, otherwise xsetroot
 # will not apply properly
+wpm=feh
 if which xfdesktop > /dev/null 2>&1; then
 	printf "  [INFO] Starting xfdesktop\n"
-	xfdesktop&
+	wpm=xfdesktop
+	xfdesktop --disable-wm-check&
 elif which feh > /dev/null 2>&1; then
 	printf "  [INFO] Setting wallpaper with feh\n"
 	printf "  [WARN] This solution may cause problems on multi-monitor systems\n"
 	feh --randomize --bg-fill ~/Pictures/Wallpapers/.active &
 elif which xsetroot > /dev/null 2>&1; then
 	printf "  [INFO] Setting root window color\n"
+	wpm=xsetroot
 	xsetroot -solid "#282828"
 else
+	wpm=none
 	printf "  [WARN] Could not find any wallpaper manager\n"
 fi
 # Don't start the compositor in a VM
@@ -89,7 +96,27 @@ else
 fi
 # Start these all the time regardless of platform
 printf "[INFO] Starting platform-independent tasks\n"
-conky&
+printf "  [INFO] Starting dunst\n"
 dunst&
+printf "  [INFO] Starting conky\n"
+if [[ $wpm == "xfdesktop" ]]; then
+	printf "    [INFO] Waiting for xfdesktop to initialize\n"
+	if which xdotool > /dev/null 2>&1; then
+		i=0
+		until xdotool search --class "xfdesktop"; do
+			i=$(expr $i + 1)
+			if [[ $i -ge 10 ]]; then
+				printf "      [WARN] Grew too impatient!\n"
+				break
+			fi
+			sleep 1
+		done
+		unset i
+	else
+		printf "      [WARN] Could not find xdotool!\n"
+	fi
+	printf "    [INFO] Finished waiting\n"
+fi
+conky&
 printf "[INFO] Finished initialization\n"