1
0
mirror of synced 2025-01-29 19:17:28 +01:00

impr: Unfocus ImGui windows when main window loses focus

This commit is contained in:
WerWolv 2024-02-03 23:56:08 +01:00
parent 64d147bf96
commit a6f4d0cdec
3 changed files with 29 additions and 0 deletions

View File

@ -219,6 +219,7 @@ namespace hex {
EVENT_DEF(EventAbnormalTermination, int);
EVENT_DEF(EventThemeChanged);
EVENT_DEF(EventOSThemeChanged);
EVENT_DEF(EventWindowFocused, bool);
/**
* @brief Called when the provider is created.

View File

@ -709,6 +709,10 @@ namespace hex {
win->m_unlockFrameRate = true;
});
glfwSetWindowFocusCallback(m_window, [](GLFWwindow *, int focused) {
EventWindowFocused::post(focused == GLFW_TRUE);
});
#if !defined(OS_WEB)
// Register key press callback
glfwSetInputMode(m_window, GLFW_LOCK_KEY_MODS, GLFW_TRUE);

View File

@ -228,6 +228,30 @@ namespace hex::plugin::builtin {
LocalizationManager::loadLanguage(it->second);
});
EventWindowFocused::subscribe([](bool focused) {
const auto ctx = ImGui::GetCurrentContext();
if (ctx == nullptr)
return;
// Get the currently focused window
const auto window = ctx->NavWindow;
if (window == nullptr)
return;
static ImGuiWindow *lastFocusedWindow = window;
if (focused) {
// If the main window gains focus again, restore the last focused window
ImGui::FocusWindow(lastFocusedWindow, ImGuiFocusRequestFlags_RestoreFocusedChild);
} else {
// If the main window loses focus, store the currently focused window
// and remove focus from it so it doesn't look like it's focused and
// cursor blink animations don't play
lastFocusedWindow = window;
ImGui::FocusWindow(nullptr);
}
});
fs::setFileBrowserErrorCallback([](const std::string& errMsg){
#if defined(NFD_PORTAL)
ui::PopupError::open(hex::format("hex.builtin.popup.error.file_dialog.portal"_lang, errMsg));