diff --git a/src/atom.coffee b/src/atom.coffee index 6985ea727..59c3d1578 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -223,12 +223,26 @@ class Atom extends Model else @center() + storeDefaultWindowDimensions: -> + dimensions = JSON.stringify(atom.getWindowDimensions()) + localStorage.setItem("defaultWindowDimensions", dimensions) + + getDefaultWindowDimensions: -> + {windowDimensions} = @getLoadSettings() + return windowDimensions if windowDimensions? + + dimensions = null + try + dimensions = JSON.parse(localStorage.getItem("defaultWindowDimensions")) + catch error + console.warn "Error parsing default window dimensions", error + localStorage.removeItem("defaultWindowDimensions") + + {width, height} = screen.getPrimaryDisplay().workAreaSize + dimensions ? {x: 0, y: 0, width: Math.min(1024, width), height: 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: -> diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 1f789f10e..5061b7fc6 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -133,7 +133,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: @focusedWindow()?.getDimensions()) @on 'application:new-file', -> (@focusedWindow() ? this).openPath() @on 'application:open', -> @promptForPath() @on 'application:open-dev', -> @promptForPath(devMode: true) @@ -265,17 +265,6 @@ class AtomApplication focusedWindow: -> _.find @windows, (atomWindow) -> atomWindow.isFocused() - # Public: Get the height and width of the focused window. - # - # Returns an object with height and width keys or null if there is no - # focused window. - getFocusedWindowSize: -> - if focusedWindow = @focusedWindow() - [width, height] = focusedWindow.getSize() - {width, height} - else - null - # Public: Opens multiple paths, in existing windows if possible. # # * options @@ -301,9 +290,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 @@ -323,7 +312,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 @@ -375,7 +364,8 @@ class AtomApplication if pack.urlMain packagePath = @packages.resolvePackagePath(packageName) bootstrapScript = path.resolve(packagePath, pack.urlMain) - new AtomWindow({bootstrapScript, @resourcePath, devMode, urlToOpen, initialSize: @getFocusedWindowSize()}) + 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 f7d89535d..4d4f71a93 100644 --- a/src/browser/atom-window.coffee +++ b/src/browser/atom-window.coffee @@ -138,12 +138,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() diff --git a/src/window-event-handler.coffee b/src/window-event-handler.coffee index 21d1940fb..002bfd20e 100644 --- a/src/window-event-handler.coffee +++ b/src/window-event-handler.coffee @@ -37,18 +37,21 @@ class WindowEventHandler @reloadRequested = false confirmed + @subscribe $(window), 'blur unload', -> + atom.storeDefaultWindowDimensions() + @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 @@ -92,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)