@@ -15,7 +15,7 @@ std::mutex windowHandleMutex;
15
15
NATIVEwindow *sharedWindow = nullptr ;
16
16
InjectionHandler mainThreadInjectionHandler;
17
17
std::mutex injectionHandlerMapMutex;
18
- // int lastX = 0 , lastY = 0 ; // XXX track this per-window
18
+ int lastX = - 1 , lastY = - 1 ; // XXX track this per-window
19
19
uint64_t lastClickTime = 0 ;
20
20
#ifdef MAIN_THREAD_POLLING
21
21
std::thread::id mainThreadId;
@@ -675,18 +675,28 @@ void APIENTRY cursorPosCB(NATIVEwindow* window, double x, double y) {
675
675
if (x<0 || x>=w) return ;
676
676
if (y<0 || y>=h) return ;
677
677
678
+ int xi = static_cast <int >(x);
679
+ int yi = static_cast <int >(y);
678
680
int movementX, movementY;
679
681
680
682
int mode = glfwGetInputMode (window, GLFW_CURSOR);
681
683
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 );
684
686
685
687
glfwSetCursorPos (window, w / 2 , h / 2 );
686
688
} 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
+ }
689
696
}
697
+
698
+ lastX = xi;
699
+ lastY = yi;
690
700
691
701
QueueEvent (window, [=](std::function<void (int , Local<Value> *)> eventHandlerFn) -> void {
692
702
Local<Object> evt = Nan::New<Object>();
0 commit comments