mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-10-02 18:17:27 +13:00
Window centering fixes
This commit is contained in:
parent
6345be78a7
commit
59ce98d9db
3 changed files with 24 additions and 30 deletions
|
@ -1,7 +1,6 @@
|
||||||
package io.xpipe.app.core;
|
package io.xpipe.app.core;
|
||||||
|
|
||||||
import io.xpipe.app.fxcomps.Comp;
|
import io.xpipe.app.fxcomps.Comp;
|
||||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
|
||||||
import io.xpipe.app.issue.ErrorEvent;
|
import io.xpipe.app.issue.ErrorEvent;
|
||||||
import io.xpipe.app.issue.TrackEvent;
|
import io.xpipe.app.issue.TrackEvent;
|
||||||
import io.xpipe.app.prefs.AppPrefs;
|
import io.xpipe.app.prefs.AppPrefs;
|
||||||
|
@ -29,7 +28,6 @@ import java.nio.file.Path;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
public class AppMainWindow {
|
public class AppMainWindow {
|
||||||
|
|
||||||
|
@ -143,19 +141,15 @@ public class AppMainWindow {
|
||||||
windowActive.set(false);
|
windowActive.set(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
AtomicBoolean shown = new AtomicBoolean(false);
|
|
||||||
stage.setOnShown(event -> {
|
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
|
// 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
|
// This fixes the alignment in these cases
|
||||||
if (state == null && !shown.get()) {
|
if (state == null && stage.getX() == 0 && stage.getY() == 0) {
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
stage.centerOnScreen();
|
stage.centerOnScreen();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
stage.requestFocus();
|
stage.requestFocus();
|
||||||
shown.set(true);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
stage.setOnCloseRequest(e -> {
|
stage.setOnCloseRequest(e -> {
|
||||||
|
|
|
@ -154,6 +154,12 @@ public class AppWindowHelper {
|
||||||
AppFont.normal(a.getDialogPane());
|
AppFont.normal(a.getDialogPane());
|
||||||
var s = (Stage) a.getDialogPane().getScene().getWindow();
|
var s = (Stage) a.getDialogPane().getScene().getWindow();
|
||||||
s.setOnShown(event -> {
|
s.setOnShown(event -> {
|
||||||
|
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 -> {
|
clampWindow(s).ifPresent(rectangle2D -> {
|
||||||
s.setX(rectangle2D.getMinX());
|
s.setX(rectangle2D.getMinX());
|
||||||
s.setY(rectangle2D.getMinY());
|
s.setY(rectangle2D.getMinY());
|
||||||
|
@ -161,6 +167,7 @@ public class AppWindowHelper {
|
||||||
s.setMaxWidth(rectangle2D.getWidth());
|
s.setMaxWidth(rectangle2D.getWidth());
|
||||||
s.setMaxHeight(rectangle2D.getHeight());
|
s.setMaxHeight(rectangle2D.getHeight());
|
||||||
});
|
});
|
||||||
|
});
|
||||||
event.consume();
|
event.consume();
|
||||||
});
|
});
|
||||||
a.getDialogPane().getScene().addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
a.getDialogPane().getScene().addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
||||||
|
|
|
@ -83,19 +83,12 @@ public class InputHelper {
|
||||||
target.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
target.addEventFilter(KeyEvent.KEY_PRESSED, event -> {
|
||||||
var c = event.getCode();
|
var c = event.getCode();
|
||||||
var list = List.of(
|
var list = List.of(
|
||||||
KeyCode.LEFT,
|
|
||||||
KeyCode.RIGHT,
|
|
||||||
KeyCode.UP,
|
|
||||||
KeyCode.DOWN,
|
|
||||||
KeyCode.SPACE,
|
KeyCode.SPACE,
|
||||||
KeyCode.ENTER,
|
KeyCode.ENTER,
|
||||||
KeyCode.SHIFT,
|
KeyCode.SHIFT,
|
||||||
KeyCode.TAB,
|
KeyCode.TAB
|
||||||
KeyCode.NUMPAD2,
|
);
|
||||||
KeyCode.NUMPAD4,
|
r.accept(list.stream().anyMatch(keyCode -> keyCode == c) || event.getCode().isNavigationKey());
|
||||||
KeyCode.NUMPAD6,
|
|
||||||
KeyCode.NUMPAD8);
|
|
||||||
r.accept(list.stream().anyMatch(keyCode -> keyCode == c));
|
|
||||||
});
|
});
|
||||||
target.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
|
target.addEventFilter(MouseEvent.MOUSE_PRESSED, event -> {
|
||||||
r.accept(false);
|
r.accept(false);
|
||||||
|
|
Loading…
Reference in a new issue