Skip to content

[Windows] Frameless window size increase on a maximize, unmaximize sequence #2498

Closed

Description

@etiktin

When I have a frameless resizeable window with min-width and min-height set, the width and height increases after returning from maximize. The width increases by 6 px while the height increases by 8 px.

How to reconstruct:

  1. Create a window using:
new BrowserWindow({
  'frame': false,
  'resizable': true,
  'width': 1020,
  'height': 720,
  'min-width': 1000,
  'min-height': 700,
}); 
  1. Open the devtools.
  2. When you start the program you should see something like this (1020x720):
    initialstate
  3. Resize the window to it's minimum size (1000x700):
    resizetominimal
  4. Maximize the window using WinKey+Up (for me this was 1924x1042 which is already weird because the screen size is 1920x1080 so the width already has 4 extra pixels):
    maximize
  5. Unmaximize using WinKey+Down (100_6_x70_8_):
    afterunmaximize

If you skip the 4th step (resize to minimum), the size still changes but from my experiments it seems only the height will increase (it increases by 8 pixels).

If I do the same without setting min-width and min-height it seems to work as expected (returns to the same size).

In an app I'm working on, there are a couple of scenarios when I open an iframe that is set to the minimum size. It looks good in the initial state and in the maximize state, but once I unmaximize the window instead of returning to it's last size, it has this extra pixels that show up around the iframe.

I tested it with Windows 8.1 64 bit using Electron v0.30.4.

Activity

  1. etiktin commented on Aug 21, 2015

    @etiktin
    ContributorAuthor

    @zcbenz, could this issue be a result of this commit?

  2. tommoor commented on Sep 5, 2015

    @tommoor
    Contributor

    I'm seeing something similar, but not the same and wondering if it's related.

    • With a framed window on Windows 10
    • Set the size to 500x500
    • Measured size of browser window produced is 490x490
  3. etiktin commented on Sep 5, 2015

    @etiktin
    ContributorAuthor

    There's seems to be a bunch of problems with Electron's window sizing on Windows.
    Another issue I encountered is that if you create a frameless, resizable window and you maximize it, the sizing you get on a FHD screen is 1938x1050. So the width is 18 pixels longer than the actual screen width (FHD resolution is 1920x1080) and the height is about 20 pixels too much when you take into account that the taskbar height is about 46-50 pixels.

    In your case did you set a min-width and/or min-height? If you remove those limits, does it change anything?

    Issue #2714 is probably also somewhat related to this.

  4. etiktin commented on Sep 8, 2015

    @etiktin
    ContributorAuthor

    As a workaround to the OP (size not restored correctly on unmaximize when min-width and/or min-height are set), I modified my workaround for #1381 and it works pretty good.
    Here's the code:

    // Possible window states
    var WND_STATE = {
        MINIMIZED: 0,
        NORMAL: 1,
        MAXIMIZED: 2,
        FULL_SCREEN: 3
    };
    
    ...
    
    mainWindow = new BrowserWindow(...);
    
    // Save the window state on the BrowserWindow instance
    mainWindow.wndState = WND_STATE.NORMAL;
    mainWindow.lastNormalSize = mainWindow.getSize();
    
    // Register listener for the resize event (resize is fired for any state change)
    mainWindow.on('resize', handleWindowSizeChange);
    
    function handleWindowSizeChange() {
        // Note: It seems that isFullScreen can be true even when minimize or maximize are true, so the
        // order of checks is important to figure out the true state
        var isMaximized = mainWindow.isMaximized();
        var isMinimized = mainWindow.isMinimized();
        var isFullScreen = mainWindow.isFullScreen();
        var state = mainWindow.wndState;
        if (isMinimized && state !== WND_STATE.MINIMIZED) {
            mainWindow.wndState = WND_STATE.MINIMIZED;
            notifyWindowSizeChange('minimize');
        } else if (isFullScreen && state !== WND_STATE.FULL_SCREEN) {
            mainWindow.wndState = WND_STATE.FULL_SCREEN;
            notifyWindowSizeChange('fullscreen');
        } else if (isMaximized && state !== WND_STATE.MAXIMIZED) {
            mainWindow.wndState = WND_STATE.MAXIMIZED;
            notifyWindowSizeChange('maximize');
        } else if (state !== WND_STATE.NORMAL) {
            mainWindow.wndState = WND_STATE.NORMAL;
            notifyWindowSizeChange('normal');
    
            // When the window is restored we resize it to the previous known normal size
            mainWindow.setSize.apply(mainWindow, mainWindow.lastNormalSize);
        } else if (!isMaximized && !isMinimized && !isFullScreen) {
            // Window was resized so we save it's new size
            mainWindow.lastNormalSize = mainWindow.getSize();
        }
    }
    
    // Implement notifyWindowSizeChange to handle the state change

    This doesn't workaround the other sizing issues mentioned in the previous 2 comments.

  5. added a commit that references this issue on Oct 5, 2015
    4d02fc5
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