Browse Source

Decorations: Remove non jni install path

The client-property approach for java >= 12 resulted in window resizing failing
if it causes the window to be realized. Setting the 'fullSizeContentView' and
'transparentTitleBar' client-properties resulted in a native resize happening
inside 'Component#reshape' causing unexpected resize results.
We replace it with our jni approach to have better control over what happens to the window sizes.

Fixes #230
macos/dialog_size
Jannis Weis 3 years ago
parent
commit
95be88027b
  1. 3
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/JNIDecorationsMacOS.java
  2. 4
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/DecorationInformation.java
  3. 38
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java
  4. 11
      macos/src/main/objcpp/Decorations.mm

3
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 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); public static native void setTitleEnabled(final long hwnd, final boolean enabled);

4
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 fullWindowContentEnabled;
protected final boolean transparentTitleBarEnabled; protected final boolean transparentTitleBarEnabled;
protected final boolean useColoredTitleBar; protected final boolean useColoredTitleBar;
protected final boolean jniInstalled;
protected final JRootPane rootPane; protected final JRootPane rootPane;
protected final boolean titleVisible; protected final boolean titleVisible;
protected final int titleBarHeight; protected final int titleBarHeight;
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 useColoredTitleBar, final boolean jniInstalled, final boolean transparentTitleBarEnabled, final boolean useColoredTitleBar,
final JRootPane rootPane, 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.useColoredTitleBar = useColoredTitleBar;
this.jniInstalled = jniInstalled;
this.rootPane = rootPane; this.rootPane = rootPane;
this.titleVisible = titleVisible; this.titleVisible = titleVisible;
this.titleBarHeight = titleBarHeight; this.titleBarHeight = titleBarHeight;

38
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); 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, false, rootPane, false, 0, 0); return new DecorationInformation(0, false, false, false, rootPane, false, 0, 0);
} }
LOGGER.fine( LOGGER.fine(
"Installing decorations for window " + windowHandle + "(coloredTitleBar = " + useColoredTitleBar + ")"); "Installing decorations for window " + windowHandle + "(coloredTitleBar = " + useColoredTitleBar + ")");
@ -55,9 +55,7 @@ public final class MacOSDecorationsUtil {
float titleFontSize = (float) JNIDecorationsMacOS.getTitleFontSize(windowHandle); float titleFontSize = (float) JNIDecorationsMacOS.getTitleFontSize(windowHandle);
int titleBarHeight = (int) JNIDecorationsMacOS.getTitleBarHeight(windowHandle); int titleBarHeight = (int) JNIDecorationsMacOS.getTitleBarHeight(windowHandle);
boolean jniInstall = !SystemInfo.isJavaVersionAtLeast("12"); setFullSizeContent(windowHandle, useColoredTitleBar);
setFullSizeContent(rootPane, windowHandle, jniInstall, useColoredTitleBar);
boolean titleVisible = SystemInfo.isMacOSMojave; boolean titleVisible = SystemInfo.isMacOSMojave;
JNIDecorationsMacOS.setTitleEnabled(windowHandle, titleVisible); JNIDecorationsMacOS.setTitleEnabled(windowHandle, titleVisible);
@ -68,19 +66,12 @@ public final class MacOSDecorationsUtil {
return new DecorationInformation( return new DecorationInformation(
windowHandle, fullWindowContent, windowHandle, fullWindowContent,
transparentTitleBar, useColoredTitleBar, transparentTitleBar, useColoredTitleBar,
jniInstall, rootPane, rootPane, titleVisible, titleBarHeight, titleFontSize);
titleVisible, titleBarHeight, titleFontSize);
} }
private static void setFullSizeContent(final JRootPane rootPane, final long windowHandle, private static void setFullSizeContent(final long windowHandle, final boolean enabled) {
final boolean jniInstall, final boolean enabled) { if (enabled) {
if (!jniInstall) { JNIDecorationsMacOS.installDecorations(windowHandle);
setTransparentTitleBarEnabled(rootPane, enabled);
setFullWindowContentEnabled(rootPane, enabled);
} else {
if (enabled) {
JNIDecorationsMacOS.installDecorations(windowHandle);
}
} }
} }
@ -89,12 +80,9 @@ public final class MacOSDecorationsUtil {
return; return;
} }
if (information.useColoredTitleBar) { if (information.useColoredTitleBar) {
if (information.jniInstalled) { JNIDecorationsMacOS.uninstallDecorations(information.windowHandle,
JNIDecorationsMacOS.uninstallDecorations(information.windowHandle); information.fullWindowContentEnabled,
} else { 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);
@ -107,12 +95,4 @@ public final class MacOSDecorationsUtil {
private static boolean isTransparentTitleBarEnabled(final JRootPane rootPane) { private static boolean isTransparentTitleBarEnabled(final JRootPane rootPane) {
return PropertyUtil.getBooleanProperty(rootPane, TRANSPARENT_TITLE_BAR_KEY); 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);
}
} }

11
macos/src/main/objcpp/Decorations.mm

@ -145,12 +145,17 @@ JNF_COCOA_EXIT(env);
} }
JNIEXPORT void JNICALL 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); JNF_COCOA_ENTER(env);
NSWindow *nsWindow = OBJC(hwnd); NSWindow *nsWindow = OBJC(hwnd);
[JNFRunLoop performOnMainThreadWaiting:YES withBlock:^{ [JNFRunLoop performOnMainThreadWaiting:YES withBlock:^{
nsWindow.styleMask &= ~NSWindowStyleMaskFullSizeContentView; if (fullSizeContent) {
nsWindow.titlebarAppearsTransparent = NO; nsWindow.styleMask |= NSWindowStyleMaskFullSizeContentView;
} else {
nsWindow.styleMask &= ~NSWindowStyleMaskFullSizeContentView;
}
nsWindow.titlebarAppearsTransparent = transparentTitleBar ? YES : NO;
[nsWindow contentView].needsDisplay = YES; [nsWindow contentView].needsDisplay = YES;
}]; }];
JNF_COCOA_EXIT(env); JNF_COCOA_EXIT(env);

Loading…
Cancel
Save