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).
This commit is contained in:
Martino Facchin 2017-08-07 10:44:56 +02:00 committed by Cristian Maglie
parent 8292989e2d
commit 328296a2c5
1 changed files with 5 additions and 11 deletions

View File

@ -59,17 +59,11 @@ public abstract class AbstractMonitor extends JFrame implements ActionListener {
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);
}
}