Skip to content

Commit 6ea6f9c

Browse files
authored
Merge pull request slovensko-digital#160 from solver-it-sro/windows-iconified-fix
Remove nasty OS-handling, just disable focusing in main menu
2 parents e07fed2 + fc3acf2 commit 6ea6f9c

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

src/main/java/digital/slovensko/autogram/ui/gui/GUIApp.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,10 @@ public void start(Stage windowStage) throws Exception {
3535
Platform.exit();
3636
});
3737

38-
if (params.isStandaloneMode()) {
39-
GUIUtils.suppressDefaultFocus(windowStage, controller);
40-
} else {
41-
GUIUtils.setIconifiedWithSuppressingDefaultFocus(windowStage, controller);
42-
}
43-
38+
if (!params.isStandaloneMode())
39+
GUIUtils.startIconified(windowStage);
4440
windowStage.setTitle("Autogram");
4541
windowStage.setScene(scene);
46-
windowStage.sizeToScene();
4742
windowStage.setResizable(false);
4843
windowStage.show();
4944
}

src/main/java/digital/slovensko/autogram/ui/gui/GUIUtils.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,6 @@ static void showOnTop(Stage stage) {
5252
}).start();
5353
}
5454

55-
public static void setIconifiedWithSuppressingDefaultFocus(Stage windowStage, MainMenuController controller) {
56-
// WARNING! DO NOT TOUCH!
57-
// Windows behaves very differently.
58-
// No focus event is fired for first time (!) iconified windowStage is opened/focused & it shows only empty window
59-
if (OperatingSystem.current() == OperatingSystem.WINDOWS) {
60-
windowStage.setOnShown(e -> GUIUtils.suppressDefaultFocus(windowStage, controller));
61-
62-
// do this only on windows since it flickers on Linux
63-
windowStage.getIcons().add(new Image(Objects.requireNonNull(GUIApp.class.getResourceAsStream("Autogram.png"))));
64-
} else {
65-
GUIUtils.suppressDefaultFocus(windowStage, controller);
66-
}
67-
windowStage.setIconified(true);
68-
}
69-
7055
public static void suppressDefaultFocus(Stage stage, SuppressedFocusController controller) {
7156
stage.focusedProperty().addListener(((observable, old, isFocused) -> {
7257
if (isFocused) controller.getNodeForLoosingFocus().requestFocus(); // everything else looses focus
@@ -76,4 +61,17 @@ public static void suppressDefaultFocus(Stage stage, SuppressedFocusController c
7661
public static void closeWindow(Node node) {
7762
((Stage) node.getScene().getWindow()).close();
7863
}
64+
65+
public static void startIconified(Stage stage) {
66+
if (OperatingSystem.current() == OperatingSystem.LINUX) {
67+
stage.setIconified(true);
68+
} else {
69+
// WINDOWS & MAC need to set iconified after showing primary stage, otherwise it starts blank
70+
stage.setOpacity(0); // prevents startup blink
71+
stage.setOnShown((e) -> Platform.runLater(() -> {
72+
stage.setIconified(true);
73+
stage.setOpacity(1);
74+
}));
75+
}
76+
}
7977
}

src/main/resources/digital/slovensko/autogram/ui/gui/main-menu.fxml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<VBox fx:id="dropZone" styleClass="autogram-dropzone">
2020
<SVGPath styleClass="autogram-icon,autogram-icon--big" content="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m3.75 9v6m3-3H9m1.5-12H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z"/>
2121
<TextFlow textAlignment="CENTER">
22-
<Button styleClass="autogram-button,autogram-button--secondary" fx:id="uploadButton" onAction="#onUploadButtonAction">Vyberte súbor</Button>
22+
<Button styleClass="autogram-button,autogram-button--secondary" focusTraversable="false" fx:id="uploadButton" onAction="#onUploadButtonAction">Vyberte súbor</Button>
2323
<Text styleClass="autogram-body" text=" alebo ho presuňte sem" />
2424
</TextFlow>
2525
</VBox>
@@ -28,7 +28,7 @@
2828
</top>
2929
<bottom>
3030
<HBox styleClass="autogram-footer">
31-
<Button styleClass="autogram-link" onAction="#onAboutButtonAction">O Autograme</Button>
31+
<Button styleClass="autogram-link" focusTraversable="false" onAction="#onAboutButtonAction">O Autograme</Button>
3232
</HBox>
3333
</bottom>
3434
</BorderPane>

0 commit comments

Comments
 (0)