electron: BrowserWindow - center option doesn't work correctly with multi monitor set-up on Linux

When you have multi monitor set-up and you start BrowserWindow with option center:

new BrowserWindow({width: 800, height: 600, center: true});

The new window is opened in the center of all the monitors, instead of the center of primary one. Basically it counts width of all monitors and put the window in the center of it.

OS: Linux only. Windows, OS X are fine ( window is opened in the center of main monitor)

Tested with: Electron 0.35.0, Ubuntu 14.04, Linux Mint 17.2

This is pretty annoying when you are showing just a little window. Thanks

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 16
  • Comments: 18 (1 by maintainers)

Most upvoted comments

I know this is an old issue, but it’s still open and still a problem if you’re using the default centering code, plus it’s the top google result for “electron linux multiple monitors”. I ended up working around this issue by using the screen API to get the bounds of the primary monitor and use that to calculate the start position. Here’s my code if it’ll be helpful to anyone.

let bounds = electron.screen.getPrimaryDisplay().bounds;
let x = bounds.x + ((bounds.width - WINDOW_WIDTH) / 2);
let y = bounds.y + ((bounds.height - WINDOW_HEIGHT) / 2);
mainWindow = new BrowserWindow({width: WINDOW_WIDTH, height: WINDOW_HEIGHT, x: x, y: y});

@AlexVFornazieri Had the same issue. Try ensuring that x and y are integers.

let x = Math.ceil(bounds.x + ((bounds.width - WINDOW_WIDTH) / 2)); let y = Math.ceil(bounds.y + ((bounds.height - WINDOW_HEIGHT) / 2));

Still an issue on Ubuntu v16.04