From ace037fbaed38813c6974c09d4f0f927127031a1 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 7 Aug 2017 10:44:12 +0200 Subject: [PATCH 1/2] Separate screen dimensions storing from recent sketches --- app/src/processing/app/Base.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 308ef17f2ea..647b3016393 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -522,16 +522,21 @@ protected boolean restoreSketches() throws Exception { return (opened > 0); } - /** - * Store list of sketches that are currently open. - * Called when the application is quitting and documents are still open. + * Store screen dimensions on last close */ - protected void storeSketches() { + protected void storeScreenDimensions() { // Save the width and height of the screen Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); PreferencesData.setInteger("last.screen.width", screen.width); PreferencesData.setInteger("last.screen.height", screen.height); + } + + /** + * Store list of sketches that are currently open. + * Called when the application is quitting and documents are still open. + */ + protected void storeSketches() { // If there is only one sketch opened save his position as default if (editors.size() == 1) { @@ -903,6 +908,7 @@ public boolean handleClose(Editor editor) { } if (editors.size() == 1) { + storeScreenDimensions(); storeSketches(); // This will store the sketch count as zero @@ -949,6 +955,7 @@ public boolean handleClose(Editor editor) { public boolean handleQuit() { // If quit is canceled, this will be replaced anyway // by a later handleQuit() that is not canceled. + storeScreenDimensions(); storeSketches(); try { Editor.serialMonitor.close(); From fdad2f7f92ca4d4c8fdc81494fbbd86b70864b5d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Mon, 7 Aug 2017 10:44:56 +0200 Subject: [PATCH 2/2] Only reapply serial monitor last location if it fits the screen There could be a couple of edge cases in this approach (for example, if someone wants to keep the serial monitor window only half visible). However, it should be at least safe (no serial monitors on the second screen) if the Window Manager acts correctly (by moving all the windows on the second monitor to the primary on detach). --- app/src/processing/app/AbstractMonitor.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/app/src/processing/app/AbstractMonitor.java b/app/src/processing/app/AbstractMonitor.java index 35c45857469..52c5b65b56b 100644 --- a/app/src/processing/app/AbstractMonitor.java +++ b/app/src/processing/app/AbstractMonitor.java @@ -59,17 +59,11 @@ public void actionPerformed(ActionEvent event) { pack(); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - if (PreferencesData.get("last.screen.height") != null) { - // if screen size has changed, the window coordinates no longer - // make sense, so don't use them unless they're identical - int screenW = PreferencesData.getInteger("last.screen.width"); - int screenH = PreferencesData.getInteger("last.screen.height"); - if ((screen.width == screenW) && (screen.height == screenH)) { - String locationStr = PreferencesData.get("last.serial.location"); - if (locationStr != null) { - int[] location = PApplet.parseInt(PApplet.split(locationStr, ',')); - setPlacement(location); - } + String locationStr = PreferencesData.get("last.serial.location"); + if (locationStr != null) { + int[] location = PApplet.parseInt(PApplet.split(locationStr, ',')); + if (location[0] + location[2] <= screen.width && location[1] + location[3] <= screen.height) { + setPlacement(location); } }