|
@@ -6545,19 +6545,31 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window)
|
|
|
if (popup_count_to_keep < g.OpenPopupStack.Size) // This test is not required but it allows to set a convenient breakpoint on the statement below
|
|
|
{
|
|
|
//IMGUI_DEBUG_LOG("ClosePopupsOverWindow(%s) -> ClosePopupToLevel(%d)\n", ref_window->Name, popup_count_to_keep);
|
|
|
- ClosePopupToLevel(popup_count_to_keep);
|
|
|
+ ClosePopupToLevel(popup_count_to_keep, false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void ImGui::ClosePopupToLevel(int remaining)
|
|
|
+void ImGui::ClosePopupToLevel(int remaining, bool apply_focus_to_window_under)
|
|
|
{
|
|
|
IM_ASSERT(remaining >= 0);
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
ImGuiWindow* focus_window = (remaining > 0) ? g.OpenPopupStack[remaining-1].Window : g.OpenPopupStack[0].ParentWindow;
|
|
|
- if (g.NavLayer == 0)
|
|
|
- focus_window = NavRestoreLastChildNavWindow(focus_window);
|
|
|
- FocusWindow(focus_window);
|
|
|
g.OpenPopupStack.resize(remaining);
|
|
|
+
|
|
|
+ // FIXME: This code is faulty and we may want to eventually to replace or remove the 'apply_focus_to_window_under=true' path completely.
|
|
|
+ // Instead of using g.OpenPopupStack[remaining-1].Window etc. we should find the highest root window that is behind the popups we are closing.
|
|
|
+ // The current code will set focus to the parent of the popup window which is incorrect.
|
|
|
+ // It rarely manifested until now because UpdateMouseMovingWindow() would call FocusWindow() again on the clicked window,
|
|
|
+ // leading to a chain of focusing A (clicked window) then B (parent window of the popup) then A again.
|
|
|
+ // However if the clicked window has the _NoMove flag set we would be left with B focused.
|
|
|
+ // For now, we have disabled this path when called from ClosePopupsOverWindow() because the users of ClosePopupsOverWindow() don't need to alter focus anyway,
|
|
|
+ // but we should inspect and fix this properly.
|
|
|
+ if (apply_focus_to_window_under)
|
|
|
+ {
|
|
|
+ if (g.NavLayer == 0)
|
|
|
+ focus_window = NavRestoreLastChildNavWindow(focus_window);
|
|
|
+ FocusWindow(focus_window);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Close the popup we have begin-ed into.
|
|
@@ -6569,7 +6581,7 @@ void ImGui::CloseCurrentPopup()
|
|
|
return;
|
|
|
while (popup_idx > 0 && g.OpenPopupStack[popup_idx].Window && (g.OpenPopupStack[popup_idx].Window->Flags & ImGuiWindowFlags_ChildMenu))
|
|
|
popup_idx--;
|
|
|
- ClosePopupToLevel(popup_idx);
|
|
|
+ ClosePopupToLevel(popup_idx, true);
|
|
|
|
|
|
// A common pattern is to close a popup when selecting a menu item/selectable that will open another window.
|
|
|
// To improve this usage pattern, we avoid nav highlight for a single frame in the parent window.
|
|
@@ -6636,7 +6648,7 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla
|
|
|
{
|
|
|
EndPopup();
|
|
|
if (is_open)
|
|
|
- ClosePopupToLevel(g.BeginPopupStack.Size);
|
|
|
+ ClosePopupToLevel(g.BeginPopupStack.Size, true);
|
|
|
return false;
|
|
|
}
|
|
|
return is_open;
|