在 KDE Wayland 环境中使用 dbus 获取 UI 缩放比例#6071
Conversation
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces automatic UI scale detection for KDE Wayland environments on Linux by querying D-Bus for the KScreen ScaleFactor. Feedback highlights a potential NullPointerException when setting system properties because the uiScale variable remains null in the D-Bus code path. Additionally, a correction was suggested for a log message to accurately reflect that the UI scale, rather than the system theme, is being retrieved.
| if (scale > 0) { | ||
| if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) { | ||
| System.getProperties().putIfAbsent("glass.win.uiScale", uiScale); | ||
| } else if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) { | ||
| LOG.warning("macOS does not support setting UI scale, so it will be ignored"); | ||
| } else { | ||
| System.getProperties().putIfAbsent("glass.gtk.uiScale", uiScale); | ||
| } | ||
| } |
There was a problem hiding this comment.
在通过 D-Bus 获取缩放比例的分支中(第 104-142 行),uiScale 变量保持为 null。由于 System.getProperties() 返回的是 Hashtable,调用 putIfAbsent 时传入 null 值会抛出 NullPointerException。此外,即使不抛出异常,也应该使用计算出的 scale 值,因为 JavaFX 的 uiScale 属性通常期望一个数值字符串,而不一定支持原始输入中的 % 或 dpi 后缀。
if (scale > 0) {
String scaleString = String.valueOf(scale);
if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS) {
System.getProperties().putIfAbsent("glass.win.uiScale", scaleString);
} else if (OperatingSystem.CURRENT_OS == OperatingSystem.MACOS) {
LOG.warning("macOS does not support setting UI scale, so it will be ignored");
} else {
System.getProperties().putIfAbsent("glass.gtk.uiScale", scaleString);
}
}Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

No description provided.