diff --git a/src/main/java/com/sparrowwallet/sparrow/AppServices.java b/src/main/java/com/sparrowwallet/sparrow/AppServices.java index cd4418e3..4bf3bb1a 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppServices.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppServices.java @@ -573,6 +573,34 @@ public class AppServices { } } + public static void runAfterDelay(long delay, Runnable runnable) { + if(delay <= 0) { + if(Platform.isFxApplicationThread()) { + runnable.run(); + } else { + Platform.runLater(runnable); + } + } else { + ScheduledService delayService = new ScheduledService<>() { + @Override + protected Task createTask() { + return new Task<>() { + @Override + protected Void call() { + return null; + } + }; + } + }; + delayService.setOnSucceeded(_ -> { + delayService.cancel(); + runnable.run(); + }); + delayService.setDelay(Duration.millis(delay)); + delayService.start(); + } + } + private static Image getWindowIcon() { if(windowIcon == null) { windowIcon = new Image(SparrowWallet.class.getResourceAsStream("/image/sparrow-icon.png")); @@ -1114,6 +1142,15 @@ public class AppServices { return Font.font("Roboto Mono", 13); } + public static boolean isOnWayland() { + if(org.controlsfx.tools.Platform.getCurrent() != org.controlsfx.tools.Platform.UNIX) { + return false; + } + + String waylandDisplay = System.getenv("WAYLAND_DISPLAY"); + return waylandDisplay != null && !waylandDisplay.isEmpty(); + } + @Subscribe public void newConnection(ConnectionEvent event) { currentBlockHeight = event.getBlockHeight(); diff --git a/src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java b/src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java index 8002db82..76fe3e58 100644 --- a/src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java +++ b/src/main/java/com/sparrowwallet/sparrow/SparrowDesktop.java @@ -90,7 +90,8 @@ public class SparrowDesktop extends Application { AppController appController = AppServices.newAppWindow(stage); final boolean showNewWallet = createNewWallet; - javafx.application.Platform.runLater(() -> { + //Delay opening new dialogs on Wayland + AppServices.runAfterDelay(AppServices.isOnWayland() ? 1000 : 0, () -> { if(showNewWallet) { appController.newWallet(null); } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystorePane.java b/src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystorePane.java index 9643c36e..b17127e7 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystorePane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/MnemonicKeystorePane.java @@ -113,23 +113,9 @@ public class MnemonicKeystorePane extends TitledDescriptionPane { wordEntry.getEditor().setText(words.get(i)); wordEntry.getEditor().setEditable(false); } else { - ScheduledService service = new ScheduledService<>() { - @Override - protected Task createTask() { - return new Task<>() { - @Override - protected Void call() { - return null; - } - }; - } - }; - service.setDelay(Duration.millis(500)); - service.setOnSucceeded(event1 -> { - service.cancel(); + AppServices.runAfterDelay(500, () -> { Platform.runLater(() -> wordEntry.getEditor().requestFocus()); }); - service.start(); } } }