Readd window pos fix

This commit is contained in:
crschnick 2024-08-16 10:23:13 +00:00
parent ab7e2f2220
commit 4d1eadf712
3 changed files with 43 additions and 0 deletions

View file

@ -117,6 +117,7 @@ public class AppMainWindow {
}
private void setupListeners() {
AppWindowBounds.fixInvalidStagePosition(stage);
stage.xProperty().addListener((c, o, n) -> {
if (windowActive.get()) {
onChange();

View file

@ -1,6 +1,7 @@
package io.xpipe.app.core.window;
import io.xpipe.app.core.App;
import io.xpipe.core.process.OsType;
import javafx.geometry.Rectangle2D;
import javafx.stage.Screen;
import javafx.stage.Stage;
@ -8,9 +9,48 @@ import javafx.stage.Stage;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
public class AppWindowBounds {
public static void fixInvalidStagePosition(Stage stage) {
if (OsType.getLocal() != OsType.LINUX) {
return;
}
var xSet = new AtomicBoolean();
stage.xProperty().addListener((observable, oldValue, newValue) -> {
var n = newValue.doubleValue();
var o = oldValue.doubleValue();
if (stage.isShowing() && areNumbersValid(o, n)) {
// Ignore rounding events
if (Math.abs(n - o) < 0.5) {
return;
}
if (!xSet.getAndSet(true) && !stage.isMaximized() && n <= 0.0 && o > 0.0 && Math.abs(n - o) > 100) {
stage.setX(o);
}
}
});
var ySet = new AtomicBoolean();
stage.yProperty().addListener((observable, oldValue, newValue) -> {
var n = newValue.doubleValue();
var o = oldValue.doubleValue();
if (stage.isShowing() && areNumbersValid(o, n)) {
// Ignore rounding events
if (Math.abs(n - o) < 0.5) {
return;
}
if (!ySet.getAndSet(true) && !stage.isMaximized() && n <= 0.0 && o > 0.0 && Math.abs(n - o) > 20) {
stage.setY(o);
}
}
});
}
public static Stage centerStage() {
var stage = new Stage() {
@Override

View file

@ -75,6 +75,7 @@ public class AppWindowHelper {
addIcons(stage);
setupContent(stage, contentFunc, bindSize, loading);
setupStylesheets(stage.getScene());
AppWindowBounds.fixInvalidStagePosition(stage);
if (AppPrefs.get() != null && AppPrefs.get().enforceWindowModality().get()) {
stage.initModality(Modality.WINDOW_MODAL);
@ -142,6 +143,7 @@ public class AppWindowHelper {
});
event.consume();
});
AppWindowBounds.fixInvalidStagePosition(s);
a.getDialogPane().getScene().addEventHandler(KeyEvent.KEY_PRESSED, event -> {
if (new KeyCodeCombination(KeyCode.W, KeyCombination.SHORTCUT_DOWN).match(event)) {
s.close();