6699851: setMaximizedbounds not working properly on dual screen environment
Reviewed-by: art, anthony
--- a/jdk/src/share/classes/java/awt/Frame.java Fri Nov 26 11:27:00 2010 +0300
+++ b/jdk/src/share/classes/java/awt/Frame.java Fri Nov 26 14:36:42 2010 +0300
@@ -828,6 +828,11 @@
return frame.state;
}
}
+ public Rectangle getMaximizedBounds(Frame frame) {
+ synchronized(frame.getObjectLock()) {
+ return frame.maximizedBounds;
+ }
+ }
}
);
}
@@ -855,8 +860,10 @@
* @see #getMaximizedBounds()
* @since 1.4
*/
- public synchronized void setMaximizedBounds(Rectangle bounds) {
- this.maximizedBounds = bounds;
+ public void setMaximizedBounds(Rectangle bounds) {
+ synchronized(getObjectLock()) {
+ this.maximizedBounds = bounds;
+ }
FramePeer peer = (FramePeer)this.peer;
if (peer != null) {
peer.setMaximizedBounds(bounds);
@@ -873,7 +880,9 @@
* @since 1.4
*/
public Rectangle getMaximizedBounds() {
- return maximizedBounds;
+ synchronized(getObjectLock()) {
+ return maximizedBounds;
+ }
}
--- a/jdk/src/share/classes/sun/awt/AWTAccessor.java Fri Nov 26 11:27:00 2010 +0300
+++ b/jdk/src/share/classes/sun/awt/AWTAccessor.java Fri Nov 26 14:36:42 2010 +0300
@@ -334,6 +334,10 @@
* Gets the state of this frame.
*/
int getExtendedState(Frame frame);
+ /*
+ * Gets the maximized bounds of this frame.
+ */
+ Rectangle getMaximizedBounds(Frame frame);
}
/*
--- a/jdk/src/windows/classes/sun/awt/windows/WFramePeer.java Fri Nov 26 11:27:00 2010 +0300
+++ b/jdk/src/windows/classes/sun/awt/windows/WFramePeer.java Fri Nov 26 14:36:42 2010 +0300
@@ -79,10 +79,50 @@
if (b == null) {
clearMaximizedBounds();
} else {
- setMaximizedBounds(b.x, b.y, b.width, b.height);
+ Rectangle adjBounds = (Rectangle)b.clone();
+ adjustMaximizedBounds(adjBounds);
+ setMaximizedBounds(adjBounds.x, adjBounds.y, adjBounds.width, adjBounds.height);
}
}
+ /**
+ * The incoming bounds describe the maximized size and position of the
+ * window on the monitor that displays the window. But the window manager
+ * expects that the bounds are based on the size and position of the
+ * primary monitor, even if the window ultimately maximizes onto a
+ * secondary monitor. And the window manager adjusts these values to
+ * compensate for differences between the primary monitor and the monitor
+ * that displays the window.
+ * The method translates the incoming bounds to the values acceptable
+ * by the window manager. For more details, please refer to 6699851.
+ */
+ private void adjustMaximizedBounds(Rectangle b) {
+ GraphicsConfiguration currentDevGC = getGraphicsConfiguration();
+
+ GraphicsDevice primaryDev = GraphicsEnvironment
+ .getLocalGraphicsEnvironment().getDefaultScreenDevice();
+ GraphicsConfiguration primaryDevGC = primaryDev.getDefaultConfiguration();
+
+ if (currentDevGC != null && currentDevGC != primaryDevGC) {
+ Rectangle currentDevBounds = currentDevGC.getBounds();
+ Rectangle primaryDevBounds = primaryDevGC.getBounds();
+
+ b.width -= (currentDevBounds.width - primaryDevBounds.width);
+ b.height -= (currentDevBounds.height - primaryDevBounds.height);
+ }
+ }
+
+ @Override
+ public boolean updateGraphicsData(GraphicsConfiguration gc) {
+ boolean result = super.updateGraphicsData(gc);
+ Rectangle bounds = AWTAccessor.getFrameAccessor().
+ getMaximizedBounds((Frame)target);
+ if (bounds != null) {
+ setMaximizedBounds(bounds);
+ }
+ return result;
+ }
+
@Override
boolean isTargetUndecorated() {
return ((Frame)target).isUndecorated();