JDK-8248126 : JavaFX ignores HiDPI scaling settings on some linux platforms
  • Type: Bug
  • Component: javafx
  • Sub-Component: window-toolkit
  • Affected Version: openjfx11,openjfx14
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: linux
  • CPU: x86
  • Submitted: 2020-06-19
  • Updated: 2021-03-02
  • Resolved: 2021-02-15
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
openjfx11.0.11Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
ADDITIONAL SYSTEM INFORMATION :
Dell XPS 13 with HiDPI (200 % scaling)
Fedora 32 Workstation with Gnome
OpenJFX 14.0.1

A DESCRIPTION OF THE PROBLEM :
On Fedora 32 Workstation (Gnome) the AppImage from Cryptomator (cryptomator.org) does not follow the system-wide scale settings from Gnome Settings.

Default setting in Fedora:
$ gsettings get org.gnome.desktop.interface scaling-factor
uint32 0

Please note the closed bug JDK-8137050 (https://bugs.openjdk.java.net/browse/JDK-8137050) which apparently did not fix the issue in Fedora Workstation 32 (Gnome).

According to the developers from Cryptomator the bug occurs in OpenJFX 14.0.1 and 11.

Related bug reports in Cryptomator for other distributions:
https://github.com/cryptomator/cryptomator/issues/1223 (Ubuntu 20.04 LTS)
https://github.com/cryptomator/cryptomator/issues/42 (Pop!OS)
https://github.com/cryptomator/cryptomator/issues/1242 (Fedora 32 Workstation Gnome)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Start AppImage from cryptomator.org

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
App window should scale according to system settings, in my case 200 %.
ACTUAL -
App window scales to 100 %.

CUSTOMER SUBMITTED WORKAROUND :
Workaround 1: $gsettings set org.gnome.desktop.interface scaling-factor 2
Workaround 2: $GDK_SCALE=2 ./cryptomator-1.5.5-x86_64.AppImage


Comments
Changeset: 782f22a1 Author: Pankaj Bansal <pbansal@openjdk.org> Date: 2021-02-15 08:11:13 +0000 URL: https://git.openjdk.java.net/jfx/commit/782f22a1
15-02-2021

The issue can be reproduced in fedora 32, Ubuntu 20.10, Ubuntu 20.04. by following these steps 1. Set the scale from Settings->Displays->Set Scale. Set scale to 2.0. This option may not be visible on some screen resolutions. 2. Start a JavaFX application/sample like Ensemble, it will not be scaled according to the scale. https://bugs.openjdk.java.net/browse/JDK-8258464 has some more information
09-02-2021

I have found that gdk_screen_get_resolution returns the screen DPI and looks like something we should be able to use. Some points about this API are 1. It is not considering the scale set by GDK_SCALE or gsetting. So this will need to be in-addition to what we are doing right now to find the scale. It is only considering the window system level scale set from Settings->Display->Set Scale. 2. The value is not considering the fractional scale. For UIScale scale 1.0, the DPI value is 96. For scale 2.0>=Scale>1.0 (like 1.25, 1.5, 1.75, 2.0), the value is 192. I am not able to test with scale >2.0 as I do not see the option on my machine settings. I am on VM, which may be a limitation. The does seem to solve the issue we are dealing in this bug. Following is a WIP patch. I have tested it on Ubuntu 20.04 and Fedora 32, it works fine on both. diff --git a/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.h b/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.h index 049ab61920..f235eaec7b 100644 --- a/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.h +++ b/modules/javafx.graphics/src/main/native-glass/gtk/glass_general.h @@ -45,6 +45,8 @@ #define JLONG_TO_PTR(value) ((void*)(intptr_t)(value)) #define PTR_TO_JLONG(value) ((jlong)(intptr_t)(value)) +#define VERBOSE + #define FILE_PREFIX "file://" #define URI_LIST_COMMENT_PREFIX "#" #define URI_LIST_LINE_BREAK "\r\n" diff --git a/modules/javafx.graphics/src/main/native-glass/gtk/glass_screen.cpp b/modules/javafx.graphics/src/main/native-glass/gtk/glass_screen.cpp index 8a44f1815e..f002e802d3 100644 --- a/modules/javafx.graphics/src/main/native-glass/gtk/glass_screen.cpp +++ b/modules/javafx.graphics/src/main/native-glass/gtk/glass_screen.cpp @@ -24,7 +24,6 @@ */ #include <stdlib.h> - #include "glass_screen.h" #include "glass_general.h" @@ -103,7 +102,7 @@ static GdkRectangle get_screen_workarea(GdkScreen *screen) { } -jfloat getUIScale() { +jfloat getUIScale(GdkScreen* screen) { jfloat uiScale; if (OverrideUIScale > 0.0f) { uiScale = OverrideUIScale; @@ -115,11 +114,18 @@ jfloat getUIScale() { } else { uiScale = (jfloat) glass_settings_get_guint_opt("org.gnome.desktop.interface", "scaling-factor", 0); + LOG1("The glass_settings_get_guint_opt scale is: %f\n", uiScale); + if (uiScale < 1) { + gdouble dpi = gdk_screen_get_resolution(screen); + uiScale = (jfloat) (dpi/96); + LOG1( "The DPI scale is: %f\n", uiScale); + } if (uiScale < 1) { uiScale = 1; } } } + LOG1("The final scale is: %f\n\n", uiScale); return uiScale; } @@ -140,7 +146,8 @@ static jobject createJavaScreen(JNIEnv* env, GdkScreen* screen, gint monitor_idx GdkRectangle working_monitor_geometry; gdk_rectangle_intersect(&workArea, &monitor_geometry, &working_monitor_geometry); - jfloat uiScale = getUIScale(); + jfloat uiScale = getUIScale(screen); + jint mx = monitor_geometry.x / uiScale; jint my = monitor_geometry.y / uiScale;
04-02-2021

the gtk_window_get_scale_factor API is always returning 1. I have tried changing the UI scale from settings to 1.0, 2.0, but the API always returns 1. I was thinking that the API may be reading the environment variable GDK_SCALE, but looks looks like it is not doing that. I just exported the GDK_SCALE and gtk_window_get_scale_factor still returns 1.0. I have looked into gtk APIs and I dont see any other API where it is dealing with scale factors. At the same time, I have seen that gtk3 applications do scale properly. So, it does have the proper scale information. As of now, I am not able to find how gtk is doing it. I have tested this on both fedora32 and Ubuntu 20.04.
26-01-2021

I tried the gdk_window_get_scale_factor, but it is always returning 1 as scale even if I set the scale 2.0 from Settings->Display. Following is the patch diff --git a/modules/javafx.graphics/src/main/native-glass/gtk/glass_screen.cpp b/modules/javafx.graphics/src/main/native-glass/gtk/glass_screen.cpp index 8a44f1815e..2ea174721c 100644 --- a/modules/javafx.graphics/src/main/native-glass/gtk/glass_screen.cpp +++ b/modules/javafx.graphics/src/main/native-glass/gtk/glass_screen.cpp @@ -103,7 +102,7 @@ static GdkRectangle get_screen_workarea(GdkScreen *screen) { } -jfloat getUIScale() { +jfloat getUIScale(GdkScreen* screen) { jfloat uiScale; if (OverrideUIScale > 0.0f) { uiScale = OverrideUIScale; @@ -115,11 +114,17 @@ jfloat getUIScale() { } else { uiScale = (jfloat) glass_settings_get_guint_opt("org.gnome.desktop.interface", "scaling-factor", 0); + LOG1("The glass_settings_get_guint_opt scale is: %f\n", uiScale); + if (uiScale < 1) { + uiScale = (jfloat) gdk_window_get_scale_factor(gdk_screen_get_root_window(screen)); + LOG1( "The gtk scale is: %f\n", uiScale); + } if (uiScale < 1) { uiScale = 1; } } } + LOG1("The final scale is: %f\n\n", uiScale); return uiScale; } @@ -140,7 +145,7 @@ static jobject createJavaScreen(JNIEnv* env, GdkScreen* screen, gint monitor_idx GdkRectangle working_monitor_geometry; gdk_rectangle_intersect(&workArea, &monitor_geometry, &working_monitor_geometry); - jfloat uiScale = getUIScale(); + jfloat uiScale = getUIScale(screen); jint mx = monitor_geometry.x / uiScale; jint my = monitor_geometry.y / uiScale;
04-01-2021

See JDK-8258464 for a report of a similar bug on Ubuntu 20.04. More detail can be found here: https://github.com/javafxports/openjdk-jfx/issues/643
16-12-2020

Raising to P3 since there is no app-level workaround (the end user needs to set an env var to get Hi-DPI scaling).
16-12-2020

See also JDK-8238077 which describes similar issue.
17-08-2020

Additional Information from Submitter: =========================== I'm using PopOS20.04 on a 2019 Dell XPS 15 7590 and I'm having the same scaling issue. I use the GDK_SCALE=2 Applications/cryptomator-1.5.6-x86_64.AppImage command and it helps the usability, but it would be better if cryptomator scaled properly without launching it in terminal this way every time.
08-07-2020

Additional Information from Submitter: =========================== I use Pop_OS! 19.10 on my Thinkpad T480s. I can confirm this problem. All apps adapt to the scaling of my desktop, only Cryptomator stays the same ->small. The only workaround that helped me so far was "GDK_SCALE=2.5x cryptomator"
29-06-2020

The detection logic in JavaFX expect that the "scaling-factor" setting in "org.gnome.desktop.interface" has the correct Hi-DPI setting. The logic in question is basically (pseudo-code) : if (GDK_SCALE is set) scale = GDK_SCALE else { scale = gsettings get "org.gnome.desktop.interface" "scaling-factor" if (scale < 1) { scale = 1 } } I note that a "scaling-factor" setting of 0 is supposed to indicate to automatically detect the scaling from the Window system. We would just need to add logic to get the scale from the Window system, using an appropriate call, such as gdk_window_get_scale_factor, in case `gsettings get "org.gnome.desktop.interface" "scaling-factor"` returns 0.
26-06-2020