From 042d85c664af848adbfa1f4399f22241296ec9f2 Mon Sep 17 00:00:00 2001 From: Glavo Date: Sat, 20 Sep 2025 15:53:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E8=BF=87=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E6=8E=A7=E5=88=B6=20UI=20=E7=BC=A9?= =?UTF-8?q?=E6=94=BE=E6=AF=94=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/jackhuang/hmcl/EntryPoint.java | 68 +++++++++++++++---- 1 file changed, 53 insertions(+), 15 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java b/HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java index 396c880f7..cc43be436 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java @@ -46,22 +46,8 @@ public final class EntryPoint { createHMCLDirectories(); LOG.start(Metadata.HMCL_CURRENT_DIRECTORY.resolve("logs")); - if ("true".equalsIgnoreCase(System.getenv("HMCL_FORCE_GPU"))) - System.getProperties().putIfAbsent("prism.forceGPU", "true"); - - String animationFrameRate = System.getenv("HMCL_ANIMATION_FRAME_RATE"); - if (animationFrameRate != null) { - try { - if (Integer.parseInt(animationFrameRate) <= 0) - throw new NumberFormatException(animationFrameRate); - - System.getProperties().putIfAbsent("javafx.animation.pulse", animationFrameRate); - } catch (NumberFormatException e) { - LOG.warning("Invalid animation frame rate: " + animationFrameRate); - } - } - checkDirectoryPath(); + setupJavaFXVMOptions(); if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) initIcon(); @@ -80,6 +66,58 @@ public final class EntryPoint { System.exit(exitCode); } + private static void setupJavaFXVMOptions() { + if ("true".equalsIgnoreCase(System.getenv("HMCL_FORCE_GPU"))) + System.getProperties().putIfAbsent("prism.forceGPU", "true"); + + String animationFrameRate = System.getenv("HMCL_ANIMATION_FRAME_RATE"); + if (animationFrameRate != null) { + LOG.info("HMCL_ANIMATION_FRAME_RATE: " + animationFrameRate); + + try { + if (Integer.parseInt(animationFrameRate) <= 0) + throw new NumberFormatException(animationFrameRate); + + System.getProperties().putIfAbsent("javafx.animation.pulse", animationFrameRate); + } catch (NumberFormatException e) { + LOG.warning("Invalid animation frame rate: " + animationFrameRate); + } + } + + String uiScale = System.getProperty("hmcl.uiScale", System.getenv("HMCL_UI_SCALE")); + if (uiScale != null) { + uiScale = uiScale.trim(); + + LOG.info("HMCL_UI_SCALE: " + uiScale); + + try { + float scaleValue; + if (uiScale.endsWith("%")) { + scaleValue = Integer.parseInt(uiScale.substring(0, uiScale.length() - 1)) / 100.0f; + } else if (uiScale.endsWith("dpi") || uiScale.endsWith("DPI")) { + scaleValue = Integer.parseInt(uiScale.substring(0, uiScale.length() - 3)) / 96.0f; + } else { + scaleValue = Float.parseFloat(uiScale); + } + + // JavaFX behavior may be abnormal when the DPI scaling factor is too high + if (scaleValue >= 0.25 && scaleValue <= 6) { + if (OperatingSystem.CURRENT_OS != OperatingSystem.MACOS) { + if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) { + System.getProperties().putIfAbsent("glass.win.uiScale", uiScale); + } else { + System.getProperties().putIfAbsent("glass.gtk.uiScale", uiScale); + } + } + } else { + LOG.warning("Invalid DPI scale: " + uiScale); + } + } catch (Throwable e) { + LOG.warning("Invalid DPI scale: " + uiScale); + } + } + } + private static void createHMCLDirectories() { if (!Files.isDirectory(Metadata.HMCL_CURRENT_DIRECTORY)) { try {