From aa14d79642249cfd4ca12bc3e455b1012bd2fdc3 Mon Sep 17 00:00:00 2001 From: Rexbas Date: Tue, 22 Aug 2023 20:28:17 +0200 Subject: [PATCH] Restore a closed minimized window at (-32000, -32000) to the last saved position Fixes #3079, second scenario. --- .../cryptomator/ui/mainwindow/ResizeController.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java b/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java index 9cda85cdb..b136fa55c 100644 --- a/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java +++ b/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java @@ -97,6 +97,17 @@ public class ResizeController implements FxController { } private void checkDisplayBounds(WindowEvent evt) { + + // Minimizing a window in Windows and closing it could result in an out of bounds position at (x, y) = (-32000, -32000) + // See https://devblogs.microsoft.com/oldnewthing/20041028-00/?p=37453 + // If the position is (-32000, -32000), restore to the last saved position + if (window.getX() == -32000 && window.getY() == -32000) { + window.setX(settings.windowXPosition.get()); + window.setY(settings.windowYPosition.get()); + window.setWidth(settings.windowWidth.get()); + window.setHeight(settings.windowHeight.get()); + } + if (!isWithinDisplayBounds()) { // If the position is illegal, then the window appears on the main screen in the middle of the window. Rectangle2D primaryScreenBounds = Screen.getPrimary().getBounds();