Browse Source

Actually fix Mac mouse issue?

tags/v0.3.0
Andrew Belt 7 years ago
parent
commit
d56c9698bf
2 changed files with 24 additions and 2 deletions
  1. +1
    -1
      ext/osdialog
  2. +23
    -1
      src/gui.cpp

+ 1
- 1
ext/osdialog

@@ -1 +1 @@
Subproject commit d2141b5b8976e8adc2e3fda60fc012cf01e40c31
Subproject commit 7368a2f1969d5fa2c02e90d24598dc69395f5b14

+ 23
- 1
src/gui.cpp View File

@@ -17,6 +17,10 @@
#define NANOSVG_IMPLEMENTATION #define NANOSVG_IMPLEMENTATION
#include "../ext/nanosvg/src/nanosvg.h" #include "../ext/nanosvg/src/nanosvg.h"


#ifdef ARCH_MAC
// For CGAssociateMouseAndMouseCursorPosition
#include <ApplicationServices/ApplicationServices.h>
#endif


namespace rack { namespace rack {


@@ -76,6 +80,21 @@ void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods) {
void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) { void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) {
Vec mousePos = Vec(xpos, ypos).round(); Vec mousePos = Vec(xpos, ypos).round();
Vec mouseRel = mousePos.minus(gMousePos); 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; gMousePos = mousePos;


// onMouseMove // onMouseMove
@@ -94,7 +113,6 @@ void cursorPosCallback(GLFWwindow* window, double xpos, double ypos) {
} }
gDragHoveredWidget = hovered; gDragHoveredWidget = hovered;
} }

} }
else { else {
if (hovered != gHoveredWidget) { if (hovered != gHoveredWidget) {
@@ -289,7 +307,11 @@ bool guiIsKeyPressed(int key) {
} }


void guiCursorLock() { void guiCursorLock() {
#ifdef ARCH_MAC
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
#else
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
#endif
} }


void guiCursorUnlock() { void guiCursorUnlock() {


Loading…
Cancel
Save