From 0e846883bf205c3ca4f96c8f90d7b01b4beea4d0 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Tue, 24 May 2016 12:23:58 +0200 Subject: [PATCH] Clarify cursor position variable names --- src/cocoa_platform.h | 2 +- src/cocoa_window.m | 12 ++++++------ src/input.c | 28 ++++++++++++++-------------- src/internal.h | 7 ++++--- src/mir_window.c | 4 ++-- src/win32_platform.h | 2 +- src/win32_window.c | 16 ++++++++-------- src/window.c | 8 +++++--- src/x11_platform.h | 4 ++-- src/x11_window.c | 14 +++++++------- 10 files changed, 50 insertions(+), 47 deletions(-) diff --git a/src/cocoa_platform.h b/src/cocoa_platform.h index 780af401..1355758a 100644 --- a/src/cocoa_platform.h +++ b/src/cocoa_platform.h @@ -78,7 +78,7 @@ typedef struct _GLFWwindowNS // The total sum of the distances the cursor has been warped // since the last cursor motion event was processed // This is kept to counteract Cocoa doing the same internally - double warpDeltaX, warpDeltaY; + double cursorWarpDeltaX, cursorWarpDeltaY; } _GLFWwindowNS; diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 13752053..cd7fd871 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -423,8 +423,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; if (window->cursorMode == GLFW_CURSOR_DISABLED) { _glfwInputCursorMotion(window, - [event deltaX] - window->ns.warpDeltaX, - [event deltaY] - window->ns.warpDeltaY); + [event deltaX] - window->ns.cursorWarpDeltaX, + [event deltaY] - window->ns.cursorWarpDeltaY); } else { @@ -434,8 +434,8 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; _glfwInputCursorMotion(window, pos.x, contentRect.size.height - pos.y); } - window->ns.warpDeltaX = 0; - window->ns.warpDeltaY = 0; + window->ns.cursorWarpDeltaX = 0; + window->ns.cursorWarpDeltaY = 0; } - (void)rightMouseDown:(NSEvent *)event @@ -1402,8 +1402,8 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) const NSRect contentRect = [window->ns.view frame]; const NSPoint pos = [window->ns.object mouseLocationOutsideOfEventStream]; - window->ns.warpDeltaX += x - pos.x; - window->ns.warpDeltaY += y - contentRect.size.height + pos.y; + window->ns.cursorWarpDeltaX += x - pos.x; + window->ns.cursorWarpDeltaY += y - contentRect.size.height + pos.y; if (window->monitor) { diff --git a/src/input.c b/src/input.c index 44772600..8f7148a5 100644 --- a/src/input.c +++ b/src/input.c @@ -59,19 +59,19 @@ static void setCursorMode(_GLFWwindow* window, int newMode) if (oldMode == GLFW_CURSOR_DISABLED) { _glfwPlatformSetCursorPos(window, - _glfw.cursorPosX, - _glfw.cursorPosY); + _glfw.restoreCursorPosX, + _glfw.restoreCursorPosY); } else if (newMode == GLFW_CURSOR_DISABLED) { int width, height; _glfwPlatformGetCursorPos(window, - &_glfw.cursorPosX, - &_glfw.cursorPosY); + &_glfw.restoreCursorPosX, + &_glfw.restoreCursorPosY); - window->cursorPosX = _glfw.cursorPosX; - window->cursorPosY = _glfw.cursorPosY; + window->virtualCursorPosX = _glfw.restoreCursorPosX; + window->virtualCursorPosY = _glfw.restoreCursorPosY; _glfwPlatformGetWindowSize(window, &width, &height); _glfwPlatformSetCursorPos(window, width / 2, height / 2); @@ -198,11 +198,11 @@ void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y) if (x == 0.0 && y == 0.0) return; - window->cursorPosX += x; - window->cursorPosY += y; + window->virtualCursorPosX += x; + window->virtualCursorPosY += y; - x = window->cursorPosX; - y = window->cursorPosY; + x = window->virtualCursorPosX; + y = window->virtualCursorPosY; } if (window->callbacks.cursorPos) @@ -356,9 +356,9 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos) if (window->cursorMode == GLFW_CURSOR_DISABLED) { if (xpos) - *xpos = window->cursorPosX; + *xpos = window->virtualCursorPosX; if (ypos) - *ypos = window->cursorPosY; + *ypos = window->virtualCursorPosY; } else _glfwPlatformGetCursorPos(window, xpos, ypos); @@ -386,8 +386,8 @@ GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos) if (window->cursorMode == GLFW_CURSOR_DISABLED) { // Only update the accumulated position if the cursor is disabled - window->cursorPosX = xpos; - window->cursorPosY = ypos; + window->virtualCursorPosX = xpos; + window->virtualCursorPosY = ypos; } else { diff --git a/src/internal.h b/src/internal.h index 6c084f8d..01c34957 100644 --- a/src/internal.h +++ b/src/internal.h @@ -359,13 +359,13 @@ struct _GLFWwindow int maxwidth, maxheight; int numer, denom; - // Window input state GLFWbool stickyKeys; GLFWbool stickyMouseButtons; - double cursorPosX, cursorPosY; int cursorMode; char mouseButtons[GLFW_MOUSE_BUTTON_LAST + 1]; char keys[GLFW_KEY_LAST + 1]; + // Virtual cursor position when cursor is disabled + double virtualCursorPosX, virtualCursorPosY; _GLFWcontext context; @@ -437,7 +437,8 @@ struct _GLFWlibrary int refreshRate; } hints; - double cursorPosX, cursorPosY; + // Where to place the cursor when re-enabled + double restoreCursorPosX, restoreCursorPosY; _GLFWcursor* cursorListHead; diff --git a/src/mir_window.c b/src/mir_window.c index ddc70fa6..b303d331 100644 --- a/src/mir_window.c +++ b/src/mir_window.c @@ -201,8 +201,8 @@ static void handlePointerButton(_GLFWwindow* window, static void handlePointerMotion(_GLFWwindow* window, const MirPointerEvent* pointer_event) { - int current_x = window->cursorPosX; - int current_y = window->cursorPosY; + int current_x = window->virtualCursorPosX; + int current_y = window->virtualCursorPosY; int x = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_x); int y = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_y); int dx = mir_pointer_event_axis_value(pointer_event, mir_pointer_axis_hscroll); diff --git a/src/win32_platform.h b/src/win32_platform.h index f3570bcc..59a1dcc1 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -237,7 +237,7 @@ typedef struct _GLFWwindowWin32 GLFWbool iconified; // The last received cursor position, regardless of source - int cursorPosX, cursorPosY; + int lastCursorPosX, lastCursorPosY; } _GLFWwindowWin32; diff --git a/src/win32_window.c b/src/win32_window.c index 15295a95..7fd4474b 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -572,14 +572,14 @@ static LRESULT CALLBACK windowProc(HWND hWnd, UINT uMsg, break; _glfwInputCursorMotion(window, - x - window->win32.cursorPosX, - y - window->win32.cursorPosY); + x - window->win32.lastCursorPosX, + y - window->win32.lastCursorPosY); } else _glfwInputCursorMotion(window, x, y); - window->win32.cursorPosX = x; - window->win32.cursorPosY = y; + window->win32.lastCursorPosX = x; + window->win32.lastCursorPosY = y; if (!window->win32.cursorTracked) { @@ -1386,8 +1386,8 @@ void _glfwPlatformPollEvents(void) // NOTE: Re-center the cursor only if it has moved since the last // call, to avoid breaking glfwWaitEvents with WM_MOUSEMOVE - if (window->win32.cursorPosX != width / 2 || - window->win32.cursorPosY != height / 2) + if (window->win32.lastCursorPosX != width / 2 || + window->win32.lastCursorPosY != height / 2) { _glfwPlatformSetCursorPos(window, width / 2, height / 2); } @@ -1435,8 +1435,8 @@ void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos) POINT pos = { (int) xpos, (int) ypos }; // Store the new position so it can be recognized later - window->win32.cursorPosX = pos.x; - window->win32.cursorPosY = pos.y; + window->win32.lastCursorPosX = pos.x; + window->win32.lastCursorPosY = pos.y; ClientToScreen(window->win32.handle, &pos); SetCursorPos(pos.x, pos.y); diff --git a/src/window.c b/src/window.c index 8f613599..503436ae 100644 --- a/src/window.c +++ b/src/window.c @@ -224,10 +224,12 @@ GLFWAPI GLFWwindow* glfwCreateWindow(int width, int height, int width, height; _glfwPlatformGetWindowSize(window, &width, &height); - window->cursorPosX = width / 2; - window->cursorPosY = height / 2; + window->virtualCursorPosX = width / 2; + window->virtualCursorPosY = height / 2; - _glfwPlatformSetCursorPos(window, window->cursorPosX, window->cursorPosY); + _glfwPlatformSetCursorPos(window, + window->virtualCursorPosX, + window->virtualCursorPosY); } else { diff --git a/src/x11_platform.h b/src/x11_platform.h index 9c76d189..48070cf2 100644 --- a/src/x11_platform.h +++ b/src/x11_platform.h @@ -118,9 +118,9 @@ typedef struct _GLFWwindowX11 int xpos, ypos; // The last received cursor position, regardless of source - double cursorPosX, cursorPosY; + double lastCursorPosX, lastCursorPosY; // The last position the cursor was warped to by GLFW - int warpPosX, warpPosY; + int warpCursorPosX, warpCursorPosY; // The information from the last KeyPress event struct { diff --git a/src/x11_window.c b/src/x11_window.c index d638be85..071b5117 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -1149,7 +1149,7 @@ static void processEvent(XEvent *event) const int x = event->xmotion.x; const int y = event->xmotion.y; - if (x != window->x11.warpPosX || y != window->x11.warpPosY) + if (x != window->x11.warpCursorPosX || y != window->x11.warpCursorPosY) { // The cursor was moved by something other than GLFW @@ -1159,15 +1159,15 @@ static void processEvent(XEvent *event) return; _glfwInputCursorMotion(window, - x - window->x11.cursorPosX, - y - window->x11.cursorPosY); + x - window->x11.lastCursorPosX, + y - window->x11.lastCursorPosY); } else _glfwInputCursorMotion(window, x, y); } - window->x11.cursorPosX = x; - window->x11.cursorPosY = y; + window->x11.lastCursorPosX = x; + window->x11.lastCursorPosY = y; return; } @@ -2071,8 +2071,8 @@ void _glfwPlatformGetCursorPos(_GLFWwindow* window, double* xpos, double* ypos) void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y) { // Store the new position so it can be recognized later - window->x11.warpPosX = (int) x; - window->x11.warpPosY = (int) y; + window->x11.warpCursorPosX = (int) x; + window->x11.warpCursorPosY = (int) y; XWarpPointer(_glfw.x11.display, None, window->x11.handle, 0,0,0,0, (int) x, (int) y);