title: GLFW Mouse event lag with window drag
body: <p>I am trying to drag an undecorated window in GLFW but am encountering some event lag, even though I am using <code>glfwWaitEvents()</code></p>
  
  <p>I have a cursor position callback, and a simple loop:</p>
  
  <pre><code>// register a cursor position callback
  glfwSetCursorPosCallback(win, cursor_pos_callback);
  
  // then loop..
  while(!glfwWindowShouldClose(win)) {
    glfwWaitEvents();
    ... some rendering...
    glfwSwapBuffers(win);
  }
  </code></pre>
  
  <p>My cursor callback does some simple tracking of the deltas and updates window position.</p>
  
  <pre><code>cursor_pos_callback(GLFWwindow *win, double xpos, double ypos) {
    // figure out delta_x and delta_y based on cursor previous position
    int delta_x, delta_y;
  
    // update window position
    if (window_drag_active) {
       int x,y;
       glfwGetWindowPos(window, &amp;x, &amp;y);
       glfwSetWindowPos(window, x + delta_x, y + delta_y);
    }
  }
  </code></pre>
  
  <p>Here is what the deltas look like <strong>when I'm dragging in a straight line</strong></p>
  
  <pre><code>delta_x:  10    delta_y:   0    |    xpos:   649    ypos: 55
  delta_x:   5    delta_y:  -1    |    xpos:   654    ypos: 54
  delta_x:   5    delta_y:   3    |    xpos:   659    ypos: 57
  delta_x:   5    delta_y:   2    |    xpos:   664    ypos: 59
  delta_x:  -5    delta_y:  -2    |    xpos:   659    ypos: 57
  delta_x:   4    delta_y:   0    |    xpos:   663    ypos: 57
  delta_x:   2    delta_y:   0    |    xpos:   665    ypos: 57
  delta_x:  -3    delta_y:  -3    |    xpos:   662    ypos: 54
  delta_x:   2    delta_y:   1    |    xpos:   664    ypos: 55
  delta_x:   2    delta_y:   0    |    xpos:   666    ypos: 55
  delta_x:   3    delta_y:   2    |    xpos:   669    ypos: 57
  delta_x:   1    delta_y:  -1    |    xpos:   670    ypos: 56
  delta_x:   2    delta_y:  -1    |    xpos:   672    ypos: 55
  delta_x:   7    delta_y:   3    |    xpos:   679    ypos: 58
  delta_x:   2    delta_y:  -1    |    xpos:   681    ypos: 57
  delta_x:  -2    delta_y:  -3    |    xpos:   679    ypos: 54
  delta_x:   0    delta_y:  -2    |    xpos:   679    ypos: 52
  delta_x:   3    delta_y:   3    |    xpos:   682    ypos: 55
  delta_x:  -5    delta_y:  -3    |    xpos:   677    ypos: 52
  </code></pre>
  
  <p>The <code>xpos</code> increments as it should, then every so often it goes backwards (stale event?)</p>
  
  <p>Maybe my window movement is not synced up with the cursor?</p>
  
  <p><strong>The result is the when I drag the window, it shakes violently and I can barely move it anywhere...</strong></p>
  
  <hr>
  
  <p>Update: I have also tried moving the <code>glfwSetWindowPos</code> logic into the main loop as well with no success—I still get the same shaking and stuttering.</p>
  
  <hr>
  
  <p>Update: When I comment out the <code>glfwSetWindowPos()</code> the window no longer moves <em>(of course)</em> but the event stream is now consistent.</p>
  
  <p>This leads me to think that the moving of the window, when done quickly is causing the jerking motion (ie. 2 steps forward, 1 step backwards).</p>