fix: Shortcuts not working in detached windows

This commit is contained in:
WerWolv
2025-01-17 12:39:55 +01:00
parent ff66b97e90
commit b6ade8b101
2 changed files with 28 additions and 14 deletions

View File

@@ -59,7 +59,7 @@ namespace hex {
std::mutex m_popupMutex;
std::list<std::string> m_popupsToOpen;
std::vector<int> m_pressedKeys;
std::set<int> m_pressedKeys;
std::atomic<bool> m_unlockFrameRate = false;

View File

@@ -874,19 +874,32 @@ namespace hex {
glfwSetWindowSize(m_window, width, height);
}
static const auto unlockFrameRate = [](GLFWwindow *, auto ...) {
auto win = static_cast<Window *>(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<Window *>(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<Window *>(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<Window *>(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<Window *>(glfwGetWindowUserPointer(window));
win->m_pressedKeys.push_back(key);
auto win = static_cast<Window *>(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());