nativefiledialog icon indicating copy to clipboard operation
nativefiledialog copied to clipboard

Fix modal disable/enable behavior on Win32

Open theOtherMichael opened this issue 2 years ago • 0 comments

This PR fixes the modal behavior of native file dialogs on Win32. Previously, opening a native file dialog would leave the calling window enabled. This is not how NFD behaves on macOS, though I do not know how it behaves on Linux.

More importantly, this issue exposes folks with immediate-mode GUI libraries like Dear ImGui to crashes on Windows. If you use WM_SIZING messages or similar to redraw an immediate mode GUI, but an NFD is open because of a call from the GUI, then a user can break things by resizing the calling window with an NFD still open. Dear ImGui, at least, does not support recursive UI rendering.

This fix simply passes the calling window handle to fileOpenDialog->Show(), which it gets from GetActiveWindow(). If GetActiveWindow() can't get a handle, it returns NULL anyways, so this change should not negatively impact existing projects. If anyone prefers to avoid disabling the base window when opening an NFD, then I'd argue that should be an API change, because again, this is the default behavior for NFD on macOS.

I tested this with Clang and MSVC on Win32.

theOtherMichael avatar Jul 25 '22 19:07 theOtherMichael