From 0c079e453bf74acebc6c8b4f64c4fa40e76af760 Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 26 Mar 2025 22:59:14 +0100 Subject: [PATCH] Backends: Win32: Viewports: fixed an issue when closing a window from the OS close button (with io.ConfigViewportsNoDecoration=false) while user code is discarding the 'bool *p_open=false output' from Begin() --- backends/imgui_impl_win32.cpp | 5 +++-- docs/CHANGELOG.txt | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp index f5939e854..238346a29 100644 --- a/backends/imgui_impl_win32.cpp +++ b/backends/imgui_impl_win32.cpp @@ -23,6 +23,7 @@ // CHANGELOG // (minor and older changes stripped away, please see git history for details) // 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface. +// 2025-03-26: [Docking] Viewports: fixed an issue when closing a window from the OS close button (with io.ConfigViewportsNoDecoration = false) while user code was discarding the 'bool* p_open = false' output from Begin(). Because we allowed the Win32 window to close early, Windows destroyed it and our imgui window became not visible even though user code was still submitting it. // 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468) // 2025-02-21: [Docking] WM_SETTINGCHANGE's SPI_SETWORKAREA message also triggers a refresh of monitor list. (#8415) // 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support. @@ -1357,14 +1358,14 @@ static LRESULT CALLBACK ImGui_ImplWin32_WndProcHandler_PlatformWindow(HWND hWnd, ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(ctx); LRESULT result = 0; if (ImGui_ImplWin32_WndProcHandlerEx(hWnd, msg, wParam, lParam, io)) - result = true; + result = 1; else if (ImGuiViewport* viewport = ImGui_ImplWin32_FindViewportByPlatformHandle(platform_io, hWnd)) { switch (msg) { case WM_CLOSE: viewport->PlatformRequestClose = true; - break; + return 0; // 0 = Operating system will ignore the message and not destroy the window. We close ourselves. case WM_MOVE: viewport->PlatformRequestMove = true; break; diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 3ef5c93f7..e646d7706 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -48,6 +48,15 @@ Other changes: - Style, InputText: added ImGuiCol_InputTextCursor to configure color of the InputText cursor/caret. (#7031) +Docking+Viewports Branch: + +- Backends: Win32: Viewports: fixed an issue when closing a window from + the OS close button (with io.ConfigViewportsNoDecoration=false) while + user code is discarding the 'bool *p_open=false output' from Begin(). + Because we allowed the Win32 window to close early, Windows destroyed + it and our imgui window became not visible even though user code was + still submitting it. + ----------------------------------------------------------------------- VERSION 1.91.9b (Released 2025-03-17)