electron: setSize can't shrink non-resizable window (but can grow it)

  • Output of node_modules/.bin/electron --version: v3.0.7
  • Operating System (Platform and Version): Windows 7
  • Output of node_modules/.bin/electron --version on last known working Electron version (if applicable): v3.0.3

Expected Behavior mainWindow.setSize can be used to resize a window, regardless if resizable argument is true or false.

Actual behavior The very first time setSize is used, the window can be shrank. After that, it can only grow. If the intended behavior is to not allow for resizing at all, then it shouldn’t be able to grow.

To Reproduce

$ git clone https://github.com/CorySanin/electron-quick-start
$ npm install
$ npm start

Clicking the resize button several times will illustrate the problem.

Additional Information I can reproduce the growing part on Ubuntu, but can’t get the initial shrink to work. Also, I think this only affects versions 3.0.4 and up. 3.0.3 seemed to work as expected.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 15 (2 by maintainers)

Commits related to this issue

Most upvoted comments

Workaround for this issue, is to call setMinimumSize with the target height and with before calling setSize.

I can confirm this is happening on Electron 8.2.0, I created a simple Electron Fiddle to demonstrate.

A workaround I found working is to use setBounds({ width, height }) instead of setSize(width, height).

The Electron version reported on this issue is no longer supported. See our supported versions documentation.

If this is still reproducible on a supported version, please open a new issue with any other new information that a maintainer should know.

Thank you for taking the time to report this issue and helping to make Electron better! Your help is appreciated.

Workaround for this issue, is to call setMinimumSize with the target height and with before calling setSize.

thank you very much, not perfect but very smart idea

This is still a problem.

if any having trouble with this… their are things that you should know.

if the browser window is in maximized or full screen setSize will not work. so to do so you have to unmaximize it first. sample code:

     win.unmaximize();
     win.setSize(1180, 650, false);

I confirmed it is related to #15038. In Windows/Linux platform, we have this piece of code for no-resizable window

void NativeWindowViews::SetBounds(const gfx::Rect& bounds, bool animate) {
#if defined(OS_WIN) || defined(USE_X11)
  // On Linux and Windows the minimum and maximum size should be updated with
  // window size when window is not resizable.
  if (!resizable_) {
    SetMaximumSize(bounds.size());
    SetMinimumSize(bounds.size());
  }
#endif

  widget()->SetBounds(bounds);
}

So as soon as we change the size, the min, max are resetted to the current size.

According to #15038 code

void TopLevelWindow::SetSize(int width, int height, mate::Arguments* args) {
  bool animate = false;
>>  gfx::Size size = window_->GetMinimumSize();
>>  size.SetToMax(gfx::Size(width, height));
  args->GetNext(&animate);
  window_->SetSize(size, animate);
}

If it is no more possible to resize less than min size.

In a nutshell, we can always increase the size of the window, never decrease ! This case is not covered by unit tests.

It would be interesting to see if we can remove this NativeWindow::SetBounds specific code.

Meanwhile, I would suggest to revert #15038, negative side effect is far more critical than benefit.