electron / electron

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS
https://electronjs.org
MIT License
112.32k stars 15.02k forks source link

[Bug]: Open BrowserWindow on secondary screen on MAc #42217

Open NykoKar opened 2 weeks ago

NykoKar commented 2 weeks ago

Preflight Checklist

Electron Version

30.0.6

What operating system are you using?

macOS

Operating System Version

MasOS Somona 14.4.1 - M1

What arch are you using?

Other (specify below)

Last Known Working Electron version

No response

Expected Behavior

Create a BrowserWindow on my secondary screen near main screen

Actual Behavior

The BrowserWindow is created on the main screen.

Testcase Gist URL

https://gist.github.com/NykoKar/f3f8e7eaec0e980d42d53c1b050e378b

Additional Information

I followed this documentation: https://www.electronjs.org/docs/latest/api/screen It works on Windows but not on MacOS.

NykoKar commented 2 weeks ago

A better gist (to test on Fiddle for example): https://gist.github.com/NykoKar/002b79bdaed2bf36ab8f9bc30dbefec3

clavin commented 1 week ago

I'm sorry, I'm unable to reproduce this issue given the test case provided on macOS. I checked my display settings and the displays reported by screen.getAllDisplays() and everything seems to be working properly.

Check out the Electron community. There are also a bunch of helpful people in this Discord that should be willing to point you in the right direction. For your question, I'd recommend the Discord - we have many active help channels and mentors, as well as fellow devs, who can help you out.

NykoKar commented 1 week ago

@clavin Thank you for your feedback but I'm not sure you understand my issue (because I really think there is one) so I'll try to explain it better.

I have two screens next to each other (main in front of me, secondary on my right) and the function screen.getAllDisplays() also give me the right values:

[
  {
    id: 2,
    label: 'DELL U2720Q',
    bounds: { x: 0, y: 0, width: 3008, height: 1692 },
    workArea: { x: 0, y: 25, width: 3008, height: 1667 },
    accelerometerSupport: 'unknown',
    monochrome: false,
    colorDepth: 24,
    colorSpace: '{primaries:BT709, transfer:SRGB, matrix:RGB, range:FULL}',
    depthPerComponent: 8,
    size: { width: 3008, height: 1692 },
    displayFrequency: 59,
    workAreaSize: { width: 3008, height: 1667 },
    scaleFactor: 2,
    rotation: 0,
    internal: false,
    touchSupport: 'unknown'
  },
  {
    id: 1,
    label: 'VG248',
    bounds: { x: 3008, y: 0, width: 1920, height: 1080 },
    workArea: { x: 3008, y: 25, width: 1920, height: 1055 },
    accelerometerSupport: 'unknown',
    monochrome: false,
    colorDepth: 24,
    colorSpace: '{r:[0.6502, 0.3292], g:[0.3301, 0.6229], b:[0.1513, 0.3292], w:[0.3127, 0.3290]}, transfer:BT709_APPLE, matrix:RGB, range:FULL}',
    depthPerComponent: 8,
    size: { width: 1920, height: 1080 },
    displayFrequency: 60,
    workAreaSize: { width: 1920, height: 1055 },
    scaleFactor: 1,
    rotation: 0,
    internal: false,
    touchSupport: 'unknown'
  }
]

So the second monitor, which is the VG248, has

bounds: { x: 3008, y: 0, width: 1920, height: 1080 },

So, to create a BrowserWindow on this monitor, I put these parameters on the constructor (x & y + 50 as indicated on electron's documentation ): new BrowserWindow({ x: 3008 + 50, y: 0 + 50, })

On my side, this BrowserWindow will be created on my primary screen whereas it should be displayed on my secondary as I have put coordinate of my secondary monitor.

Additional information: I'm working on a mac mini. So, maybe there is a difference of behaviour between macbook with 1 external screen and mac mini with 2 external screens, just an idea.