XFCE4 fix panel across the middle of the screen

Sometimes when I disconnect my Xubuntu laptop from my second display, if I don’t give it time to redetect displays before closing it, the XFCE4 panel (menu bar) will appear across the middle of the screen, like so:


XFCE appears to see a ghost display for some reason. In fact, as I took the above screenshot, I saw that it saw 1748 pixels height instead of 1080. I have checked various possible reasons for that number but nothing made much sense so I don’t know what the window system is thinking here.

For a quick fix, just make X redetect your displays using:

xrandr --auto

The panel should now be back at its intended place. For a more permanent solution check my article on making a script that runs at login.