From b45c1c7548f7614ce84d213aed75ead5c1b31f43 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 8 Apr 2014 12:35:36 -0700 Subject: [PATCH 1/9] Store the default windows position. Based on the last closed window or the last focused window --- src/atom.coffee | 4 ++++ src/window-event-handler.coffee | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/atom.coffee b/src/atom.coffee index a2384eea3..cdcd4fb19 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -223,6 +223,10 @@ class Atom extends Model else @center() + storeDefaultWindowDimensions: -> + dimensions = JSON.stringify(atom.getWindowDimensions()) + localStorage.setItem("defaultWindowDimensions", dimensions) + restoreWindowDimensions: -> workAreaSize = screen.getPrimaryDisplay().workAreaSize windowDimensions = @state.windowDimensions ? {} diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 21d1940fb..e435f7c3d 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -37,6 +37,9 @@ class WindowEventHandler @reloadRequested = false confirmed + @subscribe $(window), 'blur unload', -> + atom.setDefaultWindowDimensions() + @subscribe $(window), 'unload', -> atom.storeWindowDimensions() From 053965602c94d398427333e0148b16ec951ced41 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 8 Apr 2014 14:19:03 -0700 Subject: [PATCH 2/9] Apply default dimensions --- src/atom.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/atom.coffee b/src/atom.coffee index cdcd4fb19..8c9d207fc 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -227,6 +227,14 @@ class Atom extends Model dimensions = JSON.stringify(atom.getWindowDimensions()) localStorage.setItem("defaultWindowDimensions", dimensions) + applyDefaultWindowDimensions: -> + return unless dimensions = localStorage.getItem("defaultWindowDimensions") + try + JSON.parse(dimensions) + catch error + console.warn "Error parsing default window dimensions", error + localStorage.removeItem("defaultWindowDimensions") + restoreWindowDimensions: -> workAreaSize = screen.getPrimaryDisplay().workAreaSize windowDimensions = @state.windowDimensions ? {} From 03814246ef93997fd86d74105432d59a6859fffd Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 8 Apr 2014 15:25:49 -0700 Subject: [PATCH 3/9] Rename to storeDefaultWindowDimensions --- src/window-event-handler.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index e435f7c3d..2f636d1e8 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -38,7 +38,7 @@ class WindowEventHandler confirmed @subscribe $(window), 'blur unload', -> - atom.setDefaultWindowDimensions() + atom.storeDefaultWindowDimensions() @subscribe $(window), 'unload', -> atom.storeWindowDimensions() From 993534337ca1b293ff53ec477f1421f8522237b3 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 8 Apr 2014 15:26:08 -0700 Subject: [PATCH 4/9] Update restoreWindowDimensions --- src/atom.coffee | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 8c9d207fc..76ec3241a 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -227,20 +227,17 @@ class Atom extends Model dimensions = JSON.stringify(atom.getWindowDimensions()) localStorage.setItem("defaultWindowDimensions", dimensions) - applyDefaultWindowDimensions: -> - return unless dimensions = localStorage.getItem("defaultWindowDimensions") + getDefaultWindowDimensions: -> try - JSON.parse(dimensions) + JSON.parse(localStorage.getItem("defaultWindowDimensions")) catch error console.warn "Error parsing default window dimensions", error localStorage.removeItem("defaultWindowDimensions") + {width, height} = screen.getPrimaryDisplay().workAreaSize + {x: 0, y: 0, width: width, height: Math.min(1024, height)} restoreWindowDimensions: -> - workAreaSize = screen.getPrimaryDisplay().workAreaSize - windowDimensions = @state.windowDimensions ? {} - {initialSize} = @getLoadSettings() - windowDimensions.height ?= initialSize?.height ? workAreaSize.height - windowDimensions.width ?= initialSize?.width ? Math.min(workAreaSize.width, 1024) + windowDimensions = @state.windowDimensions ? @getDefaultWindowDimensions() @setWindowDimensions(windowDimensions) storeWindowDimensions: -> From 6fcd905d4f19e3f9f3f1cb8a82e60cd5ae2b89ec Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 8 Apr 2014 16:57:18 -0700 Subject: [PATCH 5/9] Use windowDimensions instead of initialSize --- src/browser/atom-application.coffee | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index c0f5636e8..402f00c15 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -172,7 +172,7 @@ class AtomApplication @on 'application:run-all-specs', -> @runSpecs(exitWhenDone: false, resourcePath: global.devResourcePath) @on 'application:run-benchmarks', -> @runBenchmarks() @on 'application:quit', -> app.quit() - @on 'application:new-window', -> @openPath(initialSize: @getFocusedWindowSize()) + @on 'application:new-window', -> @openPath(windowDimensions: @getFocusedWindowDimensions()) @on 'application:new-file', -> (@focusedWindow() ? this).openPath() @on 'application:open', -> @promptForPath() @on 'application:open-dev', -> @promptForPath(devMode: true) @@ -304,14 +304,15 @@ class AtomApplication focusedWindow: -> _.find @windows, (atomWindow) -> atomWindow.isFocused() - # Public: Get the height and width of the focused window. + # Public: Get the dimensions focused window. # - # Returns an object with height and width keys or null if there is no + # Returns an object with x, y height and width keys or null if there is no # focused window. - getFocusedWindowSize: -> + getFocusedWindowDimensions: -> if focusedWindow = @focusedWindow() [width, height] = focusedWindow.getSize() - {width, height} + [x, y] = focusedWindow.getPosition() + {x, y, width, height} else null @@ -340,9 +341,9 @@ class AtomApplication # Boolean of whether this should be opened in a new window. # + devMode: # Boolean to control the opened window's dev mode. - # + initialSize: + # + windowDimensions: # Object with height and width keys. - openPath: ({pathToOpen, pidToKillWhenClosed, newWindow, devMode, initialSize}={}) -> + openPath: ({pathToOpen, pidToKillWhenClosed, newWindow, devMode, windowDimensions}={}) -> if pathToOpen [basename, initialLine] = path.basename(pathToOpen).split(':') if initialLine @@ -362,7 +363,7 @@ class AtomApplication bootstrapScript ?= require.resolve('../window-bootstrap') resourcePath ?= @resourcePath - openedWindow = new AtomWindow({pathToOpen, initialLine, bootstrapScript, resourcePath, devMode, initialSize}) + openedWindow = new AtomWindow({pathToOpen, initialLine, bootstrapScript, resourcePath, devMode, windowDimensions}) if pidToKillWhenClosed? @pidsToOpenWindows[pidToKillWhenClosed] = openedWindow @@ -414,7 +415,7 @@ class AtomApplication if pack.urlMain packagePath = @packages.resolvePackagePath(packageName) bootstrapScript = path.resolve(packagePath, pack.urlMain) - new AtomWindow({bootstrapScript, @resourcePath, devMode, urlToOpen, initialSize: @getFocusedWindowSize()}) + new AtomWindow({bootstrapScript, @resourcePath, devMode, urlToOpen, windowDimensions: @getFocusedWindowDimensions()}) else console.log "Package '#{pack.name}' does not have a url main: #{urlToOpen}" else From 3393583b724fdbf66c5f2aa3a8b2e1a8463cb704 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 8 Apr 2014 16:57:52 -0700 Subject: [PATCH 6/9] Use windowDimensions from load settings if they exist --- src/atom.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/atom.coffee b/src/atom.coffee index 76ec3241a..55f9dbf91 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -228,6 +228,9 @@ class Atom extends Model localStorage.setItem("defaultWindowDimensions", dimensions) getDefaultWindowDimensions: -> + {windowDimensions} = @getLoadSettings() + return windowDimensions if windowDimensions? + try JSON.parse(localStorage.getItem("defaultWindowDimensions")) catch error From d72e3d9c812eff5e31482f11c44cd725f5d2bd37 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 8 Apr 2014 17:11:20 -0700 Subject: [PATCH 7/9] Add AtomWindow::getWindowDimensions --- src/browser/atom-application.coffee | 17 +++-------------- src/browser/atom-window.coffee | 7 +++++-- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 402f00c15..6637e92c1 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -172,7 +172,7 @@ class AtomApplication @on 'application:run-all-specs', -> @runSpecs(exitWhenDone: false, resourcePath: global.devResourcePath) @on 'application:run-benchmarks', -> @runBenchmarks() @on 'application:quit', -> app.quit() - @on 'application:new-window', -> @openPath(windowDimensions: @getFocusedWindowDimensions()) + @on 'application:new-window', -> @openPath(windowDimensions: @focusedWindow()?.getDimensions()) @on 'application:new-file', -> (@focusedWindow() ? this).openPath() @on 'application:open', -> @promptForPath() @on 'application:open-dev', -> @promptForPath(devMode: true) @@ -304,18 +304,6 @@ class AtomApplication focusedWindow: -> _.find @windows, (atomWindow) -> atomWindow.isFocused() - # Public: Get the dimensions focused window. - # - # Returns an object with x, y height and width keys or null if there is no - # focused window. - getFocusedWindowDimensions: -> - if focusedWindow = @focusedWindow() - [width, height] = focusedWindow.getSize() - [x, y] = focusedWindow.getPosition() - {x, y, width, height} - else - null - # Public: Opens multiple paths, in existing windows if possible. # # * options @@ -415,7 +403,8 @@ class AtomApplication if pack.urlMain packagePath = @packages.resolvePackagePath(packageName) bootstrapScript = path.resolve(packagePath, pack.urlMain) - new AtomWindow({bootstrapScript, @resourcePath, devMode, urlToOpen, windowDimensions: @getFocusedWindowDimensions()}) + windowDimensions = @focusedWindow()?.getDimensions() + new AtomWindow({bootstrapScript, @resourcePath, devMode, urlToOpen, windowDimensions}) else console.log "Package '#{pack.name}' does not have a url main: #{urlToOpen}" else diff --git a/src/browser/atom-window.coffee b/src/browser/atom-window.coffee index fed11e4d6..efa409c27 100644 --- a/src/browser/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -132,12 +132,15 @@ class AtomWindow action = if args[0]?.contextCommand then 'context-command' else 'command' ipc.sendChannel @browserWindow.getProcessId(), @browserWindow.getRoutingId(), action, command, args... + getDimensions: -> + [x, y] = @browserWindow.getPosition() + [width, height] = @browserWindow.getSize() + {x, y, width, height} + close: -> @browserWindow.close() focus: -> @browserWindow.focus() - getSize: -> @browserWindow.getSize() - minimize: -> @browserWindow.minimize() maximize: -> @browserWindow.maximize() From b72bb4ab6564f6f3fb436fe6ee2aeab9c5a94e95 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 8 Apr 2014 17:27:52 -0700 Subject: [PATCH 8/9] Fix default size bug --- src/atom.coffee | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/atom.coffee b/src/atom.coffee index 55f9dbf91..1eb93582b 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -231,13 +231,15 @@ class Atom extends Model {windowDimensions} = @getLoadSettings() return windowDimensions if windowDimensions? + dimensions = null try - JSON.parse(localStorage.getItem("defaultWindowDimensions")) + dimensions = JSON.parse(localStorage.getItem("defaultWindowDimensions")) catch error console.warn "Error parsing default window dimensions", error localStorage.removeItem("defaultWindowDimensions") - {width, height} = screen.getPrimaryDisplay().workAreaSize - {x: 0, y: 0, width: width, height: Math.min(1024, height)} + + {width, height} = screen.getPrimaryDisplay().workAreaSize + dimensions ? {x: 0, y: 0, width: Math.min(1024, width), height: height} restoreWindowDimensions: -> windowDimensions = @state.windowDimensions ? @getDefaultWindowDimensions() From a2f73fd6b007b97b2393eaf66c4dffb51c87916e Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Wed, 9 Apr 2014 10:13:09 -0700 Subject: [PATCH 9/9] Remove unneeded fat arrows --- src/window-event-handler.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 2f636d1e8..002bfd20e 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -43,15 +43,15 @@ class WindowEventHandler @subscribe $(window), 'unload', -> atom.storeWindowDimensions() - @subscribeToCommand $(window), 'window:toggle-full-screen', => atom.toggleFullScreen() + @subscribeToCommand $(window), 'window:toggle-full-screen', -> atom.toggleFullScreen() - @subscribeToCommand $(window), 'window:close', => atom.close() + @subscribeToCommand $(window), 'window:close', -> atom.close() @subscribeToCommand $(window), 'window:reload', => @reloadRequested = true atom.reload() - @subscribeToCommand $(window), 'window:toggle-dev-tools', => atom.toggleDevTools() + @subscribeToCommand $(window), 'window:toggle-dev-tools', -> atom.toggleDevTools() @subscribeToCommand $(document), 'core:focus-next', @focusNext @@ -95,7 +95,7 @@ class WindowEventHandler bindCommandToAction('core:redo', 'redo:') bindCommandToAction('core:select-all', 'selectAll:') - openLink: (event) => + openLink: (event) -> location = $(event.target).attr('href') if location and location[0] isnt '#' and /^https?:\/\//.test(location) shell.openExternal(location)