mirror of
https://github.com/glfw/glfw.git
synced 2026-09-19 15:25:50 +00:00
Move all cursor positioning to platform code
Due to Wayland, shared code cannot rely on cursor positioning being supported by the underlying platform. This implicitly fixes #617 as it moves cursor centering into _glfwPlatformSetCursorMode, thus separating it from the stale value of _glfw.cursorWindow. Fixes #617.
This commit is contained in:
+18
-45
@@ -37,48 +37,27 @@
|
||||
|
||||
// Sets the cursor mode for the specified window
|
||||
//
|
||||
static void setCursorMode(_GLFWwindow* window, int newMode)
|
||||
static void setCursorMode(_GLFWwindow* window, int mode)
|
||||
{
|
||||
const int oldMode = window->cursorMode;
|
||||
|
||||
if (newMode != GLFW_CURSOR_NORMAL &&
|
||||
newMode != GLFW_CURSOR_HIDDEN &&
|
||||
newMode != GLFW_CURSOR_DISABLED)
|
||||
if (mode != GLFW_CURSOR_NORMAL &&
|
||||
mode != GLFW_CURSOR_HIDDEN &&
|
||||
mode != GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid cursor mode %i", newMode);
|
||||
_glfwInputError(GLFW_INVALID_ENUM, "Invalid cursor mode %i", mode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (oldMode == newMode)
|
||||
if (window->cursorMode == mode)
|
||||
return;
|
||||
|
||||
window->cursorMode = newMode;
|
||||
_glfwPlatformGetCursorPos(window,
|
||||
&window->virtualCursorPosX,
|
||||
&window->virtualCursorPosY);
|
||||
|
||||
if (_glfw.cursorWindow == window)
|
||||
{
|
||||
if (oldMode == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
_glfwPlatformSetCursorPos(window,
|
||||
_glfw.restoreCursorPosX,
|
||||
_glfw.restoreCursorPosY);
|
||||
}
|
||||
else if (newMode == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
int width, height;
|
||||
_glfwPlatformSetCursorMode(window, mode);
|
||||
|
||||
_glfwPlatformGetCursorPos(window,
|
||||
&_glfw.restoreCursorPosX,
|
||||
&_glfw.restoreCursorPosY);
|
||||
|
||||
window->virtualCursorPosX = _glfw.restoreCursorPosX;
|
||||
window->virtualCursorPosY = _glfw.restoreCursorPosY;
|
||||
|
||||
_glfwPlatformGetWindowSize(window, &width, &height);
|
||||
_glfwPlatformSetCursorPos(window, width / 2, height / 2);
|
||||
}
|
||||
|
||||
_glfwPlatformSetCursorMode(window, window->cursorMode);
|
||||
}
|
||||
window->cursorMode = mode;
|
||||
}
|
||||
|
||||
// Set sticky keys mode for the specified window
|
||||
@@ -191,19 +170,13 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action, int mods)
|
||||
window->callbacks.mouseButton((GLFWwindow*) window, button, action, mods);
|
||||
}
|
||||
|
||||
void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y)
|
||||
void _glfwInputCursorPos(_GLFWwindow* window, double x, double y)
|
||||
{
|
||||
if (window->cursorMode == GLFW_CURSOR_DISABLED)
|
||||
{
|
||||
if (x == 0.0 && y == 0.0)
|
||||
return;
|
||||
if (window->virtualCursorPosX == x && window->virtualCursorPosY == y)
|
||||
return;
|
||||
|
||||
window->virtualCursorPosX += x;
|
||||
window->virtualCursorPosY += y;
|
||||
|
||||
x = window->virtualCursorPosX;
|
||||
y = window->virtualCursorPosY;
|
||||
}
|
||||
window->virtualCursorPosX = x;
|
||||
window->virtualCursorPosY = y;
|
||||
|
||||
if (window->callbacks.cursorPos)
|
||||
window->callbacks.cursorPos((GLFWwindow*) window, x, y);
|
||||
@@ -490,9 +463,9 @@ GLFWAPI void glfwSetCursor(GLFWwindow* windowHandle, GLFWcursor* cursorHandle)
|
||||
|
||||
_GLFW_REQUIRE_INIT();
|
||||
|
||||
_glfwPlatformSetCursor(window, cursor);
|
||||
|
||||
window->cursor = cursor;
|
||||
|
||||
_glfwPlatformSetCursor(window, cursor);
|
||||
}
|
||||
|
||||
GLFWAPI GLFWkeyfun glfwSetKeyCallback(GLFWwindow* handle, GLFWkeyfun cbfun)
|
||||
|
||||
Reference in New Issue
Block a user