Fix closing window when it loses focus.