Skip to content

Window height shrinking after being restored #16900

Closed

Description

@pcprince
  • Electron Version (output of node_modules/.bin/electron --version):
    • 4.0.4 (multiple versions have been tested, going back to 3.0.0)
  • Operating System (Platform and Version):
    • Windows 10
  • Last known working Electron version (if applicable):
    • n/a

Expected Behavior

If a window is minimised then restored, it retains its original size.

Actual behavior

The BrowserWindow is set to a precise width and height, if it is minimised using the button in the top right then restored, it will resize its height. This new height will be the original height - 20 (approximately the height of the menu bar). If the height is set again using window.setSize, then it will again be 20 off, as if the window height now takes into account the menu when it didn't before.

This can occur multiple times. Repeatedly minimising and restoring the window will reduce the window by the menu height each time.

This resize triggers the "resize" event, but not "will-resize", so it can't be blocked with e.preventDefault.

No other code interacts with the window height.

I've "fixed" this issue with the following hack:
mainWindow.on('restore', function () { if (process.platform === 'win32') { mainWindow.setSize(windowWidth, windowHeight + 20); } });

To Reproduce

Create a BrowserWindow with a fixed height and log the height before and after minimising/restoring on a Windows machine.

Additional Information

This issue has cropped up multiple times on different projects, on any Windows machine. I've tested it on other platforms and it doesn't happen.

Activity

  1. welcome commented on Feb 12, 2019

    @welcome

    👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

    To help make it easier for us to investigate your issue, please follow the contributing guidelines.

  2. 360noscope commented on May 27, 2019

    @360noscope

    About to submit new issue but i see this and i also facing this issue as well
    OS Windows 10 build 1809
    Electron Version 5.0.0

  3. sataqi commented on Jul 31, 2019

    @sataqi

    Temporary workaround until the issue is resolved:

    Save your height and width in a global variable and manually set the size of window on restore event.

    win.on('restore', (e) => {
        win.setSize(origWidth, origHeight);
    });
    

    Related: #13043

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions