Skip to content

在 KDE Wayland 环境中使用 dbus 获取 UI 缩放比例#6071

Open
Glavo wants to merge 2 commits intoHMCL-dev:mainfrom
Glavo:fix-kde-scale
Open

在 KDE Wayland 环境中使用 dbus 获取 UI 缩放比例#6071
Glavo wants to merge 2 commits intoHMCL-dev:mainfrom
Glavo:fix-kde-scale

Conversation

@Glavo
Copy link
Copy Markdown
Member

@Glavo Glavo commented May 7, 2026

No description provided.

@Glavo
Copy link
Copy Markdown
Member Author

Glavo commented May 7, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +180 to +188
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);
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

在通过 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);
            }
        }

Comment thread HMCL/src/main/java/org/jackhuang/hmcl/EntryPoint.java Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@Iamliuxiaozhen
Copy link
Copy Markdown

这是我的测试截图和环境:
环境:

  • Ubuntu Studio 26.04
  • KDE Plasma
  • Wayland
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants