From 95df61e5ede8c7fb61d00a773497b9c95c96e22f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Sun, 12 Sep 2021 17:15:59 +0200 Subject: [PATCH] Cocoa: Fix unresponsive cursor after cursor warp This is a companion to 157ebb80aafe263b86fd450f21a193f0412fb717 and fixes the same issue for calls to glfwSetCursorPos. Related to #1962 (cherry picked from commit 6ed5294223fec513c3b1e95f1857b3104e2e9b86) --- README.md | 2 ++ src/cocoa_window.m | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5cb6d958..a83506a0 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,8 @@ information on what to include when reporting a bug. - [Win32] Bugfix: Compilation with LLVM for Windows failed (#1807,#1824,#1874) - [Cocoa] Bugfix: The MoltenVK layer contents scale was updated only after related events were emitted + - [Cocoa] Bugfix: Moving the cursor programmatically would freeze it for + a fraction of a second (#1962) - [X11] Bugfix: Changing `GLFW_FLOATING` could leak memory - [Wayland] Bugfix: Some keys were not repeating in Wayland (#1908) - [Wayland] Bugfix: Non-arrow cursors are offset from the hotspot (#1706,#1899) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 182eedbe..a8add172 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -117,7 +117,8 @@ static void updateCursorMode(_GLFWwindow* window) _glfwPlatformSetCursorPos(window, _glfw.ns.restoreCursorPosX, _glfw.ns.restoreCursorPosY); - CGAssociateMouseAndMouseCursorPosition(true); + // NOTE: The matching CGAssociateMouseAndMouseCursorPosition call is + // made in _glfwPlatformSetCursorPos as part of a workaround } if (cursorInContentArea(window)) @@ -1523,6 +1524,11 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) _glfwTransformYNS(globalPoint.y))); } + // HACK: Calling this right after setting the cursor position prevents macOS + // from freezing the cursor for a fraction of a second afterwards + if (window->cursorMode != GLFW_CURSOR_DISABLED) + CGAssociateMouseAndMouseCursorPosition(true); + } // autoreleasepool }