Skip to content

Commit

Permalink
Ignore one mouse movement event after cursor ungrabbing to prevent a …
Browse files Browse the repository at this point in the history
…stale cursor position in GUIs.
  • Loading branch information
eigenraven committed Mar 13, 2023
1 parent c47e58a commit 7aa1195
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/lwjglx/input/Mouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7aa1195

Please sign in to comment.