[Hopefully] improve stability of window-change

I have the feeling it's a massive race condition, but I can't tell.