fix: More window focus event issues

This commit is contained in:
WerWolv
2025-08-16 16:47:23 +02:00
parent 23085372a1
commit 8b72ea81c0
2 changed files with 20 additions and 24 deletions

View File

@@ -380,6 +380,26 @@ namespace hex {
ImHexApi::Fonts::getDefaultFont().push();
io.FontDefault = ImHexApi::Fonts::getDefaultFont();
{
static bool lastAnyWindowFocused = false;
bool anyWindowFocused = glfwGetWindowAttrib(m_window, GLFW_FOCUSED);
if (!anyWindowFocused) {
const auto platformIo = ImGui::GetPlatformIO();
for (auto *viewport : platformIo.Viewports) {
if (platformIo.Platform_GetWindowFocus(viewport)) {
anyWindowFocused = true;
break;
}
}
}
if (lastAnyWindowFocused != anyWindowFocused)
EventWindowFocused::post(anyWindowFocused);
lastAnyWindowFocused = anyWindowFocused;
}
// Start new ImGui Frame
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
@@ -397,12 +417,6 @@ 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);

View File

@@ -357,24 +357,6 @@ namespace hex::plugin::builtin {
if (ctx == nullptr)
return;
// 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;
}
#endif
if (ImGui::IsAnyItemHovered())
return;