From 094a7c6a207109c2a66c90020e1e1a0956284518 Mon Sep 17 00:00:00 2001 From: Rexbas Date: Tue, 18 Jul 2023 20:08:13 +0200 Subject: [PATCH] Check display bounds onShowing event --- .../ui/mainwindow/ResizeController.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java b/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java index eec2ac183..8afcdc153 100644 --- a/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java +++ b/src/main/java/org/cryptomator/ui/mainwindow/ResizeController.java @@ -15,6 +15,7 @@ import javafx.scene.input.MouseEvent; import javafx.scene.layout.Region; import javafx.stage.Screen; import javafx.stage.Stage; +import javafx.stage.WindowEvent; @MainWindow public class ResizeController implements FxController { @@ -71,6 +72,9 @@ public class ResizeController implements FxController { window.setY(settings.windowYPosition.get()); } } + + window.setOnShowing(this::checkDisplayBounds); + savePositionalSettings(); } @@ -115,6 +119,18 @@ public class ResizeController implements FxController { return visibleArea == windowArea; } + private void checkDisplayBounds(WindowEvent evt) { + 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(); + window.setX((primaryScreenBounds.getWidth() - window.getMinWidth()) / 2); + window.setY((primaryScreenBounds.getHeight() - window.getMinHeight()) / 2); + window.setWidth(window.getMinWidth()); + window.setHeight(window.getMinHeight()); + savePositionalSettings(); + } + } + private String getMonitorSizes() { ObservableList screens = Screen.getScreens(); StringBuilder sb = new StringBuilder(); @@ -212,5 +228,4 @@ public class ResizeController implements FxController { public boolean isShowResizingArrows() { return showResizingArrows.get(); } - } \ No newline at end of file