Skip to content

Commit 6bc5266

Browse files
committed
Viewports: Comments, removed unnecessary use of ViewportFrontMostStampCount (the LastFrontMostStampCount is enough)
1 parent e230ec5 commit 6bc5266

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

imgui.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -3493,7 +3493,7 @@ void ImGui::UpdateMouseMovingWindowNewFrame()
34933493
g.MouseViewport = moving_window->Viewport;
34943494

34953495
// Clear the NoInput window flag set by the Viewport system
3496-
moving_window->Viewport->Flags &= ~ImGuiViewportFlags_NoInputs;
3496+
moving_window->Viewport->Flags &= ~ImGuiViewportFlags_NoInputs; // FIXME-VIEWPORT: Test engine managed to crash here because Viewport was NULL.
34973497

34983498
ClearActiveID();
34993499
g.MovingWindow = NULL;
@@ -11523,6 +11523,7 @@ void ImGui::UpdatePlatformWindows()
1152311523

1152411524
// Update our implicit z-order knowledge of platform windows, which is used when the back-end cannot provide io.MouseHoveredViewport.
1152511525
// When setting Platform_GetWindowFocus, it is expected that the platform back-end can handle calls without crashing if it doesn't have data stored.
11526+
// FIXME-VIEWPORT: We should use this information to also set dear imgui-side focus, allowing us to handle os-level alt+tab.
1152611527
if (g.PlatformIO.Platform_GetWindowFocus != NULL)
1152711528
{
1152811529
ImGuiViewportP* focused_viewport = NULL;
@@ -11533,12 +11534,10 @@ void ImGui::UpdatePlatformWindows()
1153311534
if (g.PlatformIO.Platform_GetWindowFocus(viewport))
1153411535
focused_viewport = viewport;
1153511536
}
11536-
if (focused_viewport && g.PlatformLastFocusedViewport != focused_viewport->ID)
11537-
{
11538-
if (focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount)
11539-
focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount;
11540-
g.PlatformLastFocusedViewport = focused_viewport->ID;
11541-
}
11537+
11538+
// Store a tag so we can infer z-order easily from all our windows
11539+
if (focused_viewport && focused_viewport->LastFrontMostStampCount != g.ViewportFrontMostStampCount)
11540+
focused_viewport->LastFrontMostStampCount = ++g.ViewportFrontMostStampCount;
1154211541
}
1154311542
}
1154411543

imgui_internal.h

-2
Original file line numberDiff line numberDiff line change
@@ -1353,7 +1353,6 @@ struct ImGuiContext
13531353
ImGuiViewportP* CurrentViewport; // We track changes of viewport (happening in Begin) so we can call Platform_OnChangedViewport()
13541354
ImGuiViewportP* MouseViewport;
13551355
ImGuiViewportP* MouseLastHoveredViewport; // Last known viewport that was hovered by mouse (even if we are not hovering any viewport any more) + honoring the _NoInputs flag.
1356-
ImGuiID PlatformLastFocusedViewport; // Record of last focused platform window/viewport, when this changes we stamp the viewport as front-most
13571356
int ViewportFrontMostStampCount; // Every time the front-most window changes, we stamp its viewport with an incrementing counter
13581357

13591358
// Gamepad/keyboard Navigation
@@ -1558,7 +1557,6 @@ struct ImGuiContext
15581557
CurrentDpiScale = 0.0f;
15591558
CurrentViewport = NULL;
15601559
MouseViewport = MouseLastHoveredViewport = NULL;
1561-
PlatformLastFocusedViewport = 0;
15621560
ViewportFrontMostStampCount = 0;
15631561

15641562
NavWindow = NULL;

0 commit comments

Comments
 (0)