diff --git a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/DecorationInformation.java b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/DecorationInformation.java index ca954745..6b4754fd 100644 --- a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/DecorationInformation.java +++ b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/DecorationInformation.java @@ -28,6 +28,7 @@ class DecorationInformation { protected final long windowHandle; protected final boolean fullWindowContentEnabled; protected final boolean transparentTitleBarEnabled; + protected final boolean useColoredTitleBar; protected final boolean jniInstalled; protected final JRootPane rootPane; protected final boolean titleVisible; @@ -35,11 +36,13 @@ class DecorationInformation { protected final float titleFontSize; protected DecorationInformation(final long windowHandle, final boolean fullWindowContentEnabled, - final boolean transparentTitleBarEnabled, final boolean jniInstalled, final JRootPane rootPane, + final boolean transparentTitleBarEnabled, final boolean useColoredTitleBar, final boolean jniInstalled, + final JRootPane rootPane, final boolean titleVisible, final int titleBarHeight, final float titleFontSize) { this.windowHandle = windowHandle; this.fullWindowContentEnabled = fullWindowContentEnabled; this.transparentTitleBarEnabled = transparentTitleBarEnabled; + this.useColoredTitleBar = useColoredTitleBar; this.jniInstalled = jniInstalled; this.rootPane = rootPane; this.titleVisible = titleVisible; diff --git a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java index 270a773b..0c8f4214 100644 --- a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java +++ b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java @@ -34,12 +34,13 @@ public class MacOSDecorationsUtil { private static final String FULL_WINDOW_CONTENT_KEY = "apple.awt.fullWindowContent"; private static final String TRANSPARENT_TITLE_BAR_KEY = "apple.awt.transparentTitleBar"; - protected static DecorationInformation installDecorations(final JRootPane rootPane) { + protected static DecorationInformation installDecorations(final JRootPane rootPane, + final boolean useColoredTitleBar) { if (rootPane == null) return null; Window window = SwingUtilities.getWindowAncestor(rootPane); long windowHandle = JNIDecorationsMacOS.getComponentPointer(window); if (windowHandle == 0) { - return new DecorationInformation(0, false, false, false, rootPane, false, 0, 0); + return new DecorationInformation(0, false, false, false, false, rootPane, false, 0, 0); } JNIDecorationsMacOS.retainWindow(windowHandle); boolean fullWindowContent = isFullWindowContentEnabled(rootPane); @@ -48,29 +49,41 @@ public class MacOSDecorationsUtil { int titleBarHeight = (int) JNIDecorationsMacOS.getTitleBarHeight(windowHandle); boolean jniInstall = !SystemInfo.isJavaVersionAtLeast("12"); - if (!jniInstall) { - setTransparentTitleBarEnabled(rootPane, true); - setFullWindowContentEnabled(rootPane, true); - } else { - JNIDecorationsMacOS.installDecorations(windowHandle); + + if (useColoredTitleBar) { + enableFullSizeContent(rootPane, windowHandle, jniInstall); } + boolean titleVisible = SystemInfo.isMacOSMojave; JNIDecorationsMacOS.setTitleEnabled(windowHandle, titleVisible); if (titleVisible) { boolean isDarkTheme = UIManager.getBoolean("Theme.dark"); JNIDecorationsMacOS.setDarkTheme(windowHandle, isDarkTheme); } - return new DecorationInformation(windowHandle, fullWindowContent, transparentTitleBar, jniInstall, rootPane, + return new DecorationInformation(windowHandle, fullWindowContent, transparentTitleBar, useColoredTitleBar, + jniInstall, rootPane, titleVisible, titleBarHeight, titleFontSize); } + private static void enableFullSizeContent(final JRootPane rootPane, final long windowHandle, + final boolean jniInstall) { + if (!jniInstall) { + setTransparentTitleBarEnabled(rootPane, true); + setFullWindowContentEnabled(rootPane, true); + } else { + JNIDecorationsMacOS.installDecorations(windowHandle); + } + } + protected static void uninstallDecorations(final DecorationInformation information) { if (information == null || information.windowHandle == 0) return; - if (information.jniInstalled) { - JNIDecorationsMacOS.uninstallDecorations(information.windowHandle); - } else { - setFullWindowContentEnabled(information.rootPane, information.fullWindowContentEnabled); - setTransparentTitleBarEnabled(information.rootPane, information.transparentTitleBarEnabled); + if (information.useColoredTitleBar) { + if (information.jniInstalled) { + JNIDecorationsMacOS.uninstallDecorations(information.windowHandle); + } else { + setFullWindowContentEnabled(information.rootPane, information.fullWindowContentEnabled); + setTransparentTitleBarEnabled(information.rootPane, information.transparentTitleBarEnabled); + } } JNIDecorationsMacOS.setTitleEnabled(information.windowHandle, true); JNIDecorationsMacOS.releaseWindow(information.windowHandle); diff --git a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java index 5840e754..c2c006d4 100644 --- a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java +++ b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java @@ -39,6 +39,7 @@ public class MacOSTitlePane extends CustomTitlePane { private final JRootPane rootPane; private final Window window; + private final boolean useColoredTitleBar; private WindowListener windowListener; private Color inactiveBackground; private Color activeBackground; @@ -55,6 +56,7 @@ public class MacOSTitlePane extends CustomTitlePane { public MacOSTitlePane(final JRootPane rootPane, final Window window) { this.rootPane = rootPane; this.window = window; + this.useColoredTitleBar = UIManager.getBoolean("macos.coloredTitleBar"); determineColors(); updateTitleBarVisibility(); } @@ -118,7 +120,7 @@ public class MacOSTitlePane extends CustomTitlePane { public void install() { determineColors(); JRootPane rootPane = getRootPane(); - decorationInformation = MacOSDecorationsUtil.installDecorations(rootPane); + decorationInformation = MacOSDecorationsUtil.installDecorations(rootPane, useColoredTitleBar); installListeners(); if (!decorationInformation.titleVisible) { titleLabel = new JLabel(); @@ -210,6 +212,7 @@ public class MacOSTitlePane extends CustomTitlePane { } private boolean hideTitleBar() { + if (!useColoredTitleBar) return true; if (titleBarHidden) return true; return (decorationInformation.windowHandle == 0) || JNIDecorationsMacOS.isFullscreen(decorationInformation.windowHandle)