From 0809993b37b4318b558b97713494d8b96d967c32 Mon Sep 17 00:00:00 2001 From: CmP-lt <61097734+CmP-lt@users.noreply.github.com> Date: Sat, 4 Jun 2022 19:41:00 +0300 Subject: [PATCH] fix(gui): improve restoration of windows saved state (PR #1511) * Fix restoration of windows saved state * Don't skip restoration of window saved bounds when they intersect with screen bounds. * Restore saved bounds of main window regardless of it's saved extended state (fixes divider location of main split pane being restored incorrectly when saved state of main window is maximized). * Add handling for out-of-screen(s) window bounds --- .../java/jadx/gui/settings/JadxSettings.java | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java b/jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java index 44f66abe2..bdbde34d0 100644 --- a/jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java +++ b/jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java @@ -219,29 +219,22 @@ public class JadxSettings extends JadxCLIArgs { if (pos == null || pos.getBounds() == null) { return false; } - if (window instanceof MainWindow) { - int extendedState = getMainWindowExtendedState(); - if (extendedState != JFrame.NORMAL) { - ((JFrame) window).setExtendedState(extendedState); - return true; - } - } - - if (!isContainedInAnyScreen(pos)) { + if (!isAccessibleInAnyScreen(pos)) { return false; } - window.setBounds(pos.getBounds()); + if (window instanceof MainWindow) { + ((JFrame) window).setExtendedState(getMainWindowExtendedState()); + } return true; } - private static boolean isContainedInAnyScreen(WindowLocation pos) { - Rectangle bounds = pos.getBounds(); - if (bounds.getX() > 0 && bounds.getY() > 0) { - for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { - if (gd.getDefaultConfiguration().getBounds().contains(bounds)) { - return true; - } + private static boolean isAccessibleInAnyScreen(WindowLocation pos) { + Rectangle windowBounds = pos.getBounds(); + for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { + Rectangle screenBounds = gd.getDefaultConfiguration().getBounds(); + if (screenBounds.intersects(windowBounds)) { + return true; } } LOG.debug("Window saved position was ignored: {}", pos);