diff --git a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/JNIDecorationsMacOS.java b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/JNIDecorationsMacOS.java index 82107f90..64fde4d4 100644 --- a/macos/src/main/java/com/github/weisj/darklaf/platform/macos/JNIDecorationsMacOS.java +++ b/macos/src/main/java/com/github/weisj/darklaf/platform/macos/JNIDecorationsMacOS.java @@ -35,7 +35,8 @@ public final class JNIDecorationsMacOS { public static native void installDecorations(final long hwnd); - public static native void uninstallDecorations(final long hwnd); + public static native void uninstallDecorations(final long hwnd, + final boolean fullSizeContent, final boolean transparentTitleBar); public static native void setTitleEnabled(final long hwnd, final boolean enabled); 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 74b40260..155e631c 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 @@ -29,21 +29,19 @@ class DecorationInformation { protected final boolean fullWindowContentEnabled; protected final boolean transparentTitleBarEnabled; protected final boolean useColoredTitleBar; - protected final boolean jniInstalled; protected final JRootPane rootPane; protected final boolean titleVisible; protected final int titleBarHeight; protected final float titleFontSize; protected DecorationInformation(final long windowHandle, final boolean fullWindowContentEnabled, - final boolean transparentTitleBarEnabled, final boolean useColoredTitleBar, final boolean jniInstalled, + final boolean transparentTitleBarEnabled, final boolean useColoredTitleBar, 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; this.titleBarHeight = titleBarHeight; 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 3fc5cd92..6795ec77 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 @@ -45,7 +45,7 @@ public final class MacOSDecorationsUtil { Window window = SwingUtilities.getWindowAncestor(rootPane); long windowHandle = JNIDecorationsMacOS.getComponentPointer(window); if (windowHandle == 0) { - return new DecorationInformation(0, false, false, false, false, rootPane, false, 0, 0); + return new DecorationInformation(0, false, false, false, rootPane, false, 0, 0); } LOGGER.fine( "Installing decorations for window " + windowHandle + "(coloredTitleBar = " + useColoredTitleBar + ")"); @@ -55,9 +55,7 @@ public final class MacOSDecorationsUtil { float titleFontSize = (float) JNIDecorationsMacOS.getTitleFontSize(windowHandle); int titleBarHeight = (int) JNIDecorationsMacOS.getTitleBarHeight(windowHandle); - boolean jniInstall = !SystemInfo.isJavaVersionAtLeast("12"); - - setFullSizeContent(rootPane, windowHandle, jniInstall, useColoredTitleBar); + setFullSizeContent(windowHandle, useColoredTitleBar); boolean titleVisible = SystemInfo.isMacOSMojave; JNIDecorationsMacOS.setTitleEnabled(windowHandle, titleVisible); @@ -68,19 +66,12 @@ public final class MacOSDecorationsUtil { return new DecorationInformation( windowHandle, fullWindowContent, transparentTitleBar, useColoredTitleBar, - jniInstall, rootPane, - titleVisible, titleBarHeight, titleFontSize); + rootPane, titleVisible, titleBarHeight, titleFontSize); } - private static void setFullSizeContent(final JRootPane rootPane, final long windowHandle, - final boolean jniInstall, final boolean enabled) { - if (!jniInstall) { - setTransparentTitleBarEnabled(rootPane, enabled); - setFullWindowContentEnabled(rootPane, enabled); - } else { - if (enabled) { - JNIDecorationsMacOS.installDecorations(windowHandle); - } + private static void setFullSizeContent(final long windowHandle, final boolean enabled) { + if (enabled) { + JNIDecorationsMacOS.installDecorations(windowHandle); } } @@ -89,12 +80,9 @@ public final class MacOSDecorationsUtil { return; } if (information.useColoredTitleBar) { - if (information.jniInstalled) { - JNIDecorationsMacOS.uninstallDecorations(information.windowHandle); - } else { - setFullWindowContentEnabled(information.rootPane, information.fullWindowContentEnabled); - setTransparentTitleBarEnabled(information.rootPane, information.transparentTitleBarEnabled); - } + JNIDecorationsMacOS.uninstallDecorations(information.windowHandle, + information.fullWindowContentEnabled, + information.transparentTitleBarEnabled); } JNIDecorationsMacOS.setTitleEnabled(information.windowHandle, true); JNIDecorationsMacOS.releaseWindow(information.windowHandle); @@ -107,12 +95,4 @@ public final class MacOSDecorationsUtil { private static boolean isTransparentTitleBarEnabled(final JRootPane rootPane) { return PropertyUtil.getBooleanProperty(rootPane, TRANSPARENT_TITLE_BAR_KEY); } - - private static void setFullWindowContentEnabled(final JRootPane rootPane, final boolean enabled) { - rootPane.putClientProperty(FULL_WINDOW_CONTENT_KEY, enabled); - } - - private static void setTransparentTitleBarEnabled(final JRootPane rootPane, final boolean enabled) { - rootPane.putClientProperty(TRANSPARENT_TITLE_BAR_KEY, enabled); - } } diff --git a/macos/src/main/objcpp/Decorations.mm b/macos/src/main/objcpp/Decorations.mm index 018f1720..889dac90 100644 --- a/macos/src/main/objcpp/Decorations.mm +++ b/macos/src/main/objcpp/Decorations.mm @@ -145,12 +145,17 @@ JNF_COCOA_EXIT(env); } JNIEXPORT void JNICALL -Java_com_github_weisj_darklaf_platform_macos_JNIDecorationsMacOS_uninstallDecorations(JNIEnv *env, jclass obj, jlong hwnd) { +Java_com_github_weisj_darklaf_platform_macos_JNIDecorationsMacOS_uninstallDecorations(JNIEnv *env, jclass obj, jlong hwnd, + jboolean fullSizeContent, jboolean transparentTitleBar) { JNF_COCOA_ENTER(env); NSWindow *nsWindow = OBJC(hwnd); [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^{ - nsWindow.styleMask &= ~NSWindowStyleMaskFullSizeContentView; - nsWindow.titlebarAppearsTransparent = NO; + if (fullSizeContent) { + nsWindow.styleMask |= NSWindowStyleMaskFullSizeContentView; + } else { + nsWindow.styleMask &= ~NSWindowStyleMaskFullSizeContentView; + } + nsWindow.titlebarAppearsTransparent = transparentTitleBar ? YES : NO; [nsWindow contentView].needsDisplay = YES; }]; JNF_COCOA_EXIT(env);