Browse Source

Add option to disable colored title bars on macOS. If disabled the titlebar will either be the native light or dark variant based on the theme.

pull/214/head
weisj 4 years ago
parent
commit
f9f4e490cf
  1. 5
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/DecorationInformation.java
  2. 39
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java
  3. 5
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSTitlePane.java

5
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 long windowHandle;
protected final boolean fullWindowContentEnabled; protected final boolean fullWindowContentEnabled;
protected final boolean transparentTitleBarEnabled; protected final boolean transparentTitleBarEnabled;
protected final boolean useColoredTitleBar;
protected final boolean jniInstalled; protected final boolean jniInstalled;
protected final JRootPane rootPane; protected final JRootPane rootPane;
protected final boolean titleVisible; protected final boolean titleVisible;
@ -35,11 +36,13 @@ class DecorationInformation {
protected final float titleFontSize; protected final float titleFontSize;
protected DecorationInformation(final long windowHandle, final boolean fullWindowContentEnabled, 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) { final boolean titleVisible, final int titleBarHeight, final float titleFontSize) {
this.windowHandle = windowHandle; this.windowHandle = windowHandle;
this.fullWindowContentEnabled = fullWindowContentEnabled; this.fullWindowContentEnabled = fullWindowContentEnabled;
this.transparentTitleBarEnabled = transparentTitleBarEnabled; this.transparentTitleBarEnabled = transparentTitleBarEnabled;
this.useColoredTitleBar = useColoredTitleBar;
this.jniInstalled = jniInstalled; this.jniInstalled = jniInstalled;
this.rootPane = rootPane; this.rootPane = rootPane;
this.titleVisible = titleVisible; this.titleVisible = titleVisible;

39
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 FULL_WINDOW_CONTENT_KEY = "apple.awt.fullWindowContent";
private static final String TRANSPARENT_TITLE_BAR_KEY = "apple.awt.transparentTitleBar"; 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; if (rootPane == null) return null;
Window window = SwingUtilities.getWindowAncestor(rootPane); Window window = SwingUtilities.getWindowAncestor(rootPane);
long windowHandle = JNIDecorationsMacOS.getComponentPointer(window); long windowHandle = JNIDecorationsMacOS.getComponentPointer(window);
if (windowHandle == 0) { 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); JNIDecorationsMacOS.retainWindow(windowHandle);
boolean fullWindowContent = isFullWindowContentEnabled(rootPane); boolean fullWindowContent = isFullWindowContentEnabled(rootPane);
@ -48,29 +49,41 @@ public class MacOSDecorationsUtil {
int titleBarHeight = (int) JNIDecorationsMacOS.getTitleBarHeight(windowHandle); int titleBarHeight = (int) JNIDecorationsMacOS.getTitleBarHeight(windowHandle);
boolean jniInstall = !SystemInfo.isJavaVersionAtLeast("12"); boolean jniInstall = !SystemInfo.isJavaVersionAtLeast("12");
if (!jniInstall) {
setTransparentTitleBarEnabled(rootPane, true); if (useColoredTitleBar) {
setFullWindowContentEnabled(rootPane, true); enableFullSizeContent(rootPane, windowHandle, jniInstall);
} else {
JNIDecorationsMacOS.installDecorations(windowHandle);
} }
boolean titleVisible = SystemInfo.isMacOSMojave; boolean titleVisible = SystemInfo.isMacOSMojave;
JNIDecorationsMacOS.setTitleEnabled(windowHandle, titleVisible); JNIDecorationsMacOS.setTitleEnabled(windowHandle, titleVisible);
if (titleVisible) { if (titleVisible) {
boolean isDarkTheme = UIManager.getBoolean("Theme.dark"); boolean isDarkTheme = UIManager.getBoolean("Theme.dark");
JNIDecorationsMacOS.setDarkTheme(windowHandle, isDarkTheme); JNIDecorationsMacOS.setDarkTheme(windowHandle, isDarkTheme);
} }
return new DecorationInformation(windowHandle, fullWindowContent, transparentTitleBar, jniInstall, rootPane, return new DecorationInformation(windowHandle, fullWindowContent, transparentTitleBar, useColoredTitleBar,
jniInstall, rootPane,
titleVisible, titleBarHeight, titleFontSize); 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) { protected static void uninstallDecorations(final DecorationInformation information) {
if (information == null || information.windowHandle == 0) return; if (information == null || information.windowHandle == 0) return;
if (information.jniInstalled) { if (information.useColoredTitleBar) {
JNIDecorationsMacOS.uninstallDecorations(information.windowHandle); if (information.jniInstalled) {
} else { JNIDecorationsMacOS.uninstallDecorations(information.windowHandle);
setFullWindowContentEnabled(information.rootPane, information.fullWindowContentEnabled); } else {
setTransparentTitleBarEnabled(information.rootPane, information.transparentTitleBarEnabled); setFullWindowContentEnabled(information.rootPane, information.fullWindowContentEnabled);
setTransparentTitleBarEnabled(information.rootPane, information.transparentTitleBarEnabled);
}
} }
JNIDecorationsMacOS.setTitleEnabled(information.windowHandle, true); JNIDecorationsMacOS.setTitleEnabled(information.windowHandle, true);
JNIDecorationsMacOS.releaseWindow(information.windowHandle); JNIDecorationsMacOS.releaseWindow(information.windowHandle);

5
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 JRootPane rootPane;
private final Window window; private final Window window;
private final boolean useColoredTitleBar;
private WindowListener windowListener; private WindowListener windowListener;
private Color inactiveBackground; private Color inactiveBackground;
private Color activeBackground; private Color activeBackground;
@ -55,6 +56,7 @@ public class MacOSTitlePane extends CustomTitlePane {
public MacOSTitlePane(final JRootPane rootPane, final Window window) { public MacOSTitlePane(final JRootPane rootPane, final Window window) {
this.rootPane = rootPane; this.rootPane = rootPane;
this.window = window; this.window = window;
this.useColoredTitleBar = UIManager.getBoolean("macos.coloredTitleBar");
determineColors(); determineColors();
updateTitleBarVisibility(); updateTitleBarVisibility();
} }
@ -118,7 +120,7 @@ public class MacOSTitlePane extends CustomTitlePane {
public void install() { public void install() {
determineColors(); determineColors();
JRootPane rootPane = getRootPane(); JRootPane rootPane = getRootPane();
decorationInformation = MacOSDecorationsUtil.installDecorations(rootPane); decorationInformation = MacOSDecorationsUtil.installDecorations(rootPane, useColoredTitleBar);
installListeners(); installListeners();
if (!decorationInformation.titleVisible) { if (!decorationInformation.titleVisible) {
titleLabel = new JLabel(); titleLabel = new JLabel();
@ -210,6 +212,7 @@ public class MacOSTitlePane extends CustomTitlePane {
} }
private boolean hideTitleBar() { private boolean hideTitleBar() {
if (!useColoredTitleBar) return true;
if (titleBarHidden) return true; if (titleBarHidden) return true;
return (decorationInformation.windowHandle == 0) return (decorationInformation.windowHandle == 0)
|| JNIDecorationsMacOS.isFullscreen(decorationInformation.windowHandle) || JNIDecorationsMacOS.isFullscreen(decorationInformation.windowHandle)

Loading…
Cancel
Save