@@ -164,15 +164,10 @@ case "`uname`" in
164
164
' "$@"'
165
165
;;
166
166
* )
167
- # Support 2x HiDPI scaling on Linux systems that have configured this via Xft.dpi but not via
168
- # GDK_SCALE, notably Ubuntu as of 20.04.1. Xft.dpi technically relates to the size of fonts
169
- # only, but Ubuntu sets it when the "Scaling" setting is changed in the "Displays" settings
170
- # UI. OpenJDK supports the GDK_SCALE setting at the GraphicsConfiguration level, but not
171
- # Xft.dpi (as of 2020-11-22 and LTS 11.0.9). Individual LAFs may react to the latter, though
172
- # FlatLAF in particular works correctly even both are set at the same time.
173
- #
174
- # OpenJDK does not support fractional scalings in GDK_SCALE, so we only handle the 2x case
175
- # here. OpenJDK also does not query the separate GDK_DPI_SCALE variable.
167
+ # Support HiDPI scaling on Linux systems that have configured this via Xft.dpi but not via
168
+ # GDK_SCALE, notably Ubuntu and Fedora. Xft.dpi technically relates to the size of fonts
169
+ # only, but Ubuntu and Fedora set it when the "Scaling" setting is changed in the "Displays"
170
+ # settings UI.
176
171
#
177
172
# We do not attempt to support per-monitor DPI scalings here. OpenJDK might support this
178
173
# through the ubuntu.user-interface/scale-factor setting, but as of Ubuntu 20.04.1, the
@@ -181,32 +176,59 @@ case "`uname`" in
181
176
# saying it is "not well supported yet" (presumably in their own OpenJDK fork).
182
177
# https://intellij-support.jetbrains.com/hc/en-us/articles/360007994999-HiDPI-configuration
183
178
179
+ detected_dpi=" "
180
+
184
181
# If the xrdb command does not exist, no action will be taken here.
185
- if [ " ` command xrdb -query 2> /dev/null | grep Xft.dpi | cut -d ' :' -f2 | xargs` " = 192 ]
186
- then
187
- echo " Detected 2x HiDPI scaling in Xft.dpi setting; setting GDK_SCALE=2 "
188
- export GDK_SCALE=2
182
+ xft_dpi= " ` command xrdb -query 2> /dev/null | grep Xft.dpi | cut -d ' :' -f2 | xargs` "
183
+ if [ -z " $GDK_SCALE " ] && [ -z " $J2D_UISCALE " ] && [ -n " $xft_dpi " ] && [ " $xft_dpi " -gt 96 ] && [ " $xft_dpi " -le 192 ] ; then
184
+ detected_dpi= " $xft_dpi "
185
+ echo -n " Detected $detected_dpi DPI in Xft.dpi setting; "
189
186
fi
190
187
191
- # Handle another case that indicates a need for 2x HiDPI scaling, observed on openSUSE
192
- # Tumbleweed (see NETBEANS-2360). A user with a HiDPI monitor and 2x HiDPI scaling
188
+ # Handle another case that indicates a need for HiDPI scaling, observed on openSUSE
189
+ # Tumbleweed (see NETBEANS-2360). A user with a HiDPI monitor and HiDPI scaling
193
190
# enabled reported that "xdpyinfo | grep -B 2 resolution" yielded the following:
194
191
#
195
192
# screen #0:
196
193
# dimensions: 3840x2160 pixels (508x285 millimeters)
197
194
# resolution: 192x193 dots per inch
198
195
#
199
196
# Xft.dpi was not set in this case, however. In the following test, we
200
- # set GDK_SCALE=2 if _all_ monitors report a resolution of "192x"
201
- # something (ignoring the odd "193" figure observed above).
202
- if [ " ` command xdpyinfo 2> /dev/null | grep ' resolution:.*dots per inch' | cut -d ' :' -f2 | cut -d ' x' -f1 | sort -u | xargs` " = 192 ]
203
- then
204
- echo " Detected 192 DPI on all screens in xdpyinfo; setting GDK_SCALE=2"
205
- export GDK_SCALE=2
197
+ # enable HiDPI scaling if _all_ monitors report a resolution of
198
+ # "(97-192)xsomething" (ignoring the odd 193 figure observed above).
199
+ if [ -z " $xft_dpi " ]; then
200
+ xdpyinfo_dpi=" ` command xdpyinfo 2> /dev/null | grep ' resolution:.*dots per inch' | cut -d ' :' -f2 | cut -d ' x' -f1 | sort -u | xargs` "
201
+ case " $xdpyinfo_dpi " in
202
+ * [!0-9]* ) ;;
203
+ " " ) ;;
204
+ * )
205
+ if [ -z " $GDK_SCALE " ] && [ -z " $J2D_UISCALE " ] && [ " $xdpyinfo_dpi " -gt 96 ] && [ " $xdpyinfo_dpi " -le 192 ]; then
206
+ detected_dpi=" $xdpyinfo_dpi "
207
+ echo -n " Detected $detected_dpi DPI on all screens in xdpyinfo; "
208
+ fi
209
+ ;;
210
+ esac
206
211
fi
207
212
208
213
extra_automatic_options=" "
209
214
215
+ # OpenJDK does not support fractional scalings in GDK_SCALE. OpenJDK also does not query the
216
+ # separate GDK_DPI_SCALE variable. In theory FlatLaf can do fractional scaling, but in
217
+ # practice not all parts of NetBeans are scaled properly with a flatlaf.uiScale value
218
+ # between 1 and 2. But FlatLaf also supports fractional scaling smaller than 1, so we make
219
+ # Java scale by 2 with a sun.java2d.uiScale value of 2, then we make FlatLaf scale down with
220
+ # a flatlaf.uiScale value between 0 and 1.
221
+ if [ -z " $GDK_SCALE " ] && [ -z " $J2D_UISCALE " ] && [ -n " $detected_dpi " ] && [ " $detected_dpi " -gt 96 ] && [ " $detected_dpi " -le 192 ]; then
222
+ extra_automatic_options=" -J-Dsun.java2d.uiScale=2"
223
+ echo -n " using explicit setting for Java UI scaling (-J-Dsun.java2d.uiScale=2)"
224
+ if [ " $detected_dpi " -gt 96 ] && [ " $detected_dpi " -lt 192 ]; then
225
+ scaling_factor=` awk -v dpi=" $detected_dpi " ' BEGIN {print dpi / 192}' `
226
+ extra_automatic_options=" $extra_automatic_options -J-Dflatlaf.uiScale=$scaling_factor "
227
+ echo -n " and FlatLaf UI scaling (-J-Dflatlaf.uiScale=$scaling_factor )"
228
+ fi
229
+ echo
230
+ fi
231
+
210
232
# Java/AWT/Swing will correctly detect text anti-aliasing settings on
211
233
# GNOME, but not (always) on KDE. Force anti-aliasing on in this case
212
234
# using the "awt.useSystemAAFontSettings" property, as recommended in
@@ -227,26 +249,33 @@ case "`uname`" in
227
249
# Try to detect the correct subpixel antialiasing mode
228
250
# (https://github.com/apache/netbeans/issues/4228)
229
251
252
+ antialiasing_font_settings=" "
253
+
230
254
# See https://docs.gtk.org/gtk4/property.Settings.gtk-xft-rgba.html
231
255
# See https://docs.oracle.com/javase/7/docs/technotes/guides/2d/flags.html#aaFonts
232
256
case " ` command xrdb -query 2> /dev/null | grep Xft.rgba | cut -d ' :' -f2 | xargs` " in
233
257
rgb)
234
- extra_automatic_options =" -J-Dawt.useSystemAAFontSettings=lcd_hrgb"
258
+ antialiasing_font_settings =" -J-Dawt.useSystemAAFontSettings=lcd_hrgb"
235
259
;;
236
260
bgr)
237
- extra_automatic_options =" -J-Dawt.useSystemAAFontSettings=lcd_hbgr"
261
+ antialiasing_font_settings =" -J-Dawt.useSystemAAFontSettings=lcd_hbgr"
238
262
;;
239
263
vrgb)
240
- extra_automatic_options =" -J-Dawt.useSystemAAFontSettings=lcd_vrgb"
264
+ antialiasing_font_settings =" -J-Dawt.useSystemAAFontSettings=lcd_vrgb"
241
265
;;
242
266
vbgr)
243
- extra_automatic_options =" -J-Dawt.useSystemAAFontSettings=lcd_vbgr"
267
+ antialiasing_font_settings =" -J-Dawt.useSystemAAFontSettings=lcd_vbgr"
244
268
;;
245
269
* )
246
- extra_automatic_options =" -J-Dawt.useSystemAAFontSettings=on"
270
+ antialiasing_font_settings =" -J-Dawt.useSystemAAFontSettings=on"
247
271
;;
248
272
esac
249
- echo " Detected KDE; use explicit setting for font antialiasing ($extra_automatic_options )"
273
+ echo " Detected KDE; using explicit setting for font antialiasing ($antialiasing_font_settings )"
274
+ if [ -z " $extra_automatic_options " ]; then
275
+ extra_automatic_options=" $antialiasing_font_settings "
276
+ else
277
+ extra_automatic_options=" $extra_automatic_options $antialiasing_font_settings "
278
+ fi
250
279
fi
251
280
252
281
# Add extra_automatic_options before default_options, to allow system
0 commit comments