diff --git a/platform/platform-api/src/com/intellij/openapi/util/DimensionService.java b/platform/platform-api/src/com/intellij/openapi/util/DimensionService.java index b20f07c4f1d6..23004172d4e7 100644 --- a/platform/platform-api/src/com/intellij/openapi/util/DimensionService.java +++ b/platform/platform-api/src/com/intellij/openapi/util/DimensionService.java @@ -299,20 +299,15 @@ public class DimensionService implements PersistentStateComponent { frame = WindowManager.getInstance().getFrame(project); } Rectangle screen = new Rectangle(0, 0, 0, 0); + GraphicsDevice device = null; if (frame != null) { - final Point topLeft = frame.getLocation(); - Point center = new Point(topLeft.x + frame.getWidth() / 2, topLeft.y + frame.getHeight() / 2); - for (GraphicsDevice device : env.getScreenDevices()) { - Rectangle bounds = device.getDefaultConfiguration().getBounds(); - if (bounds.contains(center)) { - screen = bounds; - break; - } - } + device = ScreenUtil.getScreenDevice(frame.getBounds()); } - else { - GraphicsConfiguration gc = env.getScreenDevices()[0].getDefaultConfiguration(); - screen = gc.getBounds(); + if (device == null) { + device = env.getDefaultScreenDevice(); + } + if (device != null) { + screen = device.getDefaultConfiguration().getBounds(); } String realKey = key + '.' + screen.x + '.' + screen.y + '.' + screen.width + '.' + screen.height; if (JBUI.isHiDPI()) { diff --git a/platform/platform-api/src/com/intellij/ui/ScreenUtil.java b/platform/platform-api/src/com/intellij/ui/ScreenUtil.java index d9cd28d2412e..ccd1eac11fc4 100644 --- a/platform/platform-api/src/com/intellij/ui/ScreenUtil.java +++ b/platform/platform-api/src/com/intellij/ui/ScreenUtil.java @@ -131,6 +131,10 @@ public class ScreenUtil { return getScreenRectangle(p.x, p.y); } + /** + * @param bounds a rectangle used to find corresponding graphics device + * @return a graphics device that contains the biggest part of the specified rectangle + */ public static GraphicsDevice getScreenDevice(Rectangle bounds) { GraphicsDevice candidate = null; int maxIntersection = 0; @@ -222,8 +226,7 @@ public class ScreenUtil { } /** - * Finds a device that is the closest to the specified point and - * returns its visible area. + * Returns a visible area for a graphics device that is the closest to the specified point. * * @param x the X coordinate of the specified point * @param y the Y coordinate of the specified point