Skip to content

Popups opened from another popup are immediately closed since 1.89.5 #6462

@cfillion

Description

@cfillion

Version/Branch of Dear ImGui:

Version: 1.89.5 and 54c1ac3, OK in 1.89.4
Branch: docking

Back-end/Renderer/OS

Observed on:

  • macOS in example_apple_metal
  • macOS in example_sdl2_opengl3
  • macOS, Linux and Windows in custom backends

Not happening on:

  • macOS in example_glfw_opengl3
  • Windows in example_win32_directx10 (EDIT: unless disabling handling of ImGuiViewportFlags_NoFocusOnClick)

My Issue/Question:

When opening a second popup while another popup that has its own viewport is open, the new popup is closed before the user can interact with it.

There was a similar regression with modal popups however that has already been fixed in #6357. A similar issue remains for non-modal popups in some backends. I haven't found what other backends do differently focus-related to work properly.

It seems that (as expected) the OS gives focus back to the underlying window ('test') when the platform window of the first popup is destroyed and that triggers this line before the platform window of the second popup is created and shown:

imgui/imgui.cpp

Line 14022 in 2e810d5

FocusWindow(focused_viewport->Window, focus_request_flags);

[148347] [focus] SetNavWindow("test")
[148352] [popup] OpenPopup("first" -> 0xCA2DB483)
[148352] [popup] OpenPopupEx(0xCA2DB483)
[148353] [viewport] Add Viewport F94658BA '##Popup_ca2db483'
[148353] [focus] SetNavWindow("##Popup_ca2db483")
[148354] [viewport] Create Platform Window F94658BA '##Popup_ca2db483'
[148404] [popup] CloseCurrentPopup 0 -> 0
[148404] [popup] ClosePopupToLevel(0), restore_focus_to_window_under_popup=1
[148404] [focus] SetNavWindow("test")
[148404] [popup] OpenPopup("second" -> 0x37F95BFE)
[148404] [popup] OpenPopupEx(0x37F95BFE)
[148405] [viewport] Add Viewport 2322D768 '##Popup_37f95bfe'
[148405] [focus] SetNavWindow("##Popup_37f95bfe")
* Platform_DestroyWindow for "##Popup_ca2db483" (first) is called here *
[148406] [focus] SetNavWindow("test")
[148406] [popup] ClosePopupsOverWindow("test")
[148406] [popup] ClosePopupToLevel(0), restore_focus_to_window_under_popup=0
[148407] [viewport] Delete Viewport F94658BA '##Popup_ca2db483'
[148408] [viewport] Delete Viewport 2322D768 '##Popup_37f95bfe'

Screenshots/Video

Screencap

Standalone, minimal, complete and verifiable example:

if(ImGui::Begin("test")) {
  if(ImGui::BeginPopup("second")) {
    ImGui::Text("success!");
    ImGui::EndPopup();
  }

  bool open_edit_popup { false };
  if(ImGui::BeginPopup("first")) {
    if(ImGui::Button("open second"))
      open_edit_popup = true;
    ImGui::EndPopup();
  }
  if(open_edit_popup)
    ImGui::OpenPopup("second");

  if(ImGui::Button("open first"))
    ImGui::OpenPopup("first");
}
ImGui::End();

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions