JDK-8326428 : [Linux] UI scaling factor cannot be fractional when using KDE
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: jfx21
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • Submitted: 2024-02-21
  • Updated: 2024-03-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
While computing a screen’s user interface scale the Linux code consults the “scaling-factor” gsetting in the “org.gnome.desktop.interface” schema. This check was added about eight years ago in the PR that addressed JDK-8166382. On the Ubuntu systems I’m familiar with this value is not set so JavaFX computes the scaling factor based on the monitor resolution reported by GDK. This technique allows JavaFX to support fractional scaling.

As of June 2023 (version 5.27.80 or so) KDE started setting the scaling-factor. Originally this was set by flooring the real scaling factor but in an upcoming version they will round upward in some cases. According to the commit comment this was to get IntelliJ IDEA to behave better. In any case KDE is now setting this and if the system scale is fractional it’s guaranteed to be wrong. See https://invent.kde.org/plasma/kde-gtk-config/-/commit/b79bd5a95d8fe9964fa695edbed1180f72ca8b69.

KDE also adds the scaling factor to Xsettingsd as “Gdk/WindowScalingFactor”. That started about a year ago but it is also a floored integer. See https://invent.kde.org/plasma/kde-gtk-config/-/commit/1debd2e0833fd62e2e1c1837387fcc1c3436340a.

I suspect the org.gnome.desktop.interface scaling-factor setting is obsolete since it only handles integral scaling. JavaFX should probably stop consulting it.
Comments
I needed to setup some KDE and Gnome VM's for keyboard testing and since I have a Retina display I was also able to do some scaling testing. All of this was with Gnome and KDE using Ubuntu 23 and 22. Even with just those two systems I can't guarantee I covered everything, there's X11 vs Wayland and fractional versus non-fractional and on the most recent version of KDE under Wayland there's a checkbox which controls how Xwayland clients are scaled. With that said: If the reported screen resolution is not 96 dividing it by 96 is the most reliable way to compute a useable UI scale. If the screen resolution is 96 JavaFX needs to continue checking the GDK_SCALE environment variable. That's how KDE in Ubuntu 22 implements non-fractional scaling (for fractional scaling GDK_SCALE isn't set and we can consult the screen resolution). In KDE 5.27.8 GDK_SCALE is never set and using the screen resolution is always the right thing to do. The conservative fix for this issue is to continue to check GDK_SCALE and "scaling-factor" but only when the reported resolution is 96. It is possible that we can ignore "scaling-factor" altogether but that would take some code research. In the versions of Gnome I tested scaling-factor is no longer used but I have no idea how far back that goes (KDE seems to be reviving this setting to get IntelliJ IDEA working).
26-02-2024

[~mfox] Before I saw your comment, I also checked when this was added, and discovered the same thing. I note that this setting has always been an int, so even when it was in regular use, it only supported integer scale. As for what to do, it seems reasonable for us to stop checking for this setting. Additional testing may be needed, since we haven't done much testing of fractional scales on Linux.
22-02-2024

Correction: the check for org.gnome.desktop.interface scaling-factor was added when HiDPI support was first implemented on Linux with JDK-8137050. This setting is deprecated and Gnome doesn't update it any more. The scaling factors are now tracked per-monitor in ~/.config/monitors.xml.
22-02-2024