From 26684fd4c761dcd2a4c93673d7732095a2050c9b Mon Sep 17 00:00:00 2001 From: ngubarkov Date: Wed, 22 Mar 2023 22:48:08 +0200 Subject: [PATCH] JBR-5265 Workaround incorrect position of content window in queryXLocation. --- .../unix/classes/sun/awt/X11/XDecoratedPeer.java | 12 ++++++++++++ .../unix/classes/sun/awt/X11/XWindowPeer.java | 15 +++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java index 29d670e76245..80fd084774b4 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java @@ -50,6 +50,9 @@ abstract class XDecoratedPeer extends XWindowPeer { // reparented - indicates that WM has adopted the top-level. boolean configure_seen; boolean insets_corrected; + // Set to true after reconfigureContentWindow is called for the first time. + // Before this, content window may not be in sync with insets. + private boolean content_reconfigured; XIconWindow iconWindow; volatile WindowDimensions dimensions; @@ -760,6 +763,7 @@ void reconfigureContentWindow(WindowDimensions dims) { return; } content.setContentBounds(dims); + content_reconfigured = true; } private XEvent pendingConfigureEvent; @@ -899,6 +903,14 @@ private void processConfigureEvent(XConfigureEvent xe) { }); } + @Override + WindowLocation queryXLocation() { + XContentWindow c = content; + boolean client = c == null || !content_reconfigured; + return new WindowLocation(XlibUtil.translateCoordinates(client ? window : c.getWindow(), + XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()), 0, 0), client); + } + private void checkShellRectSize(Rectangle shellRect) { shellRect.width = Math.max(MIN_SIZE, shellRect.width); shellRect.height = Math.max(MIN_SIZE, shellRect.height); diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java index d679c52ec528..9755dc891702 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java @@ -775,7 +775,7 @@ void xSetSize(int width, int height) { class WindowLocation { private final Point location; // Device space private final boolean client; - private WindowLocation(Point location, boolean client) { + WindowLocation(Point location, boolean client) { this.location = location; this.client = client; } @@ -804,6 +804,11 @@ Point getUserLocation() { } } + WindowLocation queryXLocation() { + return new WindowLocation(XlibUtil.translateCoordinates(getContentWindow(), + XlibWrapper.RootWindow(XToolkit.getDisplay(), getScreenNumber()), 0, 0), false); + } + WindowLocation getNewLocation(XConfigureEvent xe) { int runningWM = XWM.getWMID(); if (xe.get_send_event() || @@ -826,13 +831,11 @@ WindowLocation getNewLocation(XConfigureEvent xe) { case XWM.UNITY_COMPIZ_WM: case XWM.AWESOME_WM: { - Point xlocation = XlibUtil.translateCoordinates(getContentWindow(), XlibWrapper - .RootWindow(XToolkit.getDisplay(), - getScreenNumber()), 0, 0); + WindowLocation xlocation = queryXLocation(); if (log.isLoggable(PlatformLogger.Level.FINE)) { - log.fine("New X location: {0}", xlocation); + log.fine("New X location: {0} ({1})", xlocation.location, xlocation.client ? "client" : "bounds"); } - return new WindowLocation(xlocation, false); + return xlocation; } } }