KDAB / KDDockWidgets

KDAB's Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets
Other
747 stars 163 forks source link

Restore layout for window doesn't work if it's currently maximized #477

Closed bbc131 closed 4 months ago

bbc131 commented 4 months ago

The problem can be reproduced with the example qtwidgets_dockwidgets:

  1. Turn your mainwindow in 'normal' state, i.e. not 'maximized' etc.
  2. Save the current layout
  3. Maximize your mainwindow
  4. Restore the saved layout

Now, on Windows, the mainwindow looks like correctly restored but isn't. For example, you cannot change its size by click'n'drag on its edges, you first need to move it a bit by click'n'drag at the windows title bar. (On Ubuntu, the restoring also doesn't work, but behaves differently. The window just stays maximized.)

To fix this, I think there are two things in LayoutSaver::restoreLayout(..), that need to be changed.

  1. the window-state has to be set, if the desired state differs from the current state, not only if the desired state is not 'normal'/WindowState::None.
  2. deserializeWindowGeometry cannot set the geometry correctly, if the window is currently maximized, so the window-state should be changed beforehand.

I checked this by playing a bit and this hack seems to solve the problem:

         if (!(d->m_restoreOptions & InternalRestoreOption::SkipMainWindowGeometry)) {
             Window::Ptr window = mainWindow->view()->window();
+            if (window->windowState() != WindowState::None) {
+                if (auto w = mainWindow->view()->window()) {
+                    w->setWindowState(WindowState::None);
+                }
+            }
             d->deserializeWindowGeometry(mw, window);
-            if (mw.windowState != WindowState::None) {
+            if (mw.windowState != window->windowState()) {
                 if (auto w = mainWindow->view()->window()) {
                     w->setWindowState(mw.windowState);
                 }
iamsergio commented 4 months ago

You might be right, but I would like to reproduce this as well, to maybe write a test.

Can't repro on Win11 / Qt 6.6.2, stock qtwidgets_dockwidgets without flags.

Which versions are you on ?

bbc131 commented 4 months ago

Sure, my code above should just be a hint where / what the problems are... I use Win 10 and Qt 5.15.8 Can reproduce it with the default example qtwidgets_dockwidgets without any flags.

iamsergio commented 4 months ago

Thanks, reproduced with Qt 5

iamsergio commented 4 months ago

Works for me now, thanks for the investigation

bbc131 commented 4 months ago

I think there is a regression. The case, where you first maximize the window, save this (maximized) layout and try to restore this later, doesn't work anymore. This worked before.

iamsergio commented 4 months ago

I've added tests for that case as well now, and fixed it.

Windows and KDE pass the test. Ubuntu and macOS pass a manual test, but not the automatic one, need to investigate further.

iamsergio commented 4 months ago

Tests are passing on mac and ubuntu now