Skip to content

Instantly share code, notes, and snippets.

@Enygma2002
Last active May 8, 2024 15:55
Show Gist options
  • Save Enygma2002/c50eb108f1d8cb6b1963d75ae024000b to your computer and use it in GitHub Desktop.
Save Enygma2002/c50eb108f1d8cb6b1963d75ae024000b to your computer and use it in GitHub Desktop.
Fix disappearing WSL2 X11 windows after resuming from suspend or hibernate (or due to network changes). Workaround for https://github.com/microsoft/wslg/issues/1098 potentially fixed in WSL version 2.2.3. This script filters out smaller windows and without a clear associated PID so that only the user-relevant windows are fixed.
#!/usr/bin/bash
sx=30
sy=30
for window in $(xdotool search -name .)
do
echo
xdotool getwindowgeometry $window
echo "Name: $(xdotool getwindowname $window)"
PID=$(xdotool getwindowpid $window)
if [[ ! $PID -gt 0 ]] || [[ $(xdotool getwindowgeometry $window | grep Geometry | cut -f4 -d" " | cut -f1 -d"x") -lt 300 ]]
then
echo "[!] Skipping"
continue
fi
echo "PID: $PID"
echo "[v] Fixing..."
xdotool windowmove $window $sx $sy
xdotool windowunmap $window
xdotool windowmap $window
sx=$(($sx + 40))
sy=$(($sy + 40))
done
# inspiration: https://superuser.com/questions/1789454/disappearing-windows-now-in-wslg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment