Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NETBEANS-2360] Auto-detect HiDPI and anti-aliasing settings on Linux #3113

Merged
merged 1 commit into from Apr 19, 2022

Conversation

eirikbakke
Copy link
Contributor

@eirikbakke eirikbakke commented Aug 18, 2021

This commit modifies the NetBeans IDE launcher scripts to automatically handle two display-related conditions on Linux:

  1. Automatically enable the -Dawt.useSystemAAFontSettings system parameter if necessary to enable anti-aliased text. Veteran NetBeans users have known about this setting for a long time, but after a lot of research, I believe I have found the specific condition in which it is necessary, namely on the K desktop environment.
  2. Automatically detect cases where the user has enabled 2x HiDPI scaling, via the Xft.dpi Xresource, and set the GDK_SCALE environment variable accordingly so that OpenJDK will handle this accordingly. This seems to work on both KDE and Gnome. HiDPI scaling works best on FlatLAF, but seemed to work tolerably on the default GTK LAF as well. (Perhaps in the future we should consider making FlatLAF the default LAF on Linux. NOTE on 2022-02-20: FlatLAF is now the default LAF on all platforms.)

See the in-code comments for more details. (There are two copies of the new code: one in the IDE launcher script, and one in the launcher script for NetBeans Platform applications.)

It would be great if multiple Linux people could test NetBeans with the modified launcher scripts, on both Gnome and KDE (and any other desktop environments that exist out there).

@eirikbakke
Copy link
Contributor Author

(Tried to add @timboudreau as a suggested reviewer here, too, but his name does not show up in the dropdown.)

@eirikbakke
Copy link
Contributor Author

I also considered using the sun.java2d.uiScale system property instead of the GDK_SCALE environment variable. But looking at the JDK source code, neither of these two support fractional scalings, e.g. 1.5x. The sun.java2d.uiScale value is always rounded to an int, even though it's initially parsed as a double, and it appears as an undocumented debugging property only. Experiments confirm that fractional scalings are not supported on Linux with either property. So keep using GDK_SCALE, and handle the 2x case only.

This commit modifies the NetBeans IDE launcher scripts to automatically handle two display-related conditions on Linux:
(1) Automatically enable the -Dawt.useSystemAAFontSettings system parameter if necessary to enable anti-aliased text. Veteran NetBeans users have known about this setting for a long time, but after a lot of research, I believe I have found the specific condition in which it is necessary, namely on the K desktop environment.
(2) Automatically detect cases where the user has enabled 2x HiDPI scaling, and set the GDK_SCALE environment variable accordingly so that OpenJDK will handle this accordingly. This seems to work on both KDE and Gnome. HiDPI scaling works best on FlatLAF (which is now the default LAF for NetBeans on all platforms), but seemed to work tolerably on the default GTK LAF as well. See the in-code comments for more details. (There are two copies of the new code: one in the IDE launcher script, and one in the launcher script for NetBeans Platform applications.)
@eirikbakke
Copy link
Contributor Author

I added another condition to the script to try to handle the DPI scaling case described by Michal Hlavac in https://issues.apache.org/jira/browse/NETBEANS-2360 , on openSUSE Tumbleweed.

Copy link
Member

@DevCharly DevCharly left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Have not tried to run the modified scripts (assuming they work 😉 ), but executed single commands (xrdb -query and xdpyinfo) on various Linux distros (Ubuntu, Kubuntu and Fedora) and various scaling factors and checked the output.

BTW since Java 17, it does no longer try to detect any scaling factor on Linux:
https://github.com/openjdk/jdk/blob/master/src/java.desktop/unix/native/common/awt/systemscale/systemScale.c
A lot of code was removed for https://bugs.openjdk.java.net/browse/JDK-8239894

Regarding FlatLaf: in case that fractional scaling is used (which is supported by KDE), or "Large Text" on Gnome, FlatLaf detects this and uses a larger font and scales its components. This scaling works only if FlatLaf method UIScale.scale() is used, which is not done in NB (except in FlatLaf module).

So it is definitely a good idea to set GDK_SCALE for 200% scaling.

@eirikbakke
Copy link
Contributor Author

@DevCharly Thanks! The patch won't handle every case, but I think it should be an improvement that won't cause new problems. So I'll merge it if no one else drops by and objects within a day or two.

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

Successfully merging this pull request may close these issues.

None yet

3 participants