Unified popup closing logic (osx)