From b132d863be3ca18b8f57d432e65402ef54491572 Mon Sep 17 00:00:00 2001 From: JL2210 Date: Sun, 1 Sep 2024 20:51:55 -0400 Subject: [PATCH] Fix mouse handling (#198) --- src/main/java/org/lwjgl/input/Mouse.java | 4 ++-- src/main/java/org/lwjgl/opengl/Display.java | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/lwjgl/input/Mouse.java b/src/main/java/org/lwjgl/input/Mouse.java index 6f0629015..472f2f9a8 100644 --- a/src/main/java/org/lwjgl/input/Mouse.java +++ b/src/main/java/org/lwjgl/input/Mouse.java @@ -53,9 +53,9 @@ public static void addMoveEvent(double mouseX, double mouseY) { ignoreNextMove--; return; } - /*float scale = Display.getPixelScaleFactor(); + float scale = Display.getPixelScaleFactor(); mouseX *= scale; - mouseY *= scale;*/ + mouseY *= scale; dx += (int) mouseX - latestX; dy += Display.getHeight() - (int) mouseY - latestY; latestX = (int) mouseX; diff --git a/src/main/java/org/lwjgl/opengl/Display.java b/src/main/java/org/lwjgl/opengl/Display.java index 2ccd34c49..cab46fa45 100644 --- a/src/main/java/org/lwjgl/opengl/Display.java +++ b/src/main/java/org/lwjgl/opengl/Display.java @@ -442,10 +442,20 @@ public static float getPixelScaleFactor() { if (!isCreated()) { return 1.0f; } - float[] xScale = new float[1]; - float[] yScale = new float[1]; - glfwGetWindowContentScale(getWindow(), xScale, yScale); - return Math.max(xScale[0], yScale[0]); + int[] windowWidth = new int[1]; + int[] windowHeight = new int[1]; + int[] framebufferWidth = new int[1]; + int[] framebufferHeight = new int[1]; + float xScale, yScale; + // via technicality we actually have to divide the framebuffer + // size by the window size here, since glfwGetWindowContentScale + // returns a value not equal to 1 even on platforms where the + // framebuffer size and window size always map 1:1 + glfwGetWindowSize(getWindow(), windowWidth, windowHeight); + glfwGetFramebufferSize(getWindow(), framebufferWidth, framebufferHeight); + xScale = (float)framebufferWidth[0]/windowWidth[0]; + yScale = (float)framebufferHeight[0]/windowHeight[0]; + return Math.max(xScale, yScale); } public static void setTitle(String title) {