electron: `getPosition()` return inconsistent values when compared to `screen.getAllDisplays()`

  • Electron version: 1.1.0
  • Operating system: OS X

window.getPosition() appears to return impossible values in some screen configurations on OS X. With the screen configuration below.

screencapture-at-tue-jun-7-13_08_22-edt-2016

The following outputs are noted.

// Calling window.getPosition()
// When the window is in the top left of the left screen
[-2321, 23]

// When the window is in the top right of the left screen
[-1196, 23]

// When the window is in the top left of the right screen
[3, 23]

// When the window is in the top right of the right screen
[642,23]

Below is the output for screen.getAllDisplays()

[
  {
    "id":69677376,
    "bounds":{
      "x":0,
      "y":0,
      "width":1280,
      "height":800
    },
    "workArea":{
      "x":0,
      "y":23,
      "width":1280,
      "height":709
    },
    "size":{
      "width":1280,
      "height":800
    },
    "workAreaSize":{
      "width":1280,
      "height":709
    },
    "scaleFactor":1,
    "rotation":0,
    "touchSupport":"unknown"
  },
  {
    "id":188906641,
    "bounds":{
      "x":-1920,
      "y":0,
      "width":1920,
      "height":1080
    },
    "workArea":{
      "x":-1920,
      "y":23,
      "width":1920,
      "height":1057
    },
    "size":{
      "width":1920,
      "height":1080
    },
    "workAreaSize":{
      "width":1920,
      "height":1057
    },
    "scaleFactor":1,
    "rotation":0,
    "touchSupport":"unknown"
  }
]

As you can see, based on the workArea values for the two screen the first two position values are impossible / incorrect for where they actually are on the screen. The x values appear to be offset by the width of the screen.

This is causing issues with restoring a windows location as we are restoring a window to a location that doesn’t actually exist.

About this issue

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

Most upvoted comments

@MarshallOfSound

If you guys in Electron want to do something about this, there is an API in OSX available that displays the visible frame from the current screen. For example:

        // Retrieve information for the display that contains the window.
        NSScreen* screen = [window screen];
        if (screen == nil)
            screen = [NSScreen mainScreen];
        NSRect frame = [screen frame];
        NSRect visibleFrame = [screen visibleFrame];

Then you can calculate how to modify the frame of the window appropriately.

Unfortunately, there is no way to get this in Electron right now, causing me a lot of trouble at the moment…