Skip to content

Instantly share code, notes, and snippets.

@Enygma2002
Enygma2002 / fixWindows.sh
Last active May 8, 2024 15:55
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 ]]