Linux: fixed scaling if GDK_SCALE environment variable is set or if running on JetBrains Runtime (issue #69)

This commit is contained in:
Karl Tauber
2020-03-26 13:06:12 +01:00
parent e51ffe2a1c
commit 1d9c8ca65e
2 changed files with 24 additions and 1 deletions

View File

@@ -1,6 +1,12 @@
FlatLaf Change Log FlatLaf Change Log
================== ==================
## Unreleased
- Linux: Fixed scaling if `GDK_SCALE` environment variable is set or if running
on JetBrains Runtime. (issue #69)
## 0.28 ## 0.28
- PasswordField: Warn about enabled Caps Lock. - PasswordField: Warn about enabled Caps Lock.

View File

@@ -17,6 +17,7 @@
package com.formdev.flatlaf; package com.formdev.flatlaf;
import java.awt.Font; import java.awt.Font;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.io.BufferedReader; import java.io.BufferedReader;
@@ -31,6 +32,7 @@ import java.util.logging.Level;
import javax.swing.text.StyleContext; import javax.swing.text.StyleContext;
import com.formdev.flatlaf.util.StringUtils; import com.formdev.flatlaf.util.StringUtils;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
import com.formdev.flatlaf.util.UIScale;
/** /**
* @author Karl Tauber * @author Karl Tauber
@@ -99,6 +101,10 @@ class LinuxFontPolicy
} }
private static double getGnomeFontScale() { private static double getGnomeFontScale() {
// do not scale font here if JRE scales
if( isSystemScaling() )
return 1;
// see class com.sun.java.swing.plaf.gtk.PangoFonts background information // see class com.sun.java.swing.plaf.gtk.PangoFonts background information
Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Xft/DPI" ); Object value = Toolkit.getDefaultToolkit().getDesktopProperty( "gnome.Xft/DPI" );
@@ -168,7 +174,7 @@ class LinuxFontPolicy
// font dpi // font dpi
int dpi = 96; int dpi = 96;
if( forceFontDPI != null ) { if( forceFontDPI != null && !isSystemScaling() ) {
try { try {
dpi = Integer.parseInt( forceFontDPI ); dpi = Integer.parseInt( forceFontDPI );
if( dpi <= 0 ) if( dpi <= 0 )
@@ -247,4 +253,15 @@ class LinuxFontPolicy
} }
return null; return null;
} }
/**
* Returns true if the JRE scales, which is the case if:
* - environment variable GDK_SCALE is set and running on Java 9 or later
* - running on JetBrains Runtime 11 or later and scaling is enabled in system Settings
*/
private static boolean isSystemScaling() {
GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration();
return UIScale.getSystemScaleFactor( gc ) > 1;
}
} }