Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore maximized window state while it's currently maximized doesn't work #499

Closed
bbc131 opened this issue Apr 25, 2024 · 2 comments
Closed
Assignees

Comments

@bbc131
Copy link
Contributor

bbc131 commented Apr 25, 2024

If you set the window to "maximized", save the layout and later, while the window again is in a "maximized" state, restore the saved layout, it'll be set to "normal".
This issue is similar to #477, but a slightly different case.

I can reproduce this with the qtwidgets_dockwidgets example as well as with TestNativeQPA::tst_restoreMaximizedFromNormal, when removing the following two lines:

m->view()->showNormal();
QVERIFY(filter.waitForState(Qt::WindowNoState));

Note, that this test then covers only the case where, before restoring, the window is maximized on the same screen as it shall be restored. But this doesn't need to be the case.

I had a look at LayoutSaver::restoreLayout and at // 1. Restore main windows the else-path is taken and within deserializeWindowGeometry the saved.normalGeometry is applied.
There is a comment Later it's maximized ..., which makes sense, but this maximization later on simply seems to be missing.
If I add the following snippet at the end of deserializeWindowGeometry, the problem seems to be fixed, but this works only for Qt6!

    if (!isNormalWindowState(saved.windowState))
    {
        window->setWindowState(saved.windowState);
    }

I quite don't understand what should be handled within deserializeWindowGeometry and what within the if in restoreLayout.
Adding another else if path in the latter fixes the problem for Qt6 and Qt5:

} else if (window->windowState() == WindowState::Maximized && mw.windowState == WindowState::Maximized) {
    // Never call deserializeWindowGeometry() on a maximized window.
    // If window is maximized and we're restoring it to "maximized", then 1st change state to "normal", 
    // then set geometry and finally set it to "maximized" again.
    window->setWindowState(WindowState::None);
    d->deserializeWindowGeometry(mw, window);
    window->setWindowState(mw.windowState);
@iamsergio iamsergio self-assigned this Apr 25, 2024
iamsergio added a commit that referenced this issue Apr 30, 2024
Code is much simplified now. Basically, never call
setGeometry() on a maximized window.

Set the normal geometry on a normal window, only
then set its state.

Fixes issue #499
@iamsergio
Copy link
Contributor

Let's see if the CI says.
At least on Windows, the new test and the 2 previous tests still pass.

@iamsergio
Copy link
Contributor

yeah, still passing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants