Skip to content
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

Wrong focus on platform windows on startup #7014

Open
smilediver opened this issue Nov 15, 2023 · 1 comment
Open

Wrong focus on platform windows on startup #7014

smilediver opened this issue Nov 15, 2023 · 1 comment

Comments

@smilediver
Copy link

If you start an application with already open platform ImGui windows, then these windows are opened on top of the main application window. As I understand, in ImGui::UpdatePlatformWindows() it tries hard to maintain initial focus on the main window using this:

            if (g.FrameCount < 3)
                viewport->Flags |= ImGuiViewportFlags_NoFocusOnAppearing;

So when these new windows are opened on top of the main window, the actual main window remains focused. At this point ImGui correctly treats external windows as being on top. But when you bring the main window to the top above those platform windows there's no event (since main window already has focus), so ImGui doesn't know that and still thinks that external windows are on top of it. And at this point if you're trying to interact with ImGui in main window, you end up interacting with the ImGui in platform windows below the main window. If you focus one of the platform windows and focus back on the main window then everything fixes itself.

Removing above code snippet fixes the issue.

Repro steps:

  • Start example_glfw_opengl3 (tested on macOS, but I get the same behavior on Windows with my app too)
  • Move the demo window outside the main window so it creates a new platform window. But leave it overlapping with the main window.
  • Restart the app, so it opens with demo window outside the main window from the start.
  • Optional: example_glfw_opengl3 already brings main window to the top, but for other apps you can bring it manually.
  • Move mouse above main window and see that it interacts with the demo window bellow it.
  • Focus demo window and then back to the main window.
  • See that this problem is gone now.

Video of above scenario after the example_glfw_opengl3 was just started:

imgui_wrong_focus_on_startup

Version: v1.89.9-docking
Branch: docking
Running example_glfw_opengl3 on macOS.

@ocornut
Copy link
Owner

ocornut commented Feb 12, 2024

I believe that code:

if (g.FrameCount < 3)
viewport->Flags |= ImGuiViewportFlags_NoFocusOnAppearing;

Tangentially relates to #2304, if we had better control over imgui-windows focus restore, it would likely be easier to restore platform-focus appropriately instead of doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants