Window centering fixes

This commit is contained in:
crschnick 2024-05-17 10:57:59 +00:00
parent 6345be78a7
commit 59ce98d9db
3 changed files with 24 additions and 30 deletions

View file

@ -1,7 +1,6 @@
package io.xpipe.app.core;
import io.xpipe.app.fxcomps.Comp;
import io.xpipe.app.fxcomps.util.PlatformThread;
import io.xpipe.app.issue.ErrorEvent;
import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.prefs.AppPrefs;
@ -29,7 +28,6 @@ import java.nio.file.Path;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.atomic.AtomicBoolean;
public class AppMainWindow {
@ -143,19 +141,15 @@ public class AppMainWindow {
windowActive.set(false);
});
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();
});
}
stage.requestFocus();
shown.set(true);
});
// 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 && stage.getX() == 0 && stage.getY() == 0) {
Platform.runLater(() -> {
stage.centerOnScreen();
});
}
stage.requestFocus();
});
stage.setOnCloseRequest(e -> {

View file

@ -154,12 +154,19 @@ public class AppWindowHelper {
AppFont.normal(a.getDialogPane());
var s = (Stage) a.getDialogPane().getScene().getWindow();
s.setOnShown(event -> {
clampWindow(s).ifPresent(rectangle2D -> {
s.setX(rectangle2D.getMinX());
s.setY(rectangle2D.getMinY());
// Somehow we have to set max size as setting the normal size does not work?
s.setMaxWidth(rectangle2D.getWidth());
s.setMaxHeight(rectangle2D.getHeight());
Platform.runLater(() -> {
// 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 (s.getX() == 0 && s.getY() == 0) {
s.centerOnScreen();
}
clampWindow(s).ifPresent(rectangle2D -> {
s.setX(rectangle2D.getMinX());
s.setY(rectangle2D.getMinY());
// Somehow we have to set max size as setting the normal size does not work?
s.setMaxWidth(rectangle2D.getWidth());
s.setMaxHeight(rectangle2D.getHeight());
});
});
event.consume();
});

View file

@ -83,19 +83,12 @@ public class InputHelper {
target.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
var c = event.getCode();
var list = List.of(
KeyCode.LEFT,
KeyCode.RIGHT,
KeyCode.UP,
KeyCode.DOWN,
KeyCode.SPACE,
KeyCode.ENTER,
KeyCode.SHIFT,
KeyCode.TAB,
KeyCode.NUMPAD2,
KeyCode.NUMPAD4,
KeyCode.NUMPAD6,
KeyCode.NUMPAD8);
r.accept(list.stream().anyMatch(keyCode -> keyCode == c));
KeyCode.TAB
);
r.accept(list.stream().anyMatch(keyCode -> keyCode == c) || event.getCode().isNavigationKey());
});
target.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
r.accept(false);