From 67b39cee53c087b5e5f06bb0399889411914c4d6 Mon Sep 17 00:00:00 2001 From: dragonmacher <48328597+dragonmacher@users.noreply.github.com> Date: Thu, 11 Jun 2026 12:11:10 -0400 Subject: [PATCH] GP-6954 - Fixed tool window maximizing to the wrong window --- .../src/main/java/docking/RootNode.java | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/Ghidra/Framework/Docking/src/main/java/docking/RootNode.java b/Ghidra/Framework/Docking/src/main/java/docking/RootNode.java index 5d9dff5b4b..ff23bed0b5 100644 --- a/Ghidra/Framework/Docking/src/main/java/docking/RootNode.java +++ b/Ghidra/Framework/Docking/src/main/java/docking/RootNode.java @@ -16,9 +16,9 @@ package docking; import java.awt.*; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.util.*; +import java.awt.event.*; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import javax.swing.*; @@ -513,10 +513,7 @@ class RootNode extends WindowNode { }); List restoredPlaceholders = new ArrayList<>(); - Iterator elementIterator = rootNodeElement.getChildren().iterator(); - while (elementIterator.hasNext()) { - Element elem = (Element) elementIterator.next(); - + for (Element elem : rootNodeElement.getChildren()) { if (elem.getName().equals("WINDOW_NODE")) { Node node = new DetachedWindowNode(elem, winMgr, this, dropTargetFactory, restoredPlaceholders); @@ -668,22 +665,10 @@ class RootNode extends WindowNode { abstract String getTitle(); /** - * Stores the given bounds if they are not the maximized bounds + * Stores the given bounds. These should not be the maximized bounds. * @param bounds the bounds */ public void setLastBounds(Rectangle bounds) { - Rectangle screenBounds = WindowUtilities.getScreenBounds(getWindow()); - if (screenBounds == null) { - return; - } - - Rectangle boundsSize = new Rectangle(bounds.getSize()); - Rectangle screenSize = new Rectangle(screenBounds.getSize()); - if (boundsSize.contains(screenSize)) { - // This can happen when the bounds being set are the full screen bounds. We only - // wish to save the non-maximized bounds. - return; - } this.lastBounds = bounds; } @@ -727,11 +712,6 @@ class RootNode extends WindowNode { winMgr.setActive(wrappedDialog, true); } - @Override - public void windowStateChanged(WindowEvent e) { - // this is called when transitioning in and out of the full-screen state - setLastBounds(wrappedDialog.getBounds()); - } }; dialog.addWindowListener(windowListener); @@ -837,10 +817,25 @@ class RootNode extends WindowNode { @Override public void windowStateChanged(WindowEvent e) { // this is called when transitioning in and out of the full-screen state - setLastBounds(wrappedFrame.getBounds()); + int newState = e.getNewState(); + if (newState != Frame.MAXIMIZED_BOTH) { + // don't save the bounds when in full-screen mode; these bounds are later + // used to restore the non-full-screen state + setLastBounds(wrappedFrame.getBounds()); + } } }; + wrappedFrame.addComponentListener(new ComponentAdapter() { + @Override + public void componentMoved(ComponentEvent e) { + int state = wrappedFrame.getExtendedState(); + if (state != Frame.MAXIMIZED_BOTH) { + setLastBounds(wrappedFrame.getBounds()); + } + } + }); + wrappedFrame.addWindowListener(windowListener); wrappedFrame.addWindowStateListener(windowListener);