impr: Unfocus ImGui windows when main window loses focus
This commit is contained in:
parent
64d147bf96
commit
a6f4d0cdec
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user