Restructure atexit machinery so there is no final wait if no window or activated display