@@ -13874,21 +13874,54 @@ static void ImGui::UpdateViewportsNewFrame()
13874
13874
IM_ASSERT(g.PlatformIO.Viewports.Size <= g.Viewports.Size);
13875
13875
13876
13876
// Update Minimized status (we need it first in order to decide if we'll apply Pos/Size of the main viewport)
13877
+ // Update Focused status
13877
13878
const bool viewports_enabled = (g.ConfigFlagsCurrFrame & ImGuiConfigFlags_ViewportsEnable) != 0;
13878
13879
if (viewports_enabled)
13879
13880
{
13881
+ ImGuiViewportP* focused_viewport = NULL;
13880
13882
for (int n = 0; n < g.Viewports.Size; n++)
13881
13883
{
13882
13884
ImGuiViewportP* viewport = g.Viewports[n];
13883
13885
const bool platform_funcs_available = viewport->PlatformWindowCreated;
13884
13886
if (g.PlatformIO.Platform_GetWindowMinimized && platform_funcs_available)
13885
13887
{
13886
- bool minimized = g.PlatformIO.Platform_GetWindowMinimized(viewport);
13887
- if (minimized )
13888
+ bool is_minimized = g.PlatformIO.Platform_GetWindowMinimized(viewport);
13889
+ if (is_minimized )
13888
13890
viewport->Flags |= ImGuiViewportFlags_IsMinimized;
13889
13891
else
13890
13892
viewport->Flags &= ~ImGuiViewportFlags_IsMinimized;
13891
13893
}
13894
+
13895
+ // Update our implicit z-order knowledge of platform windows, which is used when the backend cannot provide io.MouseHoveredViewport.
13896
+ // When setting Platform_GetWindowFocus, it is expected that the platform backend can handle calls without crashing if it doesn't have data stored.
13897
+ if (g.PlatformIO.Platform_GetWindowFocus && platform_funcs_available)
13898
+ {
13899
+ bool is_focused = g.PlatformIO.Platform_GetWindowFocus(viewport);
13900
+ if (is_focused)
13901
+ viewport->Flags |= ImGuiViewportFlags_IsFocused;
13902
+ else
13903
+ viewport->Flags &= ~ImGuiViewportFlags_IsFocused;
13904
+ if (is_focused)
13905
+ focused_viewport = viewport;
13906
+ }
13907
+ }
13908
+
13909
+ // Focused viewport has changed?
13910
+ if (focused_viewport && g.PlatformLastFocusedViewportId != focused_viewport->ID)
13911
+ {
13912
+ // Store a tag so we can infer z-order easily from all our windows
13913
+ // We compare PlatformLastFocusedViewportId so newly created viewports with _NoFocusOnAppearing flag
13914
+ // will keep the front most stamp instead of losing it back to their parent viewport.
13915
+ if (focused_viewport->LastFocusedStampCount != g.ViewportFocusedStampCount)
13916
+ focused_viewport->LastFocusedStampCount = ++g.ViewportFocusedStampCount;
13917
+ g.PlatformLastFocusedViewportId = focused_viewport->ID;
13918
+
13919
+ // Focus associated dear imgui window (#6299)
13920
+ // FIXME: perhaps 'FocusTopMostWindowUnderOne()' can handle both cases?
13921
+ if (focused_viewport->Window != NULL)
13922
+ FocusWindow(NavRestoreLastChildNavWindow(focused_viewport->Window));
13923
+ else
13924
+ FocusTopMostWindowUnderOne(NULL, NULL, focused_viewport);
13892
13925
}
13893
13926
}
13894
13927
@@ -14088,7 +14121,7 @@ ImGuiViewportP* ImGui::AddUpdateViewport(ImGuiWindow* window, ImGuiID id, const
14088
14121
viewport->Pos = pos;
14089
14122
if (!viewport->PlatformRequestResize || viewport->ID == IMGUI_VIEWPORT_DEFAULT_ID)
14090
14123
viewport->Size = size;
14091
- viewport->Flags = flags | (viewport->Flags & ImGuiViewportFlags_IsMinimized); // Preserve existing flags
14124
+ viewport->Flags = flags | (viewport->Flags & ( ImGuiViewportFlags_IsMinimized | ImGuiViewportFlags_IsFocused) ); // Preserve existing flags
14092
14125
}
14093
14126
else
14094
14127
{
@@ -14472,38 +14505,6 @@ void ImGui::UpdatePlatformWindows()
14472
14505
// Clear request flags
14473
14506
viewport->ClearRequestFlags();
14474
14507
}
14475
-
14476
- // Update our implicit z-order knowledge of platform windows, which is used when the backend cannot provide io.MouseHoveredViewport.
14477
- // When setting Platform_GetWindowFocus, it is expected that the platform backend can handle calls without crashing if it doesn't have data stored.
14478
- // FIXME-VIEWPORT: We should use this information to also set dear imgui-side focus, allowing us to handle os-level alt+tab.
14479
- if (g.PlatformIO.Platform_GetWindowFocus != NULL)
14480
- {
14481
- ImGuiViewportP* focused_viewport = NULL;
14482
- for (int n = 0; n < g.Viewports.Size && focused_viewport == NULL; n++)
14483
- {
14484
- ImGuiViewportP* viewport = g.Viewports[n];
14485
- if (viewport->PlatformWindowCreated)
14486
- if (g.PlatformIO.Platform_GetWindowFocus(viewport))
14487
- focused_viewport = viewport;
14488
- }
14489
-
14490
- // Focused viewport has changed?
14491
- if (focused_viewport && g.PlatformLastFocusedViewportId != focused_viewport->ID)
14492
- {
14493
- // Store a tag so we can infer z-order easily from all our windows
14494
- // We compare PlatformLastFocusedViewportId so newly created viewports with _NoFocusOnAppearing flag
14495
- // will keep the front most stamp instead of losing it back to their parent viewport.
14496
- if (focused_viewport->LastFocusedStampCount != g.ViewportFocusedStampCount)
14497
- focused_viewport->LastFocusedStampCount = ++g.ViewportFocusedStampCount;
14498
- g.PlatformLastFocusedViewportId = focused_viewport->ID;
14499
-
14500
- // Focus associated dear imgui window (#6299)
14501
- if (focused_viewport->Window != NULL)
14502
- FocusWindow(NavRestoreLastChildNavWindow(focused_viewport->Window));
14503
- else
14504
- FocusTopMostWindowUnderOne(NULL, NULL, focused_viewport);
14505
- }
14506
- }
14507
14508
}
14508
14509
14509
14510
// This is a default/basic function for performing the rendering/swap of multiple Platform Windows.
@@ -19915,19 +19916,20 @@ void ImGui::DebugNodeViewport(ImGuiViewportP* viewport)
19915
19916
viewport->WorkOffsetMin.x, viewport->WorkOffsetMin.y, viewport->WorkOffsetMax.x, viewport->WorkOffsetMax.y,
19916
19917
viewport->PlatformMonitor, viewport->DpiScale * 100.0f);
19917
19918
if (viewport->Idx > 0) { SameLine(); if (SmallButton("Reset Pos")) { viewport->Pos = ImVec2(200, 200); viewport->UpdateWorkRect(); if (viewport->Window) viewport->Window->Pos = viewport->Pos; } }
19918
- BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s%s%s%s%s%s", viewport->Flags,
19919
+ BulletText("Flags: 0x%04X =%s%s%s%s%s%s%s%s%s%s%s%s%s ", viewport->Flags,
19919
19920
//(flags & ImGuiViewportFlags_IsPlatformWindow) ? " IsPlatformWindow" : "", // Omitting because it is the standard
19920
19921
(flags & ImGuiViewportFlags_IsPlatformMonitor) ? " IsPlatformMonitor" : "",
19922
+ (flags & ImGuiViewportFlags_IsMinimized) ? " IsMinimized" : "",
19923
+ (flags & ImGuiViewportFlags_IsFocused) ? " IsFocused" : "",
19921
19924
(flags & ImGuiViewportFlags_OwnedByApp) ? " OwnedByApp" : "",
19922
19925
(flags & ImGuiViewportFlags_NoDecoration) ? " NoDecoration" : "",
19923
19926
(flags & ImGuiViewportFlags_NoTaskBarIcon) ? " NoTaskBarIcon" : "",
19924
19927
(flags & ImGuiViewportFlags_NoFocusOnAppearing) ? " NoFocusOnAppearing" : "",
19925
19928
(flags & ImGuiViewportFlags_NoFocusOnClick) ? " NoFocusOnClick" : "",
19926
19929
(flags & ImGuiViewportFlags_NoInputs) ? " NoInputs" : "",
19927
19930
(flags & ImGuiViewportFlags_NoRendererClear) ? " NoRendererClear" : "",
19928
- (flags & ImGuiViewportFlags_TopMost) ? " TopMost" : "",
19929
- (flags & ImGuiViewportFlags_IsMinimized) ? " IsMinimized" : "",
19930
19931
(flags & ImGuiViewportFlags_NoAutoMerge) ? " NoAutoMerge" : "",
19932
+ (flags & ImGuiViewportFlags_TopMost) ? " TopMost" : "",
19931
19933
(flags & ImGuiViewportFlags_CanHostOtherWindows) ? " CanHostOtherWindows" : "");
19932
19934
for (int layer_i = 0; layer_i < IM_ARRAYSIZE(viewport->DrawDataBuilder.Layers); layer_i++)
19933
19935
for (int draw_list_i = 0; draw_list_i < viewport->DrawDataBuilder.Layers[layer_i].Size; draw_list_i++)
0 commit comments