|
1 | 1 | /* |
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
|
24 | 24 | /* |
25 | 25 | @test |
26 | 26 | @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. |
31 | 30 | @library /test/lib |
32 | | - @build jdk.test.lib.Platform |
| 31 | + @build jdk.test.lib.Platform jtreg.SkippedException |
33 | 32 | @run main MultiScreenInsetsTest |
34 | 33 | */ |
35 | 34 |
|
|
42 | 41 | import java.awt.Toolkit; |
43 | 42 |
|
44 | 43 | import jdk.test.lib.Platform; |
| 44 | +import jtreg.SkippedException; |
45 | 45 |
|
46 | 46 | public class MultiScreenInsetsTest { |
47 | 47 | 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; |
48 | 50 |
|
49 | 51 | 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 | | - |
56 | 52 | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); |
57 | 53 | GraphicsDevice[] gds = ge.getScreenDevices(); |
58 | 54 | 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!"); |
61 | 56 | } |
62 | 57 |
|
63 | 58 | for (int screen = 0; screen < gds.length; ++screen) { |
64 | 59 | GraphicsDevice gd = gds[screen]; |
65 | 60 | GraphicsConfiguration gc = gd.getDefaultConfiguration(); |
66 | 61 | Rectangle bounds = gc.getBounds(); |
67 | 62 | 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); |
68 | 66 |
|
69 | 67 | Frame frame = new Frame(gc); |
70 | 68 | frame.setLocation(bounds.x + (bounds.width - SIZE) / 2, |
71 | 69 | bounds.y + (bounds.height - SIZE) / 2); |
72 | 70 | 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 | + |
74 | 82 | frame.setVisible(true); |
75 | 83 |
|
76 | 84 | // Maximize Frame to reach the struts |
77 | 85 | frame.setExtendedState(java.awt.Frame.MAXIMIZED_BOTH); |
78 | 86 | Thread.sleep(2000); |
79 | 87 |
|
80 | 88 | Rectangle frameBounds = frame.getBounds(); |
| 89 | + System.out.println("Frame bounds: " + frameBounds); |
| 90 | + |
81 | 91 | 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 | + |
82 | 108 | if (bounds.x + insets.left != frameBounds.x |
83 | 109 | || 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) { |
86 | 112 | throw new RuntimeException("Test FAILED! Wrong screen #" + |
87 | 113 | screen + " insets: " + insets); |
88 | 114 | } |
|
0 commit comments