This is an automated email from the ASF dual-hosted git repository. ebakke pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new 921e5c3df8 [NETBEANS-2360] Auto-detect HiDPI and anti-aliasing settings on Linux. 921e5c3df8 is described below commit 921e5c3df8e0137cb5f22c122b0435e289693007 Author: Eirik Bakke <eba...@ultorg.com> AuthorDate: Tue Aug 17 21:28:32 2021 -0400 [NETBEANS-2360] Auto-detect HiDPI and anti-aliasing settings on Linux. 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 scrip [...] --- .../apisupport.harness/release/launchers/app.sh | 24 ++++++++ nb/ide.launcher/unix/netbeans | 67 ++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/harness/apisupport.harness/release/launchers/app.sh b/harness/apisupport.harness/release/launchers/app.sh index b547bbff4f..76bcc63d11 100644 --- a/harness/apisupport.harness/release/launchers/app.sh +++ b/harness/apisupport.harness/release/launchers/app.sh @@ -142,11 +142,35 @@ case "`uname`" in then sh=/bin/bash fi + + # See longer comments in nb/ide.launcher/unix/netbeans. + if [ "`command xrdb -query 2> /dev/null | grep Xft.dpi | cut -d ':' -f2 | xargs`" = 192 ] + then + echo "Detected 2x HiDPI scaling in Xft.dpi setting; setting GDK_SCALE=2" + export GDK_SCALE=2 + fi + if [ "`command xdpyinfo 2> /dev/null | grep 'resolution:.*dots per inch' | cut -d ':' -f2 | cut -d 'x' -f1 | sort -u | xargs`" = 192 ] + then + echo "Detected 192 DPI on all screens in xdpyinfo; setting GDK_SCALE=2" + export GDK_SCALE=2 + fi + + extra_automatic_options="" + + # See longer comments in nb/ide.launcher/unix/netbeans. + if [ ! -z "$KDE_FULL_SESSION" ] ; then + echo "Detected KDE; adding awt.useSystemAAFontSettings=on" + extra_automatic_options="-J-Dawt.useSystemAAFontSettings=on" + fi + + # Add extra_automatic_options before default_options, to allow system + # property definitions from the configuration file to take precedence. eval exec $sh '"$nbexec"' \ --jdkhome '"$jdkhome"' \ --clusters '"$clusters"' \ --userdir '"${userdir}"' \ --cachedir '"${cachedir}"' \ + ${extra_automatic_options} \ ${default_options} \ "$args" exit 1 diff --git a/nb/ide.launcher/unix/netbeans b/nb/ide.launcher/unix/netbeans index 42c9808e5e..b033a371a0 100644 --- a/nb/ide.launcher/unix/netbeans +++ b/nb/ide.launcher/unix/netbeans @@ -162,11 +162,78 @@ case "`uname`" in '"$@"' ;; *) + # Support 2x HiDPI scaling on Linux systems that have configured this via Xft.dpi but not via + # GDK_SCALE, notably Ubuntu as of 20.04.1. Xft.dpi technically relates to the size of fonts + # only, but Ubuntu sets it when the "Scaling" setting is changed in the "Displays" settings + # UI. OpenJDK supports the GDK_SCALE setting at the GraphicsConfiguration level, but not + # Xft.dpi (as of 2020-11-22 and LTS 11.0.9). Individual LAFs may react to the latter, though + # FlatLAF in particular works correctly even both are set at the same time. + # + # OpenJDK does not support fractional scalings in GDK_SCALE, so we only handle the 2x case + # here. OpenJDK also does not query the separate GDK_DPI_SCALE variable. + # + # We do not attempt to support per-monitor DPI scalings here. OpenJDK might support this + # through the ubuntu.user-interface/scale-factor setting, but as of Ubuntu 20.04.1, the + # Displays setting UI does not appear to touch this setting at all, and does in fact appear + # to force all monitors to use the same scaling. JetBrains mentions the scale-factor setting, + # saying it is "not well supported yet" (presumably in their own OpenJDK fork). + # https://intellij-support.jetbrains.com/hc/en-us/articles/360007994999-HiDPI-configuration + + # If the xrdb command does not exist, no action will be taken here. + if [ "`command xrdb -query 2> /dev/null | grep Xft.dpi | cut -d ':' -f2 | xargs`" = 192 ] + then + echo "Detected 2x HiDPI scaling in Xft.dpi setting; setting GDK_SCALE=2" + export GDK_SCALE=2 + fi + + # Handle another case that indicates a need for 2x HiDPI scaling, observed on openSUSE + # Tumbleweed (see NETBEANS-2360). A user with a HiDPI monitor and 2x HiDPI scaling + # enabled reported that "xdpyinfo | grep -B 2 resolution" yielded the following: + # + # screen #0: + # dimensions: 3840x2160 pixels (508x285 millimeters) + # resolution: 192x193 dots per inch + # + # Xft.dpi was not set in this case, however. In the following test, we + # set GDK_SCALE=2 if _all_ monitors report a resolution of "192x" + # something (ignoring the odd "193" figure observed above). + if [ "`command xdpyinfo 2> /dev/null | grep 'resolution:.*dots per inch' | cut -d ':' -f2 | cut -d 'x' -f1 | sort -u | xargs`" = 192 ] + then + echo "Detected 192 DPI on all screens in xdpyinfo; setting GDK_SCALE=2" + export GDK_SCALE=2 + fi + + extra_automatic_options="" + + # Java/AWT/Swing will correctly detect text anti-aliasing settings on + # GNOME, but not on KDE. Force anti-aliasing on in this case using the + # "awt.useSystemAAFontSettings" property, as recommended in + # https://bugs.openjdk.java.net/browse/JDK-6408759 . Said bug is old, + # but the relevant logic (in sun.awt.X11.XToolkit.initXSettingsIfNeeded , + # and fontpath.c ) seems not to have changed significantly since then. + # Don't set the "swing.aatext" property; it was "an interim property + # strictly for testing" that has been removed from the JDK and + # superseded by awt.useSystemAAFontSettings (see + # https://bugs.openjdk.java.net/browse/JDK-6391267 ). + + # "If you plan on using this variable to detect a running KDE session, + # check if the value is not empty instead of seeing if it equals true. + # The value might be changed in the future to include KDE version + # information." + # https://userbase.kde.org/KDE_System_Administration/Environment_Variables + if [ ! -z "$KDE_FULL_SESSION" ] ; then + echo "Detected KDE; adding awt.useSystemAAFontSettings=on" + extra_automatic_options="-J-Dawt.useSystemAAFontSettings=on" + fi + + # Add extra_automatic_options before default_options, to allow system + # property definitions from the configuration file to take precedence. eval launchNbexec \ --jdkhome '"$netbeans_jdkhome"' \ --branding nb \ --clusters '"$netbeans_clusters"' \ -J-Dnetbeans.importclass=org.netbeans.upgrade.AutoUpgrade \ + ${extra_automatic_options} \ ${netbeans_default_options} \ '"$@"' ;; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists