From a63e70148d9a5a6d32b445c158fe07db189b46ba Mon Sep 17 00:00:00 2001 From: joshaber Date: Wed, 30 Dec 2015 17:33:45 -0500 Subject: [PATCH 01/10] Cascade new windows on OS X Fixes #10057. --- src/browser/atom-application.coffee | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index e720597e3..a77591159 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -167,7 +167,7 @@ class AtomApplication safeMode: @focusedWindow()?.safeMode @on 'application:quit', -> app.quit() - @on 'application:new-window', -> @openPath(_.extend(windowDimensions: @focusedWindow()?.getDimensions(), getLoadSettings())) + @on 'application:new-window', -> @openPath(getLoadSettings()) @on 'application:new-file', -> (@focusedWindow() ? this).openPath() @on 'application:open', -> @promptForPathToOpen('all', getLoadSettings()) @on 'application:open-file', -> @promptForPathToOpen('file', getLoadSettings()) @@ -360,6 +360,15 @@ class AtomApplication focusedWindow: -> _.find @windows, (atomWindow) -> atomWindow.isFocused() + # Get the dimensions for opening a new window by cascading as appropriate. + getDimensionsForNewWindow: -> + dimensions = (@focusedWindow() ? @lastFocusedWindow)?.getDimensions() + # On OS X, new windows cascade down and to the right. + if dimensions? and process.platform is 'darwin' + dimensions.x += 20 + dimensions.y += 20 + dimensions + # Public: Opens a single path, in an existing window if possible. # # options - @@ -417,6 +426,7 @@ class AtomApplication windowInitializationScript ?= require.resolve('../initialize-application-window') resourcePath ?= @resourcePath + windowDimensions ?= @getDimensionsForNewWindow() openedWindow = new AtomWindow({locationsToOpen, windowInitializationScript, resourcePath, devMode, safeMode, windowDimensions, profileStartup}) if pidToKillWhenClosed? From 9e7cb15c2c056f99fb1f228758ef2e846549178f Mon Sep 17 00:00:00 2001 From: joshaber Date: Fri, 1 Jan 2016 12:05:42 -0500 Subject: [PATCH 02/10] Offset on Windows too. --- src/browser/atom-application.coffee | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index a77591159..b91adabac 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -360,13 +360,18 @@ class AtomApplication focusedWindow: -> _.find @windows, (atomWindow) -> atomWindow.isFocused() - # Get the dimensions for opening a new window by cascading as appropriate. + # Get the dimensions for opening a new window by cascading as appropriate to + # the platform. getDimensionsForNewWindow: -> - dimensions = (@focusedWindow() ? @lastFocusedWindow)?.getDimensions() - # On OS X, new windows cascade down and to the right. - if dimensions? and process.platform is 'darwin' - dimensions.x += 20 - dimensions.y += 20 + offsetByPlatform = + darwin: 22 + win32: 26 + + dimensions = @windows[@windows.length - 1]?.getDimensions() + offset = offsetByPlatform[process.platform] + if dimensions? and offset? + dimensions.x += offset + dimensions.y += offset dimensions # Public: Opens a single path, in an existing window if possible. From dcd860ae6fb4249ad20536b75618c9590425cb1d Mon Sep 17 00:00:00 2001 From: joshaber Date: Fri, 1 Jan 2016 12:18:48 -0500 Subject: [PATCH 03/10] Use the last focused window instead of the last opened window. --- src/browser/atom-application.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index b91adabac..fe21ae107 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -367,7 +367,7 @@ class AtomApplication darwin: 22 win32: 26 - dimensions = @windows[@windows.length - 1]?.getDimensions() + dimensions = (@focusedWindow() ? @lastFocusedWindow)?.getDimensions() offset = offsetByPlatform[process.platform] if dimensions? and offset? dimensions.x += offset From 94b77d099844c84903b338a6465cc54017a9a62c Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 5 Jan 2016 11:59:59 -0500 Subject: [PATCH 04/10] Separate the offset determination from the dimensions. --- src/browser/atom-application.coffee | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index f6934761a..a5a535b93 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -360,15 +360,18 @@ class AtomApplication focusedWindow: -> _.find @windows, (atomWindow) -> atomWindow.isFocused() - # Get the dimensions for opening a new window by cascading as appropriate to - # the platform. - getDimensionsForNewWindow: -> + # Get the platform-specific window offset for new windows. + getWindowOffsetForCurrentPlatform: -> offsetByPlatform = darwin: 22 win32: 26 + offsetByPlatform[process.platform] ? 0 + # Get the dimensions for opening a new window by cascading as appropriate to + # the platform. + getDimensionsForNewWindow: -> dimensions = (@focusedWindow() ? @lastFocusedWindow)?.getDimensions() - offset = offsetByPlatform[process.platform] + offset = @getWindowOffsetForCurrentPlatform() if dimensions? and offset? dimensions.x += offset dimensions.y += offset From 4ddadcc13580046dacc77b9b7af7198bc199e314 Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 5 Jan 2016 12:00:08 -0500 Subject: [PATCH 05/10] Integration test for new window offset. --- spec/integration/helpers/start-atom.coffee | 3 +++ spec/integration/startup-spec.coffee | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/spec/integration/helpers/start-atom.coffee b/spec/integration/helpers/start-atom.coffee index b8768f532..8290a554e 100644 --- a/spec/integration/helpers/start-atom.coffee +++ b/spec/integration/helpers/start-atom.coffee @@ -127,6 +127,9 @@ buildAtomClient = (args, env) -> .execute -> require("remote").require("app").emit("before-quit") .call(done) + .addCommand "getWindowPosition", (cb) -> + @execute((-> atom.getPosition()), cb) + module.exports = (args, env, fn) -> [chromedriver, chromedriverLogs, chromedriverExit] = [] diff --git a/spec/integration/startup-spec.coffee b/spec/integration/startup-spec.coffee index 799c7685f..374078111 100644 --- a/spec/integration/startup-spec.coffee +++ b/spec/integration/startup-spec.coffee @@ -181,6 +181,25 @@ describe "Starting Atom", -> , 5000) .waitForPaneItemCount(1, 5000) + it "opens a new window offset from the other window", -> + runAtom [path.join(tempDirPath, "new-file")], {ATOM_HOME: atomHome}, (client) -> + win0Position = null + win1Position = null + client + .waitForWindowCount(1, 10000) + .getWindowPosition() + .then ({value}) -> win0Position = value + .waitForNewWindow(-> + @startAnotherAtom([path.join(temp.mkdirSync("a-third-dir"), "a-file")], ATOM_HOME: atomHome) + , 5000) + .waitForWindowCount(2, 10000) + .getWindowPosition() + .then ({value}) -> win1Position = value + .then -> + offset = atom.getWindowOffsetForCurrentPlatform() + expect(win0Position.x).toEqual(win1Position.x + offset) + expect(win0Position.y).toEqual(win1Position.y + offset) + it "doesn't open a new window if openEmptyEditorOnStart is disabled", -> configPath = path.join(atomHome, 'config.cson') config = CSON.readFileSync(configPath) From c8c8bc941e7c0ae73c2e6e5d7c16ed98d0221188 Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 5 Jan 2016 12:27:59 -0500 Subject: [PATCH 06/10] Revert "Integration test for new window offset." This reverts commit 4ddadcc13580046dacc77b9b7af7198bc199e314. --- spec/integration/helpers/start-atom.coffee | 3 --- spec/integration/startup-spec.coffee | 19 ------------------- 2 files changed, 22 deletions(-) diff --git a/spec/integration/helpers/start-atom.coffee b/spec/integration/helpers/start-atom.coffee index 8290a554e..b8768f532 100644 --- a/spec/integration/helpers/start-atom.coffee +++ b/spec/integration/helpers/start-atom.coffee @@ -127,9 +127,6 @@ buildAtomClient = (args, env) -> .execute -> require("remote").require("app").emit("before-quit") .call(done) - .addCommand "getWindowPosition", (cb) -> - @execute((-> atom.getPosition()), cb) - module.exports = (args, env, fn) -> [chromedriver, chromedriverLogs, chromedriverExit] = [] diff --git a/spec/integration/startup-spec.coffee b/spec/integration/startup-spec.coffee index 374078111..799c7685f 100644 --- a/spec/integration/startup-spec.coffee +++ b/spec/integration/startup-spec.coffee @@ -181,25 +181,6 @@ describe "Starting Atom", -> , 5000) .waitForPaneItemCount(1, 5000) - it "opens a new window offset from the other window", -> - runAtom [path.join(tempDirPath, "new-file")], {ATOM_HOME: atomHome}, (client) -> - win0Position = null - win1Position = null - client - .waitForWindowCount(1, 10000) - .getWindowPosition() - .then ({value}) -> win0Position = value - .waitForNewWindow(-> - @startAnotherAtom([path.join(temp.mkdirSync("a-third-dir"), "a-file")], ATOM_HOME: atomHome) - , 5000) - .waitForWindowCount(2, 10000) - .getWindowPosition() - .then ({value}) -> win1Position = value - .then -> - offset = atom.getWindowOffsetForCurrentPlatform() - expect(win0Position.x).toEqual(win1Position.x + offset) - expect(win0Position.y).toEqual(win1Position.y + offset) - it "doesn't open a new window if openEmptyEditorOnStart is disabled", -> configPath = path.join(atomHome, 'config.cson') config = CSON.readFileSync(configPath) From 2a29e7d1f4fc63519b06c5095c4f5e59fc4fe911 Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 5 Jan 2016 12:48:34 -0500 Subject: [PATCH 07/10] Revert "Revert "Integration test for new window offset."" This reverts commit c8c8bc941e7c0ae73c2e6e5d7c16ed98d0221188. --- spec/integration/helpers/start-atom.coffee | 3 +++ spec/integration/startup-spec.coffee | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/spec/integration/helpers/start-atom.coffee b/spec/integration/helpers/start-atom.coffee index b8768f532..8290a554e 100644 --- a/spec/integration/helpers/start-atom.coffee +++ b/spec/integration/helpers/start-atom.coffee @@ -127,6 +127,9 @@ buildAtomClient = (args, env) -> .execute -> require("remote").require("app").emit("before-quit") .call(done) + .addCommand "getWindowPosition", (cb) -> + @execute((-> atom.getPosition()), cb) + module.exports = (args, env, fn) -> [chromedriver, chromedriverLogs, chromedriverExit] = [] diff --git a/spec/integration/startup-spec.coffee b/spec/integration/startup-spec.coffee index 799c7685f..374078111 100644 --- a/spec/integration/startup-spec.coffee +++ b/spec/integration/startup-spec.coffee @@ -181,6 +181,25 @@ describe "Starting Atom", -> , 5000) .waitForPaneItemCount(1, 5000) + it "opens a new window offset from the other window", -> + runAtom [path.join(tempDirPath, "new-file")], {ATOM_HOME: atomHome}, (client) -> + win0Position = null + win1Position = null + client + .waitForWindowCount(1, 10000) + .getWindowPosition() + .then ({value}) -> win0Position = value + .waitForNewWindow(-> + @startAnotherAtom([path.join(temp.mkdirSync("a-third-dir"), "a-file")], ATOM_HOME: atomHome) + , 5000) + .waitForWindowCount(2, 10000) + .getWindowPosition() + .then ({value}) -> win1Position = value + .then -> + offset = atom.getWindowOffsetForCurrentPlatform() + expect(win0Position.x).toEqual(win1Position.x + offset) + expect(win0Position.y).toEqual(win1Position.y + offset) + it "doesn't open a new window if openEmptyEditorOnStart is disabled", -> configPath = path.join(atomHome, 'config.cson') config = CSON.readFileSync(configPath) From f64878208f3eb47fff1e80dfe236782e9ca19129 Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 5 Jan 2016 14:07:50 -0500 Subject: [PATCH 08/10] Really don't need this to be its own command. --- spec/integration/helpers/start-atom.coffee | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/integration/helpers/start-atom.coffee b/spec/integration/helpers/start-atom.coffee index 8290a554e..b8768f532 100644 --- a/spec/integration/helpers/start-atom.coffee +++ b/spec/integration/helpers/start-atom.coffee @@ -127,9 +127,6 @@ buildAtomClient = (args, env) -> .execute -> require("remote").require("app").emit("before-quit") .call(done) - .addCommand "getWindowPosition", (cb) -> - @execute((-> atom.getPosition()), cb) - module.exports = (args, env, fn) -> [chromedriver, chromedriverLogs, chromedriverExit] = [] From 740e8c660a714b2d52d5688feb2d59dfd90e66de Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 5 Jan 2016 14:08:09 -0500 Subject: [PATCH 09/10] Put it with its friends. --- spec/integration/startup-spec.coffee | 37 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/spec/integration/startup-spec.coffee b/spec/integration/startup-spec.coffee index 374078111..d66bcb077 100644 --- a/spec/integration/startup-spec.coffee +++ b/spec/integration/startup-spec.coffee @@ -125,6 +125,24 @@ describe "Starting Atom", -> .treeViewRootDirectories() .then ({value}) -> expect(value).toEqual([otherTempDirPath]) + it "opens the new window offset from the other window", -> + runAtom [path.join(tempDirPath, "new-file")], {ATOM_HOME: atomHome}, (client) -> + win0Position = null + win1Position = null + client + .waitForWindowCount(1, 10000) + .execute -> atom.getPosition() + .then ({value}) -> win0Position = value + .waitForNewWindow(-> + @startAnotherAtom([path.join(temp.mkdirSync("a-third-dir"), "a-file")], ATOM_HOME: atomHome) + , 5000) + .waitForWindowCount(2, 10000) + .execute -> atom.getPosition() + .then ({value}) -> win1Position = value + .then -> + expect(win0Position.x).toEqual(win1Position.x + 22) + expect(win0Position.y).toEqual(win1Position.y + 22) + describe "reopening a directory that was previously opened", -> it "remembers the state of the window", -> runAtom [tempDirPath], {ATOM_HOME: atomHome}, (client) -> @@ -181,25 +199,6 @@ describe "Starting Atom", -> , 5000) .waitForPaneItemCount(1, 5000) - it "opens a new window offset from the other window", -> - runAtom [path.join(tempDirPath, "new-file")], {ATOM_HOME: atomHome}, (client) -> - win0Position = null - win1Position = null - client - .waitForWindowCount(1, 10000) - .getWindowPosition() - .then ({value}) -> win0Position = value - .waitForNewWindow(-> - @startAnotherAtom([path.join(temp.mkdirSync("a-third-dir"), "a-file")], ATOM_HOME: atomHome) - , 5000) - .waitForWindowCount(2, 10000) - .getWindowPosition() - .then ({value}) -> win1Position = value - .then -> - offset = atom.getWindowOffsetForCurrentPlatform() - expect(win0Position.x).toEqual(win1Position.x + offset) - expect(win0Position.y).toEqual(win1Position.y + offset) - it "doesn't open a new window if openEmptyEditorOnStart is disabled", -> configPath = path.join(atomHome, 'config.cson') config = CSON.readFileSync(configPath) From d224efb00d0b01a073fd75f6523731f5b5567225 Mon Sep 17 00:00:00 2001 From: joshaber Date: Tue, 5 Jan 2016 14:40:09 -0500 Subject: [PATCH 10/10] Just test the x coordinate, I suppose. --- spec/integration/startup-spec.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/integration/startup-spec.coffee b/spec/integration/startup-spec.coffee index d66bcb077..da4e08ae2 100644 --- a/spec/integration/startup-spec.coffee +++ b/spec/integration/startup-spec.coffee @@ -140,8 +140,11 @@ describe "Starting Atom", -> .execute -> atom.getPosition() .then ({value}) -> win1Position = value .then -> - expect(win0Position.x).toEqual(win1Position.x + 22) - expect(win0Position.y).toEqual(win1Position.y + 22) + expect(win1Position.x).toBeGreaterThan(win0Position.x) + # Ideally we'd test the y coordinate too, but if the window's + # already as tall as it can be, then OS X won't move it down outside + # the screen. + # expect(win1Position.y).toBeGreaterThan(win0Position.y) describe "reopening a directory that was previously opened", -> it "remembers the state of the window", ->