Skip to content

Fix bogus serial monitor location if reopened on dual monitor setup #6589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions app/src/processing/app/AbstractMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
15 changes: 11 additions & 4 deletions app/src/processing/app/Base.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -903,6 +908,7 @@ public boolean handleClose(Editor editor) {
}

if (editors.size() == 1) {
storeScreenDimensions();
storeSketches();

// This will store the sketch count as zero
Expand Down Expand Up @@ -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();
Expand Down