Fix window hiding regression, make it work for popups