Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix restoration of windows saved state #1511

Merged
merged 2 commits into from
Jun 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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