Skip to content

Commit 78ace2e

Browse files
committed
Do not maximize app window on first startup (or settings cleared)
Ref #684 Closes #801
1 parent f34f886 commit 78ace2e

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

pdfsam-gui/src/main/java/org/pdfsam/gui/WindowStatusController.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,17 @@ && hasAvailableScreen(latestStatus)) {
6666
}
6767
}
6868

69+
/**
70+
* Sets the app's window position and size on the primary screen to sensible defaults.
71+
*/
6972
private void defaultStageStatus() {
70-
Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
71-
stage.setX((primScreenBounds.getWidth() - stage.getWidth()) / 2);
72-
stage.setY((primScreenBounds.getHeight() - stage.getHeight()) / 4);
73-
stage.setMaximized(true);
73+
Rectangle2D primaryBounds = Screen.getPrimary().getVisualBounds();
74+
int w = (int) (primaryBounds.getWidth() * 0.6);
75+
int h = (int) (primaryBounds.getHeight() * 0.8);
76+
stage.setX(primaryBounds.getMinX() + (primaryBounds.getWidth() - w) / 2);
77+
stage.setY(primaryBounds.getMinY() + (primaryBounds.getHeight() - h) / 2);
78+
stage.setWidth(w);
79+
stage.setHeight(h);
7480
}
7581

7682
private void restore(StageStatus latestStatus) {

pdfsam-gui/src/test/java/org/pdfsam/gui/WindowStatusControllerTest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import org.testfx.framework.junit5.Start;
3636
import org.testfx.framework.junit5.Stop;
3737

38-
import static org.junit.jupiter.api.Assertions.assertTrue;
38+
import static org.junit.jupiter.api.Assertions.assertEquals;
39+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
3940
import static org.mockito.Mockito.mock;
4041
import static org.mockito.Mockito.when;
4142

@@ -71,19 +72,25 @@ public void stop(){
7172
}
7273

7374
@Test
74-
public void defaultOnNullStatus() {
75-
when(service.getLatestStatus()).thenReturn(StageStatus.NULL);
75+
@SetSystemProperty(key = ConfigurableSystemProperty.PDFSAM_DISABLE_UI_RESTORE, value = "true")
76+
public void defaultOnDisableRestore() {
77+
when(service.getLatestStatus()).thenReturn(new StageStatus(10, 10, 10, 10));
7678
victim.setStage(victimStage);
7779
robot.clickOn("show").sleep(200);
78-
assertTrue(victimStage.isMaximized());
80+
assertNotEquals(10, victimStage.getX());
81+
assertNotEquals(10, victimStage.getY());
82+
assertNotEquals(10, victimStage.getWidth());
83+
assertNotEquals(10, victimStage.getHeight());
7984
}
8085

8186
@Test
82-
@SetSystemProperty(key = ConfigurableSystemProperty.PDFSAM_DISABLE_UI_RESTORE, value = "true")
83-
public void defaultOnDisableRestore() {
87+
void restoreLastStatus() {
8488
when(service.getLatestStatus()).thenReturn(new StageStatus(10, 10, 10, 10));
8589
victim.setStage(victimStage);
8690
robot.clickOn("show").sleep(200);
87-
assertTrue(victimStage.isMaximized());
91+
assertEquals(10, victimStage.getX());
92+
assertEquals(10, victimStage.getY());
93+
assertEquals(10, victimStage.getWidth());
94+
assertEquals(10, victimStage.getHeight());
8895
}
8996
}

0 commit comments

Comments
 (0)