Window centering improvements

This commit is contained in:
crschnick 2024-05-14 08:53:12 +00:00
parent d77925540e
commit 6dd0e6d255
2 changed files with 11 additions and 6 deletions

View file

@ -146,6 +146,8 @@ public class AppMainWindow {
AtomicBoolean shown = new AtomicBoolean(false); AtomicBoolean shown = new AtomicBoolean(false);
stage.setOnShown(event -> { stage.setOnShown(event -> {
PlatformThread.runLaterIfNeeded(() -> { PlatformThread.runLaterIfNeeded(() -> {
// On some platforms, e.g. KDE with wayland, the screen size is not known when the window is first shown
// This fixes the alignment in these cases
if (state == null && !shown.get()) { if (state == null && !shown.get()) {
Platform.runLater(() -> { Platform.runLater(() -> {
stage.centerOnScreen(); stage.centerOnScreen();

View file

@ -85,6 +85,7 @@ public class AppWindowHelper {
stage.setOnShown(e -> { stage.setOnShown(e -> {
AppTheme.initThemeHandlers(stage); AppTheme.initThemeHandlers(stage);
Platform.runLater(() -> {
centerToMainWindow(stage); centerToMainWindow(stage);
clampWindow(stage).ifPresent(rectangle2D -> { clampWindow(stage).ifPresent(rectangle2D -> {
stage.setX(rectangle2D.getMinX()); stage.setX(rectangle2D.getMinX());
@ -93,11 +94,13 @@ public class AppWindowHelper {
stage.setHeight(rectangle2D.getHeight()); stage.setHeight(rectangle2D.getHeight());
}); });
}); });
});
return stage; return stage;
} }
private static void centerToMainWindow(Window childStage) { private static void centerToMainWindow(Window childStage) {
if (App.getApp() == null) { if (App.getApp() == null) {
childStage.centerOnScreen();
return; return;
} }