Browse Source

Hide window shadow on macOS.

pull/198/head
weisj 4 years ago committed by Jannis Weis
parent
commit
ddcb237a74
  1. 39
      core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java

39
core/src/main/java/com/github/weisj/darklaf/ui/DarkPopupFactory.java

@ -118,30 +118,32 @@ public class DarkPopupFactory extends PopupFactory {
final boolean isFocusable, final boolean startHidden) { final boolean isFocusable, final boolean startHidden) {
boolean noDecorations = PropertyUtil.getBooleanProperty(contents, KEY_NO_DECORATION); boolean noDecorations = PropertyUtil.getBooleanProperty(contents, KEY_NO_DECORATION);
boolean opaque = PropertyUtil.getBooleanProperty(contents, KEY_OPAQUE); boolean opaque = PropertyUtil.getBooleanProperty(contents, KEY_OPAQUE);
setupWindowBackground(window, opaque, !noDecorations); JRootPane rootPane = window instanceof RootPaneContainer
? ((RootPaneContainer) window).getRootPane()
: null;
setupWindowBackground(window, rootPane, opaque, !noDecorations);
setupWindowFocusableState(isFocusable, window); setupWindowFocusableState(isFocusable, window);
setupWindowDecorations(window, noDecorations); setupWindowDecorations(window, rootPane, noDecorations);
setupWindowOpacity(startHidden, window); setupWindowOpacity(startHidden, window);
} }
protected void setupWindowBackground(final Window window, final boolean opaque, final boolean decorations) { protected void setupWindowBackground(final Window window, final JRootPane rootPane,
final boolean opaque, final boolean decorations) {
/* /*
* Sometimes the background is java.awt.SystemColor[i=7] * Sometimes the background is java.awt.SystemColor[i=7]
* It results in a flash of white background, that is repainted with * It results in a flash of white background, that is repainted with
* the proper popup background later. * the proper popup background later.
* That is why we set window background explicitly. * That is why we set window background explicitly.
*/ */
if (window instanceof RootPaneContainer) { if (rootPane == null) return;
JRootPane rootPane = ((RootPaneContainer) window).getRootPane(); rootPane.setOpaque(opaque);
rootPane.setOpaque(opaque); if (opaque) {
if (opaque) { Color bg = ColorUtil.toAlpha(rootPane.getBackground(), 255);
Color bg = ColorUtil.toAlpha(rootPane.getBackground(), 255); window.setBackground(bg);
window.setBackground(bg); } else {
} else { Color bg = getTranslucentPopupBackground(decorations);
Color bg = getTranslucentPopupBackground(decorations); window.setBackground(bg);
window.setBackground(bg); rootPane.setBackground(bg);
rootPane.setBackground(bg);
}
} }
} }
@ -152,7 +154,14 @@ public class DarkPopupFactory extends PopupFactory {
} }
} }
protected void setupWindowDecorations(final Window window, final boolean noDecorations) { protected void setupWindowDecorations(final Window window, final JRootPane rootPane, final boolean noDecorations) {
if (rootPane != null) {
/*
* To ensure truly undecorated windows we need to specify the Window.shadow property to
* remove shadows on macOS.
*/
rootPane.putClientProperty("Window.shadow", !noDecorations);
}
if (DecorationsHandler.getSharedInstance().isCustomDecorationSupported()) { if (DecorationsHandler.getSharedInstance().isCustomDecorationSupported()) {
if (noDecorations) { if (noDecorations) {
DecorationsHandler.getSharedInstance().uninstallPopupWindow(window); DecorationsHandler.getSharedInstance().uninstallPopupWindow(window);

Loading…
Cancel
Save