11/*
2- * Copyright (c) 1997, 2021 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1997, 2023 , 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
3030import java .awt .GraphicsConfiguration ;
3131import java .awt .GraphicsDevice ;
3232import java .awt .GraphicsEnvironment ;
33+ import java .awt .Insets ;
3334import java .awt .Rectangle ;
3435import java .awt .Window ;
3536import java .security .AccessController ;
3637import java .security .PrivilegedAction ;
3738import java .util .ArrayList ;
3839import java .util .HashMap ;
3940import java .util .HashSet ;
41+ import java .util .Objects ;
4042
4143import sun .awt .util .ThreadGroupUtils ;
4244import sun .java2d .SunGraphicsEnvironment ;
@@ -66,12 +68,15 @@ public final class X11GraphicsDevice extends GraphicsDevice
6668 private static Boolean xrandrExtSupported ;
6769 private SunDisplayChanger topLevels = new SunDisplayChanger ();
6870 private DisplayMode origDisplayMode ;
71+ private volatile Rectangle bounds ;
72+ private volatile Insets insets ;
6973 private boolean shutdownHookRegistered ;
7074 private int scale ;
7175
7276 public X11GraphicsDevice (int screennum ) {
7377 this .screen = screennum ;
7478 this .scale = initScaleFactor ();
79+ this .bounds = getBoundsImpl ();
7580 }
7681
7782 /**
@@ -118,7 +123,7 @@ public int scaleDown(int x) {
118123 return Region .clipRound (x / (double )getScaleFactor ());
119124 }
120125
121- public Rectangle getBounds () {
126+ private Rectangle getBoundsImpl () {
122127 Rectangle rect = pGetBounds (getScreen ());
123128 if (getScaleFactor () != 1 ) {
124129 rect .x = scaleDown (rect .x );
@@ -129,6 +134,23 @@ public Rectangle getBounds() {
129134 return rect ;
130135 }
131136
137+ public Rectangle getBounds () {
138+ return bounds .getBounds ();
139+ }
140+
141+ public Insets getInsets () {
142+ return insets ;
143+ }
144+
145+ public void setInsets (Insets newInsets ) {
146+ Objects .requireNonNull (newInsets );
147+ insets = newInsets ;
148+ }
149+
150+ public void resetInsets () {
151+ insets = null ;
152+ }
153+
132154 /**
133155 * Returns the identification string associated with this graphics
134156 * device.
@@ -516,6 +538,8 @@ private synchronized DisplayMode getMatchingDisplayMode(DisplayMode dm) {
516538 @ Override
517539 public synchronized void displayChanged () {
518540 scale = initScaleFactor ();
541+ bounds = getBoundsImpl ();
542+ insets = null ;
519543 // On X11 the visuals do not change, and therefore we don't need
520544 // to reset the defaultConfig, config, doubleBufferVisuals,
521545 // neither do we need to reset the native data.
0 commit comments