From 4a83e088788596ba03ff28d2f83e5cf2d6eb52e0 Mon Sep 17 00:00:00 2001 From: Raven Szewczyk Date: Wed, 25 Jan 2023 14:00:58 +0000 Subject: [PATCH] Actually fix the teleporting mouse bug --- src/main/java/org/lwjglx/input/Mouse.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/lwjglx/input/Mouse.java b/src/main/java/org/lwjglx/input/Mouse.java index afc5e7c..780eccb 100644 --- a/src/main/java/org/lwjglx/input/Mouse.java +++ b/src/main/java/org/lwjglx/input/Mouse.java @@ -39,10 +39,18 @@ public class Mouse { private static long[] nanoTimeEvents = new long[queue.getMaxEvents()]; private static boolean clipPostionToDisplay = true; + private static boolean ignoreNextDelta = false; public static void addMoveEvent(double mouseX, double mouseY) { latestX = (int) mouseX; latestY = Display.getHeight() - (int) mouseY; + if (ignoreNextDelta) { + ignoreNextDelta = false; + x = latestX; + y = latestY; + lastX = latestX; + lastY = latestY; + } lastxEvents[queue.getNextPos()] = xEvents[queue.getNextPos()]; lastyEvents[queue.getNextPos()] = yEvents[queue.getNextPos()]; @@ -118,11 +126,11 @@ public class Mouse { public static void setGrabbed(boolean grab) { GLFW.glfwSetInputMode( Display.getWindow(), GLFW.GLFW_CURSOR, grab ? GLFW.GLFW_CURSOR_DISABLED : GLFW.GLFW_CURSOR_NORMAL); + grabbed = grab; if (!grab) { setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2); - addMoveEvent(Display.getWidth() / 2, Display.getHeight() / 2); } - grabbed = grab; + ignoreNextDelta = true; } public static boolean isGrabbed() { @@ -198,6 +206,9 @@ public class Mouse { } public static void setCursorPosition(int new_x, int new_y) { + if (grabbed) { + return; + } GLFW.glfwSetCursorPos(Display.getWindow(), new_x, new_y); }