mawie81/electron-window-state

Support portrait monitors

Closed this issue · 4 comments

rob3c commented

Hi, thanks for the nice plugin!

It's great that it remembers the monitor as well as the size and position of the window when restoring from saved settings. It works perfectly for monitors in landscape orientation, but it doesn't quite work right when restoring to a monitor in portrait orientation, unfortunately.

I have a three-monitor setup where my left monitor (1050x1680) is in portrait orientation instead of landscape like the other two. When the window is restored on the portrait monitor, its height always gets truncated to the width of the monitor (1050 i.e. what would normally be the height in landscape mode). If I save the window with a smaller height, then it restores ok. It's only when the height is more than the 1050 width that there's a problem.

Here's a sample window-state.json file (reformatted with whitespace for readability) when saving a window that takes up the full left half of my portrait monitor (I didn't save use the full width here to avoid confusion with thinking the height and width were being swapped, since that's not the problem).

{
  "width":525,
  "height":1650,
  "x":-1050,
  "y":30,
  "isMaximized":false,
  "isFullScreen":false,
  "displayBounds": {
    "x":-1050,
    "y":30,
    "width":1050,
    "height":1680
  }
}

(The 'missing' 30px is due to the taskbar at the bottom of the screen.)

For reference, here's the settings file after immediately closing the app after being restored from the above settings:

{
  "width":525,
  "height":1050,
  "x":-1050,
  "y":30,
  "isMaximized":false,
  "isFullScreen":false,
  "displayBounds": {
    "x":-1050,
    "y":30,
    "width":1050,
    "height":1680
  }
}

Notice that the height was truncated from 1650 to 1050.

I don't see an obvious problem in the validateState bounds-checking code. However, it does rely on the electron screen.getDisplayMatching method, so maybe the actual problem is in the electron code?

Thanks in advance!

Unfortunately I can not reproduce the problem.
Do you have a sample app where this is happening?
What versions of electron and electron-window-state are you using?

rob3c commented

electron: 1.4.12
electron-window-state: 4.0.1

I'll try to create a simple public project that shows the behavior when I can. For reference, my left external monitor is 1680x1050 portrait, center laptop is 1920x1080, and right external is 1680x1050 landscape. Maybe getDisplayMatching is confused between the two identical external monitors that only differ in orientation when you pass in the bounds to check?

Maybe you can try to temporary unplug the 1680x1050 landscape monitor to check if things get messed up because of this?

rob3c commented

Ouch - I'm embarrased to say that I didn't think to try that first before making the suggestion. Unfortunately, unplugging the landscape monitor didn't help - the portrait monitor still only restores to a max height equal to its width.

Anyway, I was able to do some debugging today while trying that, and I was able to confirm that you're handling the state values just fine. It turns out that it's the Electron.BrowserWindow that's not respecting the values you're passing in (or more precisely, that I'm passing in based on your saved state). If I just pass an absolute height of 1650 in the constructor options bypassing this plugin's values completely, it still gets truncated to 1050.

Since it's an upstream issue in electron, I'll go ahead and close this. Sorry to waste your time with this, but thanks for taking a look at the issue so quickly!