From d2291df55190e2f070af2635863f47a96d378a52 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 21 Apr 2023 17:34:57 +0200 Subject: [PATCH] Viewports: Fixed setting focus from platform decoration from accidentally closing modals (#6299, #6357) + Fixed double-assignment static analyzer warning. # Conflicts: # imgui.cpp --- docs/CHANGELOG.txt | 4 +++- imgui.cpp | 7 ++++--- imgui_internal.h | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 7aafa9206..b2c9f6520 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -128,7 +128,9 @@ Other changes: Docking+Viewports Branch: -- Viewports: added void* ImGuiPlatformMonitor::PlatformHandle field (backend-dependant), +- Viewports: Fixed platform-side focus (e.g. Alt+Tab) from leading to accidental + closure of Modal windows. Regression from 1.89.5. (#6357, #6299) +- Viewports: Added void* ImGuiPlatformMonitor::PlatformHandle field (backend-dependant), for usage by user code. - Backends: SDL2: Update monitor list when receiving a display event. (#6348) Note however that SDL2 currently doesn't have an event for a DPI/Scaling change, diff --git a/imgui.cpp b/imgui.cpp index 4a39721e1..569c08ab0 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13957,12 +13957,13 @@ static void ImGui::UpdateViewportsNewFrame() // FIXME: perhaps 'FocusTopMostWindowUnderOne()' can handle the 'focused_window->Window != NULL' case as well. if (!IsAnyMouseDown()) { + ImGuiFocusRequestFlags focus_request_flags = ImGuiFocusRequestFlags_UnlessBelowModal | ImGuiFocusRequestFlags_RestoreFocusedChild; if (focused_viewport->Window != NULL) - FocusWindow(NavRestoreLastChildNavWindow(focused_viewport->Window)); + FocusWindow(focused_viewport->Window, focus_request_flags); else if (focused_viewport->LastFocusedHadNavWindow) - FocusTopMostWindowUnderOne(NULL, NULL, focused_viewport, ImGuiFocusRequestFlags_None); + FocusTopMostWindowUnderOne(NULL, NULL, focused_viewport, focus_request_flags); // Focus top most in viewport else - FocusWindow(NULL); + FocusWindow(NULL, focus_request_flags); // No window had focus last time viewport was focused } } if (focused_viewport) diff --git a/imgui_internal.h b/imgui_internal.h index a98e6e784..bd23b47f1 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1765,7 +1765,7 @@ struct ImGuiViewportP : public ImGuiViewport ImVec2 BuildWorkOffsetMin; // Work Area: Offset being built during current frame. Generally >= 0.0f. ImVec2 BuildWorkOffsetMax; // Work Area: Offset being built during current frame. Generally <= 0.0f. - ImGuiViewportP() { Window = NULL; Idx = -1; LastFrameActive = DrawListsLastFrame[0] = DrawListsLastFrame[1] = LastFocusedStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; LastFocusedHadNavWindow = false; PlatformMonitor = -1; Window = NULL; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); } + ImGuiViewportP() { Window = NULL; Idx = -1; LastFrameActive = DrawListsLastFrame[0] = DrawListsLastFrame[1] = LastFocusedStampCount = -1; LastNameHash = 0; Alpha = LastAlpha = 1.0f; LastFocusedHadNavWindow = false; PlatformMonitor = -1; DrawLists[0] = DrawLists[1] = NULL; LastPlatformPos = LastPlatformSize = LastRendererSize = ImVec2(FLT_MAX, FLT_MAX); } ~ImGuiViewportP() { if (DrawLists[0]) IM_DELETE(DrawLists[0]); if (DrawLists[1]) IM_DELETE(DrawLists[1]); } void ClearRequestFlags() { PlatformRequestClose = PlatformRequestMove = PlatformRequestResize = false; }