diff --git a/main/gui/include/window.hpp b/main/gui/include/window.hpp index 9bc26a635..6e98656d0 100644 --- a/main/gui/include/window.hpp +++ b/main/gui/include/window.hpp @@ -59,7 +59,7 @@ namespace hex { std::mutex m_popupMutex; std::list m_popupsToOpen; - std::vector m_pressedKeys; + std::set m_pressedKeys; std::atomic m_unlockFrameRate = false; diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 0f744ea1d..0d6262ccc 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -874,19 +874,32 @@ namespace hex { glfwSetWindowSize(m_window, width, height); } + static const auto unlockFrameRate = [](GLFWwindow *, auto ...) { + auto win = static_cast(glfwGetWindowUserPointer(ImHexApi::System::getMainWindowHandle())); + if (win == nullptr) + return; + + win->m_unlockFrameRate = true; + }; + + static const auto isMainWindow = [](GLFWwindow *window) { + return window == ImHexApi::System::getMainWindowHandle(); + }; + // Register window move callback glfwSetWindowPosCallback(m_window, [](GLFWwindow *window, int x, int y) { - ImHexApi::System::impl::setMainWindowPosition(x, y); + unlockFrameRate(window); - auto win = static_cast(glfwGetWindowUserPointer(window)); - win->m_unlockFrameRate = true; - win->fullFrame(); + if (!isMainWindow(window)) return; + + ImHexApi::System::impl::setMainWindowPosition(x, y); }); // Register window resize callback glfwSetWindowSizeCallback(m_window, [](GLFWwindow *window, [[maybe_unused]] int width, [[maybe_unused]] int height) { - auto win = static_cast(glfwGetWindowUserPointer(window)); - win->m_unlockFrameRate = true; + unlockFrameRate(window); + + if (!isMainWindow(window)) return; #if !defined(OS_WINDOWS) if (!glfwGetWindowAttrib(window, GLFW_ICONIFIED)) @@ -903,11 +916,6 @@ namespace hex { #endif }); - static const auto unlockFrameRate = [](GLFWwindow *window, auto ...) { - auto win = static_cast(glfwGetWindowUserPointer(window)); - win->m_unlockFrameRate = true; - }; - glfwSetCursorPosCallback(m_window, unlockFrameRate); glfwSetMouseButtonCallback(m_window, unlockFrameRate); glfwSetScrollCallback(m_window, unlockFrameRate); @@ -971,14 +979,18 @@ namespace hex { } #endif - auto win = static_cast(glfwGetWindowUserPointer(window)); - win->m_pressedKeys.push_back(key); + auto win = static_cast(glfwGetWindowUserPointer(ImHexApi::System::getMainWindowHandle())); + win->m_pressedKeys.insert(key); } } }); // Register window close callback glfwSetWindowCloseCallback(m_window, [](GLFWwindow *window) { + unlockFrameRate(window); + + if (!isMainWindow(window)) return; + EventWindowClosing::post(window); }); @@ -1140,6 +1152,8 @@ namespace hex { ImGui_ImplOpenGL3_Init("#version 130"); #endif + ImGui_ImplGlfw_SetCallbacksChainForAllWindows(true); + for (const auto &plugin : PluginManager::getPlugins()) plugin.setImGuiContext(ImGui::GetCurrentContext());