Skip to content

Commit 37123ee

Browse files
committed
8312518: [macos13] setFullScreenWindow() shows black screen on macOS 13 & above
Backport-of: 999e556be4302de4b6911e6d62ee5ca556a76469
1 parent 5173435 commit 37123ee

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

src/java.desktop/macosx/native/libawt_lwawt/awt/AWTWindow.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1647,6 +1647,7 @@ + (AWTWindow *) lastKeyWindow {
16471647
int shieldLevel = CGShieldingWindowLevel();
16481648
window.preFullScreenLevel = [nsWindow level];
16491649
[nsWindow setLevel: shieldLevel];
1650+
[nsWindow makeKeyAndOrderFront: nil];
16501651

16511652
NSRect screenRect = [[nsWindow screen] frame];
16521653
[nsWindow setFrame:screenRect display:YES];
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.awt.Color;
25+
import java.awt.Frame;
26+
import java.awt.GraphicsDevice;
27+
import java.awt.GraphicsEnvironment;
28+
import java.awt.Robot;
29+
import jtreg.SkippedException;
30+
31+
import static java.awt.EventQueue.invokeAndWait;
32+
33+
/*
34+
* @test
35+
* @key headful
36+
* @bug 8312518
37+
* @library /test/lib
38+
* @summary Setting fullscreen window using setFullScreenWindow() shows up
39+
* as black screen on newer macOS versions (13 & 14).
40+
*/
41+
42+
public class SetFullScreenTest {
43+
private static Frame frame;
44+
private static GraphicsDevice gd;
45+
private static Robot robot;
46+
private static volatile int width;
47+
private static volatile int height;
48+
49+
public static void main(String[] args) throws Exception {
50+
try {
51+
robot = new Robot();
52+
invokeAndWait(() -> {
53+
gd = GraphicsEnvironment.getLocalGraphicsEnvironment().
54+
getDefaultScreenDevice();
55+
if (!gd.isFullScreenSupported()) {
56+
throw new SkippedException("Full Screen mode not supported");
57+
}
58+
});
59+
60+
invokeAndWait(() -> {
61+
frame = new Frame("Test FullScreen mode");
62+
frame.setBackground(Color.RED);
63+
frame.setSize(100, 100);
64+
frame.setLocation(10, 10);
65+
frame.setVisible(true);
66+
});
67+
robot.delay(1000);
68+
69+
invokeAndWait(() -> gd.setFullScreenWindow(frame));
70+
robot.waitForIdle();
71+
robot.delay(300);
72+
73+
invokeAndWait(() -> {
74+
width = gd.getFullScreenWindow().getWidth();
75+
height = gd.getFullScreenWindow().getHeight();
76+
});
77+
78+
if (!robot.getPixelColor(width / 2, height / 2).equals(Color.RED)) {
79+
System.err.println("Actual color: " + robot.getPixelColor(width / 2, height / 2)
80+
+ " Expected color: " + Color.RED);
81+
throw new RuntimeException("Test Failed! Window not in full screen mode");
82+
}
83+
} finally {
84+
if (frame != null) {
85+
frame.dispose();
86+
}
87+
}
88+
}
89+
}

0 commit comments

Comments
 (0)