-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Popups opened from another popup are immediately closed since 1.89.5 #6462
Comments
I found the difference between my Windows backend and imgui_impl_win32.cpp: mine wasn't handling Issue can be duplicated with imgui_impl_win32.cpp after commenting out its handling of Preventing focus isn't reliable everywhere (could be focused externally, on X11 it's only a hint to the window manager, plus I'm dealing with a parent application whose UI toolkit forces focus on click on Linux). |
Partial workaround for ocornut/imgui#6462 GDK SWELL's GetFocus() implementation is hard-coded to change on click so this does not the fix the issue above on Linux. https://github.com/justinfrankel/WDL/blob/6a7ba42ab175a859c565c4f68b890048d53b94c7/WDL/swell/swell-generic-gdk.cpp#LL1440C9-L1440C9
Thank you for the investigation and repro and report. Will be looking at this now. |
Here is a slightly different repro which showcase how it isn't specifically a The issue happens when the first window (or popup in your version) is destroyed, giving platform focus back to main viewport before the new one has a chance to appear. In my version the bug happens even if the backend handles
If popup B is opened over window A, focusing window A would normally close the popup. While I think this one specific issue probably has a specific resolution, which I am looking for, we could potentially decide to make imgui-focus-on-platform-focus an operation with less side-effects by deciding to not close popups, which would be a non-confident way of reducing the scope of work done since #6299. Not entirely opposed to it as it seems like this is can of worm. I'm certainly glad we now have this Debug Log to help. I started adding some basic platform-focus-emulation in tests for viewports (see "viewport_platform_focus" in test suite https://github.com/ocornut/imgui_test_engine/blob/main/imgui_test_suite/imgui_tests_viewports.cpp#L170) recently so the least I can do here would be to try emulating this issue in a platform agnostic way. if (ImGui::Begin("test"))
{
static bool open_window_1 = false;
if (ImGui::BeginPopup("second"))
{
ImGui::Text("success!");
ImGui::EndPopup();
}
bool open_edit_popup = false;
if (open_window_1 && ImGui::Begin("First"))
{
if (ImGui::Button("open second"))
{
open_edit_popup = true;
open_window_1 = false;
}
ImGui::End();
}
if (open_edit_popup)
ImGui::OpenPopup("second");
if (ImGui::Button("open first"))
open_window_1 = true;
}
ImGui::End(); |
Hello, I have pushed 3418d50 which I think should fix this problem, as well as a test for it. Thanks! |
…ewport is destroyed + TestSuite: added "viewport_platform_focus_3". Without support in imgui_app the test would succeed prior to fix due to reason explained in ocornut/imgui#6462 TestSuite: other fixes for viewport support of test suite.
Thank you! Fix works perfectly. I've tested with example_apple_metal & example_sdl2_opengl3 on macOS and my backend on all platforms (macOS/Linux/Windows/wine).
I like that popup-closing behavior, it behaves like native widget toolkits. My backend builds upon that by clearing ImGui focus when a non-imgui (or different context's) window gains it. Popups are closed, active item cleared (like #6467) and titlebar visibly unfocused. void onFocusLossAllImGuiPlatformWindowsInContext()
{
if(ImGui::GetTopMostPopupModal())
ImGui::ClearActiveID();
else
ImGui::FocusWindow(nullptr);
} Usecase 1: imgui popup auto-closing when focusing anything else in or outside the application: Usecase 2: imgui window losing focus and clearing active item to mimick a native window: |
Version/Branch of Dear ImGui:
Version: 1.89.5 and 54c1ac3, OK in 1.89.4
Branch: docking
Back-end/Renderer/OS
Observed on:
Not happening on:
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
Screenshots/Video
Standalone, minimal, complete and verifiable example:
The text was updated successfully, but these errors were encountered: