Selaa lähdekoodia

Viewports: Fixed setting focus from platform decoration from accidentally closing modals (#6299, #6357)

+ Fixed double-assignment static analyzer warning.

# Conflicts:
#	imgui.cpp
ocornut 2 vuotta sitten
vanhempi
commit
d2291df551
3 muutettua tiedostoa jossa 8 lisäystä ja 5 poistoa
  1. 3 1
      docs/CHANGELOG.txt
  2. 4 3
      imgui.cpp
  3. 1 1
      imgui_internal.h

+ 3 - 1
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,

+ 4 - 3
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)

+ 1 - 1
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; }