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";
/**
* Specifies whether FlatLaf native window decorations should be used
* Specifies whether native window decorations should be used
* when creating {@code JFrame} or {@code JDialog}.
* <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.
* <p>
* Setting this to {@code false} disables using FlatLaf native window decorations.
* Setting this to {@code false} disables using native window decorations.
* <p>
* This system property has higher priority than client property
* {@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>
* (based on OpenJDK).
* <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.
* Then FlatLaf native window decorations are used.
* <p>
* (requires Window 10)
* <p>
* <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";

View File

@@ -41,9 +41,22 @@ import com.formdev.flatlaf.util.SystemInfo;
*/
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
private static final boolean canUseJBRCustomDecorations
= SystemInfo.isJetBrainsJVM_11_orLater && SystemInfo.isWindows_10_orLater;
private static final boolean canUseJBRCustomDecorations =
canUseWindowDecorations &&
SystemInfo.isJetBrainsJVM_11_orLater &&
FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true );
private static Boolean supported;
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.
Window window = SwingUtilities.windowForComponent( rootPane );
if( window != null && window.isDisplayable() )
install( window, FlatSystemProperties.USE_WINDOW_DECORATIONS );
install( window );
// Install FlatLaf native window border, which must be done late,
// when the native window is already created, because it needs access to the window.
@@ -81,7 +94,7 @@ public class FlatNativeWindowBorder
PropertyChangeListener ancestorListener = e -> {
Object newValue = e.getNewValue();
if( newValue instanceof Window )
install( (Window) newValue, FlatSystemProperties.USE_WINDOW_DECORATIONS );
install( (Window) newValue );
else if( newValue == null && e.getOldValue() instanceof Window )
uninstall( (Window) e.getOldValue() );
};
@@ -89,7 +102,7 @@ public class FlatNativeWindowBorder
return ancestorListener;
}
static void install( Window window, String systemPropertyKey ) {
static void install( Window window ) {
if( hasCustomDecoration( window ) )
return;
@@ -102,7 +115,7 @@ public class FlatNativeWindowBorder
JRootPane rootPane = frame.getRootPane();
// check whether disabled via system property, client property or UI default
if( !useWindowDecorations( rootPane, systemPropertyKey ) )
if( !useWindowDecorations( rootPane ) )
return;
// do not enable native window border if frame is undecorated
@@ -120,7 +133,7 @@ public class FlatNativeWindowBorder
JRootPane rootPane = dialog.getRootPane();
// check whether disabled via system property, client property or UI default
if( !useWindowDecorations( rootPane, systemPropertyKey ) )
if( !useWindowDecorations( rootPane ) )
return;
// do not enable native window border if dialog is undecorated
@@ -149,7 +162,7 @@ public class FlatNativeWindowBorder
rootPane.removePropertyChangeListener( "ancestor", (PropertyChangeListener) data );
// 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;
// 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
Boolean enabled = FlatSystemProperties.getBooleanStrict( systemPropertyKey, null );
Boolean enabled = FlatSystemProperties.getBooleanStrict( FlatSystemProperties.USE_WINDOW_DECORATIONS, null );
if( enabled != null )
return enabled;
@@ -243,16 +256,7 @@ public class FlatNativeWindowBorder
return;
supported = false;
// requires Windows 10
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 ) )
if( !canUseWindowDecorations )
return;
try {

View File

@@ -36,7 +36,6 @@ import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.plaf.BorderUIResource;
import com.formdev.flatlaf.FlatLaf;
import com.formdev.flatlaf.FlatSystemProperties;
import com.formdev.flatlaf.util.LoggingFacade;
import com.formdev.flatlaf.util.HiDPIUtils;
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
Window window = SwingUtilities.windowForComponent( rootPane );
if( window != null ) {
FlatNativeWindowBorder.install( window, FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS );
FlatNativeWindowBorder.install( window );
return null;
}
@@ -89,7 +88,7 @@ public class JBRCustomDecorations
Container parent = e.getChangedParent();
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
// 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 )
return;
// check whether disabled via system property
if( !FlatSystemProperties.getBoolean( FlatSystemProperties.USE_JETBRAINS_CUSTOM_DECORATIONS, true ) )
return;
try {
Class<?> awtAcessorClass = Class.forName( "sun.awt.AWTAccessor" );
Class<?> compAccessorClass = Class.forName( "sun.awt.AWTAccessor$ComponentAccessor" );