fix: Focus loss getting triggered when a popup was selected

This commit is contained in:
WerWolv 2025-08-15 17:29:49 +02:00
parent 9928439f4f
commit 1c54e7e38b
2 changed files with 25 additions and 14 deletions

View File

@ -376,8 +376,9 @@ namespace hex {
}
void Window::frameBegin() {
auto &io = ImGui::GetIO();
ImHexApi::Fonts::getDefaultFont().push();
ImGui::GetIO().FontDefault = ImHexApi::Fonts::getDefaultFont();
io.FontDefault = ImHexApi::Fonts::getDefaultFont();
// Start new ImGui Frame
ImGui_ImplOpenGL3_NewFrame();
@ -396,6 +397,12 @@ namespace hex {
EventFrameBegin::post();
static bool lastFocusLost = io.AppFocusLost;
if (io.AppFocusLost != lastFocusLost) {
EventWindowFocused::post(!io.AppFocusLost);
}
lastFocusLost = io.AppFocusLost;
// Handle all undocked floating windows
ImGuiViewport *viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->WorkPos);
@ -1127,11 +1134,7 @@ namespace hex {
glfwSetCursorPosCallback(m_window, unlockFrameRate);
glfwSetMouseButtonCallback(m_window, unlockFrameRate);
glfwSetScrollCallback(m_window, unlockFrameRate);
glfwSetWindowFocusCallback(m_window, [](GLFWwindow *window, int focused) {
unlockFrameRate(window);
EventWindowFocused::post(focused == GLFW_TRUE);
});
glfwSetWindowFocusCallback(m_window, unlockFrameRate);
glfwSetWindowMaximizeCallback(m_window, [](GLFWwindow *window, int) {
glfwShowWindow(window);

View File

@ -356,16 +356,24 @@ namespace hex::plugin::builtin {
if (ctx == nullptr)
return;
if (ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup)) {
for (const auto& popup : ctx->OpenPopupStack) {
if (!(popup.Window->Flags & ImGuiWindowFlags_Modal)) {
ctx->OpenPopupStack.erase_unsorted(&popup);
log::debug("Closing popup '{}' because the main window lost focus", popup.Window->Name ? popup.Window->Name : "Unknown Popup");
break;
// Close any open non-modal popups when ImHex loses focus
// Disable this in debug mode though to allow for easier debugging
#if !defined(DEBUG)
if (ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopup)) {
for (const auto& popup : ctx->OpenPopupStack) {
if (popup.Window == nullptr)
continue;
if (!(popup.Window->Flags & ImGuiWindowFlags_Modal)) {
ctx->OpenPopupStack.erase_unsorted(&popup);
log::debug("Closing popup '{}' because the main window lost focus", popup.Window->Name ? popup.Window->Name : "Unknown Popup");
break;
}
}
return;
}
return;
}
#endif
if (ImGui::IsAnyItemHovered())
return;