8019587: [macosx] Possibility to set the same frame for the different screens
authorserb
Tue, 09 Jul 2013 21:21:55 +0400
changeset 18758 15c2b5596c57
parent 18757 5ab9e48648e5
child 18759 678de8e7eb93
8019587: [macosx] Possibility to set the same frame for the different screens Reviewed-by: art, anthony
jdk/src/share/classes/java/awt/GraphicsDevice.java
jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java
--- a/jdk/src/share/classes/java/awt/GraphicsDevice.java	Tue Jul 09 18:01:58 2013 +0400
+++ b/jdk/src/share/classes/java/awt/GraphicsDevice.java	Tue Jul 09 21:21:55 2013 +0400
@@ -296,6 +296,12 @@
                                     bgColor.getBlue(), 255);
                 w.setBackground(bgColor);
             }
+            // Check if this window is in fullscreen mode on another device.
+            final GraphicsConfiguration gc = w.getGraphicsConfiguration();
+            if (gc != null && gc.getDevice() != this
+                    && gc.getDevice().getFullScreenWindow() == w) {
+                gc.getDevice().setFullScreenWindow(null);
+            }
         }
         if (fullScreenWindow != null && windowedModeBounds != null) {
             // if the window went into fs mode before it was realized it may
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/java/awt/GraphicsDevice/IncorrectDisplayModeExitFullscreen.java	Tue Jul 09 21:21:55 2013 +0400
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+
+import java.awt.Color;
+import java.awt.DisplayMode;
+import java.awt.Frame;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Toolkit;
+
+import sun.awt.SunToolkit;
+
+/**
+ * @test
+ * @bug 8019587
+ * @author Sergey Bylokhov
+ */
+public class IncorrectDisplayModeExitFullscreen {
+
+    public static void main(final String[] args) {
+
+        final GraphicsDevice[] devices =
+                GraphicsEnvironment.getLocalGraphicsEnvironment()
+                                   .getScreenDevices();
+        if (devices.length < 2 || devices[0].getDisplayModes().length < 2
+                || !devices[0].isFullScreenSupported()
+                || !devices[1].isFullScreenSupported()) {
+            System.err.println("Testcase is not applicable");
+            return;
+        }
+        final DisplayMode defaultDM = devices[0].getDisplayMode();
+        final DisplayMode[] dms = devices[0].getDisplayModes();
+        DisplayMode nonDefaultDM = null;
+
+        for (final DisplayMode dm : dms) {
+            if (!dm.equals(defaultDM)) {
+                nonDefaultDM = dm;
+                break;
+            }
+        }
+        if (nonDefaultDM == null) {
+            System.err.println("Testcase is not applicable");
+            return;
+        }
+
+        final Frame frame = new Frame();
+        frame.setBackground(Color.GREEN);
+        frame.setUndecorated(true);
+        try {
+            devices[0].setFullScreenWindow(frame);
+            sleep();
+            devices[0].setDisplayMode(nonDefaultDM);
+            sleep();
+            devices[1].setFullScreenWindow(frame);
+            sleep();
+            if (!defaultDM.equals(devices[0].getDisplayMode())) {
+                throw new RuntimeException("DisplayMode is not restored");
+            }
+        } finally {
+            // cleaning up
+            devices[0].setFullScreenWindow(null);
+            devices[1].setFullScreenWindow(null);
+            frame.dispose();
+        }
+    }
+    private static void sleep() {
+        ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();
+        try {
+            Thread.sleep(1500);
+        } catch (InterruptedException ignored) {
+        }
+    }
+}