diff --git a/app/index.js b/app/index.js index e8b7daba..80bba5df 100644 --- a/app/index.js +++ b/app/index.js @@ -50,6 +50,33 @@ app.on('ready', () => { let cfg = plugins.getDecoratedConfig(); const [width, height] = cfg.windowSize || [540, 380]; + const { screen } = require('electron'); + + let startX = 50; + let startY = 50; + + // Open the new window roughly the height of the header away from the + // previous window. This also ensures in multi monitor setups that the + // new terminal is on the correct screen. + if (BrowserWindow.getFocusedWindow() !== null) { + const currentWindow = BrowserWindow.getFocusedWindow(); + const points = currentWindow.getPosition(); + const currentScreen = screen.getDisplayNearestPoint({ x: points[0], y: points[1] }); + + const biggestX = ((points[0] + 100 + width) - currentScreen.bounds.x); + const biggestY = ((points[1] + 100 + height) - currentScreen.bounds.y); + + if (biggestX > currentScreen.size.width) { + startX = 50; + } else { + startX = points[0] + 34; + } + if (biggestY > currentScreen.size.height) { + startY = 50; + } else { + startY = points[1] + 34; + } + } const browserDefaults = { width, @@ -63,7 +90,9 @@ app.on('ready', () => { icon: resolve(__dirname, 'static/icon.png'), // we only want to show when the prompt // is ready for user input - show: process.env.HYPERTERM_DEBUG || isDev + show: process.env.HYPERTERM_DEBUG || isDev, + x: startX, + y: startY }; const browserOptions = plugins.getDecoratedBrowserOptions(browserDefaults);