Skip to content

Commit

Permalink
fix(gui): improve restoration of windows saved state (PR #1511)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
CmP-lt committed Jun 4, 2022
1 parent 0c3afcc commit 0809993
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions jadx-gui/src/main/java/jadx/gui/settings/JadxSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,22 @@ public boolean loadWindowPos(Window window) {
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);
Expand Down

0 comments on commit 0809993

Please sign in to comment.