Skip to content

Commit 4977896

Browse files
authored
在日志中记录显示器信息 (#4581)
1 parent 8d3cb66 commit 4977896

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@
2020
import javafx.application.Application;
2121
import javafx.application.Platform;
2222
import javafx.beans.value.ObservableBooleanValue;
23+
import javafx.geometry.Rectangle2D;
2324
import javafx.scene.control.Alert;
2425
import javafx.scene.control.Alert.AlertType;
2526
import javafx.scene.control.ButtonType;
2627
import javafx.scene.input.Clipboard;
2728
import javafx.scene.input.DataFormat;
29+
import javafx.stage.Screen;
2830
import javafx.stage.Stage;
2931
import org.jackhuang.hmcl.setting.ConfigHolder;
3032
import org.jackhuang.hmcl.setting.SambaException;
@@ -54,6 +56,7 @@
5456
import java.nio.file.Files;
5557
import java.nio.file.Path;
5658
import java.nio.file.Paths;
59+
import java.text.DecimalFormat;
5760
import java.util.ArrayList;
5861
import java.util.Collections;
5962
import java.util.Objects;
@@ -79,6 +82,18 @@ public void start(Stage primaryStage) {
7982
LOG.info("Dark Mode: " + Optional.ofNullable(FXUtils.DARK_MODE).map(ObservableBooleanValue::get).orElse(false));
8083
LOG.info("Reduced Motion: " + Objects.requireNonNullElse(FXUtils.REDUCED_MOTION, false));
8184

85+
if (Screen.getScreens().isEmpty()) {
86+
LOG.info("No screen");
87+
} else {
88+
StringBuilder builder = new StringBuilder("Screens:");
89+
int count = 0;
90+
for (Screen screen : Screen.getScreens()) {
91+
builder.append("\n - Screen ").append(++count).append(": ");
92+
appendScreen(builder, screen);
93+
}
94+
LOG.info(builder.toString());
95+
}
96+
8297
try {
8398
try {
8499
ConfigHolder.init();
@@ -131,6 +146,38 @@ public void start(Stage primaryStage) {
131146
}
132147
}
133148

149+
private static void appendScreen(StringBuilder builder, Screen screen) {
150+
Rectangle2D bounds = screen.getBounds();
151+
double scale = screen.getOutputScaleX();
152+
153+
builder.append(Math.round(bounds.getWidth() * scale));
154+
builder.append('x');
155+
builder.append(Math.round(bounds.getHeight() * scale));
156+
157+
DecimalFormat decimalFormat = new DecimalFormat("#.##");
158+
159+
if (scale != 1.0) {
160+
builder.append(" @ ");
161+
builder.append(decimalFormat.format(scale));
162+
builder.append('x');
163+
}
164+
165+
double dpi = screen.getDpi();
166+
builder.append(' ');
167+
builder.append(decimalFormat.format(dpi));
168+
builder.append("dpi");
169+
170+
builder.append(" in ")
171+
.append(Math.round(Math.sqrt(bounds.getWidth() * bounds.getWidth() + bounds.getHeight() * bounds.getHeight()) / dpi))
172+
.append('"');
173+
174+
builder.append(" (").append(decimalFormat.format(bounds.getMinX()))
175+
.append(", ").append(decimalFormat.format(bounds.getMinY()))
176+
.append(", ").append(decimalFormat.format(bounds.getMaxX()))
177+
.append(", ").append(decimalFormat.format(bounds.getMaxY()))
178+
.append(")");
179+
}
180+
134181
private static ButtonType showAlert(AlertType alertType, String contentText, ButtonType... buttons) {
135182
return new Alert(alertType, contentText, buttons).showAndWait().orElse(null);
136183
}

0 commit comments

Comments
 (0)