Native window decorations: cleaned-up/simplified JetBrains Runtime custom window decorations "enabled" checking:

- `FlatSystemProperties.USE_WINDOW_DECORATIONS` is now also used for JBR custom window decorations
- `FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS` is now only used to disable JBR custom window decorations; then FlatLaf native window decorations are used
- JBR custom window decorations are now disabled when running in JetBrains Projector, Webswing or WinPE
This commit is contained in:
Karl Tauber
2021-04-03 13:32:46 +02:00
parent de1b0b1bb6
commit 63639f8e96
3 changed files with 31 additions and 34 deletions

View File

@@ -55,13 +55,13 @@ public interface FlatSystemProperties
String USE_UBUNTU_FONT = "flatlaf.useUbuntuFont"; String USE_UBUNTU_FONT = "flatlaf.useUbuntuFont";
/** /**
* Specifies whether FlatLaf native window decorations should be used * Specifies whether native window decorations should be used
* when creating {@code JFrame} or {@code JDialog}. * when creating {@code JFrame} or {@code JDialog}.
* <p> * <p>
* Setting this to {@code true} forces using FlatLaf native window decorations * Setting this to {@code true} forces using native window decorations
* even if they are not enabled by the application. * even if they are not enabled by the application.
* <p> * <p>
* Setting this to {@code false} disables using FlatLaf native window decorations. * Setting this to {@code false} disables using native window decorations.
* <p> * <p>
* This system property has higher priority than client property * This system property has higher priority than client property
* {@link FlatClientProperties#USE_WINDOW_DECORATIONS} and * {@link FlatClientProperties#USE_WINDOW_DECORATIONS} and
@@ -81,15 +81,13 @@ public interface FlatSystemProperties
* <a href="https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime">JetBrains Runtime</a> * <a href="https://confluence.jetbrains.com/display/JBR/JetBrains+Runtime">JetBrains Runtime</a>
* (based on OpenJDK). * (based on OpenJDK).
* <p> * <p>
* Setting this to {@code true} forces using JetBrains Runtime custom window decorations
* even if they are not enabled by the application.
* <p>
* Setting this to {@code false} disables using JetBrains Runtime custom window decorations. * Setting this to {@code false} disables using JetBrains Runtime custom window decorations.
* Then FlatLaf native window decorations are used.
* <p> * <p>
* (requires Window 10) * (requires Window 10)
* <p> * <p>
* <strong>Allowed Values</strong> {@code false} and {@code true}<br> * <strong>Allowed Values</strong> {@code false} and {@code true}<br>
* <strong>Default</strong> none * <strong>Default</strong> true
*/ */
String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations"; String USE_JETBRAINS_CUSTOM_DECORATIONS = "flatlaf.useJetBrainsCustomDecorations";

View File

@@ -41,9 +41,22 @@ import com.formdev.flatlaf.util.SystemInfo;
*/ */
public class FlatNativeWindowBorder public class FlatNativeWindowBorder
{ {
// can use window decorations if:
// - on Windows 10
// - not when running in JetBrains Projector, Webswing or WinPE
// - not disabled via system property
private static final boolean canUseWindowDecorations =
SystemInfo.isWindows_10_orLater &&
!SystemInfo.isProjector &&
!SystemInfo.isWebswing &&
!SystemInfo.isWinPE &&
FlatSystemProperties.getBoolean( FlatSystemProperties.USE_WINDOW_DECORATIONS, true );
// check this field before using class JBRCustomDecorations to avoid unnecessary loading of that class // check this field before using class JBRCustomDecorations to avoid unnecessary loading of that class
private static final boolean canUseJBRCustomDecorations private static final boolean canUseJBRCustomDecorations =
= SystemInfo.isJetBrainsJVM_11_orLater && SystemInfo.isWindows_10_orLater; canUseWindowDecorations &&
SystemInfo.isJetBrainsJVM_11_orLater &&
FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true );
private static Boolean supported; private static Boolean supported;
private static Provider nativeProvider; private static Provider nativeProvider;
@@ -72,7 +85,7 @@ public class FlatNativeWindowBorder
// It could be also be a window that is currently hidden, but may be shown later. // It could be also be a window that is currently hidden, but may be shown later.
Window window = SwingUtilities.windowForComponent( rootPane ); Window window = SwingUtilities.windowForComponent( rootPane );
if( window != null && window.isDisplayable() ) if( window != null && window.isDisplayable() )
install( window, FlatSystemProperties.USE_WINDOW_DECORATIONS ); install( window );
// Install FlatLaf native window border, which must be done late, // Install FlatLaf native window border, which must be done late,
// when the native window is already created, because it needs access to the window. // when the native window is already created, because it needs access to the window.
@@ -81,7 +94,7 @@ public class FlatNativeWindowBorder
PropertyChangeListener ancestorListener = e -> { PropertyChangeListener ancestorListener = e -> {
Object newValue = e.getNewValue(); Object newValue = e.getNewValue();
if( newValue instanceof Window ) if( newValue instanceof Window )
install( (Window) newValue, FlatSystemProperties.USE_WINDOW_DECORATIONS ); install( (Window) newValue );
else if( newValue == null && e.getOldValue() instanceof Window ) else if( newValue == null && e.getOldValue() instanceof Window )
uninstall( (Window) e.getOldValue() ); uninstall( (Window) e.getOldValue() );
}; };
@@ -89,7 +102,7 @@ public class FlatNativeWindowBorder
return ancestorListener; return ancestorListener;
} }
static void install( Window window, String systemPropertyKey ) { static void install( Window window ) {
if( hasCustomDecoration( window ) ) if( hasCustomDecoration( window ) )
return; return;
@@ -102,7 +115,7 @@ public class FlatNativeWindowBorder
JRootPane rootPane = frame.getRootPane(); JRootPane rootPane = frame.getRootPane();
// check whether disabled via system property, client property or UI default // check whether disabled via system property, client property or UI default
if( !useWindowDecorations( rootPane, systemPropertyKey ) ) if( !useWindowDecorations( rootPane ) )
return; return;
// do not enable native window border if frame is undecorated // do not enable native window border if frame is undecorated
@@ -120,7 +133,7 @@ public class FlatNativeWindowBorder
JRootPane rootPane = dialog.getRootPane(); JRootPane rootPane = dialog.getRootPane();
// check whether disabled via system property, client property or UI default // check whether disabled via system property, client property or UI default
if( !useWindowDecorations( rootPane, systemPropertyKey ) ) if( !useWindowDecorations( rootPane ) )
return; return;
// do not enable native window border if dialog is undecorated // do not enable native window border if dialog is undecorated
@@ -149,7 +162,7 @@ public class FlatNativeWindowBorder
rootPane.removePropertyChangeListener( "ancestor", (PropertyChangeListener) data ); rootPane.removePropertyChangeListener( "ancestor", (PropertyChangeListener) data );
// do not uninstall when switching to another FlatLaf theme and if still enabled // do not uninstall when switching to another FlatLaf theme and if still enabled
if( UIManager.getLookAndFeel() instanceof FlatLaf && useWindowDecorations( rootPane, FlatSystemProperties.USE_WINDOW_DECORATIONS ) ) if( UIManager.getLookAndFeel() instanceof FlatLaf && useWindowDecorations( rootPane ) )
return; return;
// uninstall native window border // uninstall native window border
@@ -179,9 +192,9 @@ public class FlatNativeWindowBorder
} }
} }
private static boolean useWindowDecorations( JRootPane rootPane, String systemPropertyKey ) { private static boolean useWindowDecorations( JRootPane rootPane ) {
// check whether forced to enabled/disabled via system property // check whether forced to enabled/disabled via system property
Boolean enabled = FlatSystemProperties.getBooleanStrict( systemPropertyKey, null ); Boolean enabled = FlatSystemProperties.getBooleanStrict( FlatSystemProperties.USE_WINDOW_DECORATIONS, null );
if( enabled != null ) if( enabled != null )
return enabled; return enabled;
@@ -243,16 +256,7 @@ public class FlatNativeWindowBorder
return; return;
supported = false; supported = false;
// requires Windows 10 if( !canUseWindowDecorations )
if( !SystemInfo.isWindows_10_orLater )
return;
// do not use when running in JetBrains Projector, Webswing or WinPE
if( SystemInfo.isProjector || SystemInfo.isWebswing || SystemInfo.isWinPE )
return;
// check whether disabled via system property
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_WINDOW_DECORATIONS, true ) )
return; return;
try { try {

View File

@@ -36,7 +36,6 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.plaf.BorderUIResource; import javax.swing.plaf.BorderUIResource;
import com.formdev.flatlaf.FlatLaf; import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.util.LoggingFacade; import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.HiDPIUtils; import com.formdev.flatlaf.util.HiDPIUtils;
import com.formdev.flatlaf.util.SystemInfo; import com.formdev.flatlaf.util.SystemInfo;
@@ -73,7 +72,7 @@ public class JBRCustomDecorations
// check whether root pane already has a parent, which is the case when switching LaF // check whether root pane already has a parent, which is the case when switching LaF
Window window = SwingUtilities.windowForComponent( rootPane ); Window window = SwingUtilities.windowForComponent( rootPane );
if( window != null ) { if( window != null ) {
FlatNativeWindowBorder.install( window, FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS ); FlatNativeWindowBorder.install( window );
return null; return null;
} }
@@ -89,7 +88,7 @@ public class JBRCustomDecorations
Container parent = e.getChangedParent(); Container parent = e.getChangedParent();
if( parent instanceof Window ) if( parent instanceof Window )
FlatNativeWindowBorder.install( (Window) parent, FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS ); FlatNativeWindowBorder.install( (Window) parent );
// remove listener since it is actually not possible to uninstall JBR decorations // remove listener since it is actually not possible to uninstall JBR decorations
// use invokeLater to remove listener to avoid that listener // use invokeLater to remove listener to avoid that listener
@@ -165,10 +164,6 @@ public class JBRCustomDecorations
if( !SystemInfo.isJetBrainsJVM_11_orLater || !SystemInfo.isWindows_10_orLater ) if( !SystemInfo.isJetBrainsJVM_11_orLater || !SystemInfo.isWindows_10_orLater )
return; return;
// check whether disabled via system property
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true ) )
return;
try { try {
Class<?> awtAcessorClass = Class.forName( "sun.awt.AWTAccessor" ); Class<?> awtAcessorClass = Class.forName( "sun.awt.AWTAccessor" );
Class<?> compAccessorClass = Class.forName( "sun.awt.AWTAccessor$ComponentAccessor" ); Class<?> compAccessorClass = Class.forName( "sun.awt.AWTAccessor$ComponentAccessor" );