Add support for opening the terminal on the correct display (#519)

* Add support for opening the terminal on the correct display

* Fix whitespace issue

* Start from the top left again when we run out of space

* Add semicolon
This commit is contained in:
James Hall 2016-08-02 01:00:49 +01:00 committed by GitHub
parent aa84fde6b3
commit c9fe3d82db

View file

@ -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);