diff --git a/platform/platform-api/src/com/intellij/ui/ScreenUtil.java b/platform/platform-api/src/com/intellij/ui/ScreenUtil.java index 8d87435f8e62..870bfcc327fc 100644 --- a/platform/platform-api/src/com/intellij/ui/ScreenUtil.java +++ b/platform/platform-api/src/com/intellij/ui/ScreenUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,7 @@ */ package com.intellij.ui; +import com.intellij.Patches; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; import com.intellij.util.containers.WeakHashMap; @@ -30,6 +31,7 @@ import java.util.Map; */ public class ScreenUtil { public static final String DISPOSE_TEMPORARY = "dispose.temporary"; + @Nullable private static final Map> ourInsetsCache; static { final boolean useCache = SystemInfo.isXWindow && !GraphicsEnvironment.isHeadless(); @@ -112,16 +114,16 @@ public class ScreenUtil { } private static JRootPane findMainRootPane(Component component) { - while(component != null) { + while (component != null) { Container parent = component.getParent(); - if (parent == null) - return component instanceof RootPaneContainer ? ((RootPaneContainer) component).getRootPane() : null; + if (parent == null) { + return component instanceof RootPaneContainer ? ((RootPaneContainer)component).getRootPane() : null; + } component = parent; } return null; } - private static Rectangle applyInsets(Rectangle rect, Insets i) { if (i == null) { return rect; @@ -130,16 +132,6 @@ public class ScreenUtil { return new Rectangle(rect.x + i.left, rect.y + i.top, rect.width - (i.left + i.right), rect.height - (i.top + i.bottom)); } - private static Insets fixGlobalInsets(Rectangle rect, Insets i) { - if (i == null) { - //noinspection ConstantConditions - return i; - } - int top = i.top > rect.y ? i.top - rect.y : i.top; - int left = i.left > rect.x ? i.left - rect.x : i.left; - return new Insets(top, left, i.bottom, i.right); - } - public static Insets getScreenInsets(final GraphicsConfiguration gc) { if (ourInsetsCache == null) { return calcInsets(gc); @@ -157,11 +149,11 @@ public class ScreenUtil { } private static Insets calcInsets(GraphicsConfiguration gc) { - Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc); - if (SystemInfo.isXWindow && GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length > 1) { - return fixGlobalInsets(gc.getBounds(), insets); + if (Patches.SUN_BUG_ID_4737732 && GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices().length > 1) { + return new Insets(0, 0, 0, 0); } - return insets; + + return Toolkit.getDefaultToolkit().getScreenInsets(gc); } public static Rectangle getScreenRectangle(int x, int y) { diff --git a/platform/util/src/com/intellij/Patches.java b/platform/util/src/com/intellij/Patches.java index b71ea278c002..41f2668e77d2 100644 --- a/platform/util/src/com/intellij/Patches.java +++ b/platform/util/src/com/intellij/Patches.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -115,4 +115,11 @@ public class Patches { * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6457572. */ public static final boolean SUN_BUG_ID_6457572 = SystemInfo.isWindows && !SystemInfo.isJavaVersionAtLeast("1.7"); + + /** + * Java 7 incorrectly calculates screen insets on multi-monitor X Window configurations. + * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4737732. + * todo[r.sh] put correct bug ID here once available + */ + public static final boolean SUN_BUG_ID_4737732 = SystemInfo.isXWindow && SystemInfo.isJavaVersionAtLeast("1.7"); }