From ad78992e799509fc7d3cd7367d7f8ea4fc41bdb6 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 13 Oct 2025 04:29:38 -0400 Subject: [PATCH] Fix resetting cursor pos in cursorPosCallback() for non-integer pixelRatios. --- src/window/Window.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/window/Window.cpp b/src/window/Window.cpp index fa68657b..6d9bcf88 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -103,6 +103,8 @@ struct Window::Internal { double lastFrameDuration = NAN; math::Vec lastMousePos; + double lockedCursorPosX = 0.0; + double lockedCursorPosY = 0.0; std::map> fontCache; std::map> imageCache; @@ -167,13 +169,12 @@ static void cursorPosCallback(GLFWwindow* win, double xpos, double ypos) { math::Vec mouseDelta = mousePos.minus(APP->window->internal->lastMousePos); 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; + glfwSetCursorPos(win, APP->window->internal->lockedCursorPosX, APP->window->internal->lockedCursorPosY); + mousePos = math::Vec(APP->window->internal->lockedCursorPosX, APP->window->internal->lockedCursorPosY).div(APP->window->pixelRatio / APP->window->windowRatio).round(); } + APP->window->internal->lastMousePos = mousePos; + APP->event->handleHover(mousePos, mouseDelta); // Keyboard/mouse MIDI driver @@ -633,6 +634,7 @@ void Window::cursorLock() { // GLFW_CURSOR_DISABLED is buggy. // https://github.com/glfw/glfw/issues/2523 // So hide the cursor instead and reset mouse position in cursorPosCallback(). + glfwGetCursorPos(win, &internal->lockedCursorPosX, &internal->lockedCursorPosY); glfwSetInputMode(win, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); }