Skip to content

Commit

Permalink
Merge pull request #1331 from exokitxr/mouse-movement
Browse files Browse the repository at this point in the history
Add GLFW movementX/movementY tracking
  • Loading branch information
Avaer Kazmer authored Jul 17, 2019
2 parents c147cce + c00a164 commit 42220f1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions deps/exokit-bindings/glfw/src/glfw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ std::mutex windowHandleMutex;
NATIVEwindow *sharedWindow = nullptr;
InjectionHandler mainThreadInjectionHandler;
std::mutex injectionHandlerMapMutex;
// int lastX = 0, lastY = 0; // XXX track this per-window
int lastX = -1, lastY = -1; // XXX track this per-window
uint64_t lastClickTime = 0;
#ifdef MAIN_THREAD_POLLING
std::thread::id mainThreadId;
Expand Down Expand Up @@ -675,18 +675,28 @@ void APIENTRY cursorPosCB(NATIVEwindow* window, double x, double y) {
if(x<0 || x>=w) return;
if(y<0 || y>=h) return;

int xi = static_cast<int>(x);
int yi = static_cast<int>(y);
int movementX, movementY;

int mode = glfwGetInputMode(window, GLFW_CURSOR);
if (mode == GLFW_CURSOR_DISABLED) {
movementX = x - (w / 2);
movementY = y - (h / 2);
movementX = xi - (w / 2);
movementY = yi - (h / 2);

glfwSetCursorPos(window, w / 2, h / 2);
} else {
movementX = 0;
movementY = 0;
if (lastX != -1 && lastY != -1) {
movementX = xi - lastX;
movementY = yi - lastY;
} else {
movementX = 0;
movementY = 0;
}
}

lastX = xi;
lastY = yi;

QueueEvent(window, [=](std::function<void(int, Local<Value> *)> eventHandlerFn) -> void {
Local<Object> evt = Nan::New<Object>();
Expand Down

0 comments on commit 42220f1

Please sign in to comment.