From d56c9698bf9f17fee38a477054cb2e2cd15d2bae Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 1 Sep 2017 00:57:13 -0400 Subject: [PATCH] Actually fix Mac mouse issue? --- ext/osdialog | 2 +- src/gui.cpp | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ext/osdialog b/ext/osdialog index d2141b5b..7368a2f1 160000 --- a/ext/osdialog +++ b/ext/osdialog @@ -1 +1 @@ -Subproject commit d2141b5b8976e8adc2e3fda60fc012cf01e40c31 +Subproject commit 7368a2f1969d5fa2c02e90d24598dc69395f5b14 diff --git a/src/gui.cpp b/src/gui.cpp index 5c2020c3..78af965d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -17,6 +17,10 @@ #define NANOSVG_IMPLEMENTATION #include "../ext/nanosvg/src/nanosvg.h" +#ifdef ARCH_MAC + // For CGAssociateMouseAndMouseCursorPosition + #include +#endif namespace rack { @@ -76,6 +80,21 @@ void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) { void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) { Vec mousePos = Vec(xpos, ypos).round(); Vec mouseRel = mousePos.minus(gMousePos); + +#ifdef ARCH_MAC + // Workaround for Mac. We can't use GLFW_CURSOR_DISABLED because it's buggy, so implement it on our own. + // This is not an ideal implementation. For example, if the user drags off the screen, the new mouse position will be clamped. + int mouseMode = glfwGetInputMode(window, GLFW_CURSOR); + if (mouseMode == GLFW_CURSOR_HIDDEN) { + // CGSetLocalEventsSuppressionInterval(0.0); + glfwSetCursorPos(window, gMousePos.x, gMousePos.y); + CGAssociateMouseAndMouseCursorPosition(true); + mousePos = gMousePos; + } + // Because sometimes the cursor turns into an arrow when its position is on the boundary of the window + glfwSetCursor(window, NULL); +#endif + gMousePos = mousePos; // onMouseMove @@ -94,7 +113,6 @@ void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) { } gDragHoveredWidget = hovered; } - } else { if (hovered != gHoveredWidget) { @@ -289,7 +307,11 @@ bool guiIsKeyPressed(int key) { } void guiCursorLock() { +#ifdef ARCH_MAC + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +#else glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); +#endif } void guiCursorUnlock() {