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,12 +85,14 @@ public class AppWindowHelper {
stage.setOnShown(e -> { stage.setOnShown(e -> {
AppTheme.initThemeHandlers(stage); AppTheme.initThemeHandlers(stage);
centerToMainWindow(stage); Platform.runLater(() -> {
clampWindow(stage).ifPresent(rectangle2D -> { centerToMainWindow(stage);
stage.setX(rectangle2D.getMinX()); clampWindow(stage).ifPresent(rectangle2D -> {
stage.setY(rectangle2D.getMinY()); stage.setX(rectangle2D.getMinX());
stage.setWidth(rectangle2D.getWidth()); stage.setY(rectangle2D.getMinY());
stage.setHeight(rectangle2D.getHeight()); stage.setWidth(rectangle2D.getWidth());
stage.setHeight(rectangle2D.getHeight());
});
}); });
}); });
return stage; return stage;
@ -98,6 +100,7 @@ public class AppWindowHelper {
private static void centerToMainWindow(Window childStage) { private static void centerToMainWindow(Window childStage) {
if (App.getApp() == null) { if (App.getApp() == null) {
childStage.centerOnScreen();
return; return;
} }