mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-30 02:08:58 -04:00
Fix popup positioning issue for linux
This commit is contained in:
parent
7b82bdb41e
commit
0c465a9ec3
1 changed files with 19 additions and 14 deletions
|
@ -71,6 +71,7 @@ public class Popup {
|
||||||
protected Label headLineLabel;
|
protected Label headLineLabel;
|
||||||
private String dontShowAgainId;
|
private String dontShowAgainId;
|
||||||
private Preferences preferences;
|
private Preferences preferences;
|
||||||
|
private ChangeListener<Number> positionListener;
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -105,6 +106,11 @@ public class Popup {
|
||||||
|
|
||||||
cleanup();
|
cleanup();
|
||||||
PopupManager.isHidden(this);
|
PopupManager.isHidden(this);
|
||||||
|
|
||||||
|
if (Utilities.isUnix()) {
|
||||||
|
owner.getScene().getWindow().xProperty().removeListener(positionListener);
|
||||||
|
owner.getScene().getWindow().yProperty().removeListener(positionListener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void cleanup() {
|
protected void cleanup() {
|
||||||
|
@ -244,26 +250,25 @@ public class Popup {
|
||||||
|
|
||||||
MainView.blurLight();
|
MainView.blurLight();
|
||||||
|
|
||||||
// sometimes the positioning fails if UI is very busy and app window gets moved
|
if (Utilities.isUnix()) {
|
||||||
ChangeListener<Number> positionListener = (observable, oldValue, newValue) -> {
|
// On Linux the owner stage does not move the child stage as it does on Mac
|
||||||
if (stage != null)
|
// So we need to apply centerPopup. Further with fast movements the handler loses
|
||||||
UserThread.runAfter(this::centerPopup, 1);
|
// the latest position, with a delay it fixes that.
|
||||||
|
positionListener = (observable, oldValue, newValue) -> {
|
||||||
|
if (stage != null) {
|
||||||
|
centerPopup();
|
||||||
|
UserThread.runAfter(this::centerPopup, 3);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
owner.getScene().getWindow().xProperty().addListener(positionListener);
|
owner.getScene().getWindow().xProperty().addListener(positionListener);
|
||||||
owner.getScene().getWindow().yProperty().addListener(positionListener);
|
owner.getScene().getWindow().yProperty().addListener(positionListener);
|
||||||
|
}
|
||||||
UserThread.runAfter(() -> {
|
|
||||||
owner.getScene().getWindow().xProperty().removeListener(positionListener);
|
|
||||||
owner.getScene().getWindow().yProperty().removeListener(positionListener);
|
|
||||||
}, 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void centerPopup() {
|
protected void centerPopup() {
|
||||||
Window window = owner.getScene().getWindow();
|
Window window = owner.getScene().getWindow();
|
||||||
double titleBarHeight = window.getHeight() - owner.getScene().getHeight();
|
double titleBarHeight = window.getHeight() - owner.getScene().getHeight();
|
||||||
Point2D point = owner.localToScene(0, 0);
|
Point2D point = owner.localToScene(0, 0);
|
||||||
log.error("window window.getX()=" + window.getX());
|
|
||||||
log.error("window window.getY()=" + window.getY());
|
|
||||||
stage.setX(Math.round(window.getX() + point.getX() + (owner.getWidth() - stage.getWidth()) / 2));
|
stage.setX(Math.round(window.getX() + point.getX() + (owner.getWidth() - stage.getWidth()) / 2));
|
||||||
stage.setY(Math.round(window.getY() + titleBarHeight + point.getY() + (owner.getHeight() - stage.getHeight()) / 2));
|
stage.setY(Math.round(window.getY() + titleBarHeight + point.getY() + (owner.getHeight() - stage.getHeight()) / 2));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue