Opening a popup when clicking in a window will not trigger IsItemDeactivated on a widget that was active in another window.
The same thing happens when calling SetWindowFocus instead of opening a popup.
Interesting to note is, that this only happens when checking for IsMouseClicked(ImGuiMouseButton_Right) but NOT for ImGuiMouseButton_Left.
{ //Note the comment at the bottom about window order
ImGui::Begin("Main");
static int cnt = 0;
ImGui::Text("Deactivated count: %d", cnt);
//Always make this textbox active before clicking into one of the test windows below.
//When clicking the windows, the textbox becomes inactive and 'Deactivated count' should increment.
//For the two 'BAD' windows, the textbox becomes inactive but the count does not increment
static char buf[256] = { 0 };
ImGui::InputText("MyText", buf, sizeof(buf));
if (ImGui::IsItemDeactivated()) {
cnt++;
}
ImGui::End();
}
bool openPopup = false;
ImGui::Begin("Left_Popup_OK"); //OK
if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
openPopup = true;
ImGui::End();
ImGui::Begin("Left_Focus_OK"); //OK
if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left))
ImGui::SetWindowFocus();
ImGui::End();
ImGui::Begin("Right_Popup_BAD"); //BAD
if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right))
openPopup = true;
ImGui::End();
ImGui::Begin("Right_Focus_BAD"); //BAD
if (ImGui::IsWindowHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right))
ImGui::SetWindowFocus();
ImGui::End();
//Open/Begin popup here or directly inside the windows, makes no difference
if (openPopup)
ImGui::OpenPopup("MyPopup");
if (ImGui::BeginPopup("MyPopup")) {
ImGui::Text("Popup");
ImGui::EndPopup();
}
//Moving the code for window 'Main' down here resolves the issue.
//Not always an option or hard to keep track of and ensure in complex applications
What's curious to me is the fact that it seems like ImGui does indeed handle windows stealing focus correctly, just not on 'right' mouse clicks. But why would the mouse button matter?
Also note that this only happens when the test window's code comes AFTER the window the contains the widget in question.
Reordering the windows is not always an option and one could easily imagine a scenario where two windows both contain IsItemDeactivated widgets as well as context menus.
Version/Branch of Dear ImGui:
Version 1.90.6 (19052), Branch: docking (master/docking/etc.)
Back-ends:
imgui_impl_win32.cpp + imgui_impl_opengl3.cpp
Compiler, OS:
Visual Studio 2022 MSVC C++ 20
Full config/build information:
Details:
Opening a popup when clicking in a window will not trigger
IsItemDeactivated
on a widget that was active in another window. The same thing happens when callingSetWindowFocus
instead of opening a popup. Interesting to note is, that this only happens when checking forIsMouseClicked(ImGuiMouseButton_Right)
but NOT forImGuiMouseButton_Left
.What's curious to me is the fact that it seems like ImGui does indeed handle windows stealing focus correctly, just not on 'right' mouse clicks. But why would the mouse button matter? Also note that this only happens when the test window's code comes AFTER the window the contains the widget in question. Reordering the windows is not always an option and one could easily imagine a scenario where two windows both contain
IsItemDeactivated
widgets as well as context menus.Screenshots/Video:
No response
Minimal, Complete and Verifiable Example code:
No response