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);
stage.setOnShown(event -> {
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()) {
Platform.runLater(() -> {
stage.centerOnScreen();

View file

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