Browse Source

macOS: Restore window bounds after decorations have been installed.

Installing the custom decorations may cause the window to be resized
as Cocoa tries to compensate for the removal of the titlebar. Hence,
any previously set size for the window wil be incorrect. We circumvent
this issue by restoring the window bounds after the installation is
completed.

Relates to #292
spotless
Jannis Weis 3 years ago
parent
commit
378b6f19ea
No known key found for this signature in database
GPG Key ID: 7C9D8D4B558049AB
  1. 8
      macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java
  2. 2
      platform-base/src/main/java/com/github/weisj/darklaf/platform/decorations/CustomTitlePane.java

8
macos/src/main/java/com/github/weisj/darklaf/platform/macos/ui/MacOSDecorationsUtil.java

@ -47,8 +47,11 @@ public final class MacOSDecorationsUtil {
if (windowHandle == 0) {
return new DecorationInformation(0, false, false, false, rootPane, false, 0, 0);
}
LOGGER.fine(
"Installing decorations for window " + windowHandle + "(coloredTitleBar = " + useColoredTitleBar + ")");
// Removing the decorations may cause the window to be resized.
// Hence, we save the current bounds to restore them later.
Rectangle windowBounds = window.getBounds();
LOGGER.fine("Installing decorations for window " + windowHandle
+ "(coloredTitleBar = " + useColoredTitleBar + ")");
JNIDecorationsMacOS.retainWindow(windowHandle);
boolean fullWindowContent = isFullWindowContentEnabled(rootPane);
boolean transparentTitleBar = isTransparentTitleBarEnabled(rootPane);
@ -63,6 +66,7 @@ public final class MacOSDecorationsUtil {
boolean isDarkTheme = UIManager.getBoolean("Theme.dark");
JNIDecorationsMacOS.setDarkTheme(windowHandle, isDarkTheme);
}
window.setBounds(windowBounds);
return new DecorationInformation(
windowHandle, fullWindowContent,
transparentTitleBar, useColoredTitleBar,

2
platform-base/src/main/java/com/github/weisj/darklaf/platform/decorations/CustomTitlePane.java

@ -21,8 +21,6 @@
*/
package com.github.weisj.darklaf.platform.decorations;
import java.awt.*;
import javax.swing.*;
public abstract class CustomTitlePane extends JComponent {

Loading…
Cancel
Save