From 7aa1195f1efbe5a78c8e5810dc248a7d18e8a389 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Mon, 13 Mar 2023 16:41:02 +0000 Subject: [PATCH] Ignore one mouse movement event after cursor ungrabbing to prevent a stale cursor position in GUIs. --- src/main/java/org/lwjglx/input/Mouse.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/org/lwjglx/input/Mouse.java b/src/main/java/org/lwjglx/input/Mouse.java index 624aeea3..3ffd67eb 100644 --- a/src/main/java/org/lwjglx/input/Mouse.java +++ b/src/main/java/org/lwjglx/input/Mouse.java @@ -47,8 +47,13 @@ public class Mouse { private static boolean clipPostionToDisplay = true; private static boolean ignoreNextDelta = false; + private static boolean ignoreNextMove = false; public static void addMoveEvent(double mouseX, double mouseY) { + if (ignoreNextMove) { + ignoreNextMove = false; + return; + } latestX = (int) mouseX; latestY = Display.getHeight() - (int) mouseY; if (ignoreNextDelta) { @@ -241,6 +246,8 @@ public static void setCursorPosition(int new_x, int new_y) { return; } GLFW.glfwSetCursorPos(Display.getWindow(), new_x, new_y); + addMoveEvent(new_x, new_y); + ignoreNextMove = true; } public static Cursor setNativeCursor(Cursor cursor) throws LWJGLException {