Skip to content

Commit

Permalink
macOS: Restore window bounds after decorations have been installed.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
weisJ committed Dec 29, 2021
1 parent e2ceb6e commit 378b6f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ static DecorationInformation installDecorations(final JRootPane rootPane,
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);
Expand All @@ -63,6 +66,7 @@ static DecorationInformation installDecorations(final JRootPane rootPane,
boolean isDarkTheme = UIManager.getBoolean("Theme.dark");
JNIDecorationsMacOS.setDarkTheme(windowHandle, isDarkTheme);
}
window.setBounds(windowBounds);
return new DecorationInformation(
windowHandle, fullWindowContent,
transparentTitleBar, useColoredTitleBar,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
*/
package com.github.weisj.darklaf.platform.decorations;

import java.awt.*;

import javax.swing.*;

public abstract class CustomTitlePane extends JComponent {
Expand Down

0 comments on commit 378b6f1

Please sign in to comment.