From aa3364a73e4a4dab6ae387f8e85581cd694f07a3 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 30 Apr 2013 15:50:01 +0200 Subject: [PATCH] Fixed jitter in captured cursor mode. --- src/x11_platform.h | 4 ++++ src/x11_window.c | 23 +++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/x11_platform.h b/src/x11_platform.h index 14f89f83..e5fea416 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -86,7 +86,11 @@ typedef struct _GLFWwindowX11 GLboolean cursorGrabbed; // True if cursor is currently grabbed GLboolean cursorHidden; // True if cursor is currently hidden GLboolean cursorCentered; // True if cursor was moved since last poll + + // The last received cursor position, regardless of source double cursorPosX, cursorPosY; + // The last position the cursor was warped to by GLFW + int warpPosX, warpPosY; } _GLFWwindowX11; diff --git a/src/x11_window.c b/src/x11_window.c index 596d0f06..55c36eea 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -580,8 +580,8 @@ static void processEvent(XEvent *event) case MotionNotify: { - if (event->xmotion.x != window->x11.cursorPosX || - event->xmotion.y != window->x11.cursorPosY) + if (event->xmotion.x != window->x11.warpPosX || + event->xmotion.y != window->x11.warpPosY) { // The cursor was moved by something other than GLFW @@ -601,13 +601,12 @@ static void processEvent(XEvent *event) y = event->xmotion.y; } - window->x11.cursorPosX = event->xmotion.x; - window->x11.cursorPosY = event->xmotion.y; window->x11.cursorCentered = GL_FALSE; - _glfwInputCursorMotion(window, x, y); } + window->x11.cursorPosX = event->xmotion.x; + window->x11.cursorPosY = event->xmotion.y; break; } @@ -744,8 +743,8 @@ static void processEvent(XEvent *event) window = _glfwFindWindowByHandle(data->event); if (window) { - if (data->event_x != window->x11.cursorPosX || - data->event_y != window->x11.cursorPosY) + if (data->event_x != window->x11.warpPosX || + data->event_y != window->x11.warpPosY) { // The cursor was moved by something other than GLFW @@ -765,12 +764,12 @@ static void processEvent(XEvent *event) y = data->event_y; } - window->x11.cursorPosX = data->event_x; - window->x11.cursorPosY = data->event_y; window->x11.cursorCentered = GL_FALSE; - _glfwInputCursorMotion(window, x, y); } + + window->x11.cursorPosX = data->event_x; + window->x11.cursorPosY = data->event_y; } } } @@ -1094,8 +1093,8 @@ void _glfwPlatformWaitEvents(void) void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) { // Store the new position so it can be recognized later - window->x11.cursorPosX = x; - window->x11.cursorPosY = y; + window->x11.warpPosX = (int) x; + window->x11.warpPosY = (int) y; XWarpPointer(_glfw.x11.display, None, window->x11.handle, 0,0,0,0, (int) x, (int) y);