@@ -15,7 +15,7 @@ std::mutex windowHandleMutex;
1515NATIVEwindow *sharedWindow = nullptr ;
1616InjectionHandler mainThreadInjectionHandler;
1717std::mutex injectionHandlerMapMutex;
18- // int lastX = 0 , lastY = 0 ; // XXX track this per-window
18+ int lastX = - 1 , lastY = - 1 ; // XXX track this per-window
1919uint64_t lastClickTime = 0 ;
2020#ifdef MAIN_THREAD_POLLING
2121std::thread::id mainThreadId;
@@ -675,18 +675,28 @@ void APIENTRY cursorPosCB(NATIVEwindow* window, double x, double y) {
675675 if (x<0 || x>=w) return ;
676676 if (y<0 || y>=h) return ;
677677
678+ int xi = static_cast <int >(x);
679+ int yi = static_cast <int >(y);
678680 int movementX, movementY;
679681
680682 int mode = glfwGetInputMode (window, GLFW_CURSOR);
681683 if (mode == GLFW_CURSOR_DISABLED) {
682- movementX = x - (w / 2 );
683- movementY = y - (h / 2 );
684+ movementX = xi - (w / 2 );
685+ movementY = yi - (h / 2 );
684686
685687 glfwSetCursorPos (window, w / 2 , h / 2 );
686688 } else {
687- movementX = 0 ;
688- movementY = 0 ;
689+ if (lastX != -1 && lastY != -1 ) {
690+ movementX = xi - lastX;
691+ movementY = yi - lastY;
692+ } else {
693+ movementX = 0 ;
694+ movementY = 0 ;
695+ }
689696 }
697+
698+ lastX = xi;
699+ lastY = yi;
690700
691701 QueueEvent (window, [=](std::function<void (int , Local<Value> *)> eventHandlerFn) -> void {
692702 Local<Object> evt = Nan::New<Object>();
0 commit comments