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 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);

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 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;

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);
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);
}
}

11
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);

Loading…
Cancel
Save