From 99ba47a5541e60806332b9cdf4080db3132b6f41 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 27 Dec 2023 21:23:54 +0100 Subject: [PATCH] impr: Even less laggy UI --- main/gui/source/window/window.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index 5c568cd33..72a09170f 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -177,7 +177,7 @@ namespace hex { static i32 lockTimeout = 0; if (!shouldLongSleep) { - lockTimeout = ImHexApi::System::getTargetFPS() / 2; + lockTimeout = (1.0 / m_lastFrameTime); } else if (lockTimeout > 0) { lockTimeout -= 1; } @@ -1043,6 +1043,8 @@ namespace hex { if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) return; auto win = static_cast(glfwGetWindowUserPointer(window)); + win->m_unlockFrameRate = true; + win->frameBegin(); win->frame(); win->frameEnd(); @@ -1056,11 +1058,20 @@ namespace hex { if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) return; auto win = static_cast(glfwGetWindowUserPointer(window)); + win->m_unlockFrameRate = true; + win->frameBegin(); win->frame(); win->frameEnd(); }); + glfwSetCursorPosCallback(m_window, [](GLFWwindow *window, double, double) { + if (auto g = ImGui::GetCurrentContext(); g == nullptr || g->WithinFrameScope) return; + + auto win = static_cast(glfwGetWindowUserPointer(window)); + win->m_unlockFrameRate = true; + }); + #if !defined(OS_WEB) // Register key press callback glfwSetKeyCallback(m_window, [](GLFWwindow *window, int key, int scanCode, int action, int mods) { @@ -1088,6 +1099,7 @@ namespace hex { key != GLFW_KEY_LEFT_SUPER && key != GLFW_KEY_RIGHT_SUPER ) { auto win = static_cast(glfwGetWindowUserPointer(window)); + win->m_unlockFrameRate = true; win->m_pressedKeys.push_back(key); } }