From 9eebd37b592826d91c5a90564093423c88bd4594 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 16 Jan 2026 16:26:19 +0100 Subject: [PATCH] Viewports: update LastFocusedStampCount earlier. Fix (#8948, #9172, #9131, #9128) but probably have other side effects too. Amend f1ae07e532. Initial value of LastFocusedStampCount was set at the time of platform ShowWindow which is too late for first-frame UpdateTryMergeWindowIntoHostViewport() evaluation. --- docs/CHANGELOG.txt | 8 ++++++-- imgui.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index c5ab8cc83..f340284a9 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -210,9 +210,13 @@ Other Changes: Docking+Viewports Branch: -- Fixed an assert in background dimming code, which could trigger after using - gamepad/keyboard to move a window to another viewport. (#9053) [@lut0pia, @ocornut] - Fixed implicit/fallback "Debug" window from staying visible if once docked. (#9151) +- Viewports: + - Fixed a regression in 1.92.4 which could cause combos/popups window from + appearing under their parent viewport if their geometry overlapped the main + viewport. (#8948, #9172, #9131, #9128) + - Fixed an assert in background dimming code, which could trigger after using + gamepad/keyboard to move a window to another viewport. (#9053) [@lut0pia, @ocornut] - Backends: - GLFW: dynamically load X11 functions to avoid -lx11 linking requirement introduced in 1.92.3. (#9116, #9109) [@ramenguy99] diff --git a/imgui.cpp b/imgui.cpp index 6a829fdbb..4ddc2730e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -16989,6 +16989,10 @@ ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const g.ViewportCreatedCount++; IMGUI_DEBUG_LOG_VIEWPORT("[viewport] Add Viewport %08X '%s'\n", id, window ? window->Name : ""); + // We assume the window becomes front-most (even when ImGuiViewportFlags_NoFocusOnAppearing is used). + // This is useful for our platform z-order heuristic when io.MouseHoveredViewport is not available. + viewport->LastFocusedStampCount = ++g.ViewportFocusedStampCount; + // We normally setup for all viewports in NewFrame() but here need to handle the mid-frame creation of a new viewport. // We need to extend the fullscreen clip rect so the OverlayDrawList clip is correct for that the first frame g.DrawListSharedData.ClipRectFullscreen.x = ImMin(g.DrawListSharedData.ClipRectFullscreen.x, viewport->Pos.x); @@ -17363,11 +17367,6 @@ void ImGui::UpdatePlatformWindows() // Show window g.PlatformIO.Platform_ShowWindow(viewport); - - // Even without focus, we assume the window becomes front-most. - // This is useful for our platform z-order heuristic when io.MouseHoveredViewport is not available. - if (viewport->LastFocusedStampCount != g.ViewportFocusedStampCount) - viewport->LastFocusedStampCount = ++g.ViewportFocusedStampCount; } // Clear request flags