Skip to content

Commit 3229780

Browse files
author
duke
committed
Backport 651ac3cc0f2a8b3edf5cddb42df1d38d4aa0e1a6
1 parent 70ba5d4 commit 3229780

File tree

2 files changed

+50
-39
lines changed

2 files changed

+50
-39
lines changed

src/java.desktop/windows/native/libawt/windows/awt_Toolkit.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,28 +2036,13 @@ JNIEnv* AwtToolkit::GetEnv() {
20362036

20372037
BOOL AwtToolkit::GetScreenInsets(int screenNum, RECT * rect)
20382038
{
2039-
/* if primary display */
2040-
if (screenNum == 0) {
2041-
RECT rRW;
2042-
if (::SystemParametersInfo(SPI_GETWORKAREA,0,(void *) &rRW,0) == TRUE) {
2043-
rect->top = rRW.top;
2044-
rect->left = rRW.left;
2045-
rect->bottom = ::GetSystemMetrics(SM_CYSCREEN) - rRW.bottom;
2046-
rect->right = ::GetSystemMetrics(SM_CXSCREEN) - rRW.right;
2047-
return TRUE;
2048-
}
2049-
}
2050-
/* if additional display */
2051-
else {
2052-
MONITORINFO *miInfo;
2053-
miInfo = AwtWin32GraphicsDevice::GetMonitorInfo(screenNum);
2054-
if (miInfo) {
2055-
rect->top = miInfo->rcWork.top - miInfo->rcMonitor.top;
2056-
rect->left = miInfo->rcWork.left - miInfo->rcMonitor.left;
2057-
rect->bottom = miInfo->rcMonitor.bottom - miInfo->rcWork.bottom;
2058-
rect->right = miInfo->rcMonitor.right - miInfo->rcWork.right;
2059-
return TRUE;
2060-
}
2039+
MONITORINFO *miInfo = AwtWin32GraphicsDevice::GetMonitorInfo(screenNum);
2040+
if (miInfo) {
2041+
rect->top = miInfo->rcWork.top - miInfo->rcMonitor.top;
2042+
rect->left = miInfo->rcWork.left - miInfo->rcMonitor.left;
2043+
rect->bottom = miInfo->rcMonitor.bottom - miInfo->rcWork.bottom;
2044+
rect->right = miInfo->rcMonitor.right - miInfo->rcWork.right;
2045+
return TRUE;
20612046
}
20622047
return FALSE;
20632048
}

test/jdk/java/awt/Multiscreen/MultiScreenInsetsTest/MultiScreenInsetsTest.java

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2025, 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
@@ -24,12 +24,11 @@
2424
/*
2525
@test
2626
@key headful
27-
@bug 8020443
28-
@summary Frame is not created on the specified GraphicsDevice with two
29-
monitors
30-
@author Oleg Pekhovskiy
27+
@bug 8020443 6899304
28+
@summary Test to check if the frame is created on the specified GraphicsDevice
29+
and if getScreenInsets()returns the correct values across multiple monitors.
3130
@library /test/lib
32-
@build jdk.test.lib.Platform
31+
@build jdk.test.lib.Platform jtreg.SkippedException
3332
@run main MultiScreenInsetsTest
3433
*/
3534

@@ -42,47 +41,74 @@
4241
import java.awt.Toolkit;
4342

4443
import jdk.test.lib.Platform;
44+
import jtreg.SkippedException;
4545

4646
public class MultiScreenInsetsTest {
4747
private static final int SIZE = 100;
48+
// Allow a margin tolerance of 1 pixel due to scaling
49+
private static final int MARGIN_TOLERANCE = 1;
4850

4951
public static void main(String[] args) throws InterruptedException {
50-
if (!Platform.isLinux()) {
51-
System.out.println("This test is for Linux only..." +
52-
"skipping!");
53-
return;
54-
}
55-
5652
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
5753
GraphicsDevice[] gds = ge.getScreenDevices();
5854
if (gds.length < 2) {
59-
System.out.println("It's a multi-screen test... skipping!");
60-
return;
55+
throw new SkippedException("It's a multi-screen test... skipping!");
6156
}
6257

6358
for (int screen = 0; screen < gds.length; ++screen) {
6459
GraphicsDevice gd = gds[screen];
6560
GraphicsConfiguration gc = gd.getDefaultConfiguration();
6661
Rectangle bounds = gc.getBounds();
6762
Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);
63+
System.out.println("Screen #" + screen);
64+
System.out.println("Screen Bounds: " + bounds);
65+
System.out.println("Insets: " + insets);
6866

6967
Frame frame = new Frame(gc);
7068
frame.setLocation(bounds.x + (bounds.width - SIZE) / 2,
7169
bounds.y + (bounds.height - SIZE) / 2);
7270
frame.setSize(SIZE, SIZE);
73-
frame.setUndecorated(true);
71+
72+
/*
73+
* On Windows, undecorated maximized frames are placed over the taskbar.
74+
* Use a decorated frame instead.
75+
*/
76+
if (Platform.isWindows()) {
77+
frame.setUndecorated(false);
78+
} else {
79+
frame.setUndecorated(true);
80+
}
81+
7482
frame.setVisible(true);
7583

7684
// Maximize Frame to reach the struts
7785
frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
7886
Thread.sleep(2000);
7987

8088
Rectangle frameBounds = frame.getBounds();
89+
System.out.println("Frame bounds: " + frameBounds);
90+
8191
frame.dispose();
92+
93+
/*
94+
* On Windows, the top-left corner of an undecorated maximized frame
95+
* may have negative coordinates (x, y).
96+
* Adjust the frame bounds accordingly.
97+
*/
98+
if (frameBounds.x < bounds.x) {
99+
frameBounds.width -= (bounds.x - frameBounds.x) * 2;
100+
frameBounds.x = bounds.x;
101+
}
102+
if (frameBounds.y < bounds.y) {
103+
frameBounds.height -= (bounds.y - frameBounds.y) * 2;
104+
frameBounds.y = bounds.y;
105+
}
106+
System.out.println("Adjusted Frame bounds: " + frameBounds);
107+
82108
if (bounds.x + insets.left != frameBounds.x
83109
|| bounds.y + insets.top != frameBounds.y
84-
|| bounds.width - insets.right - insets.left != frameBounds.width
85-
|| bounds.height - insets.bottom - insets.top != frameBounds.height) {
110+
|| Math.abs((bounds.width - insets.right - insets.left) - frameBounds.width) > MARGIN_TOLERANCE
111+
|| Math.abs((bounds.height - insets.bottom - insets.top) - frameBounds.height) > MARGIN_TOLERANCE) {
86112
throw new RuntimeException("Test FAILED! Wrong screen #" +
87113
screen + " insets: " + insets);
88114
}

0 commit comments

Comments
 (0)