[SOLVED] ComponentPeer not updating constrainer when maximising

Hi,
while on OSX everything works fine, on Windows the constrainer associated to a DocumentWindow is not informed about resize changes when the user presses the (native) maximize button of the window.
To be clear, while on mac ComponentBoundsConstrainer::resizeEnd() is called when the window gets maximized, on Windows it is not.
Unfortunately I’m unable to find a workaround for this issue without modifying Juce.
I see that on OSX Juce uses NSWindow’s windowDidEndLiveResize notification to do this, what about doing something vaguely similar in the Windows implementation?
Maybe in HWNDComponentPeer::setFullScreen (bool shouldBeFullScreen) ?
Thanks!

Are you setting your window to be resizable with a call to the ResizableWindow::setResizable method in your MainWindow’s constructor? If you set the shouldBeResizable flag to true then when you press the maximise button the constrainer should behave as expected.

When a window is set to not resizable then you should always disable the maximise button to avoid this issue.

Ed

Hello Ed,
yes of course I’m already doing that.
Maybe my explanation wasn’t clear enough. If you see the mac implementation in juce/modules/juce_gui_basics/juce_mac_NSViewComponentPeer.mm, the constrainer associated with the window is correctly informed about resize start/end operations, by these 2 functions:

void liveResizingStart()
{
    if (constrainer != nullptr)
        constrainer->resizeStart();
}

void liveResizingEnd()
{
    if (constrainer != nullptr)
        constrainer->resizeEnd();
}

here liveResizeEnd() is called not only when the user manually resizes the window, but also when he maximises the window using the maximise button (because it responds to NSWindow’s notifications).

In the Windows implementation (juce/modules/juce_gui_basics/juce_win32_Windowing.cpp) we have just this:

void doCaptureChanged()
{
    if (constrainerIsResizing)
    {
        if (constrainer != nullptr)
            constrainer->resizeEnd();

        constrainerIsResizing = false;
    }

    if (isDragging)
        doMouseUp (getCurrentMousePos(), (WPARAM) 0);
}

And on Windows this function is not invoked when the user maximises the window using the maximise button.

Now, since I need to have a consistent behaviour between the 2 platforms, and I need resizeEnd() to be called on my constrainer, I propose the following patch:
In juce/modules/juce_gui_basics/juce_win32_Windowing.cpp, inside the setFullScreen function, add this at line 784:

if (constrainer != nullptr)
        constrainer->resizeStart();

And after line 807 add this:

if (constrainer != nullptr)
        constrainer->resizeEnd();

If you need a test application to replicate this I can write the code for you, but really, it’s just matter of creating a subclass of ComponentBoundsConstrainer, passing it to the window and see when resizeStart() and resizeEnd() are called.
Thank you for your time :slight_smile:

OK that seems like a reasonable suggestion. I’ve pushed that change to the develop branch - thanks for flagging it up!

Ed

Great, thanks!