From d10f033439e712bfb536e0a61ecaefe91d338a4e Mon Sep 17 00:00:00 2001 From: WerWolv Date: Fri, 2 Jun 2023 14:43:45 +0200 Subject: [PATCH] fix: Key presses not always unlocking frame rate correctly --- main/include/window.hpp | 2 +- main/source/window/window.cpp | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/main/include/window.hpp b/main/include/window.hpp index 6472c9885..186f9ce53 100644 --- a/main/include/window.hpp +++ b/main/include/window.hpp @@ -61,7 +61,7 @@ namespace hex { std::list m_popupsToOpen; std::vector m_pressedKeys; - bool m_mouseButtonDown = false; + bool m_buttonDown = false; bool m_hadEvent = false; bool m_frameRateTemporarilyUnlocked = false; diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index a756b6b92..9b9e99f30 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -170,7 +170,7 @@ namespace hex { bool frameRateUnlocked = ImGui::IsPopupOpen(ImGuiID(0), ImGuiPopupFlags_AnyPopupId) || TaskManager::getRunningTaskCount() > 0 || - this->m_mouseButtonDown || + this->m_buttonDown || this->m_hadEvent || !this->m_pressedKeys.empty(); @@ -830,9 +830,9 @@ namespace hex { auto win = static_cast(glfwGetWindowUserPointer(window)); if (action == GLFW_PRESS) - win->m_mouseButtonDown = true; + win->m_buttonDown = true; else if (action == GLFW_RELEASE) - win->m_mouseButtonDown = false; + win->m_buttonDown = false; win->processEvent(); }); @@ -848,17 +848,24 @@ namespace hex { glfwSetKeyCallback(this->m_window, [](GLFWwindow *window, int key, int scancode, int action, int mods) { hex::unused(mods); + auto win = static_cast(glfwGetWindowUserPointer(window)); + + if (action == GLFW_RELEASE) { + win->m_buttonDown = false; + } else { + win->m_buttonDown = true; + } + if (key == GLFW_KEY_UNKNOWN) return; auto keyName = glfwGetKeyName(key, scancode); if (keyName != nullptr) key = std::toupper(keyName[0]); - auto win = static_cast(glfwGetWindowUserPointer(window)); - if (action == GLFW_PRESS || action == GLFW_REPEAT) { win->m_pressedKeys.push_back(key); } + win->processEvent(); });