Skip to content

Commit 139681a

Browse files
Maxim KartashevAlexey Ushakov
Maxim Kartashev
authored and
Alexey Ushakov
committedMar 12, 2024
8326497: Window.toFront() fails for iconified windows on Linux
Reviewed-by: tr, prr
1 parent 9f7aff4 commit 139681a

File tree

3 files changed

+124
-2
lines changed

3 files changed

+124
-2
lines changed
 

‎src/java.desktop/unix/classes/sun/awt/X11/XFramePeer.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2002, 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
@@ -328,6 +328,15 @@ void setExtendedState(int newState) {
328328
XWM.getWM().setExtendedState(this, newState);
329329
}
330330

331+
@Override
332+
public void toFront() {
333+
if ((state & Frame.ICONIFIED) != 0) {
334+
changeState(state & ~Frame.ICONIFIED);
335+
}
336+
337+
super.toFront();
338+
}
339+
331340
public void handlePropertyNotify(XEvent xev) {
332341
super.handlePropertyNotify(xev);
333342
XPropertyEvent ev = xev.get_xproperty();

‎src/java.desktop/windows/classes/sun/awt/windows/WFramePeer.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 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
@@ -65,6 +65,16 @@ public int getExtendedState() {
6565
return AWTAccessor.getFrameAccessor().getExtendedState((Frame)target);
6666
}
6767

68+
@Override
69+
public void toFront() {
70+
int state = getState();
71+
if ((state & Frame.ICONIFIED) != 0) {
72+
setState(state & ~Frame.ICONIFIED);
73+
}
74+
75+
super.toFront();
76+
}
77+
6878
// Convenience methods to save us from trouble of extracting
6979
// Rectangle fields in native code.
7080
private native void setMaximizedBounds(int x, int y, int w, int h);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2024, JetBrains s.r.o.. All rights reserved.
4+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5+
*
6+
* This code is free software; you can redistribute it and/or modify it
7+
* under the terms of the GNU General Public License version 2 only, as
8+
* published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT
11+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13+
* version 2 for more details (a copy is included in the LICENSE file that
14+
* accompanied this code).
15+
*
16+
* You should have received a copy of the GNU General Public License version
17+
* 2 along with this work; if not, write to the Free Software Foundation,
18+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19+
*
20+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21+
* or visit www.oracle.com if you need additional information or have any
22+
* questions.
23+
*/
24+
25+
/* @test
26+
* @key headful
27+
* @bug 8326497
28+
* @summary Verifies that an iconified window is restored with Window.toFront()
29+
* @library /test/lib
30+
* @run main IconifiedToFront
31+
*/
32+
33+
import java.awt.Color;
34+
import java.awt.FlowLayout;
35+
import java.awt.Frame;
36+
import java.awt.Label;
37+
import java.awt.Robot;
38+
import java.awt.Toolkit;
39+
40+
public class IconifiedToFront {
41+
private static final int PAUSE_MS = 500;
42+
private static Robot robot;
43+
44+
public static void main(String[] args) throws Exception {
45+
if (!Toolkit.getDefaultToolkit().isFrameStateSupported(Frame.ICONIFIED)) {
46+
return; // Nothing to test
47+
}
48+
49+
robot = new Robot();
50+
IconifiedToFront.test1();
51+
IconifiedToFront.test2();
52+
}
53+
54+
private static void test1() {
55+
Frame frame1 = new Frame("IconifiedToFront Test 1");
56+
try {
57+
frame1.setLayout(new FlowLayout());
58+
frame1.setSize(400, 300);
59+
frame1.setBackground(Color.green);
60+
frame1.add(new Label("test"));
61+
frame1.setVisible(true);
62+
pause();
63+
frame1.setExtendedState(Frame.ICONIFIED);
64+
pause();
65+
frame1.toFront();
66+
pause();
67+
int state = frame1.getExtendedState();
68+
if ((state & Frame.ICONIFIED) != 0) {
69+
throw new RuntimeException("Test Failed: state is still ICONIFIED: " + state);
70+
}
71+
} finally {
72+
frame1.dispose();
73+
}
74+
}
75+
76+
private static void test2() {
77+
Frame frame1 = new Frame("IconifiedToFront Test 3");
78+
try {
79+
frame1.setLayout(new FlowLayout());
80+
frame1.setSize(400, 300);
81+
frame1.setBackground(Color.green);
82+
frame1.add(new Label("test"));
83+
frame1.setUndecorated(true);
84+
frame1.setVisible(true);
85+
pause();
86+
frame1.setExtendedState(Frame.ICONIFIED);
87+
pause();
88+
frame1.toFront();
89+
pause();
90+
int state = frame1.getExtendedState();
91+
if ((state & Frame.ICONIFIED) != 0) {
92+
throw new RuntimeException("Test Failed: state is still ICONIFIED: " + state);
93+
}
94+
} finally {
95+
frame1.dispose();
96+
}
97+
}
98+
99+
private static void pause() {
100+
robot.delay(PAUSE_MS);
101+
robot.waitForIdle();
102+
}
103+
}

0 commit comments

Comments
 (0)
Please sign in to comment.