Calling wm_window_close() within handler code always seemed a bit
dangerous to me. In this case it causes use-after-free. Tried to simply
avoid accessing the dangling pointers but that's quite tricky and fragile.
For normal file window closing it basically works 'by luck'.
So idea is to delay window closing like we do it for workspace deletion,
screen change, etc. Unfortunately that implies that the file browser
windows still exists on save. This patch implements two ways to address
this (toggled with USE_WIN_REM_LIST_HACK):
- Skip windows scheduled for closing on file write. One ugly thing about this is that pointers to these windows may still be stored as they are still in the window list. Screen data of the windows is also still around and saved, we'd have to explicitly skip that too.
- [USE_WIN_REM_LIST_HACK defined] Schedules the window for closing and removes it from the window list. We may have to restore it temporarily if the window manager is free'd on file read.