Bug 337353

Summary: dolphin wont save the size nor window position when closed and reopened
Product: [Frameworks and Libraries] frameworks-kxmlgui Reporter: simonlang1984
Component: generalAssignee: kdelibs bugs <kdelibs-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: Ben.Kevan, cfeck, hrvoje.senjan, mklapetek, simonandric5, simonlang1984, thomas.luebking, tittiatcoke
Priority: NOR    
Version: 5.0.0   
Target Milestone: ---   
Platform: Kubuntu   
OS: Linux   
URL: https://git.reviewboard.kde.org/r/120078/
Latest Commit: Version Fixed In:
Sentry Crash Report:
Bug Depends on: 338804    
Bug Blocks:    

Description simonlang1984 2014-07-11 09:37:08 UTC
dolphine wont save the size nor window position when closed and reopened

Reproducible: Always

Steps to Reproduce:
1. open dolphin
2. move the window arround, change its size, close dolphin
3. reopen again. it appears very small and forgets the size and position
Actual Results:  
dolphin window appears small and out of position

Expected Results:  
should keep its position and size

workarround is to just to define a position and size right click on dolphin border, chose  "more actions", "special application settings" and define a size and position.

that makes it less bad, but still i want dolphin to keep it size and position individually from last time open.
Comment 1 Christoph Feck 2014-07-11 11:31:58 UTC
Are there any other KF5 applications with the same bug? It could be a problem with KMainWindow/KConfig integration.
Comment 2 simonlang1984 2014-07-11 11:59:48 UTC
@christoph

this looks to be the case with Konsole and Kate as well. But not with Quassel IRC for example. anything else i could/should test?
Comment 3 Christoph Feck 2014-07-15 19:10:15 UTC
Confirmed also with Okteta, so it's definitively not a Dolphin problem.
Comment 4 Martin Klapetek 2014-07-18 10:52:46 UTC
I've been doing some investigation into this.

It looks like setting a central widget (setCentralWidget()) on KXmlGuiWindow breaks restoring the size because of some code in QWidget.

I'll see where I can get and will keep this bug updated.
Comment 5 Ben Kevan 2014-07-19 04:51:22 UTC
I hate to do a +1, but I also see this on many qml based system configuration screens from systemsettings.
Comment 6 Christoph Feck 2014-08-12 09:52:40 UTC
*** Bug 338212 has been marked as a duplicate of this bug. ***
Comment 7 Raymond Wooninck 2014-09-04 12:54:32 UTC
Is there any update on this bug ??  

More and more programs are being ported to Frameworks, but all suffer from the same issue. And this becomes slowly quite annoying.
Comment 8 simonlang1984 2014-09-04 13:01:49 UTC
yep i can confirm that this is still an issue. and as long as it's not fixed i'll stay with kde4 (which is very awesome and i am sure kde devs will bring kde plasma next to at least that point if not even better)
Comment 9 Martin Klapetek 2014-09-04 13:16:19 UTC
This is a bug in Qt -- https://bugreports.qt-project.org/browse/QTBUG-40584

You might want to ping it there, that would be bigger help actually ;)
Comment 10 Raymond Wooninck 2014-09-04 13:52:14 UTC
Hi Martin,

Wasn't aware that there was a QTBUG for it :)  Added a comment and a vote.

Thanks
Comment 11 Thomas Lübking 2014-09-05 20:38:49 UTC
Possible workaround (untested) - adapted from https://git.reviewboard.kde.org/r/119594/

diff --git a/src/kmainwindow.cpp b/src/kmainwindow.cpp
index e273a76..be95a42 100644
--- a/src/kmainwindow.cpp
+++ b/src/kmainwindow.cpp
@@ -609,6 +609,10 @@ void KMainWindow::applyMainWindowSettings(const KConfigGroup &cg)
 
     if (!d->sizeApplied) {
         KWindowConfig::restoreWindowSize(windowHandle(), cg);
+        // NOTICE: QWindow::setGeometry() does NOT impact the backing QWidget geometry even if the platform
+        // window was created -> QTBUG-40584. We therefore copy the size here.
+        // TODO: remove once this was resolved in QWidget QPA
+        resize(windowHandle()->size());
         d->sizeApplied = true;
     }
Comment 12 Hrvoje Senjan 2014-09-05 21:15:55 UTC
looks like this has some effect; with dolphin at least, size is now saved. however the patch triggers kwrite segfault (this is with the Qt patch applied):

Thread 1 (Thread 0x7ffff7f4e7c0 (LWP 19656)):
#0  0x00007ffff619a098 in KMainWindow::applyMainWindowSettings(KConfigGroup const&) (this=this@entry=0x6a34a0, cg=...)
    at /usr/src/debug/kxmlgui-5.1.0git/src/kmainwindow.cpp:616
#1  0x00007ffff61d2e72 in KXmlGuiWindow::applyMainWindowSettings(KConfigGroup const&) (this=0x6a34a0, config=...)
    at /usr/src/debug/kxmlgui-5.1.0git/src/kxmlguiwindow.cpp:374
#2  0x00007ffff619a44c in KMainWindow::setAutoSaveSettings(QString const&, bool) (this=0x6a34a0, groupName=..., saveWindowSize=<optimized out>) at /usr/src/debug/kxmlgui-5.1.0git/src/kmainwindow.cpp:705
#3  0x00007ffff7bd3fc8 in  () at /usr/lib64/libkdeinit5_kwrite.so
#4  0x00007ffff7bd0f87 in kdemain () at /usr/lib64/libkdeinit5_kwrite.so
#5  0x00007ffff783db05 in __libc_start_main () at /lib64/libc.so.6
#6  0x00000000004007ee in _start ()
Comment 13 Thomas Lübking 2014-09-05 21:27:52 UTC
Thanks for testing.
Means applyMainWindowSettings() is also run w/o a real window (ie. restoreWindowSize() is noop)

Adjusted patch:

diff --git a/src/kmainwindow.cpp b/src/kmainwindow.cpp
index e273a76..d7f7442 100644
--- a/src/kmainwindow.cpp
+++ b/src/kmainwindow.cpp
@@ -608,7 +608,12 @@ void KMainWindow::applyMainWindowSettings(const KConfigGroup &cg)
     d->letDirtySettings = false;
 
     if (!d->sizeApplied) {
+        winId(); // ensure there's a window created
         KWindowConfig::restoreWindowSize(windowHandle(), cg);
+        // NOTICE: QWindow::setGeometry() does NOT impact the backing QWidget geometry even if the platform
+        // window was created -> QTBUG-40584. We therefore copy the size here.
+        // TODO: remove once this was resolved in QWidget QPA
+        resize(windowHandle()->size());
         d->sizeApplied = true;
     }
Comment 14 Hrvoje Senjan 2014-09-05 21:33:52 UTC
that's it! fixes the bug, and no segfaults now!
Comment 15 Thomas Lübking 2014-09-06 09:08:10 UTC
(In reply to Hrvoje Senjan from comment #14)
> that's it! fixes the bug, and no segfaults now!

If you've already the Qt patch applied, simply creating the window handle (calling winId()) might be sufficient - evtl. accomplished by https://git.reviewboard.kde.org/r/119593/ ?
Comment 16 Thomas Lübking 2014-09-06 09:09:51 UTC
patch review: https://git.reviewboard.kde.org/r/120078/
Comment 17 Thomas Lübking 2014-09-07 11:02:28 UTC
Git commit 1b9eed7738470ddfd495ded2e023aef6b8d079e5 by Thomas Lübking.
Committed on 07/09/2014 at 10:56.
Pushed by luebking into branch 'master'.

fix kmainwindow size restorage, WA QTBUG 40584

This
a) ensures there's windowaHandle() to restore the size for
b) works around a pending Qt bug by explicitly coyping the
   restored QWindow size to the QWidget size
REVIEW: 120078

M  +6    -0    src/kmainwindow.cpp

http://commits.kde.org/kxmlgui/1b9eed7738470ddfd495ded2e023aef6b8d079e5