From 0a805b5399ffaa825cebcebf8e0d99e70d1c4042 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 13 Oct 2025 04:06:51 -0400 Subject: [PATCH] Fix Window::cursorLock() delta again using new method. --- src/window/Window.cpp | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/window/Window.cpp b/src/window/Window.cpp index a5ee5452..fa68657b 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -98,7 +98,6 @@ struct Window::Internal { int lastWindowHeight = 0; int frame = 0; - double ignoreMouseDeltaUntil = -INFINITY; double monitorRefreshRate = 0.0; double frameTime = NAN; double lastFrameDuration = NAN; @@ -167,16 +166,13 @@ static void cursorPosCallback(GLFWwindow* win, double xpos, double ypos) { math::Vec mousePos = math::Vec(xpos, ypos).div(APP->window->pixelRatio / APP->window->windowRatio).round(); math::Vec mouseDelta = mousePos.minus(APP->window->internal->lastMousePos); - // if (glfwGetInputMode(win, GLFW_CURSOR) != GLFW_CURSOR_NORMAL && std::fabs(mouseDelta.y) > 20.0) { - // DEBUG("%d (%f, %f) (%f, %f)", APP->window->internal->frame, VEC_ARGS(mousePos), VEC_ARGS(mouseDelta)); - // } - - // Workaround for GLFW warping mouse to a different position when the cursor is locked or unlocked. - if (APP->window->internal->ignoreMouseDeltaUntil > APP->window->internal->frameTime) { - mouseDelta = math::Vec(); + if (glfwGetInputMode(win, GLFW_CURSOR) == GLFW_CURSOR_HIDDEN) { + math::Vec lastMousePos = APP->window->internal->lastMousePos; + glfwSetCursorPos(win, lastMousePos.x, lastMousePos.y); + } + else { + APP->window->internal->lastMousePos = mousePos; } - - APP->window->internal->lastMousePos = mousePos; APP->event->handleHover(mousePos, mouseDelta); @@ -634,14 +630,10 @@ void Window::cursorLock() { if (!settings::allowCursorLock) return; - glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_DISABLED); - - // Due to a bug in GLFW, setting GLFW_CURSOR_DISABLED causes a spurious mouse position delta after a few frames. + // GLFW_CURSOR_DISABLED is buggy. // https://github.com/glfw/glfw/issues/2523 - // Empirically, this seems to be up to 3-6 frames at 60 Hz but in fewer frames at lower framerates, so we use time units. -#if defined ARCH_MAC - internal->ignoreMouseDeltaUntil = internal->frameTime + 0.15; -#endif + // So hide the cursor instead and reset mouse position in cursorPosCallback(). + glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); }